diff options
Diffstat (limited to 'subprojects/frontend')
-rw-r--r-- | subprojects/frontend/src/index.tsx | 8 | ||||
-rw-r--r-- | subprojects/frontend/src/language/indentation.ts | 2 | ||||
-rw-r--r-- | subprojects/frontend/src/language/problem.grammar | 91 | ||||
-rw-r--r-- | subprojects/frontend/src/language/problemLanguageSupport.ts | 11 |
4 files changed, 77 insertions, 35 deletions
diff --git a/subprojects/frontend/src/index.tsx b/subprojects/frontend/src/index.tsx index 2c0259bf..b42b8062 100644 --- a/subprojects/frontend/src/index.tsx +++ b/subprojects/frontend/src/index.tsx | |||
@@ -20,6 +20,12 @@ enum TaxStatus { | |||
20 | child, student, adult, retired | 20 | child, student, adult, retired |
21 | } | 21 | } |
22 | 22 | ||
23 | int ageDifference(Person p, Person q) = | ||
24 | children(p, q), age(p, pAge), age(q, qAge) -> qAge - pAge. | ||
25 | |||
26 | error invalidAgeDifference(Person p, Person q) <-> | ||
27 | children(p, q), ageDifference(p, q) <= 0. | ||
28 | |||
23 | % A child cannot have any dependents. | 29 | % A child cannot have any dependents. |
24 | pred invalidTaxStatus(Person p) <-> | 30 | pred invalidTaxStatus(Person p) <-> |
25 | taxStatus(p, child), | 31 | taxStatus(p, child), |
@@ -29,7 +35,7 @@ pred invalidTaxStatus(Person p) <-> | |||
29 | parent(p, q), | 35 | parent(p, q), |
30 | !taxStatus(q, retired). | 36 | !taxStatus(q, retired). |
31 | 37 | ||
32 | indiv family. | 38 | individual family. |
33 | Family(family). | 39 | Family(family). |
34 | members(family, anne). | 40 | members(family, anne). |
35 | members(family, bob). | 41 | members(family, bob). |
diff --git a/subprojects/frontend/src/language/indentation.ts b/subprojects/frontend/src/language/indentation.ts index b49d6563..a0f7032d 100644 --- a/subprojects/frontend/src/language/indentation.ts +++ b/subprojects/frontend/src/language/indentation.ts | |||
@@ -78,7 +78,7 @@ export function indentDeclaration(context: TreeIndentContext): number { | |||
78 | 78 | ||
79 | export function indentPredicateOrRule(context: TreeIndentContext): number { | 79 | export function indentPredicateOrRule(context: TreeIndentContext): number { |
80 | const clauseIndent = indentDeclarationStrategy(context, 1); | 80 | const clauseIndent = indentDeclarationStrategy(context, 1); |
81 | if (/^\s+(?:==>|[;.])/.exec(context.textAfter) !== null) { | 81 | if (/^\s+(?:->|==>|[;.])/.exec(context.textAfter) !== null) { |
82 | return clauseIndent - context.unit; | 82 | return clauseIndent - context.unit; |
83 | } | 83 | } |
84 | return clauseIndent; | 84 | return clauseIndent; |
diff --git a/subprojects/frontend/src/language/problem.grammar b/subprojects/frontend/src/language/problem.grammar index d630b9c4..4235c433 100644 --- a/subprojects/frontend/src/language/problem.grammar +++ b/subprojects/frontend/src/language/problem.grammar | |||
@@ -2,56 +2,69 @@ | |||
2 | 2 | ||
3 | @external prop implicitCompletion from './props' | 3 | @external prop implicitCompletion from './props' |
4 | 4 | ||
5 | @precedence { | ||
6 | containment @cut, | ||
7 | prefix, | ||
8 | exponential @right, | ||
9 | multiplicative @left, | ||
10 | additive @left, | ||
11 | comparison @left | ||
12 | } | ||
13 | |||
5 | @top Problem { statement* } | 14 | @top Problem { statement* } |
6 | 15 | ||
7 | statement { | 16 | statement { |
8 | ProblemDeclaration { | 17 | ProblemDeclaration { |
9 | ckw<"problem"> QualifiedName "." | 18 | kw<"problem"> QualifiedName "." |
10 | } | | 19 | } | |
11 | ClassDefinition { | 20 | ClassDefinition { |
12 | ckw<"abstract">? ckw<"class"> RelationName | 21 | kw<"abstract">? kw<"class"> RelationName |
13 | (ckw<"extends"> sep<",", RelationName>)? | 22 | (kw<"extends"> sep<",", RelationName>)? |
14 | (ClassBody { "{" ReferenceDeclaration* "}" } | ".") | 23 | (ClassBody { "{" ReferenceDeclaration* "}" } | ".") |
15 | } | | 24 | } | |
16 | EnumDefinition { | 25 | EnumDefinition { |
17 | ckw<"enum"> RelationName | 26 | kw<"enum"> RelationName |
18 | (EnumBody { "{" sep<",", IndividualNodeName> "}" } | ".") | 27 | (EnumBody { "{" sep<",", IndividualNodeName> "}" } | ".") |
19 | } | | 28 | } | |
20 | PredicateDefinition { | 29 | PredicateDefinition { |
21 | ( | 30 | ( |
22 | (ckw<"error"> | ckw<"contained"> | ckw<"containment">) ckw<"pred">? | | 31 | (kw<"error"> | ckw<"contained"> | kw<"containment">)? kw<"pred"> | |
23 | ckw<"pred"> | 32 | kw<"error"> |
24 | ) | 33 | ) |
25 | RelationName ParameterList<Parameter>? | 34 | RelationName ParameterList<Parameter>? |
26 | PredicateBody { ("<->" sep<OrOp, Conjunction>)? "." } | 35 | PredicateBody { ("<->" sep<OrOp, Conjunction>)? "." } |
36 | } | | ||
37 | FunctionDefinition { | ||
38 | RelationName RelationName ParameterList<Parameter>? | ||
39 | FunctionBody { ("=" sep<OrOp, Case>)? "." } | ||
27 | } | | 40 | } | |
28 | //RuleDefinition { | 41 | //RuleDefinition { |
29 | // ckw<"rule"> | 42 | // kw<"rule"> |
30 | // RuleName ParameterList<Parameter>? | 43 | // RuleName ParameterList<Parameter>? |
31 | // RuleBody { ":" sep<OrOp, Conjunction> "==>" sep<OrOp, Consequent> "." } | 44 | // RuleBody { ":" sep<OrOp, Conjunction> "==>" sep<OrOp, Consequent> "." } |
32 | //} | | 45 | //} | |
33 | Assertion { | 46 | Assertion { |
34 | ckw<"default">? (NotOp | UnknownOp)? RelationName | 47 | kw<"default">? (NotOp | UnknownOp)? RelationName |
35 | ParameterList<AssertionArgument> (":" LogicValue)? "." | 48 | ParameterList<AssertionArgument> (":" LogicValue)? "." |
36 | } | | 49 | } | |
37 | NodeValueAssertion { | 50 | NodeValueAssertion { |
38 | QualifiedName ":" Constant "." | 51 | QualifiedName ":" Constant "." |
39 | } | | 52 | } | |
40 | IndividualDeclaration { | 53 | IndividualDeclaration { |
41 | ckw<"indiv"> sep<",", IndividualNodeName> "." | 54 | kw<"individual"> sep<",", IndividualNodeName> "." |
42 | } | | 55 | } | |
43 | ScopeDeclaration { | 56 | ScopeDeclaration { |
44 | ckw<"scope"> sep<",", ScopeElement> "." | 57 | kw<"scope"> sep<",", ScopeElement> "." |
45 | } | 58 | } |
46 | } | 59 | } |
47 | 60 | ||
48 | ReferenceDeclaration { | 61 | ReferenceDeclaration { |
49 | ( | 62 | ( |
50 | ExplicitContainmentReference[@dynamicPrecedence=1] { | 63 | ExplicitContainmentReference { |
51 | (ckw<"refers"> | ckw<"contains"> | ckw<"container">) RelationName ~containment | 64 | !containment (kw<"refers"> | ckw<"contains"> | kw<"container">) RelationName |
52 | } | | 65 | } | |
53 | ImplicitContainmentReference { | 66 | ImplicitContainmentReference { |
54 | RelationName ~containment | 67 | RelationName |
55 | } | 68 | } |
56 | ) | 69 | ) |
57 | ("[" Multiplicity? "]")? | 70 | ("[" Multiplicity? "]")? |
@@ -62,50 +75,68 @@ ReferenceDeclaration { | |||
62 | 75 | ||
63 | Parameter { Modality? RelationName? VariableName } | 76 | Parameter { Modality? RelationName? VariableName } |
64 | 77 | ||
65 | Conjunction { ("," | Literal)+ } | 78 | Conjunction { ("," | Expr)+ } |
79 | |||
80 | Case { Conjunction ("->" Expr)? } | ||
66 | 81 | ||
67 | OrOp { ";" } | 82 | OrOp { ";" } |
68 | 83 | ||
69 | Literal { | 84 | Expr { |
70 | Modality? (NotOp | ckw<"count">)? Modality? Atom | 85 | UnaryExpr | BinaryExpr | Aggregation | VariableName | Atom | Constant | "(" Expr ")" |
71 | ((":=" | "<:") LogicValue | ComparisonOp int)? | 86 | } |
87 | |||
88 | BinaryExpr[@dynamicPrecedence=1] { | ||
89 | Expr !comparison ComparisonOp Expr | | ||
90 | Expr !additive ("+" | "-") Expr | | ||
91 | Expr !multiplicative (StarMult | Divide) Expr | | ||
92 | Expr !exponential "**" Expr | ||
93 | } | ||
94 | |||
95 | UnaryExpr { | ||
96 | !prefix ("+" | "-" | "!" | "#" | Modality) Expr | ||
97 | } | ||
98 | |||
99 | Aggregation { | ||
100 | AggregationOp "{" Expr "|" Expr "}" | ||
72 | } | 101 | } |
73 | 102 | ||
74 | Atom { RelationName "+"? ParameterList<Argument> } | 103 | Atom { RelationName "+"? ParameterList<Expr> } |
75 | 104 | ||
76 | //Consequent { ("," | Action)+ } | 105 | //Consequent { ("," | Action)+ } |
77 | 106 | ||
78 | //Action { | 107 | //Action { |
79 | // ckw<"new"> VariableName ("<:" VariableName)? | | 108 | // ckw<"new"> VariableName ("<:" VariableName)? | |
80 | // ckw<"delete"> VariableName | | 109 | // kw<"delete"> VariableName | |
81 | // Literal | 110 | // Literal |
82 | //} | 111 | //} |
83 | 112 | ||
84 | Argument { VariableName | Constant } | ||
85 | |||
86 | AssertionArgument { NodeName | StarArgument | Constant } | 113 | AssertionArgument { NodeName | StarArgument | Constant } |
87 | 114 | ||
88 | Constant { Real | String } | 115 | Constant { Real | String } |
89 | 116 | ||
90 | LogicValue { | 117 | LogicValue { |
91 | ckw<"true"> | ckw<"false"> | ckw<"unknown"> | ckw<"error"> | 118 | ckw<"true"> | ckw<"false"> | kw<"unknown"> | kw<"error"> |
92 | } | 119 | } |
93 | 120 | ||
94 | Modality { | 121 | Modality { |
95 | ckw<"must"> | ckw<"may"> | ckw<"current"> | 122 | kw<"must"> | kw<"may"> | kw<"current"> |
123 | } | ||
124 | |||
125 | AggregationOp { | ||
126 | ckw<"sum"> | ckw<"prod"> | ckw<"min"> | ckw<"max"> | ||
96 | } | 127 | } |
97 | 128 | ||
98 | ScopeElement { RelationName ("=" | "+=") Multiplicity } | 129 | ScopeElement { RelationName ("=" | "+=") Multiplicity } |
99 | 130 | ||
100 | Multiplicity { (IntMult "..")? (IntMult | StarMult)} | 131 | Multiplicity { (IntMult "..")? (IntMult | StarMult)} |
101 | 132 | ||
102 | RelationName { QualifiedName } | 133 | RelationName { QualifiedName ~name } |
103 | 134 | ||
104 | //RuleName { QualifiedName } | 135 | //RuleName { QualifiedName } |
105 | 136 | ||
106 | IndividualNodeName { QualifiedName } | 137 | IndividualNodeName { QualifiedName } |
107 | 138 | ||
108 | VariableName { QualifiedName } | 139 | VariableName[@dynamicPrecedence=10] { QualifiedName ~name } |
109 | 140 | ||
110 | NodeName { QualifiedName } | 141 | NodeName { QualifiedName } |
111 | 142 | ||
@@ -134,7 +165,9 @@ sep1<separator, content> { content (separator content)* } | |||
134 | 165 | ||
135 | blockCommentAfterStar { "/" | "*" blockCommentAfterStar | ![/*] blockCommentRest } | 166 | blockCommentAfterStar { "/" | "*" blockCommentAfterStar | ![/*] blockCommentRest } |
136 | 167 | ||
137 | @precedence { BlockComment, LineComment } | 168 | Divide { "/" } |
169 | |||
170 | @precedence { BlockComment, LineComment, Divide } | ||
138 | 171 | ||
139 | identifier { $[A-Za-z_] $[a-zA-Z0-9_]* } | 172 | identifier { $[A-Za-z_] $[a-zA-Z0-9_]* } |
140 | 173 | ||
@@ -144,7 +177,7 @@ sep1<separator, content> { content (separator content)* } | |||
144 | 177 | ||
145 | StarMult { "*" } | 178 | StarMult { "*" } |
146 | 179 | ||
147 | Real { "-"? (exponential | int ("." (int | exponential))?) } | 180 | Real { (exponential | int ("." (int | exponential))?) } |
148 | 181 | ||
149 | exponential { int ("e" | "E") ("+" | "-")? int } | 182 | exponential { int ("e" | "E") ("+" | "-")? int } |
150 | 183 | ||
@@ -161,5 +194,5 @@ sep1<separator, content> { content (separator content)* } | |||
161 | 194 | ||
162 | StarArgument { "*" } | 195 | StarArgument { "*" } |
163 | 196 | ||
164 | "{" "}" "(" ")" "[" "]" "." ".." "," ":" "<->" "~>" | 197 | "{" "}" "(" ")" "[" "]" "." ".." "," ":" "->" "<->" "+" "-" "**" "=" "+=" |
165 | } | 198 | } |
diff --git a/subprojects/frontend/src/language/problemLanguageSupport.ts b/subprojects/frontend/src/language/problemLanguageSupport.ts index a96b5402..cde8b157 100644 --- a/subprojects/frontend/src/language/problemLanguageSupport.ts +++ b/subprojects/frontend/src/language/problemLanguageSupport.ts | |||
@@ -21,11 +21,12 @@ const parserWithMetadata = parser.configure({ | |||
21 | styleTags({ | 21 | styleTags({ |
22 | LineComment: t.lineComment, | 22 | LineComment: t.lineComment, |
23 | BlockComment: t.blockComment, | 23 | BlockComment: t.blockComment, |
24 | 'problem class enum pred indiv scope': t.definitionKeyword, | 24 | 'problem class enum pred individual scope': t.definitionKeyword, |
25 | 'abstract extends refers contains container opposite': t.modifier, | 25 | 'abstract extends refers contains container opposite': t.modifier, |
26 | 'default error contained containment': t.modifier, | 26 | 'default error contained containment': t.modifier, |
27 | 'true false unknown error': t.operatorKeyword, | 27 | 'true false unknown error': t.operatorKeyword, |
28 | 'may must current count': t.operatorKeyword, | 28 | 'may must current': t.operatorKeyword, |
29 | 'sum prod min max': t.operatorKeyword, | ||
29 | // 'new delete': t.keyword, | 30 | // 'new delete': t.keyword, |
30 | NotOp: t.operator, | 31 | NotOp: t.operator, |
31 | UnknownOp: t.operator, | 32 | UnknownOp: t.operator, |
@@ -42,13 +43,14 @@ const parserWithMetadata = parser.configure({ | |||
42 | '( )': t.paren, | 43 | '( )': t.paren, |
43 | '[ ]': t.squareBracket, | 44 | '[ ]': t.squareBracket, |
44 | '. .. , :': t.separator, | 45 | '. .. , :': t.separator, |
45 | '<-> ==>': t.definitionOperator, | 46 | '<-> = -> ==>': t.definitionOperator, |
46 | }), | 47 | }), |
47 | indentNodeProp.add({ | 48 | indentNodeProp.add({ |
48 | ProblemDeclaration: indentDeclaration, | 49 | ProblemDeclaration: indentDeclaration, |
49 | UniqueDeclaration: indentDeclaration, | 50 | UniqueDeclaration: indentDeclaration, |
50 | ScopeDeclaration: indentDeclaration, | 51 | ScopeDeclaration: indentDeclaration, |
51 | PredicateBody: indentPredicateOrRule, | 52 | PredicateBody: indentPredicateOrRule, |
53 | FunctionBody: indentPredicateOrRule, | ||
52 | // RuleBody: indentPredicateOrRule, | 54 | // RuleBody: indentPredicateOrRule, |
53 | BlockComment: indentBlockComment, | 55 | BlockComment: indentBlockComment, |
54 | }), | 56 | }), |
@@ -57,6 +59,7 @@ const parserWithMetadata = parser.configure({ | |||
57 | EnumBody: foldInside, | 59 | EnumBody: foldInside, |
58 | ParameterList: foldInside, | 60 | ParameterList: foldInside, |
59 | PredicateBody: foldInside, | 61 | PredicateBody: foldInside, |
62 | FunctionBody: foldInside, | ||
60 | // RuleBody: foldInside, | 63 | // RuleBody: foldInside, |
61 | Conjunction: foldConjunction, | 64 | Conjunction: foldConjunction, |
62 | // Consequent: foldWholeNode, | 65 | // Consequent: foldWholeNode, |
@@ -77,7 +80,7 @@ const problemLanguage = LRLanguage.define({ | |||
77 | }, | 80 | }, |
78 | line: '%', | 81 | line: '%', |
79 | }, | 82 | }, |
80 | indentOnInput: /^\s*(?:\{|\}|\(|\)|;|\.)$/, | 83 | indentOnInput: /^\s*(?:\{|\}|\(|\)|->|;|\.)$/, |
81 | }, | 84 | }, |
82 | }); | 85 | }); |
83 | 86 | ||