File: syntax.bnf

package info (click to toggle)
storm-lang 0.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 52,004 kB
  • sloc: ansic: 261,462; cpp: 140,405; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (41 lines) | stat: -rw-r--r-- 1,719 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use lang.bs;
use core.lang;

optional delimiter = SDelimiter;
required delimiter = SRequiredDelimiter;

// Rule to generate proper overloads for the parser.
SPlainFileItem => parserOverloads(parser) : SParser(env) parser;

// Create the actual parser (we want to be able to use the -> syntax).
Parser SParser(Scope env);
SParser => parser
  : lang.bs.SName name #fnName, ":", "parser" #keyword, "(", SParserType(env, name) parser - SParserOptions(parser), ")", SFreeOptions@ -> setOptions, "{" [, SParserBody -> setSyntax, ]+ "}";


// Parser types. This creates the actual parser instance to use, also makes the system extensible.
Parser SParserType(Scope env, SStr name) #keyword;
SParserType => RecursiveParser(env, name) : "recursive" ~ "descent";
SParserType => RecursiveParser(env, name) : "recursive";
SParserType => BacktrackingParser(env, name) : "backtracking" - (~ "recursive")?;
SParserType => BacktrackingParser(env, name) : "backtracking" ~ "recursive" ~ "descent";


// Additional options for the parser.
void SParserOptions(Parser parser);
SParserOptions : ;
SParserOptions : ",", SParserOption(parser), SParserOptions(parser);

void SParserOption(Parser parser);
SParserOption => makeBinary(parser) : "binary" #keyword;
SParserOption => makeDual(parser) : "text" #keyword ~ "and" #keyword ~ "binary" #keyword;


// Body for a parser.
// Note: We don't currently support 'extend', extra syntax may be included from the regular BS use stmts instead.
ParserSyntax SParserBody();
SParserBody => ParserSyntax() : (lang.bnf.SDocFileItem() -> push, ";", )*;

// Additional things that may appear in our syntax.
SParserBody..lang.bnf.SFileItem => StartDecl(rule) : "start" #keyword, "=", lang.bnf.SName rule;