More tests and fixes for Dart parser
authorJan Vrany <jan.vrany@fit.cvut.cz>
Fri, 11 Jan 2013 15:53:03 +0000
changeset 606efdfe62106
parent 5 77d56b3a771b
child 7 cccc239c8833
More tests and fixes for Dart parser
compiler/Dart__Parser.st
compiler/Dart__ParserTests.st
compiler/Dart__ScannerTests.st
compiler/compiler.rc
     1.1 --- a/compiler/Dart__Parser.st	Fri Jan 11 13:43:38 2013 +0000
     1.2 +++ b/compiler/Dart__Parser.st	Fri Jan 11 15:53:03 2013 +0000
     1.3 @@ -111,7 +111,7 @@
     1.4  
     1.5  arguments
     1.6  
     1.7 -	^('(' asParser) , (argumentList optional) , (')' asParser)
     1.8 +	^(TokenParser for:$() , (argumentList optional) , (TokenParser for:$))
     1.9  !
    1.10  
    1.11  assignableExpression
    1.12 @@ -132,20 +132,21 @@
    1.13  
    1.14  assignmentOperator
    1.15  
    1.16 -	^ ('=' asParser)
    1.17 -	/ ('*=' asParser)
    1.18 -	/ ('/=' asParser)
    1.19 -	/ ('~/=' asParser)
    1.20 -	/ ('%=' asParser)
    1.21 -	/ ('+=' asParser)
    1.22 -	/ ('-=' asParser)
    1.23 -	/ ('<<=' asParser)
    1.24 -	/ (('>' asParser) , ('>' asParser) , ('>' asParser) , ('=' asParser))
    1.25 -	/ (('>' asParser) , ('>' asParser) , ('=' asParser))
    1.26 -	/ ('&=' asParser)
    1.27 -	/ ('^=' asParser)
    1.28 -	/ ('|=' asParser)
    1.29 -	
    1.30 +        ^ (TokenParser for: $=)
    1.31 +        / (TokenParser for: #'*=' )
    1.32 +        / (TokenParser for: #'/=' )
    1.33 +        / (TokenParser for: #'~/=' )
    1.34 +        / (TokenParser for: #'%=' )
    1.35 +        / (TokenParser for: #'+=' )
    1.36 +        / (TokenParser for: #'-=' )
    1.37 +        / (TokenParser for: #'<<=' )
    1.38 +        / (('>' asParser) , ('>' asParser) , ('>' asParser) , ('=' asParser))
    1.39 +        / (('>' asParser) , ('>' asParser) , ('=' asParser))
    1.40 +        / (TokenParser for: #'&=' )
    1.41 +        / (TokenParser for: #'^=' )
    1.42 +        / (TokenParser for: #'|=' )
    1.43 +
    1.44 +    "Modified: / 11-01-2013 / 15:51:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    1.45  !
    1.46  
    1.47  bitwiseAndExpression
    1.48 @@ -180,25 +181,27 @@
    1.49  
    1.50  block
    1.51  
    1.52 -	^('{' asParser) , statements , ('}' asParser)
    1.53 +        ^(TokenParser for:${) , statements , (TokenParser for:$})
    1.54 +
    1.55 +    "Modified: / 11-01-2013 / 15:06:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    1.56  !
    1.57  
    1.58  catchPart
    1.59  
    1.60 -	^(TokenParser for:#catch) , ('(' asParser) , declaredIdentifier , (((',' asParser) , declaredIdentifier) optional) , (')' asParser) , block
    1.61 +	^(TokenParser for:#catch) , (TokenParser for:$() , declaredIdentifier , (((',' asParser) , declaredIdentifier) optional) , (TokenParser for:$)) , block
    1.62  !
    1.63  
    1.64  classDefinition
    1.65  
    1.66 -	^ ((TokenParser for:#class) , identifier , (typeParameters optional) , (superclass optional) , (interfaces optional) , ('{' asParser) , (classMemberDefinition star) , ('}' asParser))
    1.67 -	/ ((TokenParser for:#class) , identifier , (typeParameters optional) , (interfaces optional) , (TokenParser for:#native) , (TokenParser for:#string) , ('{' asParser) , (classMemberDefinition star) , ('}' asParser))
    1.68 +	^ ((TokenParser for:#class) , identifier , (typeParameters optional) , (superclass optional) , (interfaces optional) , (TokenParser for:${) , (classMemberDefinition star) , (TokenParser for:$}))
    1.69 +	/ ((TokenParser for:#class) , identifier , (typeParameters optional) , (interfaces optional) , (TokenParser for:#native) , (TokenParser for:#string) , (TokenParser for:${) , (classMemberDefinition star) , (TokenParser for:$}))
    1.70  	
    1.71  !
    1.72  
    1.73  classMemberDefinition
    1.74  
    1.75 -	^ (declaration , (';' asParser))
    1.76 -	/ (constructorDeclaration , (';' asParser))
    1.77 +	^ (declaration , (TokenParser for:$;))
    1.78 +	/ (constructorDeclaration , (TokenParser for:$;))
    1.79  	/ (methodDeclaration , functionBodyOrNative)
    1.80  	/ ((TokenParser for:#const) , factoryConstructorDeclaration , functionNative)
    1.81  	
    1.82 @@ -284,7 +287,7 @@
    1.83  
    1.84  directive
    1.85  
    1.86 -	^('#' asParser) , identifier , arguments , (';' asParser)
    1.87 +	^('#' asParser) , identifier , arguments , (TokenParser for:$;)
    1.88  !
    1.89  
    1.90  equalityExpression
    1.91 @@ -313,7 +316,7 @@
    1.92  
    1.93  expressionInParentheses
    1.94  
    1.95 -	^('(' asParser) , constantExpression , (')' asParser)
    1.96 +	^(TokenParser for:$() , constantExpression , (TokenParser for:$))
    1.97  !
    1.98  
    1.99  expressionList
   1.100 @@ -356,14 +359,14 @@
   1.101  
   1.102  forInitializerStatement
   1.103  
   1.104 -	^ (initializedVariableDeclaration , (';' asParser))
   1.105 -	/ ((constantExpression optional) , (';' asParser))
   1.106 +	^ (initializedVariableDeclaration , (TokenParser for:$;))
   1.107 +	/ ((constantExpression optional) , (TokenParser for:$;))
   1.108  	
   1.109  !
   1.110  
   1.111  forLoopParts
   1.112  
   1.113 -	^ (forInitializerStatement , (constantExpression optional) , (';' asParser) , (expressionList optional))
   1.114 +	^ (forInitializerStatement , (constantExpression optional) , (TokenParser for:$;) , (expressionList optional))
   1.115  	/ (declaredIdentifier , (TokenParser for:#in) , constantExpression)
   1.116  	/ (identifier , (TokenParser for:#in) , constantExpression)
   1.117  	
   1.118 @@ -371,14 +374,14 @@
   1.119  
   1.120  formalParameterList
   1.121  
   1.122 -	^ (('(' asParser) , (namedFormalParameters optional) , (')' asParser))
   1.123 -	/ (('(' asParser) , normalFormalParameter , (normalFormalParameterTail optional) , (')' asParser))
   1.124 +	^ ((TokenParser for:$() , (namedFormalParameters optional) , (TokenParser for:$)))
   1.125 +	/ ((TokenParser for:$() , normalFormalParameter , (normalFormalParameterTail optional) , (TokenParser for:$)))
   1.126  	
   1.127  !
   1.128  
   1.129  functionBody
   1.130  
   1.131 -	^ (('=>' asParser) , constantExpression , (';' asParser))
   1.132 +	^ (('=>' asParser) , constantExpression , (TokenParser for:$;))
   1.133  	/ block
   1.134  	
   1.135  !
   1.136 @@ -410,7 +413,7 @@
   1.137  
   1.138  functionNative
   1.139  
   1.140 -	^(TokenParser for:#native) , ((TokenParser for:#string) optional) , (';' asParser)
   1.141 +	^(TokenParser for:#native) , ((TokenParser for:#string) optional) , (TokenParser for:$;)
   1.142  !
   1.143  
   1.144  functionPrefix
   1.145 @@ -420,7 +423,7 @@
   1.146  
   1.147  functionTypeAlias
   1.148  
   1.149 -	^(TokenParser for:#typedef) , functionPrefix , (typeParameters optional) , formalParameterList , (';' asParser)
   1.150 +	^(TokenParser for:#typedef) , functionPrefix , (typeParameters optional) , formalParameterList , (TokenParser for:$;)
   1.151  !
   1.152  
   1.153  getOrSet
   1.154 @@ -433,7 +436,7 @@
   1.155  identifier
   1.156  
   1.157          ^ (TokenParser for:#identifier_no_dollar)
   1.158 -        / (TokenParser for:#identifier)
   1.159 +        / (TokenParser for:#Identifier)
   1.160          / (TokenParser for:#abstract)
   1.161          / (TokenParser for:#assert)
   1.162          / (TokenParser for:#class)
   1.163 @@ -453,7 +456,7 @@
   1.164          / (TokenParser for:#static)
   1.165          / (TokenParser for:#typedef)
   1.166  
   1.167 -    "Modified: / 11-01-2013 / 13:25:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   1.168 +    "Modified: / 11-01-2013 / 15:04:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   1.169  !
   1.170  
   1.171  importReference
   1.172 @@ -496,17 +499,17 @@
   1.173  
   1.174  interfaceDefinition
   1.175  
   1.176 -	^(TokenParser for:#interface) , identifier , (typeParameters optional) , (superinterfaces optional) , (factorySpecification optional) , ('{' asParser) , (interfaceMemberDefinition star) , ('}' asParser)
   1.177 +	^(TokenParser for:#interface) , identifier , (typeParameters optional) , (superinterfaces optional) , (factorySpecification optional) , (TokenParser for:${) , (interfaceMemberDefinition star) , (TokenParser for:$})
   1.178  !
   1.179  
   1.180  interfaceMemberDefinition
   1.181  
   1.182 -	^ ((TokenParser for:#static) , (TokenParser for:#final) , (type optional) , initializedIdentifierList , (';' asParser))
   1.183 -	/ (functionDeclaration , (';' asParser))
   1.184 -	/ (constantConstructorDeclaration , (';' asParser))
   1.185 -	/ (namedConstructorDeclaration , (';' asParser))
   1.186 -	/ (specialSignatureDefinition , (';' asParser))
   1.187 -	/ (variableDeclaration , (';' asParser))
   1.188 +	^ ((TokenParser for:#static) , (TokenParser for:#final) , (type optional) , initializedIdentifierList , (TokenParser for:$;))
   1.189 +	/ (functionDeclaration , (TokenParser for:$;))
   1.190 +	/ (constantConstructorDeclaration , (TokenParser for:$;))
   1.191 +	/ (namedConstructorDeclaration , (TokenParser for:$;))
   1.192 +	/ (specialSignatureDefinition , (TokenParser for:$;))
   1.193 +	/ (variableDeclaration , (TokenParser for:$;))
   1.194  	
   1.195  !
   1.196  
   1.197 @@ -522,9 +525,9 @@
   1.198  
   1.199  iterationStatement
   1.200  
   1.201 -	^ ((TokenParser for:#while) , ('(' asParser) , constantExpression , (')' asParser) , statement)
   1.202 -	/ ((TokenParser for:#do) , statement , (TokenParser for:#while) , ('(' asParser) , constantExpression , (')' asParser) , (';' asParser))
   1.203 -	/ ((TokenParser for:#for) , ('(' asParser) , forLoopParts , (')' asParser) , statement)
   1.204 +	^ ((TokenParser for:#while) , (TokenParser for:$() , constantExpression , (TokenParser for:$)) , statement)
   1.205 +	/ ((TokenParser for:#do) , statement , (TokenParser for:#while) , (TokenParser for:$() , constantExpression , (TokenParser for:$)) , (TokenParser for:$;))
   1.206 +	/ ((TokenParser for:#for) , (TokenParser for:$() , forLoopParts , (TokenParser for:$)) , statement)
   1.207  	
   1.208  !
   1.209  
   1.210 @@ -540,7 +543,7 @@
   1.211  
   1.212  libraryDefinition
   1.213  
   1.214 -	^(TokenParser for:#library) , ('{' asParser) , libraryBody , ('}' asParser)
   1.215 +	^(TokenParser for:#library) , (TokenParser for:${) , libraryBody , (TokenParser for:$})
   1.216  !
   1.217  
   1.218  libraryImport
   1.219 @@ -570,10 +573,11 @@
   1.220          ^ (TokenParser for: #null)
   1.221          / (TokenParser for: #true)
   1.222          / (TokenParser for: #false)
   1.223 -        / (TokenParser for: #number)
   1.224 +        / (TokenParser for: #Integer)
   1.225 +        / (TokenParser for: #Float)
   1.226          / (TokenParser for:#string)
   1.227  
   1.228 -    "Modified: / 11-01-2013 / 10:08:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   1.229 +    "Modified: / 11-01-2013 / 15:17:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   1.230  !
   1.231  
   1.232  logicalAndExpression
   1.233 @@ -588,7 +592,7 @@
   1.234  
   1.235  mapLiteral
   1.236  
   1.237 -	^('{' asParser) , ((mapLiteralEntry , (((',' asParser) , mapLiteralEntry) star) , ((',' asParser) optional)) optional) , ('}' asParser)
   1.238 +	^(TokenParser for:${) , ((mapLiteralEntry , (((',' asParser) , mapLiteralEntry) star) , ((',' asParser) optional)) optional) , (TokenParser for:$})
   1.239  !
   1.240  
   1.241  mapLiteralEntry
   1.242 @@ -647,16 +651,16 @@
   1.243  nonLabelledStatement
   1.244  
   1.245          ^ block
   1.246 -        / (initializedVariableDeclaration , (';' asParser))
   1.247 +        / (initializedVariableDeclaration , (TokenParser for:$;))
   1.248          / iterationStatement
   1.249          / selectionStatement
   1.250          / tryStatement
   1.251 -        / ((TokenParser for: #break) , (identifier optional) , (';' asParser))
   1.252 -        / ((TokenParser for: #continue) , (identifier optional) , (';' asParser))
   1.253 -        / ((TokenParser for: #return) , (constantExpression optional) , (';' asParser))
   1.254 -        / ((TokenParser for: #throw) , (constantExpression optional) , (';' asParser))
   1.255 -        / ((constantExpression optional) , (';' asParser))
   1.256 -        / ((TokenParser for: #assert) , ('(' asParser) , conditionalExpression , (')' asParser) , (';' asParser))
   1.257 +        / ((TokenParser for: #break) , (identifier optional) , (TokenParser for:$;))
   1.258 +        / ((TokenParser for: #continue) , (identifier optional) , (TokenParser for:$;))
   1.259 +        / ((TokenParser for: #return) , (constantExpression optional) , (TokenParser for:$;))
   1.260 +        / ((TokenParser for: #throw) , (constantExpression optional) , (TokenParser for:$;))
   1.261 +        / ((constantExpression optional) , (TokenParser for:$;))
   1.262 +        / ((TokenParser for: #assert) , (TokenParser for:$() , conditionalExpression , (TokenParser for:$)) , (TokenParser for:$;))
   1.263          / (functionDeclaration , functionBody)
   1.264  
   1.265      "Modified: / 11-01-2013 / 10:09:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   1.266 @@ -761,8 +765,8 @@
   1.267  
   1.268  selectionStatement
   1.269  
   1.270 -        ^ ((TokenParser for: #if) , ('(' asParser) , constantExpression , (')' asParser) , statement , (((TokenParser for: #else) , statement) optional))
   1.271 -        / ((TokenParser for: #switch) , ('(' asParser) , constantExpression , (')' asParser) , ('{' asParser) , (switchCase star) , (defaultCase optional) , ('}' asParser))
   1.272 +        ^ ((TokenParser for: #if) , (TokenParser for:$() , constantExpression , (TokenParser for:$)) , statement , (((TokenParser for: #else) , statement) optional))
   1.273 +        / ((TokenParser for: #switch) , (TokenParser for:$() , constantExpression , (TokenParser for:$)) , (TokenParser for:${) , (switchCase star) , (defaultCase optional) , (TokenParser for:$}))
   1.274  
   1.275      "Modified: / 11-01-2013 / 10:10:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   1.276  !
   1.277 @@ -863,8 +867,8 @@
   1.278  	/ functionTypeAlias
   1.279  	/ (functionDeclaration , functionBodyOrNative)
   1.280  	/ ((returnType optional) , getOrSet , identifier , formalParameterList , functionBodyOrNative)
   1.281 -	/ ((TokenParser for:#final) , (type optional) , staticFinalDeclarationList , (';' asParser))
   1.282 -	/ (constInitializedVariableDeclaration , (';' asParser))
   1.283 +	/ ((TokenParser for:#final) , (type optional) , staticFinalDeclarationList , (TokenParser for:$;))
   1.284 +	/ (constInitializedVariableDeclaration , (TokenParser for:$;))
   1.285  	
   1.286  !
   1.287  
     2.1 --- a/compiler/Dart__ParserTests.st	Fri Jan 11 13:43:38 2013 +0000
     2.2 +++ b/compiler/Dart__ParserTests.st	Fri Jan 11 15:53:03 2013 +0000
     2.3 @@ -28,12 +28,68 @@
     2.4      "Modified: / 11-01-2013 / 13:28:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     2.5  !
     2.6  
     2.7 -parse: aString rule: aSymbol 
     2.8 +parse: aString rule: aSymbol
     2.9 +        | production |
    2.10 +        production := self parserInstance.
    2.11 +        aSymbol = #start ifFalse: [ 
    2.12 +                production := production productionAt: aSymbol.
    2.13 +                production := production , (Dart::Parser::TokenParser for: #EOF).
    2.14 +        ].
    2.15  
    2.16 -    ^super parse: (Dart::Scanner for: aString) rule: aSymbol
    2.17 +        result := production parse: (Dart::Scanner for: aString).
    2.18 +        self 
    2.19 +            assert: result isPetitFailure not
    2.20 +            description: 'Unable to parse ' , aString printString.
    2.21 +
    2.22 +        ^ result
    2.23  
    2.24      "Created: / 14-03-2012 / 22:51:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    2.25 -    "Modified: / 11-01-2013 / 13:29:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    2.26 +    "Modified: / 11-01-2013 / 15:35:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    2.27 +! !
    2.28 +
    2.29 +!ParserTests methodsFor:'tests - expressions'!
    2.30 +
    2.31 +test_expression_01
    2.32 +
    2.33 +    self parse:'1 + 1' rule: #expression
    2.34 +
    2.35 +    "Created: / 11-01-2013 / 15:12:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    2.36 +!
    2.37 +
    2.38 +test_expression_02
    2.39 +
    2.40 +    self parse:'a.foo()' rule: #expression
    2.41 +
    2.42 +    "Created: / 11-01-2013 / 15:19:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    2.43 +!
    2.44 +
    2.45 +test_expression_04
    2.46 +
    2.47 +    self parse:'new Foo()' rule: #expression
    2.48 +
    2.49 +    "Created: / 11-01-2013 / 15:38:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    2.50 +! !
    2.51 +
    2.52 +!ParserTests methodsFor:'tests - literals'!
    2.53 +
    2.54 +test_literal_01
    2.55 +
    2.56 +    self parse: '1' rule: #literal.
    2.57 +    self parse: '1.0' rule: #literal.
    2.58 +    self parse: 'true' rule: #literal.
    2.59 +    self parse: 'false' rule: #literal.
    2.60 +    self parse: 'null' rule: #literal.
    2.61 +
    2.62 +    "Created: / 11-01-2013 / 15:13:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    2.63 +! !
    2.64 +
    2.65 +!ParserTests methodsFor:'tests - misc'!
    2.66 +
    2.67 +test_misc_01
    2.68 +
    2.69 +    self parse:'=' rule: #assignmentOperator
    2.70 +
    2.71 +    "Created: / 11-01-2013 / 15:49:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    2.72  ! !
    2.73  
    2.74  !ParserTests methodsFor:'tests - smoke'!
    2.75 @@ -55,7 +111,7 @@
    2.76  !
    2.77  
    2.78  test_smoke_02
    2.79 -    self parse: 'import ''dart:html'';
    2.80 +    self parse: '
    2.81  
    2.82  void main() {
    2.83      var a = 1 + 1;
    2.84 @@ -63,6 +119,7 @@
    2.85  }'
    2.86  
    2.87      "Created: / 11-01-2013 / 13:30:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    2.88 +    "Modified: / 11-01-2013 / 15:07:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    2.89  !
    2.90  
    2.91  test_smoke_03
    2.92 @@ -83,6 +140,22 @@
    2.93      "Created: / 11-01-2013 / 13:34:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    2.94  ! !
    2.95  
    2.96 +!ParserTests methodsFor:'tests - statements'!
    2.97 +
    2.98 +test_statement_01
    2.99 +
   2.100 +    self parse:'a = 1;' rule: #statement
   2.101 +
   2.102 +    "Created: / 11-01-2013 / 15:40:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   2.103 +!
   2.104 +
   2.105 +test_statement_02
   2.106 +
   2.107 +    self parse:'return 1;' rule: #statement
   2.108 +
   2.109 +    "Created: / 11-01-2013 / 15:44:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   2.110 +! !
   2.111 +
   2.112  !ParserTests class methodsFor:'documentation'!
   2.113  
   2.114  version_HG
     3.1 --- a/compiler/Dart__ScannerTests.st	Fri Jan 11 13:43:38 2013 +0000
     3.2 +++ b/compiler/Dart__ScannerTests.st	Fri Jan 11 15:53:03 2013 +0000
     3.3 @@ -19,6 +19,15 @@
     3.4              = #(#import #String $; #void #identifier $( $) ${ $} )
     3.5  
     3.6      "Created: / 11-01-2013 / 12:53:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     3.7 +!
     3.8 +
     3.9 +test_02
    3.10 +
    3.11 +    self assert:
    3.12 +        (Dart::Scanner scan: 'a |= 1') asArray
    3.13 +            = #()
    3.14 +
    3.15 +    "Created: / 11-01-2013 / 15:46:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    3.16  ! !
    3.17  
    3.18  !ScannerTests class methodsFor:'documentation'!
     4.1 --- a/compiler/compiler.rc	Fri Jan 11 13:43:38 2013 +0000
     4.2 +++ b/compiler/compiler.rc	Fri Jan 11 15:53:03 2013 +0000
     4.3 @@ -25,7 +25,7 @@
     4.4        VALUE "LegalCopyright", "My CopyRight or CopyLeft\0"
     4.5        VALUE "ProductName", "ProductName\0"
     4.6        VALUE "ProductVersion", "6.2.3.0\0"
     4.7 -      VALUE "ProductDate", "Fri, 11 Jan 2013 13:43:14 GMT\0"
     4.8 +      VALUE "ProductDate", "Fri, 11 Jan 2013 15:52:43 GMT\0"
     4.9      END
    4.10  
    4.11    END