Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: include namespace in grammar, also concat op #43

Merged
merged 7 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/syntax.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ declaration[@isGroup=Declaration]
| EntityTypeDeclaration
| ConstraintDeclaration
| ModuleDeclaration
| NamespaceDeclaration
| WithUseDeclaration
mcmcgrath13 marked this conversation as resolved.
Show resolved Hide resolved
| ImportDeclaration
}

/*
Expand Down Expand Up @@ -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<Alias>)
}

ImportDeclaration {
kw<"from"> LhsId kw<"import"> ("..." | commaSep1<Alias>)
}

id { BasicId | ConstructorId | kw<"value"> | kw<"entity"> | kw<"type"> }

ParenOpId { "(" Operator !parenOp ")" }
Expand Down Expand Up @@ -436,6 +446,7 @@ formalsParen { "(" Formals? ")" }
| ":>"
| "<++"
| "++>"
| "++"
}

decimalLiteral { $[0-9]+ }
Expand Down Expand Up @@ -489,7 +500,7 @@ formalsParen { "(" Formals? ")" }
RelnameStringLiteral { ":" StaticStringLiteral }
RelnameMultilineStringLiteral { ":" StaticMultilineStringLiteral }

QualifiedNameElem { ":" (BasicId | ConstructorId) | ":(" Operator ")" }
QualifiedNameElem { ":" (BasicId | ConstructorId) | ":(" Operator ")" | "::" (BasicId | ConstructorId) | "::(" Operator ")" }
InterpolationId { "%" basicIdentifier }

quote1 { '"' }
Expand Down
31 changes: 31 additions & 0 deletions test/Declarations.test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Loading