From 4a3cdd67cd1b5c6d407c5702a1c50a19bc17fc20 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Tue, 4 Oct 2022 01:12:01 +0200 Subject: refactor(language): disable rule parsing Rules have too complex semantics to implement in the first prototype. --- subprojects/frontend/src/index.tsx | 8 ---- subprojects/frontend/src/language/folding.ts | 2 +- subprojects/frontend/src/language/problem.grammar | 24 +++++----- .../src/language/problemLanguageSupport.ts | 21 ++++----- .../java/tools/refinery/language/Problem.xtext | 52 +++++++++++----------- .../refinery/language/utils/SymbolCollector.java | 29 +++--------- 6 files changed, 54 insertions(+), 82 deletions(-) (limited to 'subprojects') diff --git a/subprojects/frontend/src/index.tsx b/subprojects/frontend/src/index.tsx index 55e0590f..f7fe61b9 100644 --- a/subprojects/frontend/src/index.tsx +++ b/subprojects/frontend/src/index.tsx @@ -36,14 +36,6 @@ pred invalidTaxStatus(Person p) <-> parent(p, q), !taxStatus(q, retired). -rule createChild(may Person p, must Person newPerson): - may children(p, newPerson), - may !equals(newPerson, newPerson) -==> - new q <: newPerson, - children(p, q), - taxStatus(q, child). - indiv family. Family(family). members(family, anne). diff --git a/subprojects/frontend/src/language/folding.ts b/subprojects/frontend/src/language/folding.ts index 9d1c04a3..4dabfa27 100644 --- a/subprojects/frontend/src/language/folding.ts +++ b/subprojects/frontend/src/language/folding.ts @@ -103,7 +103,7 @@ function foldWithSibling(node: SyntaxNode): FoldRange | null { return null; } -export function foldWholeNode(node: SyntaxNode): FoldRange { +function foldWholeNode(node: SyntaxNode): FoldRange { return { from: node.from, to: node.to, diff --git a/subprojects/frontend/src/language/problem.grammar b/subprojects/frontend/src/language/problem.grammar index 7feb6bfe..1e1ef70f 100644 --- a/subprojects/frontend/src/language/problem.grammar +++ b/subprojects/frontend/src/language/problem.grammar @@ -25,11 +25,11 @@ statement { RelationName ParameterList? PredicateBody { ("<->" sep)? "." } } | - RuleDefinition { - ckw<"rule"> - RuleName ParameterList? - RuleBody { ":" sep "==>" sep "." } - } | + //RuleDefinition { + // ckw<"rule"> + // RuleName ParameterList? + // RuleBody { ":" sep "==>" sep "." } + //} | Assertion { ckw<"default">? (NotOp | UnknownOp)? RelationName ParameterList (":" LogicValue)? "." @@ -73,13 +73,13 @@ Literal { Atom { RelationName "+"? ParameterList } -Consequent { ("," | Action)+ } +//Consequent { ("," | Action)+ } -Action { - ckw<"new"> VariableName ("<:" VariableName)? | - ckw<"delete"> VariableName | - Literal -} +//Action { +// ckw<"new"> VariableName ("<:" VariableName)? | +// ckw<"delete"> VariableName | +// Literal +//} Argument { VariableName | Constant } @@ -101,7 +101,7 @@ Multiplicity { (IntMult "..")? (IntMult | StarMult)} RelationName { QualifiedName } -RuleName { QualifiedName } +//RuleName { QualifiedName } IndividualNodeName { QualifiedName } diff --git a/subprojects/frontend/src/language/problemLanguageSupport.ts b/subprojects/frontend/src/language/problemLanguageSupport.ts index 03a7c4cc..a96b5402 100644 --- a/subprojects/frontend/src/language/problemLanguageSupport.ts +++ b/subprojects/frontend/src/language/problemLanguageSupport.ts @@ -8,12 +8,7 @@ import { } from '@codemirror/language'; import { styleTags, tags as t } from '@lezer/highlight'; -import { - foldBlockComment, - foldConjunction, - foldDeclaration, - foldWholeNode, -} from './folding'; +import { foldBlockComment, foldConjunction, foldDeclaration } from './folding'; import { indentBlockComment, indentDeclaration, @@ -26,12 +21,12 @@ const parserWithMetadata = parser.configure({ styleTags({ LineComment: t.lineComment, BlockComment: t.blockComment, - 'problem class enum pred rule indiv scope': t.definitionKeyword, + 'problem class enum pred indiv scope': t.definitionKeyword, 'abstract extends refers contains container opposite': t.modifier, 'default error contained containment': t.modifier, 'true false unknown error': t.operatorKeyword, 'may must current count': t.operatorKeyword, - 'new delete': t.keyword, + // 'new delete': t.keyword, NotOp: t.operator, UnknownOp: t.operator, OrOp: t.separator, @@ -40,7 +35,7 @@ const parserWithMetadata = parser.configure({ StarMult: t.number, String: t.string, 'RelationName/QualifiedName': t.typeName, - 'RuleName/QualifiedName': t.typeName, + // 'RuleName/QualifiedName': t.typeName, 'IndividualNodeName/QualifiedName': t.atom, 'VariableName/QualifiedName': t.variableName, '{ }': t.brace, @@ -54,7 +49,7 @@ const parserWithMetadata = parser.configure({ UniqueDeclaration: indentDeclaration, ScopeDeclaration: indentDeclaration, PredicateBody: indentPredicateOrRule, - RuleBody: indentPredicateOrRule, + // RuleBody: indentPredicateOrRule, BlockComment: indentBlockComment, }), foldNodeProp.add({ @@ -62,9 +57,9 @@ const parserWithMetadata = parser.configure({ EnumBody: foldInside, ParameterList: foldInside, PredicateBody: foldInside, - RuleBody: foldInside, + // RuleBody: foldInside, Conjunction: foldConjunction, - Consequent: foldWholeNode, + // Consequent: foldWholeNode, UniqueDeclaration: foldDeclaration, ScopeDeclaration: foldDeclaration, BlockComment: foldBlockComment, @@ -82,7 +77,7 @@ const problemLanguage = LRLanguage.define({ }, line: '%', }, - indentOnInput: /^\s*(?:\{|\}|\(|\)|;|\.|==>)$/, + indentOnInput: /^\s*(?:\{|\}|\(|\)|;|\.)$/, }, }); diff --git a/subprojects/language/src/main/java/tools/refinery/language/Problem.xtext b/subprojects/language/src/main/java/tools/refinery/language/Problem.xtext index 2a5af628..f514e96c 100644 --- a/subprojects/language/src/main/java/tools/refinery/language/Problem.xtext +++ b/subprojects/language/src/main/java/tools/refinery/language/Problem.xtext @@ -8,7 +8,7 @@ Problem: statements+=Statement*; Statement: - ClassDeclaration | EnumDeclaration | PredicateDefinition | RuleDefinition | Assertion | NodeValueAssertion | + ClassDeclaration | EnumDeclaration | PredicateDefinition | /* RuleDefinition | */ Assertion | NodeValueAssertion | ScopeDeclaration | IndividualDeclaration; @@ -48,13 +48,13 @@ PredicateDefinition: ("<->" bodies+=Conjunction (";" bodies+=Conjunction)*)? "."; -RuleDefinition: - "rule" - name=Identifier - "(" (parameters+=Parameter ("," parameters+=Parameter)*)? ")" - (":" bodies+=Conjunction (";" bodies+=Conjunction)* - "==>" consequents+=Consequent (";" consequents+=Consequent)*)? - "."; +//RuleDefinition: +// "rule" +// name=Identifier +// "(" (parameters+=Parameter ("," parameters+=Parameter)*)? ")" +// (":" bodies+=Conjunction (";" bodies+=Conjunction)* +// "==>" consequents+=Consequent (";" consequents+=Consequent)*)? +// "."; Parameter: (modality=Modality? parameterType=[Relation|QualifiedName])? name=Identifier; @@ -62,8 +62,8 @@ Parameter: Conjunction: literals+=Literal ("," literals+=Literal)*; -Consequent: - actions+=Action ("," actions+=Action)*; +//Consequent: +// actions+=Action ("," actions+=Action)*; Literal: Atom | NegativeLiteral | CountLiteral; @@ -77,21 +77,21 @@ enum ComparisonOp: CountLiteral: modality=Modality? "count" atom=Atom op=ComparisonOp threshold=INT; -Action: - AssertionAction | DeleteAction | NewAction; - -AssertionAction: - value=ShortLogicValue? atom=Atom | - atom=Atom (overwrite?=":=" | "<:") value=LogicValue; - -DeleteAction: - "delete" variableOrNode=[VariableOrNode|QualifiedName]; - -NewAction: - "new" variable=NewVariable ("<:" parent=[VariableOrNode|QualifiedName])?; - -NewVariable: - name=Identifier; +//Action: +// AssertionAction | DeleteAction | NewAction; +// +//AssertionAction: +// value=ShortLogicValue? atom=Atom | +// atom=Atom (overwrite?=":=" | "<:") value=LogicValue; +// +//DeleteAction: +// "delete" variableOrNode=[VariableOrNode|QualifiedName]; +// +//NewAction: +// "new" variable=NewVariable ("<:" parent=[VariableOrNode|QualifiedName])?; +// +//NewVariable: +// name=Identifier; enum Modality: MAY="may" | MUST="must" | CURRENT="current"; @@ -191,7 +191,7 @@ QualifiedName hidden(): NonRelationKindIdentifier: ID | "true" | "false" | "unknown" | "error" | "class" | "abstract" | "extends" | "enum" | - "pred" | "indiv" | "problem" | "new" | "delete" | "rule" | "may" | "must" | "current" | + "pred" | "indiv" | "problem" | /* "new" | "delete" | "rule" | */ "may" | "must" | "current" | "count" | "default" | "scope" | "contained" | "containment"; Identifier: diff --git a/subprojects/language/src/main/java/tools/refinery/language/utils/SymbolCollector.java b/subprojects/language/src/main/java/tools/refinery/language/utils/SymbolCollector.java index 87cce1f3..a386db7f 100644 --- a/subprojects/language/src/main/java/tools/refinery/language/utils/SymbolCollector.java +++ b/subprojects/language/src/main/java/tools/refinery/language/utils/SymbolCollector.java @@ -1,32 +1,15 @@ package tools.refinery.language.utils; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - +import com.google.inject.Inject; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.xtext.naming.IQualifiedNameConverter; import org.eclipse.xtext.naming.IQualifiedNameProvider; +import tools.refinery.language.model.problem.*; -import com.google.inject.Inject; - -import tools.refinery.language.model.problem.Assertion; -import tools.refinery.language.model.problem.ClassDeclaration; -import tools.refinery.language.model.problem.ConstantAssertionArgument; -import tools.refinery.language.model.problem.EnumDeclaration; -import tools.refinery.language.model.problem.IndividualDeclaration; -import tools.refinery.language.model.problem.IntConstant; -import tools.refinery.language.model.problem.LogicValue; -import tools.refinery.language.model.problem.Node; -import tools.refinery.language.model.problem.NodeValueAssertion; -import tools.refinery.language.model.problem.PredicateDefinition; -import tools.refinery.language.model.problem.PredicateKind; -import tools.refinery.language.model.problem.Problem; -import tools.refinery.language.model.problem.ProblemFactory; -import tools.refinery.language.model.problem.RealConstant; -import tools.refinery.language.model.problem.Relation; -import tools.refinery.language.model.problem.StringConstant; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; class SymbolCollector { @Inject @@ -64,6 +47,8 @@ class SymbolCollector { collectClass(classDeclaration); } else if (statement instanceof EnumDeclaration enumDeclaration) { collectEnum(enumDeclaration); + } else if (statement instanceof RuleDefinition) { + throw new UnsupportedOperationException("Rules are not currently supported"); } } } -- cgit v1.2.3-54-g00ecf