compiler/Dart__Parser.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 10 Jan 2013 13:21:04 +0000
changeset 1 46dd2b3b6974
child 2 8fedb5e096fc
permissions -rw-r--r--
Initial outline of Dart parser

"{ 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> $'
! !