aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/language
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-08-01 01:44:06 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-08-01 01:44:06 +0200
commite86447b4d74677d86271336727e0bbff9f4c54b5 (patch)
tree5f32aa78c8aa8a72ec0303cb5675eb83877b3700 /subprojects/frontend/src/language
parentchore(deps): bump dependencies (diff)
downloadrefinery-e86447b4d74677d86271336727e0bbff9f4c54b5.tar.gz
refinery-e86447b4d74677d86271336727e0bbff9f4c54b5.tar.zst
refinery-e86447b4d74677d86271336727e0bbff9f4c54b5.zip
refactor: direct predicates
* Remove the direct keyword because it can be inferred * Use may/must/current instead of value literals * Transformation rule changes
Diffstat (limited to 'subprojects/frontend/src/language')
-rw-r--r--subprojects/frontend/src/language/indentation.ts4
-rw-r--r--subprojects/frontend/src/language/problem.grammar18
-rw-r--r--subprojects/frontend/src/language/problemLanguageSupport.ts15
3 files changed, 21 insertions, 16 deletions
diff --git a/subprojects/frontend/src/language/indentation.ts b/subprojects/frontend/src/language/indentation.ts
index 55dcd7f1..1c38637f 100644
--- a/subprojects/frontend/src/language/indentation.ts
+++ b/subprojects/frontend/src/language/indentation.ts
@@ -80,8 +80,8 @@ export function indentPredicateOrRule(context: TreeIndentContext): number {
80 if (/^\s+[;.]/.exec(context.textAfter) !== null) { 80 if (/^\s+[;.]/.exec(context.textAfter) !== null) {
81 return clauseIndent - 2; 81 return clauseIndent - 2;
82 } 82 }
83 if (/^\s+(~>)/.exec(context.textAfter) !== null) { 83 if (/^\s+(==>)/.exec(context.textAfter) !== null) {
84 return clauseIndent - 3; 84 return clauseIndent - 4;
85 } 85 }
86 return clauseIndent; 86 return clauseIndent;
87} 87}
diff --git a/subprojects/frontend/src/language/problem.grammar b/subprojects/frontend/src/language/problem.grammar
index 1ace2872..6fb188d8 100644
--- a/subprojects/frontend/src/language/problem.grammar
+++ b/subprojects/frontend/src/language/problem.grammar
@@ -18,14 +18,14 @@ statement {
18 (EnumBody { "{" sep<",", IndividualNodeName> "}" } | ".") 18 (EnumBody { "{" sep<",", IndividualNodeName> "}" } | ".")
19 } | 19 } |
20 PredicateDefinition { 20 PredicateDefinition {
21 (ckw<"error"> ckw<"pred">? | ckw<"direct">? ckw<"pred">) 21 (ckw<"error"> ckw<"pred">? | ckw<"pred">)
22 RelationName ParameterList<Parameter>? 22 RelationName ParameterList<Parameter>?
23 PredicateBody { ("<->" sep<OrOp, Conjunction>)? "." } 23 PredicateBody { ("<->" sep<OrOp, Conjunction>)? "." }
24 } | 24 } |
25 RuleDefinition { 25 RuleDefinition {
26 ckw<"direct">? ckw<"rule"> 26 ckw<"rule">
27 RuleName ParameterList<Parameter>? 27 RuleName ParameterList<Parameter>?
28 RuleBody { ":" sep<OrOp, Conjunction> "~>" sep<OrOp, Action> "." } 28 RuleBody { ":" sep<OrOp, Conjunction> "==>" sep<OrOp, Consequent> "." }
29 } | 29 } |
30 Assertion { 30 Assertion {
31 kw<"default">? (NotOp | UnknownOp)? RelationName 31 kw<"default">? (NotOp | UnknownOp)? RelationName
@@ -57,14 +57,14 @@ Conjunction { ("," | Literal)+ }
57 57
58OrOp { ";" } 58OrOp { ";" }
59 59
60Literal { NotOp? Atom (("=" | ":") sep1<"|", LogicValue>)? } 60Literal { Modality? NotOp? Modality? Atom ((":" | "=") LogicValue)? }
61 61
62Atom { RelationName "+"? ParameterList<Argument> } 62Atom { RelationName "+"? ParameterList<Argument> }
63 63
64Action { ("," | ActionLiteral)+ } 64Consequent { ("," | Action)+ }
65 65
66ActionLiteral { 66Action {
67 ckw<"new"> VariableName | 67 ckw<"new"> VariableName (":" VariableName)? |
68 ckw<"delete"> VariableName | 68 ckw<"delete"> VariableName |
69 Literal 69 Literal
70} 70}
@@ -79,6 +79,10 @@ LogicValue {
79 ckw<"true"> | ckw<"false"> | ckw<"unknown"> | ckw<"error"> 79 ckw<"true"> | ckw<"false"> | ckw<"unknown"> | ckw<"error">
80} 80}
81 81
82Modality {
83 ckw<"must"> | ckw<"may"> | ckw<"current">
84}
85
82ScopeElement { RelationName ("=" | "+=") Multiplicity } 86ScopeElement { RelationName ("=" | "+=") Multiplicity }
83 87
84Multiplicity { (IntMult "..")? (IntMult | StarMult)} 88Multiplicity { (IntMult "..")? (IntMult | StarMult)}
diff --git a/subprojects/frontend/src/language/problemLanguageSupport.ts b/subprojects/frontend/src/language/problemLanguageSupport.ts
index b6e2f14e..550532ef 100644
--- a/subprojects/frontend/src/language/problemLanguageSupport.ts
+++ b/subprojects/frontend/src/language/problemLanguageSupport.ts
@@ -28,12 +28,13 @@ const parserWithMetadata = (parser as LRParser).configure({
28 LineComment: t.lineComment, 28 LineComment: t.lineComment,
29 BlockComment: t.blockComment, 29 BlockComment: t.blockComment,
30 'problem class enum pred rule indiv scope': t.definitionKeyword, 30 'problem class enum pred rule indiv scope': t.definitionKeyword,
31 'abstract extends refers contains opposite error direct default': t.modifier, 31 'abstract extends refers contains opposite error default': t.modifier,
32 'true false unknown error': t.keyword, 32 'true false unknown error': t.keyword,
33 'may must current': t.operatorKeyword,
33 'new delete': t.operatorKeyword, 34 'new delete': t.operatorKeyword,
34 NotOp: t.keyword, 35 NotOp: t.operator,
35 UnknownOp: t.keyword, 36 UnknownOp: t.operator,
36 OrOp: t.keyword, 37 OrOp: t.punctuation,
37 StarArgument: t.keyword, 38 StarArgument: t.keyword,
38 'IntMult StarMult Real': t.number, 39 'IntMult StarMult Real': t.number,
39 StarMult: t.number, 40 StarMult: t.number,
@@ -46,7 +47,7 @@ const parserWithMetadata = (parser as LRParser).configure({
46 '( )': t.paren, 47 '( )': t.paren,
47 '[ ]': t.squareBracket, 48 '[ ]': t.squareBracket,
48 '. .. , :': t.separator, 49 '. .. , :': t.separator,
49 '<-> ~>': t.definitionOperator, 50 '<-> ==>': t.definitionOperator,
50 }), 51 }),
51 indentNodeProp.add({ 52 indentNodeProp.add({
52 ProblemDeclaration: indentDeclaration, 53 ProblemDeclaration: indentDeclaration,
@@ -63,7 +64,7 @@ const parserWithMetadata = (parser as LRParser).configure({
63 PredicateBody: foldInside, 64 PredicateBody: foldInside,
64 RuleBody: foldInside, 65 RuleBody: foldInside,
65 Conjunction: foldConjunction, 66 Conjunction: foldConjunction,
66 Action: foldWholeNode, 67 Consequent: foldWholeNode,
67 UniqueDeclaration: foldDeclaration, 68 UniqueDeclaration: foldDeclaration,
68 ScopeDeclaration: foldDeclaration, 69 ScopeDeclaration: foldDeclaration,
69 BlockComment: foldBlockComment, 70 BlockComment: foldBlockComment,
@@ -81,7 +82,7 @@ const problemLanguage = LRLanguage.define({
81 }, 82 },
82 line: '%', 83 line: '%',
83 }, 84 },
84 indentOnInput: /^\s*(?:\{|\}|\(|\)|;|\.|~>)$/, 85 indentOnInput: /^\s*(?:\{|\}|\(|\)|;|\.|==>)$/,
85 }, 86 },
86}); 87});
87 88