[java2python] r165 committed - removes selector and grammar. dumb idea.

1 view
Skip to first unread message

codesite...@google.com

unread,
Jul 18, 2010, 4:57:24 AM7/18/10
to java2pyth...@googlegroups.com
Revision: 165
Author: troy.melhase
Date: Sun Jul 18 01:57:03 2010
Log: removes selector and grammar. dumb idea.
http://code.google.com/p/java2python/source/detail?r=165

Deleted:
/branches/0.5/java2python/lang/Selector.g
Modified:
/branches/0.5/java2python/compiler/transformer.py
/branches/0.5/java2python/lang/Makefile

=======================================
--- /branches/0.5/java2python/lang/Selector.g Sat Jul 17 04:01:55 2010
+++ /dev/null
@@ -1,112 +0,0 @@
-grammar Selector;
-
-
-options {
- backtrack=true;
- memoize=true;
- language=Python;
- output=AST;
- ASTLabelType=CommonTree;
-}
-
-tokens {
-COMMA = ',' ;
-DQUOTE = '"' ;
-EQ = '=' ;
-GT = '>' ;
-LSQUARE = '[' ;
-PLUS = '+' ;
-RSQUARE = ']' ;
-STAR = '*' ;
-
-
-NTH;
-MATCH;
-MATCH_CHILD;
-MATCH_DESCEND;
-MATCH_NTH;
-MATCH_OP;
-MATCH_SIBLING;
-MATCH_STAR;
-MATCH_TEXT;
-MATCH_TYPE;
-OP;
-SELECTOR;
-TEXT;
-}
-
-
-selector
- : expression+
- -> ^(SELECTOR expression+)
- ;
-
-
-expression
- : primary
- -> ^(primary)
- | primary optail
- -> ^(MATCH_OP primary optail)
- | primary subtail
- -> ^(MATCH_NTH primary subtail)
- ;
-
-
-primary
- : STAR -> ^(MATCH_STAR[$STAR])
- | TYPE -> ^(MATCH_TYPE[$TYPE])
- ;
-
-
-optail
- : (GT expression*)
- -> ^(OP['>'] expression*)
- | (PLUS expression*)
- -> ^(OP['+'] expression*)
- ;
-
-
-subtail
- : LSQUARE index RSQUARE expression*
- -> ^(NTH[$index.text] expression*)
- | LSQUARE text RSQUARE expression*
- -> ^(TEXT[$text.text] expression*)
- ;
-
-
-index : INDEX;
-text : LITERAL;
-
-
-// lexer
-
-
-LLETTERS : ('a'..'z');
-ULETTERS : ('A'..'Z');
-HASH : '#';
-USCORE : '_';
-
-
-fragment TYPE_START : ULETTERS+ ;
-fragment TYPE_PART : TYPE_START | USCORE ;
-TYPE : TYPE_START (TYPE_PART)* ;
-LITERAL : '"' ( ESCAPE_SEQUENCE | ~('\\'|'"') )* '"' ;
-
-fragment
-ESCAPE_SEQUENCE
- : '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
- | UNICODE_ESCAPE
- | OCTAL_ESCAPE
- ;
-
-fragment
-OCTAL_ESCAPE
- : '\\' ('0'..'3') ('0'..'7') ('0'..'7')
- | '\\' ('0'..'7') ('0'..'7')
- | '\\' ('0'..'7')
- ;
-
-fragment UNICODE_ESCAPE : '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT
HEX_DIGIT ;
-fragment HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;
-INDEX : ('0' | '1'..'9' '0'..'9'*);
-WS : (' '|'\r'|'\t'|'\u000C'|'\n') { $channel = HIDDEN };
=======================================
--- /branches/0.5/java2python/compiler/transformer.py Sat Jul 17 04:01:55
2010
+++ /branches/0.5/java2python/compiler/transformer.py Sun Jul 18 01:57:03
2010
@@ -19,8 +19,6 @@
##
# Configuration-based tree transformer.
from java2python.lang import tokens
-from java2python.lang import SelectorLexer, SelectorParser
-

from antlr3 import ANTLRStringStream, CommonTokenStream, Lexer, Parser
from antlr3.tree import CommonTreeAdaptor, CommonTree
@@ -28,15 +26,7 @@


def parseSelector(text):
- stream = ANTLRStringStream(text)
- lexer = SelectorLexer.SelectorLexer(stream)
- tokenStream = CommonTokenStream(lexer)
- parser = SelectorParser.SelectorParser(tokenStream)
- val = parser.selector()
- return [val.tree] #.children
- #return [val.tree] + val.tree.children
-
-## mini selector language?
+ return

s1 = "METHOD_CALL DOT DOT (IDENT IDENT)"
s1 = [tokens.METHOD_CALL, tokens.DOT, tokens.DOT, []]
@@ -90,18 +80,6 @@
print gchild.text, gchild.children


-
-def selectorTokenNames():
- mapping = {}
- for name in SelectorParser.tokenNames:
- value = getattr(SelectorParser, name, None)
- if value:
- mapping[value] = name
- return mapping
-
-selectorTokenNames = selectorTokenNames()
-
-
def selectorDump(root, i=0):
token = root.token
typeName = selectorTokenNames[token.type]
@@ -124,42 +102,17 @@
#tree.dump(sys.stdout)


- print '0:'
- for tree in parseSelector('*'):
- selectorDump(tree)
- print
-
- print '1:'
- for tree in parseSelector('FU'):
- selectorDump(tree)
- print
-
- for tree in parseSelector('FU BAR BAZ'):
- print '2:'
- selectorDump(tree)
- print
-
-
- for tree in parseSelector('PAR > CHILD'):
- print '4:'
- selectorDump(tree)
- print
-
-
- for tree in parseSelector('AA BB[1] CC[2]'):
- print '6:'
- selectorDump(tree)
- print
-
-
- for tree in parseSelector('FIRST["r1"] SEC["r2"] ZZ[333] * YY'):
- print '7:'
- selectorDump(tree)
- print
-
-
-
- for tree in (): # parseSelector('DD["zz"] BB["text what"] ZZ[4] >
AA[3] + YY[33]'):
- print '8:'
- selectorDump(tree)
- print
+ selectors = [
+ '(*)',
+ '(FU)',
+ '(FU (BAR (BAZ)))',
+ '(PARENT (CHILD))',
+ '(APAR (ARRAY[1] (ARRAY[2])))',
+# 'FIRST["r1"] SEC["r2"] THIRD["r3"] YY[4] * ZZ',
+# 'FIRST["r1"] > SEC["r2"] THIRD["r3"]',
+ ]
+ for index, selector in enumerate(selectors):
+ print '{0}: "{1}"'.format(index, selector)
+ for tree in parseSelector(selector):
+ selectorDump(tree)
+ print
=======================================
--- /branches/0.5/java2python/lang/Makefile Sat Jul 17 04:01:55 2010
+++ /branches/0.5/java2python/lang/Makefile Sun Jul 18 01:57:03 2010
@@ -1,7 +1,7 @@
.PHONY: all clean
.SILENT: clean

-all: JavaParser.py JavaLexer.py SelectorParser.py SelectorLexer.py
+all: JavaParser.py JavaLexer.py


JavaParser.py: Java.g
@@ -12,13 +12,6 @@
antlr3 Java.g


-SelectorParser.py: Selector.g
- antlr3 Selector.g
-
-SelectorLexer.py: Selector.g
- antlr3 Selector.g
-
-
clean:
rm -f *.pyo
rm -f *.pyc

Reply all
Reply to author
Forward
0 new messages