SP Grammar-Specification Syntax =============================== * Lexical declarations: "=" names a token specified by the regular expression in . Defining a lexical token called "whitespace" will override the internal whitespace matching which defaults to "[ \t\n\r]+". * Code inclusion: include file with name directly in the generated parser code. (...) include s-expression in the generated code. * Parsing rule declarations: "->" defines a parsing rule named . -> "|" "|" ... [":" ] alternatives and optional semantic action -> "(" "|" "|" ... ")" nested alternatives | "[" "]" optional match | "{" "}" ["+"] zero/one or more matches | "..." zero or more matches | "_" [] failed match with syntax error | "~" failed match and rule | "!" match with current position | ["(" "~" ... ")"] match literal string (optionally with test for non-match) | match literal character | "=" bind variable to match-result | match token definition | match if expression is true -> produce | produce N-th match in rule | produce result of expression | "*" use default action * Semantic actions: Actions may be either: return as parse result. return -th submatch in this alternative branch. Scheme code returning a parse result The code in a semantic action should return a value that represents the matched input. Inside the dynamic extent of a semantic action the Scheme procedure "return-to" may be called with the result of a "!" submatch and a semantic value to restore the input position to the point where the "!" matched. Inside test- and action-expressions "(current-state)", "(current-line)", "(current-column)", "(current-source)" and "(current-position)" can be used to access the current parsing state. Inside test- and action-expression the variables defined by " = " (for the current rule) are visible and can be accessed freely. * Start rule: Parsing begins by invoking the rule "start". * Limitations Left-recursion is detected but must be dealed with manually.