From 01960723de5ca42e28dc8f162d4fe9e24c23c0b8 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Tue, 20 Feb 2024 01:27:51 +0100 Subject: feat(language): datatype declarations Also changes ReferenceDeclaration to declare attributes, since reference and attributes can only be distinguished at linking time. --- subprojects/frontend/src/language/problem.grammar | 19 ++++++++++--------- .../frontend/src/language/problemLanguageSupport.ts | 8 ++++---- 2 files changed, 14 insertions(+), 13 deletions(-) (limited to 'subprojects/frontend/src/language') diff --git a/subprojects/frontend/src/language/problem.grammar b/subprojects/frontend/src/language/problem.grammar index b69ee73f..32f76f6a 100644 --- a/subprojects/frontend/src/language/problem.grammar +++ b/subprojects/frontend/src/language/problem.grammar @@ -42,6 +42,9 @@ statement { kw<"enum"> RelationName (EnumBody { "{" sep<",", AtomNodeName> "}" } | ".") } | + DatatypeDeclaration { + kw<"extern"> kw<"datatype"> DatatypeName "." + } | PredicateDefinition { ( (kw<"error"> | ckw<"contained"> | kw<"containment">)? kw<"pred"> | @@ -50,10 +53,10 @@ statement { RelationName ParameterList? PredicateBody { ("<->" sep)? "." } } | - FunctionDefinition { - kw<"fn"> PrimitiveType RelationName ParameterList? - FunctionBody { ("=" sep)? "." } - } | + // FunctionDefinition { + // kw<"fn"> RelationName RelationName ParameterList? + // FunctionBody { ("=" sep)? "." } + // } | //RuleDefinition { // kw<"rule"> // RuleName ParameterList? @@ -77,7 +80,7 @@ FeatureDeclaration { ReferenceKind !feature ~featureHead } | FeatureDeclarationHeadWithoutKind { - (PrimitiveType | kw<"bool">)? ~featureHead + ~featureHead } ) RelationName @@ -137,10 +140,6 @@ ReferenceKind { kw<"refers"> | ckw<"contains"> | kw<"container"> } -PrimitiveType { - kw<"int"> | kw<"real"> | kw<"string"> -} - LogicValue { kw<"true"> | kw<"false"> | kw<"unknown"> | kw<"error"> } @@ -165,6 +164,8 @@ Multiplicity { (IntMult "..")? (IntMult | StarMult)} // but will go with the transtive closure (and highlight `a` as a relation) if forced. RelationName { QualifiedName ~name } +DatatypeName { QualifiedName } + //RuleName { QualifiedName } AtomNodeName { QualifiedName } diff --git a/subprojects/frontend/src/language/problemLanguageSupport.ts b/subprojects/frontend/src/language/problemLanguageSupport.ts index 14826363..9500fbf2 100644 --- a/subprojects/frontend/src/language/problemLanguageSupport.ts +++ b/subprojects/frontend/src/language/problemLanguageSupport.ts @@ -28,11 +28,10 @@ const parserWithMetadata = parser.configure({ LineComment: t.lineComment, BlockComment: t.blockComment, 'module problem class enum pred fn scope': t.definitionKeyword, - 'import as declare atom multi': t.definitionKeyword, + 'import as declare atom multi extern datatype': t.definitionKeyword, 'abstract extends refers contains container opposite': t.modifier, 'default error contained containment': t.modifier, 'true false unknown error': t.keyword, - 'int real string bool': t.keyword, 'may must current count': t.operatorKeyword, 'sum prod min max in': t.operatorKeyword, // 'new delete': t.keyword, @@ -44,6 +43,7 @@ const parserWithMetadata = parser.configure({ StarMult: t.number, String: t.string, 'RelationName/QualifiedName': t.typeName, + 'DatatypeName/QualifiedName': t.keyword, // 'RuleName/QualifiedName': t.typeName, 'AtomNodeName/QualifiedName': t.atom, 'VariableName/QualifiedName': t.variableName, @@ -60,7 +60,7 @@ const parserWithMetadata = parser.configure({ NodeDeclaration: indentDeclaration, ScopeDeclaration: indentDeclaration, PredicateBody: indentPredicateOrRule, - FunctionBody: indentPredicateOrRule, + // FunctionBody: indentPredicateOrRule, // RuleBody: indentPredicateOrRule, BlockComment: indentBlockComment, }), @@ -69,7 +69,7 @@ const parserWithMetadata = parser.configure({ EnumBody: foldInside, ParameterList: foldInside, PredicateBody: foldInside, - FunctionBody: foldInside, + // FunctionBody: foldInside, // RuleBody: foldInside, Conjunction: foldConjunction, // Consequent: foldWholeNode, -- cgit v1.2.3-70-g09d2