From 0c90942472375f7212ef926786cf3091106ca134 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Thu, 9 Dec 2010 15:02:07 +0300 Subject: [PATCH] Attributes --- grammar/src/attributes.grm | 11 ++++++++ grammar/src/class.grm | 39 ++++++++--------------------- grammar/src/class_members.grm | 34 ++++++++----------------- grammar/src/extension.grm | 8 +++--- grammar/src/lexical.grm | 7 ------ grammar/src/match.grm | 2 +- grammar/src/modifiers.grm | 47 +++++++++++++++++++++++++++++++++++ grammar/src/other.grm | 0 8 files changed, 83 insertions(+), 65 deletions(-) create mode 100644 grammar/src/attributes.grm create mode 100644 grammar/src/modifiers.grm delete mode 100644 grammar/src/other.grm diff --git a/grammar/src/attributes.grm b/grammar/src/attributes.grm new file mode 100644 index 00000000000..1bc4324748c --- /dev/null +++ b/grammar/src/attributes.grm @@ -0,0 +1,11 @@ +attributes + : attributeAnnotation* + ; + +attributeAnnotation + : "[" attribute{","} "]" + ; + +attribute + : SimpleName{"."} valueArguments? + ; \ No newline at end of file diff --git a/grammar/src/class.grm b/grammar/src/class.grm index abe86e7dd97..5cf2b467ee9 100644 --- a/grammar/src/class.grm +++ b/grammar/src/class.grm @@ -11,31 +11,19 @@ internal class Example>(protected val x : Foo, y : So */ class - : classModifier* "class" SimpleName - ("<" typeParameter{","} ">")? + : modifiers "class" SimpleName + typeParameters? "wraps"? ("(" primaryConstructorParameter{","} ")")? - (":" delegationSpecifier{","})? - ("where" typeConstraint{","})? // TODO: Syntax is questionable + (":" attributes delegationSpecifier{","})? classBody? ; -classModifier - : accessModifier - : "abstract" - : "virtual" - : "enum" - : "extendable" // TODO: open? - // sealed by default +typeParameters + : "<" typeParameter{","} ">" + ("where" typeConstraint{","})? // TODO: Syntax is questionable ; -accessModifier - : "private" - : "protected" - : "public" - : "internal" - ; - classBody : ("{" memberDeclaration{","} "}")? ; @@ -50,21 +38,14 @@ explicitDelegation ; typeParameter - : varianceAnnotation? SimpleName (":" userType)? - ; - -varianceAnnotation - : "in" - : "out" + : modifiers SimpleName (":" userType)? ; typeConstraint - : userType ":" (userType | "this") // "this" for self-type + : attributes userType ":" (userType | "this") // "this" for self-type // TODO: other constraints, maybe ; primaryConstructorParameter - : accessModifier? ("val" | "var")? parameter - ; - - + : modifiers ("val" | "var")? parameter // TODO: ref/out? + ; \ No newline at end of file diff --git a/grammar/src/class_members.grm b/grammar/src/class_members.grm index 3ee92cc10a7..a9432bb7aa5 100644 --- a/grammar/src/class_members.grm +++ b/grammar/src/class_members.grm @@ -40,11 +40,11 @@ memberDeclaration ; classObject - : "class" objectLiteral + : modifiers "class" objectLiteral ; constructor - : accessModifier? "this" functionParameters (":" initializers) block + : modifiers "this" functionParameters (":" initializers) block ; functionParameters @@ -52,18 +52,12 @@ functionParameters ; functionParameter - : parameterKind parameter ("=" expression)? - ; - -parameterKind - : "lazy" - : "out" - : "ref" + : modifiers parameter ("=" expression)? ; initializers - : "this" valueArguments - : constructorInvocation // type parameters may (must?) be omitted + : attributes "this" valueArguments + : attributes constructorInvocation // type parameters may (must?) be omitted ; block @@ -71,19 +65,11 @@ block ; decomposer // TODO: consider other names - : "decomposer" SimpleName "(" SimpleName{","} ")" // Public properties only + : attributes "decomposer" SimpleName "(" (attributes SimpleName){","} ")" // Public properties only ; method - : memberModifier* "fun" functionRest - ; - -memberModifier - : accessModifier - : "override" - : "virtual" - : "abstract" - : // TODO: inline + : modifiers "fun" functionRest ; functionRest @@ -96,7 +82,7 @@ functionBody ; property - : memberModifier* "lazy"? ("val" | "var") propertyRest + : modifiers "lazy"? ("val" | "var") propertyRest ; propertyRest @@ -105,11 +91,11 @@ propertyRest ; getter - : memberModifier* "get" "(" ")" functionBody + : modifiers "get" "(" ")" functionBody ; setter - : memberModifier* "set" "(" parameter ")" functionBody + : modifiers "set" "(" modifiers parameter ")" functionBody // TODO: Can the parameter be lazy? ; parameter diff --git a/grammar/src/extension.grm b/grammar/src/extension.grm index b919f270664..fbf10f12ac9 100644 --- a/grammar/src/extension.grm +++ b/grammar/src/extension.grm @@ -6,17 +6,17 @@ extension ; completeExtension - : accessModifier? "extension" SimpleName? typeParameters? "for" type classBody? // properties cannot be lazy, cannot have backing fields + : modifiers "extension" SimpleName? typeParameters? "for" type classBody? // properties cannot be lazy, cannot have backing fields ; extensionMethod - : accessModifier? "fun" type "." functionRest + : modifiers "fun" type "." functionRest ; extensionProperty - : accessModifier? propertyModifier? ("val" | "var") type "." propertyRest // Extension property cannot be lazy + : modifiers ("val" | "var") type "." propertyRest // Extension property cannot be lazy ; extensionDecomposer - : "decomposer" (type ".")? SimpleName "(" SimpleName{","} ")" // Public properties only + : attributes "decomposer" (type ".")? SimpleName "(" attributes SimpleName{","} ")" // Public properties only ; \ No newline at end of file diff --git a/grammar/src/lexical.grm b/grammar/src/lexical.grm index f5814a08814..3b463728ef6 100644 --- a/grammar/src/lexical.grm +++ b/grammar/src/lexical.grm @@ -10,10 +10,3 @@ CharacterLiteral : /*character as in Java*/; StringWithTemplates : /*single-quoted string, $ can be escaped*/; NoEscapeString : /* """-quoted string */; -/* -val foo = @" - |Blah-blah-blah - foobar - barfoo -" -*/ \ No newline at end of file diff --git a/grammar/src/match.grm b/grammar/src/match.grm index 99c1e8ca479..563727f4e96 100644 --- a/grammar/src/match.grm +++ b/grammar/src/match.grm @@ -3,7 +3,7 @@ match ; matchEntry - : "case" pattern ("if" "(" expression ")")? "=>" expression // TODO: Consider other options than "=>" + : attributes "case" pattern ("if" "(" expression ")")? "=>" expression // TODO: Consider other options than "=>" ; pattern diff --git a/grammar/src/modifiers.grm b/grammar/src/modifiers.grm new file mode 100644 index 00000000000..7f9bb4a73ae --- /dev/null +++ b/grammar/src/modifiers.grm @@ -0,0 +1,47 @@ +modifiers + : modifier* + ; + +modifier + : classModifier + : accessModifier + : varianceAnnotation + : memberModifier + : parameterKind + : attributes + // sealed by default + ; + +classModifier + : "abstract" + : "virtual" + : "enum" + : "extendable" // TODO: open? + : "attribute" + ; + +memberModifier + : "override" + : "virtual" + : "abstract" + : // TODO: inline + ; + +accessModifier + : "private" + : "protected" + : "public" + : "internal" + ; + +varianceAnnotation + : "in" + : "out" + ; + +parameterKind + : "lazy" + : "out" + : "ref" + ; + diff --git a/grammar/src/other.grm b/grammar/src/other.grm deleted file mode 100644 index e69de29bb2d..00000000000