Grammar reviewed
This commit is contained in:
+22
-8
@@ -16,19 +16,28 @@ class
|
||||
"wraps"?
|
||||
("(" primaryConstructorParameter{","} ")")?
|
||||
(":" delegationSpecifier{","})?
|
||||
("where" typeConstraint{","})? // Syntax is questionable
|
||||
("where" typeConstraint{","})? // TODO: Syntax is questionable
|
||||
classBody?
|
||||
;
|
||||
|
||||
classBody
|
||||
: ("{" memberDeclaration{","} "}"
|
||||
;
|
||||
|
||||
classModifier
|
||||
: accessModifier
|
||||
: "abstract"
|
||||
: "interface" // TODO: better name
|
||||
: "sealed"
|
||||
: "virtual"
|
||||
: "enum"
|
||||
: "extendable" // TODO: open?
|
||||
// sealed by default
|
||||
;
|
||||
|
||||
accessModifier
|
||||
: "private"
|
||||
: "protected"
|
||||
: "public"
|
||||
: "internal"
|
||||
;
|
||||
|
||||
classBody
|
||||
: ("{" memberDeclaration{","} "}")?
|
||||
;
|
||||
|
||||
delegationSpecifier
|
||||
@@ -44,8 +53,13 @@ typeParameter
|
||||
: varianceAnnotation? SimpleName (":" userType)?
|
||||
;
|
||||
|
||||
varianceAnnotation
|
||||
: "in"
|
||||
: "out"
|
||||
;
|
||||
|
||||
typeConstraint
|
||||
: userType ":" (userType | "this")
|
||||
: userType ":" (userType | "this") // "this" for self-type
|
||||
// TODO: other constraints, maybe
|
||||
;
|
||||
|
||||
|
||||
@@ -39,10 +39,6 @@ memberDeclaration
|
||||
: class
|
||||
;
|
||||
|
||||
decomposer // TODO: consider other names
|
||||
: "decomposer" SimpleName "(" SimpleName{","} ")" // Public properties only
|
||||
;
|
||||
|
||||
classObject
|
||||
: "class" objectLiteral
|
||||
;
|
||||
@@ -51,38 +47,57 @@ constructor
|
||||
: accessModifier? "this" functionParameters (":" initializers) block
|
||||
;
|
||||
|
||||
functionParameters
|
||||
: "(" functionParameter{","}? ")" // default values
|
||||
;
|
||||
|
||||
functionParameter
|
||||
: parameterKind parameter ("=" expression)?
|
||||
;
|
||||
|
||||
parameterKind
|
||||
: "lazy"
|
||||
: "out"
|
||||
: "ref"
|
||||
;
|
||||
|
||||
initializers
|
||||
: "this" functionArguments
|
||||
: "this" valueArguments
|
||||
: constructorInvocation // type parameters may (must?) be omitted
|
||||
;
|
||||
|
||||
super
|
||||
: "super" "<" name ">"
|
||||
block
|
||||
: "{" expression "}"
|
||||
;
|
||||
|
||||
decomposer // TODO: consider other names
|
||||
: "decomposer" SimpleName "(" SimpleName{","} ")" // Public properties only
|
||||
;
|
||||
|
||||
method
|
||||
: methodModifier* "fun" functionRest
|
||||
: memberModifier* "fun" functionRest
|
||||
;
|
||||
|
||||
memberModifier
|
||||
: accessModifier
|
||||
: "override"
|
||||
: "virtual"
|
||||
: "abstract"
|
||||
: // TODO: inline
|
||||
;
|
||||
|
||||
functionRest
|
||||
: SimpleName typeParameters? functionParameters (":" type)? functionBody?
|
||||
;
|
||||
|
||||
functionParameters
|
||||
: "(" ((parameter ("=" expression)?){","})? ")" // default values
|
||||
;
|
||||
|
||||
block
|
||||
: "{" expression* "}"
|
||||
;
|
||||
|
||||
functionBody
|
||||
: block
|
||||
: "=" expression
|
||||
;
|
||||
|
||||
property
|
||||
: propertyModifier* ("val" | "var")
|
||||
: memberModifier* "lazy"? ("val" | "var") propertyRest
|
||||
;
|
||||
|
||||
propertyRest
|
||||
: SimpleName (":" type)? ("=" expression)?
|
||||
@@ -90,10 +105,13 @@ propertyRest
|
||||
;
|
||||
|
||||
getter
|
||||
: methodModifier* "get" "(" ")" functionBody
|
||||
: memberModifier* "get" "(" ")" functionBody
|
||||
;
|
||||
|
||||
setter
|
||||
: methodModifier* "set" "(" parameter ")" functionBody
|
||||
: memberModifier* "set" "(" parameter ")" functionBody
|
||||
;
|
||||
|
||||
parameter
|
||||
: SimpleName ":" type
|
||||
;
|
||||
@@ -2,6 +2,12 @@ if
|
||||
: "if" "(" expression ")" expression ("else" expression)?
|
||||
;
|
||||
|
||||
loop
|
||||
: for
|
||||
: while
|
||||
: doWhile
|
||||
;
|
||||
|
||||
for
|
||||
: "for" "(" valOrVar? (SimpleName | parameter) "in" expression ")" expression
|
||||
;
|
||||
|
||||
+35
-26
@@ -7,15 +7,32 @@ expression
|
||||
: mapLiteral
|
||||
: range
|
||||
: "null"
|
||||
: "this"
|
||||
: "this" ("<" type ">")?
|
||||
: memberAccessExpression
|
||||
: expressionWithPrecedences
|
||||
: match
|
||||
: if
|
||||
: "typeof"
|
||||
: "typeof" // TODO: another keyword
|
||||
: "new" constructorInvocation // TODO: Do we need "new"?, see factory methods
|
||||
: objectLiteral
|
||||
: declaration
|
||||
: jump
|
||||
: loop
|
||||
// block is syntactically equivalent to a functionLiteral with no parameters
|
||||
;
|
||||
|
||||
literalConstant
|
||||
: "true" | "false"
|
||||
: StringWithTemplates
|
||||
: NoEscapeString
|
||||
: IntegerLiteral
|
||||
: HexadecimalLiteral
|
||||
: CharacterLiteral
|
||||
;
|
||||
|
||||
declaration
|
||||
: function
|
||||
: property
|
||||
;
|
||||
|
||||
expressionWithPrecedences // See the precedence table, everything associates to the left
|
||||
@@ -25,6 +42,11 @@ expressionWithPrecedences // See the precedence table, everything associates to
|
||||
: unOpExpression
|
||||
: castExpression
|
||||
: typingExpression
|
||||
: memberAccessExpression
|
||||
;
|
||||
|
||||
memberAccessExpression
|
||||
: (expression ".")? memberAccess
|
||||
;
|
||||
|
||||
typingExpression
|
||||
@@ -32,18 +54,15 @@ typingExpression
|
||||
;
|
||||
|
||||
typingOperation
|
||||
: "as" : "is" : "isnot"
|
||||
: "as"
|
||||
: "is"
|
||||
: "isnot"
|
||||
;
|
||||
|
||||
binOpExpression
|
||||
: expression binaryOperation expression // see priorities
|
||||
;
|
||||
|
||||
unOpExpression
|
||||
: expression postfixUnaryOperation
|
||||
: prefixUnaryOperation expression
|
||||
;
|
||||
|
||||
binaryOperation // Decreasing precedence
|
||||
// .
|
||||
// unary
|
||||
@@ -68,6 +87,11 @@ assignment
|
||||
: memberAccessExpression assignmentOperator expression // Assignment to functions prohibited by a semantic check
|
||||
;
|
||||
|
||||
unOpExpression
|
||||
: expression postfixUnaryOperation
|
||||
: prefixUnaryOperation expression
|
||||
;
|
||||
|
||||
prefixUnaryOperation
|
||||
: "-" : "+"
|
||||
: "++" : "--"
|
||||
@@ -120,11 +144,11 @@ constructorInvocation
|
||||
;
|
||||
|
||||
listLiteral
|
||||
: "[" expression{","} "]"
|
||||
: "[" expression{","}? "]"
|
||||
;
|
||||
|
||||
mapLiteral
|
||||
: "[" mapEntryLiteral ("," mapEntryLiteral)* "]"
|
||||
: "[" mapEntryLiteral{","} "]"
|
||||
: "[" ":" "]"
|
||||
;
|
||||
|
||||
@@ -132,25 +156,10 @@ mapEntryLiteral
|
||||
: expression ":" expression
|
||||
;
|
||||
|
||||
literalConstant
|
||||
: booleanLiteral
|
||||
: IntegerLiteral
|
||||
: HexadecimalLiteral
|
||||
: CharacterLiteral
|
||||
: SingleLineStringLiteral
|
||||
: SingleLineStringTemplate
|
||||
: MultiLineStringLiteral
|
||||
: MultiLineStringTemplate
|
||||
;
|
||||
|
||||
range
|
||||
: "[" expression ".." expression "]"
|
||||
;
|
||||
|
||||
memberAccessExpression
|
||||
: (expression ".")? memberAccess
|
||||
;
|
||||
|
||||
memberAccess
|
||||
: functionCall
|
||||
: fieldOrPropertyAccess
|
||||
@@ -166,7 +175,7 @@ arrayAccess
|
||||
;
|
||||
|
||||
objectLiteral
|
||||
: "object" delegationSpecifier{","} classBody?
|
||||
: "object" delegationSpecifier{","}? classBody?
|
||||
;
|
||||
|
||||
/* Factory methods:
|
||||
|
||||
@@ -6,7 +6,7 @@ extension
|
||||
;
|
||||
|
||||
completeExtension
|
||||
: accessModifier? "extension" SimpleName? typeParameters? "for" type classBody?
|
||||
: accessModifier? "extension" SimpleName? typeParameters? "for" type classBody? // properties cannot be lazy, cannot have backing fields
|
||||
;
|
||||
|
||||
extensionMethod
|
||||
@@ -14,7 +14,7 @@ extensionMethod
|
||||
;
|
||||
|
||||
extensionProperty
|
||||
: accessModifier? propertyModifier? ("val" | "var") type "." propertyRest
|
||||
: accessModifier? propertyModifier? ("val" | "var") type "." propertyRest // Extension property cannot be lazy
|
||||
;
|
||||
|
||||
extensionDecomposer
|
||||
|
||||
@@ -5,7 +5,9 @@ IntegerLiteral : Digit+ "L"?
|
||||
[helper] HexDigit : Digit | ["A"-"F", "a"-"f"];
|
||||
HexadecimalLiteral : "0x" HexDigit+;
|
||||
|
||||
StringWithPatterns : /*single-quoted string, $ can be escaped*/;
|
||||
CharacterLiteral : /*character as in Java*/
|
||||
|
||||
StringWithTemplates : /*single-quoted string, $ can be escaped*/;
|
||||
NoEscapeString : /* @-prefixed string, maybe allow putting a bar for indentation correction */;
|
||||
|
||||
/*
|
||||
|
||||
@@ -14,6 +14,10 @@ pattern
|
||||
: decomposerPattern // labeled components are allowed
|
||||
;
|
||||
|
||||
constantPattern
|
||||
: literalConstant
|
||||
;
|
||||
|
||||
tuplePattern
|
||||
: "(" ((SimpleName "=")? pattern{","})? ")"
|
||||
;
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
accessModifier
|
||||
: "private"
|
||||
: "protected"
|
||||
: "public"
|
||||
: "internal"
|
||||
;
|
||||
|
||||
parameter
|
||||
: SimpleName ":" type
|
||||
// TODO: lazy, out, ref ...
|
||||
;
|
||||
|
||||
functionArguments
|
||||
: "(" (expression{","})* ")"
|
||||
;
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
jetlFile
|
||||
[start] jetlFile
|
||||
: preamble toplevelObject*
|
||||
;
|
||||
|
||||
[start] script
|
||||
: expression
|
||||
|
||||
preamble
|
||||
: namespaceHeader? import*
|
||||
;
|
||||
|
||||
@@ -16,13 +16,7 @@ type
|
||||
;
|
||||
|
||||
userType
|
||||
: name ("<" (projectionSpecifier type){","} ">")?
|
||||
;
|
||||
|
||||
projectionSpecifier
|
||||
: "in"
|
||||
: "out"
|
||||
: empty
|
||||
: SimpleName{"."} ("<" (varianceSpecifier? type){","} ">")?
|
||||
;
|
||||
|
||||
functionType
|
||||
|
||||
Reference in New Issue
Block a user