compiler/Dart__Parser.st
changeset 1 46dd2b3b6974
child 2 8fedb5e096fc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/compiler/Dart__Parser.st	Thu Jan 10 13:21:04 2013 +0000
@@ -0,0 +1,65 @@
+"{ Package: 'jv:dart/compiler' }"
+
+"{ NameSpace: Dart }"
+
+PPCompositeParser subclass:#Parser
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Languages-Dart-Parser'
+!
+
+PPParser subclass:#TokenParser
+	instanceVariableNames:'tokenType'
+	classVariableNames:''
+	poolDictionaries:''
+	privateIn:Parser
+!
+
+
+!Parser::TokenParser class methodsFor:'instance creation'!
+
+for: tokenType
+
+    ^self new tokenType: tokenType
+
+    "Created: / 14-03-2012 / 23:10:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!Parser::TokenParser methodsFor:'accessing'!
+
+tokenType
+    ^ tokenType
+!
+
+tokenType:aSymbol
+    tokenType := aSymbol.
+! !
+
+!Parser::TokenParser methodsFor:'parsing'!
+
+parseOn:aJavaScanner
+    "Parse aStream with the receiving parser and answer the parse-result or an instance of PPFailure. 
+    Override this method in subclasses to specify custom parse behavior. Do not call this method from outside, 
+    instead use #parse:."
+
+    | pos |
+
+    pos := aJavaScanner position.
+
+    ^(aJavaScanner nextToken = tokenType) ifTrue:[
+        aJavaScanner token
+    ] ifFalse:[
+        aJavaScanner position: pos.
+        PPFailure message: (tokenType printString , ' token expected (got ', aJavaScanner tokenType , ' {',(aJavaScanner tokenValue ? '<nil>') printString,'})') at: aJavaScanner position
+    ]
+
+    "Modified: / 17-03-2012 / 13:34:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!Parser class methodsFor:'documentation'!
+
+version_HG
+
+    ^ '$Changeset: <not expanded> $'
+! !