diff --git a/src/syntax.grammar b/src/syntax.grammar index aa12222..690afb0 100644 --- a/src/syntax.grammar +++ b/src/syntax.grammar @@ -39,7 +39,9 @@ declaration[@isGroup=Declaration] | EntityTypeDeclaration | ConstraintDeclaration | ModuleDeclaration + | NamespaceDeclaration | WithUseDeclaration + | ImportDeclaration } /* @@ -97,10 +99,18 @@ ModuleDeclaration { Docstring? Annotation* kw<"module"> LhsId formalsBracket* declaration* kw<"end"> } +NamespaceDeclaration { + Docstring? Annotation* kw<"namespace"> LhsId formalsBracket* declaration* kw<"end"> +} + WithUseDeclaration { kw<"with"> expression kw<"use"> ("..." | commaSep1) } +ImportDeclaration { + kw<"from"> LhsId kw<"import"> ("..." | commaSep1) +} + id { BasicId | ConstructorId | kw<"value"> | kw<"entity"> | kw<"type"> } ParenOpId { "(" Operator !parenOp ")" } @@ -436,6 +446,7 @@ formalsParen { "(" Formals? ")" } | ":>" | "<++" | "++>" + | "++" } decimalLiteral { $[0-9]+ } @@ -489,7 +500,7 @@ formalsParen { "(" Formals? ")" } RelnameStringLiteral { ":" StaticStringLiteral } RelnameMultilineStringLiteral { ":" StaticMultilineStringLiteral } - QualifiedNameElem { ":" (BasicId | ConstructorId) | ":(" Operator ")" } + QualifiedNameElem { ":" (BasicId | ConstructorId) | ":(" Operator ")" | "::" (BasicId | ConstructorId) | "::(" Operator ")" } InterpolationId { "%" basicIdentifier } quote1 { '"' } diff --git a/test/Declarations.test.txt b/test/Declarations.test.txt index 5fc2412..91128e3 100644 --- a/test/Declarations.test.txt +++ b/test/Declarations.test.txt @@ -14,6 +14,22 @@ Rel( BasicExpression(IntLiteral)), Keyword)) +# Namespace Declaration + +namespace store def a = 1 end + +==> + +Rel( + NamespaceDeclaration( + Keyword, + LhsId(BasicId), + DefinitionDeclaration( + Keyword, + LhsId(BasicId), + BasicExpression(IntLiteral)), + Keyword)) + # Value-Type Declaration value type Distance = Float @@ -86,3 +102,18 @@ Rel( Alias(BasicId), Alias(BasicId), Alias(BasicId))) + +# From-Import Declaration + +from ns::subns import a, b, c + +==> + +Rel( + ImportDeclaration( + Keyword, + LhsId(QualifiedName(QualifiedNameId(BasicId),QualifiedNameElem)), + Keyword, + Alias(BasicId), + Alias(BasicId), + Alias(BasicId)))