aboutsummaryrefslogtreecommitdiffstats
path: root/language-web/src/main/js
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2021-10-11 01:42:22 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2021-10-31 19:26:10 +0100
commite1d6802843960e911f19c7e9c4a4b626ae854b90 (patch)
treee62d4d3fa0bc4f3ce1582eb2edb35b2d0d030994 /language-web/src/main/js
parentfix(web): a11y issue reported by Lighthouse (diff)
downloadrefinery-e1d6802843960e911f19c7e9c4a4b626ae854b90.tar.gz
refinery-e1d6802843960e911f19c7e9c4a4b626ae854b90.tar.zst
refinery-e1d6802843960e911f19c7e9c4a4b626ae854b90.zip
feat(web): simplify contextual parsing
* More relaxted parsing in the browser for stable variable/node identifier classification. * String support in the browser. * contains, refers, and opposite keywords are no longer contextual, which simplifies parsing in the browser.
Diffstat (limited to 'language-web/src/main/js')
-rw-r--r--language-web/src/main/js/editor/EditorParent.ts3
-rw-r--r--language-web/src/main/js/editor/problem.grammar23
-rw-r--r--language-web/src/main/js/editor/problemLanguageSupport.ts3
-rw-r--r--language-web/src/main/js/index.tsx2
4 files changed, 22 insertions, 9 deletions
diff --git a/language-web/src/main/js/editor/EditorParent.ts b/language-web/src/main/js/editor/EditorParent.ts
index 316c5072..a2f6c266 100644
--- a/language-web/src/main/js/editor/EditorParent.ts
+++ b/language-web/src/main/js/editor/EditorParent.ts
@@ -65,6 +65,9 @@ export const EditorParent = styled('div')(({ theme }) => ({
65 '.cmt-number': { 65 '.cmt-number': {
66 color: '#6188a6', 66 color: '#6188a6',
67 }, 67 },
68 '.cmt-string': {
69 color: theme.palette.secondary.dark,
70 },
68 '.cmt-keyword': { 71 '.cmt-keyword': {
69 color: theme.palette.primary.main, 72 color: theme.palette.primary.main,
70 }, 73 },
diff --git a/language-web/src/main/js/editor/problem.grammar b/language-web/src/main/js/editor/problem.grammar
index 921cec53..cf940698 100644
--- a/language-web/src/main/js/editor/problem.grammar
+++ b/language-web/src/main/js/editor/problem.grammar
@@ -1,4 +1,3 @@
1
2@top Problem { statement* } 1@top Problem { statement* }
3 2
4statement { 3statement {
@@ -7,6 +6,7 @@ statement {
7 } | 6 } |
8 ClassDefinition { 7 ClassDefinition {
9 ckw<"abstract">? ckw<"class"> RelationName 8 ckw<"abstract">? ckw<"class"> RelationName
9 (ckw<"extends"> sep<",", RelationName>)?
10 (ClassBody { "{" ReferenceDeclaration* "}" } | ".") 10 (ClassBody { "{" ReferenceDeclaration* "}" } | ".")
11 } | 11 } |
12 EnumDefinition { 12 EnumDefinition {
@@ -21,6 +21,9 @@ statement {
21 ckw<"default">? (NotOp | UnknownOp)? RelationName 21 ckw<"default">? (NotOp | UnknownOp)? RelationName
22 ParameterList<AssertionArgument> (":" LogicValue)? "." 22 ParameterList<AssertionArgument> (":" LogicValue)? "."
23 } | 23 } |
24 NodeValueAssertion {
25 UniqueNodeName ":" Constant "."
26 } |
24 UniqueDeclaration { 27 UniqueDeclaration {
25 ckw<"unique"> sep<",", UniqueNodeName> "." 28 ckw<"unique"> sep<",", UniqueNodeName> "."
26 } | 29 } |
@@ -30,18 +33,17 @@ statement {
30} 33}
31 34
32ReferenceDeclaration { 35ReferenceDeclaration {
33 ((kw<"refers"> | kw<"contains">) !times RelationName | !plus RelationName) 36 (kw<"refers"> | kw<"contains">)?
37 RelationName
34 RelationName 38 RelationName
35 ( "[" Multiplicity? "]" )? 39 ( "[" Multiplicity? "]" )?
36 (kw<"opposite"> RelationName)? 40 (kw<"opposite"> RelationName)?
37 ";"? 41 ";"?
38} 42}
39 43
40@precedence { times @left, plus }
41
42Parameter { RelationName? VariableName } 44Parameter { RelationName? VariableName }
43 45
44Conjunction { sep1<",", Literal> } 46Conjunction { ("," | Literal)+ }
45 47
46OrOp { ";" } 48OrOp { ";" }
47 49
@@ -49,9 +51,11 @@ Literal { NotOp? Atom }
49 51
50Atom { RelationName ParameterList<Argument>? } 52Atom { RelationName ParameterList<Argument>? }
51 53
52Argument { VariableName | Real } 54Argument { VariableName | Constant }
53 55
54AssertionArgument { NodeName | StarArgument | Real } 56AssertionArgument { NodeName | StarArgument | Constant }
57
58Constant { Real | String }
55 59
56LogicValue { 60LogicValue {
57 ckw<"true"> | ckw<"false"> | ckw<"unknown"> | ckw<"error"> 61 ckw<"true"> | ckw<"false"> | ckw<"unknown"> | ckw<"error">
@@ -108,6 +112,11 @@ sep1<separator, content> { content (separator content?)* }
108 112
109 exponential { int ("e" | "E") ("+" | "-")? int } 113 exponential { int ("e" | "E") ("+" | "-")? int }
110 114
115 String {
116 "'" (![\\'\n] | "\\" ![\n] | "\\\n")+ "'" |
117 "\"" (![\\"\n] | "\\" (![\n] | "\n"))* "\""
118 }
119
111 NotOp { "!" } 120 NotOp { "!" }
112 121
113 UnknownOp { "?" } 122 UnknownOp { "?" }
diff --git a/language-web/src/main/js/editor/problemLanguageSupport.ts b/language-web/src/main/js/editor/problemLanguageSupport.ts
index 2bf7c7a4..c9e61b31 100644
--- a/language-web/src/main/js/editor/problemLanguageSupport.ts
+++ b/language-web/src/main/js/editor/problemLanguageSupport.ts
@@ -26,7 +26,7 @@ const parserWithMetadata = (parser as LRParser).configure({
26 LineComment: t.lineComment, 26 LineComment: t.lineComment,
27 BlockComment: t.blockComment, 27 BlockComment: t.blockComment,
28 'problem class enum pred unique scope': t.definitionKeyword, 28 'problem class enum pred unique scope': t.definitionKeyword,
29 'abstract refers contains opposite error default': t.modifier, 29 'abstract extends refers contains opposite error default': t.modifier,
30 'true false unknown error': t.keyword, 30 'true false unknown error': t.keyword,
31 NotOp: t.keyword, 31 NotOp: t.keyword,
32 UnknownOp: t.keyword, 32 UnknownOp: t.keyword,
@@ -34,6 +34,7 @@ const parserWithMetadata = (parser as LRParser).configure({
34 StarArgument: t.keyword, 34 StarArgument: t.keyword,
35 'IntMult StarMult Real': t.number, 35 'IntMult StarMult Real': t.number,
36 StarMult: t.number, 36 StarMult: t.number,
37 String: t.string,
37 'RelationName/QualifiedName': t.typeName, 38 'RelationName/QualifiedName': t.typeName,
38 'UniqueNodeName/QualifiedName': t.atom, 39 'UniqueNodeName/QualifiedName': t.atom,
39 'VariableName/QualifiedName': t.variableName, 40 'VariableName/QualifiedName': t.variableName,
diff --git a/language-web/src/main/js/index.tsx b/language-web/src/main/js/index.tsx
index 1b24eadb..9316db4d 100644
--- a/language-web/src/main/js/index.tsx
+++ b/language-web/src/main/js/index.tsx
@@ -26,7 +26,7 @@ enum TaxStatus {
26% A child cannot have any dependents. 26% A child cannot have any dependents.
27error invalidTaxStatus(Person p) <-> 27error invalidTaxStatus(Person p) <->
28 taxStatus(p, child), 28 taxStatus(p, child),
29 children(p, _q) 29 children(p, _q),
30; taxStatus(p, retired), 30; taxStatus(p, retired),
31 parent(p, q), 31 parent(p, q),
32 !taxStatus(q, retired). 32 !taxStatus(q, retired).