diff options
author | 2021-10-11 01:03:21 +0200 | |
---|---|---|
committer | 2021-10-31 19:26:10 +0100 | |
commit | 299c4d93597b3065e6a1017ebe692cde66fc5e39 (patch) | |
tree | 57d634cec30ca37f0af81a37c3011e027589c35c /language-web/src/main/js/editor/problem.grammar | |
parent | feat(web): add CodeMirror 6 editor (diff) | |
download | refinery-299c4d93597b3065e6a1017ebe692cde66fc5e39.tar.gz refinery-299c4d93597b3065e6a1017ebe692cde66fc5e39.tar.zst refinery-299c4d93597b3065e6a1017ebe692cde66fc5e39.zip |
feat(web): experiment with Lezer parser
Diffstat (limited to 'language-web/src/main/js/editor/problem.grammar')
-rw-r--r-- | language-web/src/main/js/editor/problem.grammar | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/language-web/src/main/js/editor/problem.grammar b/language-web/src/main/js/editor/problem.grammar new file mode 100644 index 00000000..c64402b0 --- /dev/null +++ b/language-web/src/main/js/editor/problem.grammar | |||
@@ -0,0 +1,117 @@ | |||
1 | |||
2 | @top Problem { statement* } | ||
3 | |||
4 | statement { | ||
5 | ProblemDeclaration { | ||
6 | kw<"problem"> QualifiedName "." | ||
7 | } | | ||
8 | ClassDefinition { | ||
9 | kw<"abstract">? kw<"class"> RelationName | ||
10 | (ClassBody { "{" ReferenceDeclaration* "}" } | ".") | ||
11 | } | | ||
12 | EnumDefinition { | ||
13 | kw<"enum"> RelationName | ||
14 | (EnumBody { "{" sep<",", UniqueNodeName> "}" } | ".") | ||
15 | } | | ||
16 | PredicateDefinition { | ||
17 | (kw<"error"> kw<"pred">? | kw<"pred">) RelationName ParameterList<Parameter>? | ||
18 | PredicateBody { ("<->" sep<OrOp, Conjunction>)? "." } | ||
19 | } | | ||
20 | Assertion { | ||
21 | kw<"default">? (NotOp | UnknownOp)? RelationName | ||
22 | ParameterList<AssertionArgument> (":" LogicValue)? "." | ||
23 | } | | ||
24 | UniqueDeclaration { | ||
25 | kw<"unique"> sep<",", UniqueNodeName> "." | ||
26 | } | | ||
27 | ScopeDeclaration { | ||
28 | kw<"scope"> sep<",", ScopeElement> "." | ||
29 | } | ||
30 | } | ||
31 | |||
32 | ReferenceDeclaration { | ||
33 | (kw<"refers"> | kw<"contains">)? | ||
34 | RelationName | ||
35 | RelationName | ||
36 | ( "[" Multiplicity? "]" )? | ||
37 | (kw<"opposite"> RelationName)? | ||
38 | ";"? | ||
39 | } | ||
40 | |||
41 | Parameter { RelationName? VariableName } | ||
42 | |||
43 | Conjunction { sep1<",", Literal> } | ||
44 | |||
45 | OrOp { ";" } | ||
46 | |||
47 | Literal { NotOp? Atom } | ||
48 | |||
49 | Atom { RelationName ParameterList<Argument>? } | ||
50 | |||
51 | Argument { VariableName | Real } | ||
52 | |||
53 | AssertionArgument { NodeName | StarArgument | Real } | ||
54 | |||
55 | LogicValue { | ||
56 | kw<"true"> | kw<"false"> | kw<"unknown"> | kw<"error"> | ||
57 | } | ||
58 | |||
59 | ScopeElement { RelationName ("=" | "+=") Multiplicity } | ||
60 | |||
61 | Multiplicity { (IntMult "..")? (IntMult | StarMult)} | ||
62 | |||
63 | RelationName { QualifiedName } | ||
64 | |||
65 | UniqueNodeName { QualifiedName } | ||
66 | |||
67 | VariableName { QualifiedName } | ||
68 | |||
69 | NodeName { QualifiedName } | ||
70 | |||
71 | QualifiedName { identifier ("::" identifier)* } | ||
72 | |||
73 | kw<term> { @specialize[@name={term}]<identifier, term> } | ||
74 | |||
75 | ParameterList<content> { "(" sep<",", content> ")" } | ||
76 | |||
77 | sep<separator, content> { sep1<separator, content>? } | ||
78 | |||
79 | sep1<separator, content> { content (separator content?)* } | ||
80 | |||
81 | @skip { LineComment | BlockComment | whitespace } | ||
82 | |||
83 | @tokens { | ||
84 | whitespace { std.whitespace+ } | ||
85 | |||
86 | LineComment { ("//" | "%") ![\n]* } | ||
87 | |||
88 | BlockComment { "/*" blockCommentRest } | ||
89 | |||
90 | blockCommentRest { ![*] blockCommentRest | "*" blockCommentAfterStar } | ||
91 | |||
92 | blockCommentAfterStar { "/" | "*" blockCommentAfterStar | ![/*] blockCommentRest } | ||
93 | |||
94 | @precedence { BlockComment, LineComment } | ||
95 | |||
96 | identifier { $[A-Za-z_] $[a-zA-Z0-9_]* } | ||
97 | |||
98 | int { $[0-9]+ } | ||
99 | |||
100 | IntMult { int } | ||
101 | |||
102 | StarMult { "*" } | ||
103 | |||
104 | Real { "-"? (exponential | int ("." (int | exponential))?) } | ||
105 | |||
106 | exponential { int ("e" | "E") ("+" | "-")? int } | ||
107 | |||
108 | NotOp { "!" } | ||
109 | |||
110 | UnknownOp { "?" } | ||
111 | |||
112 | StarArgument { "*" } | ||
113 | |||
114 | "{" "}" "(" ")" "[" "]" "." ".." "," ":" "<->" | ||
115 | } | ||
116 | |||
117 | @detectDelim | ||