# HG changeset patch # User Jan Vrany # Date 1357919583 0 # Node ID 06efdfe62106945929f89d70e9c12aa09eed4d00 # Parent 77d56b3a771ba55bcc402d2989d119deb34e4f81 More tests and fixes for Dart parser diff -r 77d56b3a771b -r 06efdfe62106 compiler/Dart__Parser.st --- a/compiler/Dart__Parser.st Fri Jan 11 13:43:38 2013 +0000 +++ b/compiler/Dart__Parser.st Fri Jan 11 15:53:03 2013 +0000 @@ -111,7 +111,7 @@ arguments - ^('(' asParser) , (argumentList optional) , (')' asParser) + ^(TokenParser for:$() , (argumentList optional) , (TokenParser for:$)) ! assignableExpression @@ -132,20 +132,21 @@ assignmentOperator - ^ ('=' asParser) - / ('*=' asParser) - / ('/=' asParser) - / ('~/=' asParser) - / ('%=' asParser) - / ('+=' asParser) - / ('-=' asParser) - / ('<<=' asParser) - / (('>' asParser) , ('>' asParser) , ('>' asParser) , ('=' asParser)) - / (('>' asParser) , ('>' asParser) , ('=' asParser)) - / ('&=' asParser) - / ('^=' asParser) - / ('|=' asParser) - + ^ (TokenParser for: $=) + / (TokenParser for: #'*=' ) + / (TokenParser for: #'/=' ) + / (TokenParser for: #'~/=' ) + / (TokenParser for: #'%=' ) + / (TokenParser for: #'+=' ) + / (TokenParser for: #'-=' ) + / (TokenParser for: #'<<=' ) + / (('>' asParser) , ('>' asParser) , ('>' asParser) , ('=' asParser)) + / (('>' asParser) , ('>' asParser) , ('=' asParser)) + / (TokenParser for: #'&=' ) + / (TokenParser for: #'^=' ) + / (TokenParser for: #'|=' ) + + "Modified: / 11-01-2013 / 15:51:31 / Jan Vrany " ! bitwiseAndExpression @@ -180,25 +181,27 @@ block - ^('{' asParser) , statements , ('}' asParser) + ^(TokenParser for:${) , statements , (TokenParser for:$}) + + "Modified: / 11-01-2013 / 15:06:22 / Jan Vrany " ! catchPart - ^(TokenParser for:#catch) , ('(' asParser) , declaredIdentifier , (((',' asParser) , declaredIdentifier) optional) , (')' asParser) , block + ^(TokenParser for:#catch) , (TokenParser for:$() , declaredIdentifier , (((',' asParser) , declaredIdentifier) optional) , (TokenParser for:$)) , 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)) + ^ ((TokenParser for:#class) , identifier , (typeParameters optional) , (superclass optional) , (interfaces optional) , (TokenParser for:${) , (classMemberDefinition star) , (TokenParser for:$})) + / ((TokenParser for:#class) , identifier , (typeParameters optional) , (interfaces optional) , (TokenParser for:#native) , (TokenParser for:#string) , (TokenParser for:${) , (classMemberDefinition star) , (TokenParser for:$})) ! classMemberDefinition - ^ (declaration , (';' asParser)) - / (constructorDeclaration , (';' asParser)) + ^ (declaration , (TokenParser for:$;)) + / (constructorDeclaration , (TokenParser for:$;)) / (methodDeclaration , functionBodyOrNative) / ((TokenParser for:#const) , factoryConstructorDeclaration , functionNative) @@ -284,7 +287,7 @@ directive - ^('#' asParser) , identifier , arguments , (';' asParser) + ^('#' asParser) , identifier , arguments , (TokenParser for:$;) ! equalityExpression @@ -313,7 +316,7 @@ expressionInParentheses - ^('(' asParser) , constantExpression , (')' asParser) + ^(TokenParser for:$() , constantExpression , (TokenParser for:$)) ! expressionList @@ -356,14 +359,14 @@ forInitializerStatement - ^ (initializedVariableDeclaration , (';' asParser)) - / ((constantExpression optional) , (';' asParser)) + ^ (initializedVariableDeclaration , (TokenParser for:$;)) + / ((constantExpression optional) , (TokenParser for:$;)) ! forLoopParts - ^ (forInitializerStatement , (constantExpression optional) , (';' asParser) , (expressionList optional)) + ^ (forInitializerStatement , (constantExpression optional) , (TokenParser for:$;) , (expressionList optional)) / (declaredIdentifier , (TokenParser for:#in) , constantExpression) / (identifier , (TokenParser for:#in) , constantExpression) @@ -371,14 +374,14 @@ formalParameterList - ^ (('(' asParser) , (namedFormalParameters optional) , (')' asParser)) - / (('(' asParser) , normalFormalParameter , (normalFormalParameterTail optional) , (')' asParser)) + ^ ((TokenParser for:$() , (namedFormalParameters optional) , (TokenParser for:$))) + / ((TokenParser for:$() , normalFormalParameter , (normalFormalParameterTail optional) , (TokenParser for:$))) ! functionBody - ^ (('=>' asParser) , constantExpression , (';' asParser)) + ^ (('=>' asParser) , constantExpression , (TokenParser for:$;)) / block ! @@ -410,7 +413,7 @@ functionNative - ^(TokenParser for:#native) , ((TokenParser for:#string) optional) , (';' asParser) + ^(TokenParser for:#native) , ((TokenParser for:#string) optional) , (TokenParser for:$;) ! functionPrefix @@ -420,7 +423,7 @@ functionTypeAlias - ^(TokenParser for:#typedef) , functionPrefix , (typeParameters optional) , formalParameterList , (';' asParser) + ^(TokenParser for:#typedef) , functionPrefix , (typeParameters optional) , formalParameterList , (TokenParser for:$;) ! getOrSet @@ -433,7 +436,7 @@ identifier ^ (TokenParser for:#identifier_no_dollar) - / (TokenParser for:#identifier) + / (TokenParser for:#Identifier) / (TokenParser for:#abstract) / (TokenParser for:#assert) / (TokenParser for:#class) @@ -453,7 +456,7 @@ / (TokenParser for:#static) / (TokenParser for:#typedef) - "Modified: / 11-01-2013 / 13:25:43 / Jan Vrany " + "Modified: / 11-01-2013 / 15:04:57 / Jan Vrany " ! importReference @@ -496,17 +499,17 @@ interfaceDefinition - ^(TokenParser for:#interface) , identifier , (typeParameters optional) , (superinterfaces optional) , (factorySpecification optional) , ('{' asParser) , (interfaceMemberDefinition star) , ('}' asParser) + ^(TokenParser for:#interface) , identifier , (typeParameters optional) , (superinterfaces optional) , (factorySpecification optional) , (TokenParser for:${) , (interfaceMemberDefinition star) , (TokenParser for:$}) ! interfaceMemberDefinition - ^ ((TokenParser for:#static) , (TokenParser for:#final) , (type optional) , initializedIdentifierList , (';' asParser)) - / (functionDeclaration , (';' asParser)) - / (constantConstructorDeclaration , (';' asParser)) - / (namedConstructorDeclaration , (';' asParser)) - / (specialSignatureDefinition , (';' asParser)) - / (variableDeclaration , (';' asParser)) + ^ ((TokenParser for:#static) , (TokenParser for:#final) , (type optional) , initializedIdentifierList , (TokenParser for:$;)) + / (functionDeclaration , (TokenParser for:$;)) + / (constantConstructorDeclaration , (TokenParser for:$;)) + / (namedConstructorDeclaration , (TokenParser for:$;)) + / (specialSignatureDefinition , (TokenParser for:$;)) + / (variableDeclaration , (TokenParser for:$;)) ! @@ -522,9 +525,9 @@ 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) + ^ ((TokenParser for:#while) , (TokenParser for:$() , constantExpression , (TokenParser for:$)) , statement) + / ((TokenParser for:#do) , statement , (TokenParser for:#while) , (TokenParser for:$() , constantExpression , (TokenParser for:$)) , (TokenParser for:$;)) + / ((TokenParser for:#for) , (TokenParser for:$() , forLoopParts , (TokenParser for:$)) , statement) ! @@ -540,7 +543,7 @@ libraryDefinition - ^(TokenParser for:#library) , ('{' asParser) , libraryBody , ('}' asParser) + ^(TokenParser for:#library) , (TokenParser for:${) , libraryBody , (TokenParser for:$}) ! libraryImport @@ -570,10 +573,11 @@ ^ (TokenParser for: #null) / (TokenParser for: #true) / (TokenParser for: #false) - / (TokenParser for: #number) + / (TokenParser for: #Integer) + / (TokenParser for: #Float) / (TokenParser for:#string) - "Modified: / 11-01-2013 / 10:08:48 / Jan Vrany " + "Modified: / 11-01-2013 / 15:17:53 / Jan Vrany " ! logicalAndExpression @@ -588,7 +592,7 @@ mapLiteral - ^('{' asParser) , ((mapLiteralEntry , (((',' asParser) , mapLiteralEntry) star) , ((',' asParser) optional)) optional) , ('}' asParser) + ^(TokenParser for:${) , ((mapLiteralEntry , (((',' asParser) , mapLiteralEntry) star) , ((',' asParser) optional)) optional) , (TokenParser for:$}) ! mapLiteralEntry @@ -647,16 +651,16 @@ nonLabelledStatement ^ block - / (initializedVariableDeclaration , (';' asParser)) + / (initializedVariableDeclaration , (TokenParser for:$;)) / 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)) + / ((TokenParser for: #break) , (identifier optional) , (TokenParser for:$;)) + / ((TokenParser for: #continue) , (identifier optional) , (TokenParser for:$;)) + / ((TokenParser for: #return) , (constantExpression optional) , (TokenParser for:$;)) + / ((TokenParser for: #throw) , (constantExpression optional) , (TokenParser for:$;)) + / ((constantExpression optional) , (TokenParser for:$;)) + / ((TokenParser for: #assert) , (TokenParser for:$() , conditionalExpression , (TokenParser for:$)) , (TokenParser for:$;)) / (functionDeclaration , functionBody) "Modified: / 11-01-2013 / 10:09:27 / Jan Vrany " @@ -761,8 +765,8 @@ 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)) + ^ ((TokenParser for: #if) , (TokenParser for:$() , constantExpression , (TokenParser for:$)) , statement , (((TokenParser for: #else) , statement) optional)) + / ((TokenParser for: #switch) , (TokenParser for:$() , constantExpression , (TokenParser for:$)) , (TokenParser for:${) , (switchCase star) , (defaultCase optional) , (TokenParser for:$})) "Modified: / 11-01-2013 / 10:10:15 / Jan Vrany " ! @@ -863,8 +867,8 @@ / functionTypeAlias / (functionDeclaration , functionBodyOrNative) / ((returnType optional) , getOrSet , identifier , formalParameterList , functionBodyOrNative) - / ((TokenParser for:#final) , (type optional) , staticFinalDeclarationList , (';' asParser)) - / (constInitializedVariableDeclaration , (';' asParser)) + / ((TokenParser for:#final) , (type optional) , staticFinalDeclarationList , (TokenParser for:$;)) + / (constInitializedVariableDeclaration , (TokenParser for:$;)) ! diff -r 77d56b3a771b -r 06efdfe62106 compiler/Dart__ParserTests.st --- a/compiler/Dart__ParserTests.st Fri Jan 11 13:43:38 2013 +0000 +++ b/compiler/Dart__ParserTests.st Fri Jan 11 15:53:03 2013 +0000 @@ -28,12 +28,68 @@ "Modified: / 11-01-2013 / 13:28:58 / Jan Vrany " ! -parse: aString rule: aSymbol +parse: aString rule: aSymbol + | production | + production := self parserInstance. + aSymbol = #start ifFalse: [ + production := production productionAt: aSymbol. + production := production , (Dart::Parser::TokenParser for: #EOF). + ]. - ^super parse: (Dart::Scanner for: aString) rule: aSymbol + result := production parse: (Dart::Scanner for: aString). + self + assert: result isPetitFailure not + description: 'Unable to parse ' , aString printString. + + ^ result "Created: / 14-03-2012 / 22:51:09 / Jan Vrany " - "Modified: / 11-01-2013 / 13:29:05 / Jan Vrany " + "Modified: / 11-01-2013 / 15:35:46 / Jan Vrany " +! ! + +!ParserTests methodsFor:'tests - expressions'! + +test_expression_01 + + self parse:'1 + 1' rule: #expression + + "Created: / 11-01-2013 / 15:12:33 / Jan Vrany " +! + +test_expression_02 + + self parse:'a.foo()' rule: #expression + + "Created: / 11-01-2013 / 15:19:17 / Jan Vrany " +! + +test_expression_04 + + self parse:'new Foo()' rule: #expression + + "Created: / 11-01-2013 / 15:38:04 / Jan Vrany " +! ! + +!ParserTests methodsFor:'tests - literals'! + +test_literal_01 + + self parse: '1' rule: #literal. + self parse: '1.0' rule: #literal. + self parse: 'true' rule: #literal. + self parse: 'false' rule: #literal. + self parse: 'null' rule: #literal. + + "Created: / 11-01-2013 / 15:13:09 / Jan Vrany " +! ! + +!ParserTests methodsFor:'tests - misc'! + +test_misc_01 + + self parse:'=' rule: #assignmentOperator + + "Created: / 11-01-2013 / 15:49:57 / Jan Vrany " ! ! !ParserTests methodsFor:'tests - smoke'! @@ -55,7 +111,7 @@ ! test_smoke_02 - self parse: 'import ''dart:html''; + self parse: ' void main() { var a = 1 + 1; @@ -63,6 +119,7 @@ }' "Created: / 11-01-2013 / 13:30:54 / Jan Vrany " + "Modified: / 11-01-2013 / 15:07:11 / Jan Vrany " ! test_smoke_03 @@ -83,6 +140,22 @@ "Created: / 11-01-2013 / 13:34:08 / Jan Vrany " ! ! +!ParserTests methodsFor:'tests - statements'! + +test_statement_01 + + self parse:'a = 1;' rule: #statement + + "Created: / 11-01-2013 / 15:40:02 / Jan Vrany " +! + +test_statement_02 + + self parse:'return 1;' rule: #statement + + "Created: / 11-01-2013 / 15:44:24 / Jan Vrany " +! ! + !ParserTests class methodsFor:'documentation'! version_HG diff -r 77d56b3a771b -r 06efdfe62106 compiler/Dart__ScannerTests.st --- a/compiler/Dart__ScannerTests.st Fri Jan 11 13:43:38 2013 +0000 +++ b/compiler/Dart__ScannerTests.st Fri Jan 11 15:53:03 2013 +0000 @@ -19,6 +19,15 @@ = #(#import #String $; #void #identifier $( $) ${ $} ) "Created: / 11-01-2013 / 12:53:30 / Jan Vrany " +! + +test_02 + + self assert: + (Dart::Scanner scan: 'a |= 1') asArray + = #() + + "Created: / 11-01-2013 / 15:46:48 / Jan Vrany " ! ! !ScannerTests class methodsFor:'documentation'! diff -r 77d56b3a771b -r 06efdfe62106 compiler/compiler.rc --- a/compiler/compiler.rc Fri Jan 11 13:43:38 2013 +0000 +++ b/compiler/compiler.rc Fri Jan 11 15:53:03 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", "Fri, 11 Jan 2013 13:43:14 GMT\0" + VALUE "ProductDate", "Fri, 11 Jan 2013 15:52:43 GMT\0" END END