--- a/src/tools/JavaParserI.st Sat Mar 10 21:32:25 2012 +0000
+++ b/src/tools/JavaParserI.st Sun Mar 11 15:43:39 2012 +0000
@@ -16,7 +16,7 @@
exponentPart floatTypeSuffix exponentIndicator signedInteger sign
hexSignificand binaryExponent binaryExponentIndicator
escapeSequence singleCharacter stringCharacters stringCharacter
- octalEscape zeroToThree input operators separators'
+ octalEscape zeroToThree input operators separators block'
classVariableNames:''
poolDictionaries:''
category:'Languages-Java-Parser'
@@ -29,6 +29,13 @@
privateIn:JavaParserI
!
+JavaParserI::SubParser subclass:#MultiLineCommentParser
+ instanceVariableNames:''
+ classVariableNames:''
+ poolDictionaries:''
+ privateIn:JavaParserI
+!
+
JavaParserI::SubParser subclass:#SingleLineCommentParser
instanceVariableNames:''
classVariableNames:''
@@ -36,8 +43,8 @@
privateIn:JavaParserI
!
-JavaParserI::SubParser subclass:#MultiLineCommentParser
- instanceVariableNames:''
+JavaParserI::SubParser subclass:#BlockParser
+ instanceVariableNames:'openBlockChar closeBlockChar innerBlockCount'
classVariableNames:''
poolDictionaries:''
privateIn:JavaParserI
@@ -93,6 +100,15 @@
^ input end
! !
+!JavaParserI methodsFor:'grammar-blocks'!
+
+block
+ "Do no parse content of the block"
+ ^(BlockParser for: self) trim
+
+ "Created: / 11-03-2012 / 13:20:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
!JavaParserI methodsFor:'grammar-comments'!
charactersInLine
@@ -197,6 +213,118 @@
!JavaParserI methodsFor:'grammar-keywords'!
+abstractKW
+ ^ 'abstract' asParser trim
+!
+
+assertKW
+ ^ 'assert' asParser trim
+!
+
+booleanKW
+ ^ 'boolean' asParser trim
+!
+
+breakKW
+ ^ 'break' asParser trim
+!
+
+byteKW
+ ^ 'byte' asParser trim
+!
+
+caseKW
+ ^ 'case' asParser trim
+!
+
+catchKW
+ ^ 'catch' asParser trim
+!
+
+charKW
+ ^ 'char' asParser trim
+!
+
+classKW
+ ^ 'class' asParser trim
+!
+
+constKW
+ ^ 'const' asParser trim
+!
+
+continueKW
+ ^ 'continue' asParser trim
+!
+
+defaultKW
+ ^ 'default' asParser trim
+!
+
+doKW
+ ^ 'do' asParser trim
+!
+
+doubleKW
+ ^ 'double' asParser trim
+!
+
+elseKW
+ ^ 'else' asParser trim
+!
+
+enumKW
+ ^ 'enum' asParser trim
+!
+
+extendsKW
+ ^ 'extends' asParser trim
+!
+
+finalKW
+ ^ 'final' asParser trim
+!
+
+finallyKW
+ ^ 'finally' asParser trim
+!
+
+floatKW
+ ^ 'float' asParser trim
+!
+
+forKW
+ ^ 'for' asParser trim
+!
+
+gotoKW
+ ^ 'goto' asParser trim
+!
+
+ifKW
+ ^ 'if' asParser trim
+!
+
+implementsKW
+ ^ 'implements' asParser trim
+!
+
+importKW
+ ^ 'import' asParser trim
+!
+
+instanceofKW
+ ^ 'instanceof' asParser trim
+!
+
+intKW
+ ^ 'int' asParser trim
+!
+
+interfaceKW
+ ^ 'interface' asParser trim
+!
+
keyword
| keywordParsers keywordParser |
@@ -217,6 +345,18 @@
"Modified: / 09-03-2012 / 20:48:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+longKW
+ ^ 'long' asParser trim
+!
+
+nativeKW
+ ^ 'native' asParser trim
+!
+
+newKW
+ ^ 'new' asParser trim
+!
+
operator
| operatorParsers operatorParser |
@@ -235,6 +375,82 @@
^ "self asToken: "operatorParser
"Modified: / 09-03-2012 / 20:50:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+packageKW
+ ^ 'package' asParser trim
+!
+
+privateKW
+ ^ 'private' asParser trim
+!
+
+protectedKW
+ ^ 'protected' asParser trim
+!
+
+publicKW
+ ^ 'public' asParser trim
+!
+
+returnKW
+ ^ 'return' asParser trim
+!
+
+shortKW
+ ^ 'short' asParser trim
+!
+
+staticKW
+ ^ 'static' asParser trim
+!
+
+strictfpKW
+ ^ 'strictfp' asParser trim
+!
+
+superKW
+ ^ 'super' asParser trim
+!
+
+switchKW
+ ^ 'switch' asParser trim
+!
+
+synchronizedKW
+ ^ 'synchronized' asParser trim
+!
+
+thisKW
+ ^ 'this' asParser trim
+!
+
+throwKW
+ ^ 'throw' asParser trim
+!
+
+throwsKW
+ ^ 'throws' asParser trim
+!
+
+transientKW
+ ^ 'transient' asParser trim
+!
+
+tryKW
+ ^ 'try' asParser trim
+!
+
+voidKW
+ ^ 'void' asParser trim
+!
+
+volatileKW
+ ^ 'volatile' asParser trim
+!
+
+whileKW
+ ^ 'while' asParser trim
! !
!JavaParserI methodsFor:'grammar-lineTerminators'!
@@ -600,16 +816,17 @@
!JavaParserI methodsFor:'utility'!
-asToken: aParser
+asToken:aParser
+ ^aParser
- ^aParser "javaToken"
-
- "Modified: / 09-03-2012 / 20:50:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Created: / 11-03-2012 / 08:43:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
emptySquaredParenthesis
- ^ self asToken: (((self tokenFor: '['), (self tokenFor: ']')))
+ ^ '[' asParser trim , ']' asParser trim
+
+ "Created: / 11-03-2012 / 00:02:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
tokenFor: aString
@@ -655,32 +872,6 @@
masterParser := aJavaPetitParser.
! !
-!JavaParserI::SingleLineCommentParser methodsFor:'parsing'!
-
-parseOn: aStream
- | literal wasStar start end b|
- wasStar := false.
- start := aStream position + 1.
-
- (aStream next: 2) = '//' ifFalse: [
- ^ PPFailure message: '// expected' at: aStream position.
- ].
-
- [literal := aStream next.
- literal = (Character cr) or: [ aStream atEnd ]
- ] whileFalse.
- end := aStream position.
-
- ^(b := self builder) notNil ifTrue:[
- b start: start stop: end line: nil;
- newComment: nil.
- ] ifFalse:[
- nil
- ]
-
- "Modified: / 10-03-2012 / 12:19:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
!JavaParserI::MultiLineCommentParser methodsFor:'parsing'!
buildNodeFrom: start to: end line: line text: text
@@ -728,6 +919,98 @@
^ '/*'
! !
+!JavaParserI::SingleLineCommentParser methodsFor:'parsing'!
+
+parseOn: aStream
+ | literal wasStar start end b|
+ wasStar := false.
+ start := aStream position + 1.
+
+ (aStream next: 2) = '//' ifFalse: [
+ ^ PPFailure message: '// expected' at: aStream position.
+ ].
+
+ [literal := aStream next.
+ literal = (Character cr) or: [ aStream atEnd ]
+ ] whileFalse.
+ end := aStream position.
+
+ ^(b := self builder) notNil ifTrue:[
+ b start: start stop: end line: nil;
+ newComment: nil.
+ ] ifFalse:[
+ nil
+ ]
+
+ "Modified: / 10-03-2012 / 12:19:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!JavaParserI::BlockParser methodsFor:'accessing'!
+
+closeBlockChar: anObject
+ closeBlockChar := anObject
+!
+
+openBlockChar: anObject
+ openBlockChar := anObject
+! !
+
+!JavaParserI::BlockParser methodsFor:'initialization'!
+
+initialize
+ innerBlockCount := 0.
+ openBlockChar := ${.
+ closeBlockChar := $}.
+! !
+
+!JavaParserI::BlockParser methodsFor:'parsing'!
+
+decInnerBlockCount
+ innerBlockCount := innerBlockCount - 1.
+!
+
+incInnerBlockCount
+ innerBlockCount := innerBlockCount + 1.
+!
+
+parseLoop: aStream
+ | literal |
+
+ aStream atEnd ifFalse:
+ [
+ literal := aStream uncheckedPeek.
+ literal = openBlockChar ifTrue: [ self incInnerBlockCount].
+ literal = closeBlockChar ifTrue: [ self decInnerBlockCount].
+ aStream next.
+ ^true
+ ].
+ ^false
+!
+
+parseOn: aStream
+ | literal |
+" self halt.
+"
+ (self parseLoop: aStream) ifFalse:
+ [
+ ^ PPFailure message: 'unexpected end of input' at: aStream position
+ ].
+
+ self zeroBlockCount ifTrue: [ ^ PPFailure message: ('expected ' copyWith: openBlockChar) at: aStream position ].
+
+ [self zeroBlockCount] whileFalse: [
+ (self parseLoop: aStream) ifFalse:
+ [
+ ^ PPFailure message: 'unexpected end of input' at: aStream position
+ ]
+ ].
+ ^ nil.
+!
+
+zeroBlockCount
+ ^ innerBlockCount = 0
+! !
+
!JavaParserI class methodsFor:'documentation'!
version_SVN