PreviousUpNext

15.4.861  src/lib/regex/front/abstract-regular-expression.pkg

## abstract-regular-expression.pkg

# Compiled by:
#     src/lib/std/standard.lib

# This is the abstract syntax tree used to represent regular expressions.
# It serves as the glue between different frontends (implementing
# different RE specification languages), and different backends (implementing
# different compilation/searching algorithms).



###                 "Programming is an art form that fights back."


generic package  abstract_regular_expression_g (char:  Char)
: (weak) 
Abstract_Regular_Expression                                     # Abstract_Regular_Expression           is from   src/lib/regex/front/abstract-regular-expression.api
where
    char == char
=
package {
 
    exception CANNOT_PARSE;
    exception CANNOT_COMPILE;
  
    package char = char;



    # Use something faster than ListSet -- Allen Leung 
    #   
    package char_set
        = 
        red_black_set_g (package { Key = char::Char ;
                          compare = char::compare ;
                      });

    Abstract_Regular_Expression
        = GROUP        Abstract_Regular_Expression
        | ALT          List( Abstract_Regular_Expression )
        | CONCAT       List( Abstract_Regular_Expression )
        | INTERVAL     ((Abstract_Regular_Expression, Int, Null_Or( Int )) )
        | MATCH_SET    char_set::Set
        | NONMATCH_SET char_set::Set
        | CHAR         char::Char
        | OPTION       Abstract_Regular_Expression              #  == Interval (re, 0, THE 1) 
        | STAR         Abstract_Regular_Expression              #  == Interval (re, 0, NULL) 
        | PLUS         Abstract_Regular_Expression              #  == Interval (re, 1, NULL) 
        | BEGIN                                                 #  Matches beginning of stream 
        | END                                                   #  Matches end of stream 

          #  Extensions 

        | ASSIGN   ((Int, (String -> String), Abstract_Regular_Expression))

             #  Define a reference 

        | BACK_REF (((String -> String), Int))   #  Back references 

        | GUARD    (((String -> Bool), Abstract_Regular_Expression))

        | BOUNDARY { prev: Null_Or( char::Char ),
                     this: Null_Or( char::Char ),
                     next: Null_Or( char::Char )
                   }
                   -> Bool;

    fun add_range (s, min_c, max_c)
        = 
        char_set::add_list (s, list::from_fn (char::to_int (max_c)-char::to_int (min_c)+1,
                            \\ v =  char::from_int (v+char::to_int (min_c))));

    all_chars
        =
        add_range (char_set::empty, char::min_char, char::max_char);
          
};

package abstract_regular_expression
    =
    abstract_regular_expression_g( char );


## COPYRIGHT (c) 1995 AT&T Bell Laboratories.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext