forked from natural/java2python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
37 lines (30 loc) · 1.26 KB
/
__init__.py
File metadata and controls
37 lines (30 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# java2python.compiler package marker.
#
# This module provides a simpler facade over the rest of the compiler
# subpackage. Client code should use the values in this module
# instead of using directly referencing items within the subpackage.
from java2python.compiler.block import Module
from java2python.lang import Lexer, Parser, StringStream, TokenStream, TreeAdaptor
def buildAST(source):
""" Returns an AST for the given source. """
lexer = Lexer(StringStream(source))
parser = Parser(TokenStream(lexer))
adapter = TreeAdaptor(lexer, parser)
parser.setTreeAdaptor(adapter)
scope = parser.javaSource()
return scope.tree
def buildJavaDocAST(source):
""" Returns an AST for the given javadoc source. """
from java2python.lang.JavaDocLexer import JavaDocLexer
from java2python.lang.JavaDocParser import JavaDocParser
lexer = JavaDocLexer(StringStream(source))
parser = JavaDocParser(TokenStream(lexer))
scope = parser.commentBody()
return scope.tree
def transformAST(tree, config):
""" Walk the tree and apply the transforms in the config. """
for selector, call in config.last('astTransforms', ()):
for node in selector.walk(tree):
call(node, config)