Here are procedures for defining rules for the syntax types introduced in Precedence Parsing Overview.
For the rule-defining procedures that follow, the variable tk may be a character, string, or symbol, or a list composed of characters, strings, and symbols. Each element of tk is treated as though the procedure were called for each element.
For procedures prec:delim, ..., prec:prestfix, if the sop
argument is #f, then the token which triggered this rule is
converted to a symbol and returned. A false sop argument to the
procedures prec:commentfix, prec:matchfix, or prec:inmatchfix has a
different meaning.
Character tk arguments will match only character tokens; i.e. characters for which no token-group is assigned. Symbols and strings will both match token strings; i.e. tokens resulting from token groups.
Returns a rule specifying that tk should not be returned from parsing; i.e. tk's function is purely syntactic. The end-of-file is always treated as a delimiter.
Returns a rule specifying the following actions take place when tk is parsed:
- If sop is a procedure, it is called with no arguments; the resulting value is incorporated into the expression being built. Otherwise, the list of sop is incorporated.
Returns a rule specifying the following actions take place when tk is parsed:
- The rules rule1 ... augment and, in case of conflict, override rules currently in effect.
prec:parse1is called with binding-power bp.- If sop is a procedure, it is called with the expression returned from
prec:parse1; the resulting value is incorporated into the expression being built. Otherwise, the list of sop and the expression returned fromprec:parse1is incorporated.- The ruleset in effect before tk was parsed is restored; rule1 ... are forgotten.
Returns a rule declaring the left-binding-precedence of the token tk is lbp and specifying the following actions take place when tk is parsed:
- The rules rule1 ... augment and, in case of conflict, override rules currently in effect.
- One expression is parsed with binding-power lbp. If instead a delimiter is encountered, a warning is issued.
- If sop is a procedure, it is applied to the list of left and the parsed expression; the resulting value is incorporated into the expression being built. Otherwise, the list of sop, the left expression, and the parsed expression is incorporated.
- The ruleset in effect before tk was parsed is restored; rule1 ... are forgotten.
Returns a rule declaring the left-binding-precedence of the token tk is bp and specifying the following actions take place when tk is parsed:
- Expressions are parsed with binding-power bp as far as they are interleaved with the token tk.
- If sop is a procedure, it is applied to the list of left and the parsed expressions; the resulting value is incorporated into the expression being built. Otherwise, the list of sop, the left expression, and the parsed expressions is incorporated.
Returns a rule declaring the left-binding-precedence of the token tk is lbp and specifying the following actions take place when tk is parsed:
- If sop is a procedure, it is called with the left expression; the resulting value is incorporated into the expression being built. Otherwise, the list of sop and the left expression is incorporated.
Returns a rule specifying the following actions take place when tk is parsed:
- The rules rule1 ... augment and, in case of conflict, override rules currently in effect.
- Expressions are parsed with binding-power bp until a delimiter is reached.
- If sop is a procedure, it is applied to the list of parsed expressions; the resulting value is incorporated into the expression being built. Otherwise, the list of sop and the parsed expressions is incorporated.
- The ruleset in effect before tk was parsed is restored; rule1 ... are forgotten.
Returns rules specifying the following actions take place when tk is parsed:
- The rules rule1 ... augment and, in case of conflict, override rules currently in effect.
- Characters are read until and end-of-file or a sequence of characters is read which matches the string match.
- If stp is a procedure, it is called with the string of all that was read between the tk and match (exclusive).
- The ruleset in effect before tk was parsed is restored; rule1 ... are forgotten.
Parsing of commentfix syntax differs from the others in several ways. It reads directly from input without tokenizing; It calls stp but does not return its value; nay any value. I added the stp argument so that comment text could be echoed.
Returns a rule specifying the following actions take place when tk is parsed:
- The rules rule1 ... augment and, in case of conflict, override rules currently in effect.
- A rule declaring the token match a delimiter takes effect.
- Expressions are parsed with binding-power
0until the token match is reached. If the token sep does not appear between each pair of expressions parsed, a warning is issued.- If sop is a procedure, it is applied to the list of parsed expressions; the resulting value is incorporated into the expression being built. Otherwise, the list of sop and the parsed expressions is incorporated.
- The ruleset in effect before tk was parsed is restored; rule1 ... are forgotten.
Returns a rule declaring the left-binding-precedence of the token tk is lbp and specifying the following actions take place when tk is parsed:
- The rules rule1 ... augment and, in case of conflict, override rules currently in effect.
- A rule declaring the token match a delimiter takes effect.
- Expressions are parsed with binding-power
0until the token match is reached. If the token sep does not appear between each pair of expressions parsed, a warning is issued.- If sop is a procedure, it is applied to the list of left and the parsed expressions; the resulting value is incorporated into the expression being built. Otherwise, the list of sop, the left expression, and the parsed expressions is incorporated.
- The ruleset in effect before tk was parsed is restored; rule1 ... are forgotten.