tools/JavaParser.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sat, 24 Aug 2013 17:11:15 +0100
branchdevelopment
changeset 2667 5daa560d20d8
parent 2501 53d731454d43
child 2672 5e4a61287345
permissions -rw-r--r--
More work on Java code partitioner.

"{ Package: 'stx:libjava/tools' }"

JavaParserII subclass:#JavaParser
	instanceVariableNames:'builder'
	classVariableNames:''
	poolDictionaries:''
	category:'Languages-Java-Parser'
!

!JavaParser class methodsFor:'documentation'!

documentation
"
    PetitParser based parser for Java. One may pass in a builder, that
    is called whenever a rule is parsed. Builder can build AST or do
    some analysis. 

    Unfinished.

    [author:]
        Jan Vrany <jan.vrany@fit.cvut.cz>

    [instance variables:]

    [class variables:]

    [see also:]

"
! !

!JavaParser class methodsFor:'accessing'!

namesToIgnore

        ^super namesToIgnore ,
        #(builder)

    "Created: / 03-04-2013 / 23:51:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaParser methodsFor:'accessing'!

builder
    ^ builder
!

builder:aJavaParseNodeBuilder
    builder := aJavaParseNodeBuilder.
! !

!JavaParser methodsFor:'grammar'!

compilationUnit 
        "
        ^ 
        (annotations optional, packageDeclaration) optional , 
        importDeclaration star , 
        typeDeclaration star ,
        (self tokenParserFor:#EOF) end
        "

        ^super compilationUnit ==> [:nodes |
            | pkg |

            pkg := (nodes at:1) notNil ifTrue:[(nodes at:1) second] ifFalse:[nil].
            builder newSourceFile_package: pkg imports: (nodes at:2) types: (nodes at:3)            
        ]

    "Created: / 03-04-2013 / 23:18:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 12-04-2013 / 20:24:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

packageDeclaration 
    "
        ^ (self  packageKW) , qualifiedName , (self tokenFor:';')
    "
    ^super packageDeclaration ==> [:nodes |
        builder newPackageDeclaration: (nodes at:2)
    ]

    "Created: / 03-04-2013 / 23:48:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

typeDeclaration

        ^ ((self tokenFor: ';') ==> nil) / classOrInterfaceDeclaration

    "Created: / 03-04-2013 / 23:58:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaParser methodsFor:'grammar-classes'!

classBody 

    ^ super classBody ==> [:nodes | nodes second reject:[:e|e isNil] ]

    "Created: / 24-08-2013 / 01:40:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

normalClassDeclaration 
    "
        ^ classModifiers , (self  classKW) , self typeNameIdentifier ,
                typeParameters optional,
                jsuper optional,
                interfaces optional ,
                classBody
    "
    ^ super normalClassDeclaration ==> [:nodes|
        builder newClassDeclaration_modifiers: (nodes at:1)
                    name: (nodes at:3)
                    typeParameters: (nodes at:4)
                    superclass: (nodes at:5)
                    interfaces: (nodes at:6)
                    members: (nodes at:7)
    ]

    "Created: / 04-04-2013 / 00:04:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaParser methodsFor:'grammar-classes-method'!

constructorDeclaration

"/        ^ constructorModifiers optional , 
"/           typeParameters optional , 
"/           self constructorNameIdentifier,
"/           formalParameters ,
"/           throws optional , 
"/           block

    ^ super constructorDeclaration ==> [:nodes |
        builder newConstructorDeclaration_modifiers: (nodes at:1)
                    typeParameters: (nodes at: 2)
                        parameters: (nodes at: 4)
                        exceptions: (nodes at: 5)
                              body: (nodes at: 6)
    ]

    "Created: / 24-08-2013 / 01:57:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

methodNotConstructorDeclaration

"/        ^ methodModifiers,
"/           typeParameters optional,
"/           ((self  voidKW) / type),
"/           self methodNameIdentifier,
"/           formalParameters ,
"/           emptySquaredParenthesis star ,
"/           throws optional,
"/           (block / (self tokenFor: ';'))

    ^ super methodNotConstructorDeclaration ==> [:nodes |
        builder newMethodDeclaration_modifiers: (nodes at:1)
                    typeParameters: (nodes at: 2)
                        returnType: (nodes at: 3)
                              name: (nodes at: 4)
                        parameters: (nodes at: 5)
                        exceptions: (nodes at: 7)
                              body: (nodes at: 8)      
    ]

    "Created: / 24-08-2013 / 02:00:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaParser methodsFor:'initialization'!

initialize
    super initialize.
    builder := JavaParseNodeBuilder new.

    "Created: / 03-04-2013 / 23:52:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaParser class methodsFor:'documentation'!

version_CVS
    ^ '$Header: /cvs/stx/stx/libjava/tools/JavaParser.st,v 1.2 2013-02-25 11:15:35 vrany Exp $'
!

version_HG

    ^ '$Changeset: <not expanded> $'
!

version_SVN
    ^ '§Id§'
! !