From a96c52b21e7e590bbdd70b80896780a446fa2e8b Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Mon, 13 Dec 2021 02:07:04 +0100 Subject: build: separate module for frontend This allows us to simplify the webpack configuration and the gradle build scripts. --- subprojects/frontend/src/language/problem.grammar | 149 ++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 subprojects/frontend/src/language/problem.grammar (limited to 'subprojects/frontend/src/language/problem.grammar') diff --git a/subprojects/frontend/src/language/problem.grammar b/subprojects/frontend/src/language/problem.grammar new file mode 100644 index 00000000..1ace2872 --- /dev/null +++ b/subprojects/frontend/src/language/problem.grammar @@ -0,0 +1,149 @@ +@detectDelim + +@external prop implicitCompletion from '../../../../src/language/props.ts' + +@top Problem { statement* } + +statement { + ProblemDeclaration { + ckw<"problem"> QualifiedName "." + } | + ClassDefinition { + ckw<"abstract">? ckw<"class"> RelationName + (ckw<"extends"> sep<",", RelationName>)? + (ClassBody { "{" ReferenceDeclaration* "}" } | ".") + } | + EnumDefinition { + ckw<"enum"> RelationName + (EnumBody { "{" sep<",", IndividualNodeName> "}" } | ".") + } | + PredicateDefinition { + (ckw<"error"> ckw<"pred">? | ckw<"direct">? ckw<"pred">) + RelationName ParameterList? + PredicateBody { ("<->" sep)? "." } + } | + RuleDefinition { + ckw<"direct">? ckw<"rule"> + RuleName ParameterList? + RuleBody { ":" sep "~>" sep "." } + } | + Assertion { + kw<"default">? (NotOp | UnknownOp)? RelationName + ParameterList (":" LogicValue)? "." + } | + NodeValueAssertion { + IndividualNodeName ":" Constant "." + } | + IndividualDeclaration { + ckw<"indiv"> sep<",", IndividualNodeName> "." + } | + ScopeDeclaration { + kw<"scope"> sep<",", ScopeElement> "." + } +} + +ReferenceDeclaration { + (kw<"refers"> | kw<"contains">)? + RelationName + RelationName + ( "[" Multiplicity? "]" )? + (kw<"opposite"> RelationName)? + ";"? +} + +Parameter { RelationName? VariableName } + +Conjunction { ("," | Literal)+ } + +OrOp { ";" } + +Literal { NotOp? Atom (("=" | ":") sep1<"|", LogicValue>)? } + +Atom { RelationName "+"? ParameterList } + +Action { ("," | ActionLiteral)+ } + +ActionLiteral { + ckw<"new"> VariableName | + ckw<"delete"> VariableName | + Literal +} + +Argument { VariableName | Constant } + +AssertionArgument { NodeName | StarArgument | Constant } + +Constant { Real | String } + +LogicValue { + ckw<"true"> | ckw<"false"> | ckw<"unknown"> | ckw<"error"> +} + +ScopeElement { RelationName ("=" | "+=") Multiplicity } + +Multiplicity { (IntMult "..")? (IntMult | StarMult)} + +RelationName { QualifiedName } + +RuleName { QualifiedName } + +IndividualNodeName { QualifiedName } + +VariableName { QualifiedName } + +NodeName { QualifiedName } + +QualifiedName[implicitCompletion=true] { identifier ("::" identifier)* } + +kw { @specialize[@name={term},implicitCompletion=true] } + +ckw { @extend[@name={term},implicitCompletion=true] } + +ParameterList { "(" sep<",", content> ")" } + +sep { sep1? } + +sep1 { content (separator content)* } + +@skip { LineComment | BlockComment | whitespace } + +@tokens { + whitespace { std.whitespace+ } + + LineComment { ("//" | "%") ![\n]* } + + BlockComment { "/*" blockCommentRest } + + blockCommentRest { ![*] blockCommentRest | "*" blockCommentAfterStar } + + blockCommentAfterStar { "/" | "*" blockCommentAfterStar | ![/*] blockCommentRest } + + @precedence { BlockComment, LineComment } + + identifier { $[A-Za-z_] $[a-zA-Z0-9_]* } + + int { $[0-9]+ } + + IntMult { int } + + StarMult { "*" } + + Real { "-"? (exponential | int ("." (int | exponential))?) } + + exponential { int ("e" | "E") ("+" | "-")? int } + + String { + "'" (![\\'\n] | "\\" ![\n] | "\\\n")+ "'" | + "\"" (![\\"\n] | "\\" (![\n] | "\n"))* "\"" + } + + NotOp { "!" } + + UnknownOp { "?" } + + StarArgument { "*" } + + "{" "}" "(" ")" "[" "]" "." ".." "," ":" "<->" "~>" +} + +@detectDelim -- cgit v1.2.3-70-g09d2