GNU Info

Info Node: (slib.info)Ruleset Definition and Use

(slib.info)Ruleset Definition and Use


Next: Token definition Prev: Precedence Parsing Overview Up: Precedence Parsing
Enter node , (file) or (file)node

Ruleset Definition and Use
--------------------------

 - Variable: *syn-defs*
     A grammar is built by one or more calls to `prec:define-grammar'.
     The rules are appended to *SYN-DEFS*.  The value of *SYN-DEFS* is
     the grammar suitable for passing as an argument to `prec:parse'.

 - Constant: *syn-ignore-whitespace*
     Is a nearly empty grammar with whitespace characters set to group
     0, which means they will not be made into tokens.  Most rulesets
     will want to start with `*syn-ignore-whitespace*'

In order to start defining a grammar, either

     (set! *syn-defs* '())

or

     (set! *syn-defs* *syn-ignore-whitespace*)

 - Function: prec:define-grammar rule1 ...
     Appends RULE1 ... to *SYN-DEFS*.  `prec:define-grammar' is used to
     define both the character classes and rules for tokens.

Once your grammar is defined, save the value of `*syn-defs*' in a
variable (for use when calling `prec:parse').

     (define my-ruleset *syn-defs*)

 - Function: prec:parse ruleset delim
 - Function: prec:parse ruleset delim port
     The RULESET argument must be a list of rules as constructed by
     `prec:define-grammar' and extracted from *SYN-DEFS*.

     The token DELIM may be a character, symbol, or string.  A
     character DELIM argument will match only a character token; i.e. a
     character for which no token-group is assigned.  A symbols or
     string will match only a token string; i.e. a token resulting from
     a token group.

     `prec:parse' reads a RULESET grammar expression delimited by DELIM
     from the given input PORT.  `prec:parse' returns the next object
     parsable from the given input PORT, updating PORT to point to the
     first character past the end of the external representation of the
     object.

     If an end of file is encountered in the input before any
     characters are found that can begin an object, then an end of file
     object is returned.  If a delimiter (such as DELIM) is found
     before any characters are found that can begin an object, then
     `#f' is returned.

     The PORT argument may be omitted, in which case it defaults to the
     value returned by `current-input-port'.  It is an error to parse
     from a closed port.


automatically generated by info2www version 1.2.2.9