# HG changeset patch # User Jan Vrany # Date 1357899161 0 # Node ID 8fedb5e096fc9a1e6ca2c228010b0266c07271af # Parent 46dd2b3b697495a1d41c32745fdce8b97337daf5 Initial grammar definition based on http://slps.github.com/zoo/index.html#Google_Dart. diff -r 46dd2b3b6974 -r 8fedb5e096fc compiler/Dart__Parser.st --- a/compiler/Dart__Parser.st Thu Jan 10 13:21:04 2013 +0000 +++ b/compiler/Dart__Parser.st Fri Jan 11 10:12:41 2013 +0000 @@ -3,7 +3,44 @@ "{ NameSpace: Dart }" PPCompositeParser subclass:#Parser - instanceVariableNames:'' + instanceVariableNames:'additiveExpression additiveOperator argumentList arguments + assignableExpression assignableSelector assignmentOperator + bitwiseAndExpression bitwiseOperator bitwiseOrExpression + bitwiseXorExpression block catchPart classDefinition + classMemberDefinition compilationUnit compoundLiteral + conditionalExpression constInitializedIdentifier + constInitializedVariableDeclaration + constantConstructorDeclaration constantExpression + constructorDeclaration declaration declaredIdentifier defaultCase + defaultFormalParameter directive equalityExpression + equalityOperator expression expressionInParentheses + expressionList factoryConstructorDeclaration factorySpecification + fieldFormalParameter fieldInitializer finalVarOrType finallyPart + forInitializerStatement forLoopParts formalParameterList + functionBody functionBodyOrNative functionDeclaration + functionExpression functionExpressionBody functionNative + functionPrefix functionTypeAlias getOrSet identifier + importReference importReferences incrementOperator + initializedIdentifier initializedIdentifierList + initializedVariableDeclaration initializers interfaceDefinition + interfaceMemberDefinition interfaces isOperator + iterationStatement label libraryBody libraryDefinition + libraryImport librarySource libraryUnit listLiteral literal + logicalAndExpression logicalOrExpression mapLiteral + mapLiteralEntry methodDeclaration multiplicativeExpression + multiplicativeOperator namedArgument namedConstructorDeclaration + namedFormalParameters negateOperator nonLabelledStatement + normalFormalParameter normalFormalParameterTail postfixExpression + postfixOperator prefixOperator primary primaryFE primaryNoFE + qualified redirection relationalExpression relationalOperator + returnType selectionStatement selector shiftExpression + shiftOperator simpleFormalParameter sourceUrls + specialSignatureDefinition statement statements + staticFinalDeclaration staticFinalDeclarationList + superCallOrFieldInitializer superclass superinterfaces switchCase + topLevelDefinition tryStatement type typeArguments typeList + typeParameter typeParameters unaryExpression + userDefinableOperator variableDeclaration' classVariableNames:'' poolDictionaries:'' category:'Languages-Dart-Parser' @@ -17,6 +54,837 @@ ! +!Parser methodsFor:'grammar'! + +additiveExpression + + ^ (multiplicativeExpression , ((additiveOperator , multiplicativeExpression) star)) + / ((TokenParser for: #super) , ((additiveOperator , multiplicativeExpression) plus)) + + "Modified: / 11-01-2013 / 09:59:56 / Jan Vrany " +! + +additiveOperator + + ^ ('+' asParser) + / ('-' asParser) + +! + +argumentList + + ^ (namedArgument , (((',' asParser) , namedArgument) star)) + / (expressionList , (((',' asParser) , namedArgument) star)) + +! + +arguments + + ^('(' asParser) , (argumentList optional) , (')' asParser) +! + +assignableExpression + + ^ (primary , (((arguments star) , assignableSelector) plus)) + / ((TokenParser for: #super) , assignableSelector) + / identifier + + "Modified: / 11-01-2013 / 10:00:12 / Jan Vrany " +! + +assignableSelector + + ^ (('[' asParser) , constantExpression , (']' asParser)) + / (('.' asParser) , identifier) + +! + +assignmentOperator + + ^ ('=' asParser) + / ('*=' asParser) + / ('/=' asParser) + / ('~/=' asParser) + / ('%=' asParser) + / ('+=' asParser) + / ('-=' asParser) + / ('<<=' asParser) + / (('>' asParser) , ('>' asParser) , ('>' asParser) , ('=' asParser)) + / (('>' asParser) , ('>' asParser) , ('=' asParser)) + / ('&=' asParser) + / ('^=' asParser) + / ('|=' asParser) + +! + +bitwiseAndExpression + + ^ (equalityExpression , ((('&' asParser) , equalityExpression) star)) + / ((TokenParser for: #super) , ((('&' asParser) , equalityExpression) plus)) + + "Modified: / 11-01-2013 / 10:00:21 / Jan Vrany " +! + +bitwiseOperator + + ^ ('&' asParser) + / ('^' asParser) + / ('|' asParser) + +! + +bitwiseOrExpression + + ^ (bitwiseXorExpression , ((('|' asParser) , bitwiseXorExpression) star)) + / ((TokenParser for:#super) , ((('|' asParser) , bitwiseXorExpression) plus)) + +! + +bitwiseXorExpression + + ^ (bitwiseAndExpression , ((('^' asParser) , bitwiseAndExpression) star)) + / ((TokenParser for:#super) , ((('^' asParser) , bitwiseAndExpression) plus)) + +! + +block + + ^('{' asParser) , statements , ('}' asParser) +! + +catchPart + + ^(TokenParser for:#catch) , ('(' asParser) , declaredIdentifier , (((',' asParser) , declaredIdentifier) optional) , (')' asParser) , block +! + +classDefinition + + ^ ((TokenParser for:#class) , identifier , (typeParameters optional) , (superclass optional) , (interfaces optional) , ('{' asParser) , (classMemberDefinition star) , ('}' asParser)) + / ((TokenParser for:#class) , identifier , (typeParameters optional) , (interfaces optional) , (TokenParser for:#native) , (TokenParser for:#string) , ('{' asParser) , (classMemberDefinition star) , ('}' asParser)) + +! + +classMemberDefinition + + ^ (declaration , (';' asParser)) + / (constructorDeclaration , (';' asParser)) + / (methodDeclaration , functionBodyOrNative) + / ((TokenParser for:#const) , factoryConstructorDeclaration , functionNative) + +! + +compilationUnit + + ^( ((TokenParser for: #'#!!') optional) , (directive star) , (topLevelDefinition star) ) end + + "Modified: / 11-01-2013 / 10:02:29 / Jan Vrany " +! + +compoundLiteral + + ^ listLiteral + / mapLiteral + +! + +conditionalExpression + + ^logicalOrExpression , ((('?' asParser) , constantExpression , (':' asParser) , constantExpression) optional) +! + +constInitializedIdentifier + + ^identifier , ((('=' asParser) , constantExpression) optional) +! + +constInitializedVariableDeclaration + + ^declaredIdentifier , ((('=' asParser) , constantExpression) optional) , (((',' asParser) , constInitializedIdentifier) star) +! + +constantConstructorDeclaration + + ^(TokenParser for:#const) , qualified , formalParameterList +! + +constantExpression + + ^ (assignableExpression , assignmentOperator , constantExpression) + / conditionalExpression + +! + +constructorDeclaration + + ^ (identifier , formalParameterList , ((redirection / initializers ) optional)) + / (namedConstructorDeclaration , ((redirection / initializers ) optional)) + +! + +declaration + + ^ (constantConstructorDeclaration , ((redirection / initializers ) optional)) + / (functionDeclaration , redirection) + / (namedConstructorDeclaration , redirection) + / ((TokenParser for:#abstract) , specialSignatureDefinition) + / ((TokenParser for:#abstract) , functionDeclaration) + / ((TokenParser for:#static) , (TokenParser for:#final) , (type optional) , staticFinalDeclarationList) + / (((TokenParser for:#static) optional) , constInitializedVariableDeclaration) + +! + +declaredIdentifier + + ^ ((TokenParser for:#final) , (type optional) , identifier) + / ((TokenParser for:#var) , identifier) + / (type , identifier) + +! + +defaultCase + + ^(label optional) , (((TokenParser for:#case) , constantExpression , (':' asParser)) star) , (TokenParser for:#default) , (':' asParser) , statements +! + +defaultFormalParameter + + ^normalFormalParameter , ((('=' asParser) , constantExpression) optional) +! + +directive + + ^('#' asParser) , identifier , arguments , (';' asParser) +! + +equalityExpression + + ^ (relationalExpression , ((equalityOperator , relationalExpression) optional)) + / ((TokenParser for:#super) , equalityOperator , relationalExpression) + +! + +equalityOperator + + ^ ('==' asParser) + / ('!!=' asParser) + / ('===' asParser) + / ('!!==' asParser) + +! + +expressionInParentheses + + ^('(' asParser) , constantExpression , (')' asParser) +! + +expressionList + + ^constantExpression , (((',' asParser) , constantExpression) star) +! + +factoryConstructorDeclaration + + ^(TokenParser for:#factory) , qualified , (typeParameters optional) , ((('.' asParser) , identifier) optional) , formalParameterList +! + +factorySpecification + + ^(TokenParser for:#factory) , type +! + +fieldFormalParameter + + ^(finalVarOrType optional) , (TokenParser for:#this) , ('.' asParser) , identifier +! + +fieldInitializer + + ^(((TokenParser for:#this) , ('.' asParser)) optional) , identifier , ('=' asParser) , conditionalExpression +! + +finalVarOrType + + ^ ((TokenParser for:#final) , (type optional)) + / (TokenParser for:#var) + / type + +! + +finallyPart + + ^(TokenParser for:#finally) , block +! + +forInitializerStatement + + ^ (initializedVariableDeclaration , (';' asParser)) + / ((constantExpression optional) , (';' asParser)) + +! + +forLoopParts + + ^ (forInitializerStatement , (constantExpression optional) , (';' asParser) , (expressionList optional)) + / (declaredIdentifier , (TokenParser for:#in) , constantExpression) + / (identifier , (TokenParser for:#in) , constantExpression) + +! + +formalParameterList + + ^ (('(' asParser) , (namedFormalParameters optional) , (')' asParser)) + / (('(' asParser) , normalFormalParameter , (normalFormalParameterTail optional) , (')' asParser)) + +! + +functionBody + + ^ (('=>' asParser) , constantExpression , (';' asParser)) + / block + +! + +functionBodyOrNative + + ^ ((TokenParser for:#native) , functionBody) + / functionNative + / functionBody + +! + +functionDeclaration + + ^(returnType optional) , identifier , formalParameterList +! + +functionExpression + + ^(((returnType optional) , identifier) optional) , formalParameterList , functionExpressionBody +! + +functionExpressionBody + + ^ (('=>' asParser) , constantExpression) + / block + +! + +functionNative + + ^(TokenParser for:#native) , ((TokenParser for:#string) optional) , (';' asParser) +! + +functionPrefix + + ^(returnType optional) , identifier +! + +functionTypeAlias + + ^(TokenParser for:#typedef) , functionPrefix , (typeParameters optional) , formalParameterList , (';' asParser) +! + +getOrSet + + ^ (TokenParser for:#get) + / (TokenParser for:#set) + +! + +identifier + + ^ IDENTIFIER_NO_DOLLAR + / (TokenParser for:#identifier) + / (TokenParser for:#abstract) + / ASSERT + / (TokenParser for:#class) + / EXTENDS + / (TokenParser for:#factory) + / (TokenParser for:#get) + / (TokenParser for:#implements) + / (TokenParser for:#import) + / (TokenParser for:#interface) + / (TokenParser for:#is) + / (TokenParser for:#library) + / (TokenParser for:#native) + / NEGATE + / OPERATOR + / (TokenParser for:#set) + / (TokenParser for:#source) + / (TokenParser for:#static) + / (TokenParser for:#typedef) + +! + +importReference + + ^(((TokenParser for:#identifier) , (':' asParser)) optional) , (TokenParser for:#string) +! + +importReferences + + ^importReference , (((',' asParser) , importReference) star) , ((',' asParser) optional) +! + +initializedIdentifier + + ^identifier , ((('=' asParser) , constantExpression) optional) +! + +initializedIdentifierList + + ^initializedIdentifier , (((',' asParser) , initializedIdentifier) star) +! + +initializedVariableDeclaration + + ^declaredIdentifier , ((('=' asParser) , constantExpression) optional) , (((',' asParser) , initializedIdentifier) star) +! + +initializers + + ^(':' asParser) , superCallOrFieldInitializer , (((',' asParser) , superCallOrFieldInitializer) star) +! + +interfaceDefinition + + ^(TokenParser for:#interface) , identifier , (typeParameters optional) , (superinterfaces optional) , (factorySpecification optional) , ('{' asParser) , (interfaceMemberDefinition star) , ('}' asParser) +! + +interfaceMemberDefinition + + ^ ((TokenParser for:#static) , (TokenParser for:#final) , (type optional) , initializedIdentifierList , (';' asParser)) + / (functionDeclaration , (';' asParser)) + / (constantConstructorDeclaration , (';' asParser)) + / (namedConstructorDeclaration , (';' asParser)) + / (specialSignatureDefinition , (';' asParser)) + / (variableDeclaration , (';' asParser)) + +! + +interfaces + + ^(TokenParser for:#implements) , typeList +! + +isOperator + + ^(TokenParser for:#is) , (('!!' asParser) optional) +! + +iterationStatement + + ^ ((TokenParser for:#while) , ('(' asParser) , constantExpression , (')' asParser) , statement) + / ((TokenParser for:#do) , statement , (TokenParser for:#while) , ('(' asParser) , constantExpression , (')' asParser) , (';' asParser)) + / ((TokenParser for:#for) , ('(' asParser) , forLoopParts , (')' asParser) , statement) + +! + +label + + ^identifier , (':' asParser) +! + +libraryBody + + ^(libraryImport optional) , (librarySource optional) +! + +libraryDefinition + + ^(TokenParser for:#library) , ('{' asParser) , libraryBody , ('}' asParser) +! + +libraryImport + + ^(TokenParser for:#import) , ('=' asParser) , ('[' asParser) , (importReferences optional) , (']' asParser) +! + +librarySource + + ^(TokenParser for:#source) , ('=' asParser) , ('[' asParser) , (sourceUrls optional) , (']' asParser) +! + +libraryUnit + + ^libraryDefinition end + + "Modified: / 11-01-2013 / 10:07:55 / Jan Vrany " +! + +listLiteral + + ^('[' asParser) , ((expressionList , ((',' asParser) optional)) optional) , (']' asParser) +! + +literal + + ^ (TokenParser for: #null) + / (TokenParser for: #true) + / (TokenParser for: #false) + / (TokenParser for: #number) + / (TokenParser for:#string) + + "Modified: / 11-01-2013 / 10:08:48 / Jan Vrany " +! + +logicalAndExpression + + ^bitwiseOrExpression , ((('&&' asParser) , bitwiseOrExpression) star) +! + +logicalOrExpression + + ^logicalAndExpression , ((('||' asParser) , logicalAndExpression) star) +! + +mapLiteral + + ^('{' asParser) , ((mapLiteralEntry , (((',' asParser) , mapLiteralEntry) star) , ((',' asParser) optional)) optional) , ('}' asParser) +! + +mapLiteralEntry + + ^(TokenParser for:#string) , (':' asParser) , constantExpression +! + +methodDeclaration + + ^ factoryConstructorDeclaration + / ((TokenParser for:#static) , functionDeclaration) + / specialSignatureDefinition + / (functionDeclaration , (initializers optional)) + / (namedConstructorDeclaration , (initializers optional)) + +! + +multiplicativeExpression + + ^ (unaryExpression , ((multiplicativeOperator , unaryExpression) star)) + / ((TokenParser for:#super) , ((multiplicativeOperator , unaryExpression) plus)) + +! + +multiplicativeOperator + + ^ ('*' asParser) + / ('/' asParser) + / ('%' asParser) + / ('~/' asParser) + +! + +namedArgument + + ^label , constantExpression +! + +namedConstructorDeclaration + + ^identifier , ('.' asParser) , identifier , formalParameterList +! + +namedFormalParameters + + ^('[' asParser) , defaultFormalParameter , (((',' asParser) , defaultFormalParameter) star) , (']' asParser) +! + +negateOperator + + ^ ('!!' asParser) + / ('~' asParser) + +! + +nonLabelledStatement + + ^ block + / (initializedVariableDeclaration , (';' asParser)) + / iterationStatement + / selectionStatement + / tryStatement + / ((TokenParser for: #break) , (identifier optional) , (';' asParser)) + / ((TokenParser for: #continue) , (identifier optional) , (';' asParser)) + / ((TokenParser for: #return) , (constantExpression optional) , (';' asParser)) + / ((TokenParser for: #throw) , (constantExpression optional) , (';' asParser)) + / ((constantExpression optional) , (';' asParser)) + / ((TokenParser for: #assert) , ('(' asParser) , conditionalExpression , (')' asParser) , (';' asParser)) + / (functionDeclaration , functionBody) + + "Modified: / 11-01-2013 / 10:09:27 / Jan Vrany " +! + +normalFormalParameter + + ^ functionDeclaration + / fieldFormalParameter + / simpleFormalParameter + +! + +normalFormalParameterTail + + ^ ((',' asParser) , namedFormalParameters) + / ((',' asParser) , normalFormalParameter , (normalFormalParameterTail optional)) + +! + +postfixExpression + + ^ (assignableExpression , postfixOperator) + / (primary , (selector star)) + +! + +postfixOperator + + ^ ('++' asParser) + / ('--' asParser) + +! + +prefixOperator + + ^ additiveOperator + / negateOperator + +! + +primary + + ^ primaryNoFE + / primaryFE + +! + +primaryFE + + ^ functionExpression + / primaryNoFE + +! + +primaryNoFE + + ^ (TokenParser for:#this) + / ((TokenParser for:#super) , assignableSelector) + / literal + / identifier + / (((TokenParser for:#const) optional) , (typeArguments optional) , compoundLiteral) + / (((TokenParser for: #new) / (TokenParser for:#const) ) , type , ((('.' asParser) , identifier) optional) , arguments) + / expressionInParentheses + + "Modified: / 11-01-2013 / 10:09:39 / Jan Vrany " +! + +qualified + + ^identifier , ((('.' asParser) , identifier) optional) +! + +redirection + + ^(':' asParser) , (TokenParser for:#this) , ((('.' asParser) , identifier) optional) , arguments +! + +relationalExpression + + ^ (shiftExpression , (((isOperator , type) / (relationalOperator , shiftExpression) ) optional)) + / ((TokenParser for:#super) , relationalOperator , shiftExpression) + +! + +relationalOperator + + ^ (('>' asParser) , ('=' asParser)) + / ('>' asParser) + / ('<=' asParser) + / ('<' asParser) + +! + +returnType + + ^ (TokenParser for: #void) + / type + + "Modified: / 11-01-2013 / 10:09:53 / Jan Vrany " +! + +selectionStatement + + ^ ((TokenParser for: #if) , ('(' asParser) , constantExpression , (')' asParser) , statement , (((TokenParser for: #else) , statement) optional)) + / ((TokenParser for: #switch) , ('(' asParser) , constantExpression , (')' asParser) , ('{' asParser) , (switchCase star) , (defaultCase optional) , ('}' asParser)) + + "Modified: / 11-01-2013 / 10:10:15 / Jan Vrany " +! + +selector + + ^ assignableSelector + / arguments + +! + +shiftExpression + + ^ (additiveExpression , ((shiftOperator , additiveExpression) star)) + / ((TokenParser for:#super) , ((shiftOperator , additiveExpression) plus)) + +! + +shiftOperator + + ^ ('<<' asParser) + / (('>' asParser) , ('>' asParser) , ('>' asParser)) + / (('>' asParser) , ('>' asParser)) + +! + +simpleFormalParameter + + ^ declaredIdentifier + / identifier + +! + +sourceUrls + + ^(TokenParser for:#string) , (((',' asParser) , (TokenParser for:#string)) star) , ((',' asParser) optional) +! + +specialSignatureDefinition + + ^ (((TokenParser for:#static) optional) , (returnType optional) , getOrSet , identifier , formalParameterList) + / ((returnType optional) , (TokenParser for: #operator) , userDefinableOperator , formalParameterList) + + "Modified: / 11-01-2013 / 10:10:28 / Jan Vrany " +! + +statement + + ^(label star) , nonLabelledStatement +! + +statements + + ^statement star +! + +staticFinalDeclaration + + ^identifier , ('=' asParser) , constantExpression +! + +staticFinalDeclarationList + + ^staticFinalDeclaration , (((',' asParser) , staticFinalDeclaration) star) +! + +superCallOrFieldInitializer + + ^ ((TokenParser for:#super) , arguments) + / ((TokenParser for:#super) , ('.' asParser) , identifier , arguments) + / fieldInitializer + +! + +superclass + + ^(TokenParser for: #extends) , type + + "Modified: / 11-01-2013 / 10:10:38 / Jan Vrany " +! + +superinterfaces + + ^(TokenParser for: #extends) , typeList + + "Modified: / 11-01-2013 / 10:10:45 / Jan Vrany " +! + +switchCase + + ^(label optional) , (((TokenParser for:#case) , constantExpression , (':' asParser)) plus) , statements +! + +topLevelDefinition + + ^ classDefinition + / interfaceDefinition + / functionTypeAlias + / (functionDeclaration , functionBodyOrNative) + / ((returnType optional) , getOrSet , identifier , formalParameterList , functionBodyOrNative) + / ((TokenParser for:#final) , (type optional) , staticFinalDeclarationList , (';' asParser)) + / (constInitializedVariableDeclaration , (';' asParser)) + +! + +tryStatement + + ^(TokenParser for: #try) , block , (((catchPart plus) , (finallyPart optional)) / finallyPart ) + + "Modified: / 11-01-2013 / 10:10:54 / Jan Vrany " +! + +type + + ^qualified , (typeArguments optional) +! + +typeArguments + + ^('<' asParser) , typeList , ('>' asParser) +! + +typeList + + ^type , (((',' asParser) , type) star) +! + +typeParameter + + ^identifier , (((TokenParser for: #extends) , type) optional) + + "Modified: / 11-01-2013 / 10:11:03 / Jan Vrany " +! + +typeParameters + + ^('<' asParser) , typeParameter , (((',' asParser) , typeParameter) star) , ('>' asParser) +! + +unaryExpression + + ^ postfixExpression + / (prefixOperator , unaryExpression) + / (negateOperator , (TokenParser for:#super)) + / (('-' asParser) , (TokenParser for:#super)) + / (postfixOperator , assignableExpression) + +! + +userDefinableOperator + + ^ multiplicativeOperator + / additiveOperator + / shiftOperator + / relationalOperator + / bitwiseOperator + / ('==' asParser) + / ('~' asParser) + / (TokenParser for: #negate) + / (('[' asParser) , (']' asParser)) + / (('[' asParser) , (']' asParser) , ('=' asParser)) + + "Modified: / 11-01-2013 / 10:11:13 / Jan Vrany " +! + +variableDeclaration + + ^declaredIdentifier , (((',' asParser) , identifier) star) +! ! + !Parser::TokenParser class methodsFor:'instance creation'! for: tokenType diff -r 46dd2b3b6974 -r 8fedb5e096fc compiler/compiler.rc --- a/compiler/compiler.rc Thu Jan 10 13:21:04 2013 +0000 +++ b/compiler/compiler.rc Fri Jan 11 10:12:41 2013 +0000 @@ -25,7 +25,7 @@ VALUE "LegalCopyright", "My CopyRight or CopyLeft\0" VALUE "ProductName", "ProductName\0" VALUE "ProductVersion", "6.2.3.0\0" - VALUE "ProductDate", "Thu, 10 Jan 2013 13:20:39 GMT\0" + VALUE "ProductDate", "Fri, 11 Jan 2013 10:12:00 GMT\0" END END