"Fossies" - the Fresh Open Source Software Archive

Member "scalpel-2.0/tre-0.7.5-win32/lib/tre-ast.h" (20 Apr 2011, 4132 Bytes) of archive /linux/misc/scalpel-2.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "tre-ast.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2   tre-ast.h - Abstract syntax tree (AST) definitions
    3 
    4   Copyright (c) 2001-2006 Ville Laurikari <vl@iki.fi>
    5 
    6   This library is free software; you can redistribute it and/or
    7   modify it under the terms of the GNU Lesser General Public
    8   License as published by the Free Software Foundation; either
    9   version 2.1 of the License, or (at your option) any later version.
   10 
   11   This library is distributed in the hope that it will be useful,
   12   but WITHOUT ANY WARRANTY; without even the implied warranty of
   13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   14   Lesser General Public License for more details.
   15 
   16   You should have received a copy of the GNU Lesser General Public
   17   License along with this library; if not, write to the Free Software
   18   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   19 
   20 */
   21 
   22 
   23 #ifndef TRE_AST_H
   24 #define TRE_AST_H 1
   25 
   26 #include "tre-mem.h"
   27 #include "tre-internal.h"
   28 #include "tre-compile.h"
   29 
   30 /* The different AST node types. */
   31 typedef enum {
   32   LITERAL,
   33   CATENATION,
   34   ITERATION,
   35   UNION
   36 } tre_ast_type_t;
   37 
   38 /* Special subtypes of TRE_LITERAL. */
   39 #define EMPTY     -1   /* Empty leaf (denotes empty string). */
   40 #define ASSERTION -2   /* Assertion leaf. */
   41 #define TAG   -3   /* Tag leaf. */
   42 #define BACKREF   -4   /* Back reference leaf. */
   43 #define PARAMETER -5   /* Parameter. */
   44 
   45 #define IS_SPECIAL(x)   ((x)->code_min < 0)
   46 #define IS_EMPTY(x) ((x)->code_min == EMPTY)
   47 #define IS_ASSERTION(x) ((x)->code_min == ASSERTION)
   48 #define IS_TAG(x)   ((x)->code_min == TAG)
   49 #define IS_BACKREF(x)   ((x)->code_min == BACKREF)
   50 #define IS_PARAMETER(x) ((x)->code_min == PARAMETER)
   51 
   52 
   53 /* A generic AST node.  All AST nodes consist of this node on the top
   54    level with `obj' pointing to the actual content. */
   55 typedef struct {
   56   tre_ast_type_t type;   /* Type of the node. */
   57   void *obj;             /* Pointer to actual node. */
   58   int nullable;
   59   int submatch_id;
   60   int num_submatches;
   61   int num_tags;
   62   tre_pos_and_tags_t *firstpos;
   63   tre_pos_and_tags_t *lastpos;
   64 } tre_ast_node_t;
   65 
   66 
   67 /* A "literal" node.  These are created for assertions, back references,
   68    tags, matching parameter settings, and all expressions that match one
   69    character. */
   70 typedef struct {
   71   long code_min;
   72   long code_max;
   73   int position;
   74   union {
   75     tre_ctype_t class;
   76     int *params;
   77   } u;
   78   tre_ctype_t *neg_classes;
   79 } tre_literal_t;
   80 
   81 /* A "catenation" node.  These are created when two regexps are concatenated.
   82    If there are more than one subexpressions in sequence, the `left' part
   83    holds all but the last, and `right' part holds the last subexpression
   84    (catenation is left associative). */
   85 typedef struct {
   86   tre_ast_node_t *left;
   87   tre_ast_node_t *right;
   88 } tre_catenation_t;
   89 
   90 /* An "iteration" node.  These are created for the "*", "+", "?", and "{m,n}"
   91    operators. */
   92 typedef struct {
   93   /* Subexpression to match. */
   94   tre_ast_node_t *arg;
   95   /* Minimum number of consecutive matches. */
   96   int min;
   97   /* Maximum number of consecutive matches. */
   98   int max;
   99   /* If 0, match as many characters as possible, if 1 match as few as
  100      possible.  Note that this does not always mean the same thing as
  101      matching as many/few repetitions as possible. */
  102   unsigned int minimal:1;
  103   /* Approximate matching parameters (or NULL). */
  104   int *params;
  105 } tre_iteration_t;
  106 
  107 /* An "union" node.  These are created for the "|" operator. */
  108 typedef struct {
  109   tre_ast_node_t *left;
  110   tre_ast_node_t *right;
  111 } tre_union_t;
  112 
  113 tre_ast_node_t *
  114 tre_ast_new_node(tre_mem_t mem, tre_ast_type_t type, size_t size);
  115 
  116 tre_ast_node_t *
  117 tre_ast_new_literal(tre_mem_t mem, int code_min, int code_max, int position);
  118 
  119 tre_ast_node_t *
  120 tre_ast_new_iter(tre_mem_t mem, tre_ast_node_t *arg, int min, int max,
  121          int minimal);
  122 
  123 tre_ast_node_t *
  124 tre_ast_new_union(tre_mem_t mem, tre_ast_node_t *left, tre_ast_node_t *right);
  125 
  126 tre_ast_node_t *
  127 tre_ast_new_catenation(tre_mem_t mem, tre_ast_node_t *left,
  128                tre_ast_node_t *right);
  129 
  130 #ifdef TRE_DEBUG
  131 void
  132 tre_ast_print(tre_ast_node_t *tree);
  133 
  134 /* XXX - rethink AST printing API */
  135 void
  136 tre_print_params(int *params);
  137 #endif /* TRE_DEBUG */
  138 
  139 #endif /* TRE_AST_H */
  140 
  141 /* EOF */