JavaSyntaxError raised for unknown reasons
chenyangyc opened this issue · 5 comments
My code was like this and got a JavaSyntaxError and I wonder why this happened
code = "protected void addMoveIfValid(List<Integer[]> validMoves,int dst_x,int dst_y) throws Exception{"
"if(isValidMove(loc_x,loc_y,dst_x,dst_y)&&board.causesCheck(this,dst_x,dst_y)){validMoves.add(new "
"Integer{loc_x,loc_y,dst_x,dst_y});}} "
tokens = javalang.tokenizer.tokenize(code)
parser = javalang.parser.Parser(tokens)
code = parser.parse_member_declaration()
File "/Users/yangchen/Desktop/TransASTNN/predict_pipeline.py", line 282, in parse_source
code = parser.parse_member_declaration()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 801, in parse_member_declaration
member = self.parse_void_method_declarator_rest()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 905, in parse_void_method_declarator_rest
body = self.parse_block()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1274, in parse_block
statement = self.parse_block_statement()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1339, in parse_block_statement
return self.parse_statement()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1385, in parse_statement
then = self.parse_statement()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1368, in parse_statement
block = self.parse_block()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1274, in parse_block
statement = self.parse_block_statement()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1349, in parse_block_statement
return self.parse_statement()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1520, in parse_statement
expression = self.parse_expression()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1752, in parse_expression
expressionl = self.parse_expressionl()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1767, in parse_expressionl
expression_2 = self.parse_expression_2()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1793, in parse_expression_2
expression_3 = self.parse_expression_3()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1849, in parse_expression_3
primary = self.parse_primary()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1975, in parse_primary
identifier_suffix = self.parse_identifier_suffix()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 2163, in parse_identifier_suffix
arguments = self.parse_arguments()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 2025, in parse_arguments
expression = self.parse_expression()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1752, in parse_expression
expressionl = self.parse_expressionl()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1767, in parse_expressionl
expression_2 = self.parse_expression_2()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1793, in parse_expression_2
expression_3 = self.parse_expression_3()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1849, in parse_expression_3
primary = self.parse_primary()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1951, in parse_primary
return self.parse_creator()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 2099, in parse_creator
arguments, body = self.parse_class_creator_rest()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 2126, in parse_class_creator_rest
arguments = self.parse_arguments()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 2019, in parse_arguments
self.accept('(')
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 131, in accept
self.illegal("Expected {}".format(accept))
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 119, in illegal
raise JavaSyntaxError(description, at)
The syntax error is here,
new Integer{loc_x,loc_y,dst_x,dst_y}
I suspect what was intended is,
new Integer[]{loc_x,loc_y,dst_x,dst_y}
Ohhhhh!Thanks!
Thank u soooooooooooo much for ur help last time~
I am back again :-)
This time I believe there are no syntax errors in the code snippet. And I wonder why this happened again :(
The code snippet is:
public void test(){
swtich (c[pos.getIndex()]){
case QUOTE :
next(pos);
return appendTo==null?null:appendTo.append(c,lastHold,pos.getIndex()-lastHold);
default :
next(pos);
}
}
My code is like this:
tokens = javalang.tokenizer.tokenize('public void test(){
swtich (c[pos.getIndex()]){ \
case QUOTE : \
next(pos); \
return appendTo==null?null:appendTo.append(c,lastHold,pos.getIndex()-lastHold); \
default : \
next(pos); \
}
}')
parser = javalang.parser.Parser(tokens)
code = parser.parse_member_declaration()
And the JavaSyntaxError raised is this:
Traceback (most recent call last):
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1345, in parse_block_statement
statement = self.parse_local_variable_declaration_statement()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1355, in parse_local_variable_declaration_statement
declarators = self.parse_variable_declarators()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1207, in parse_variable_declarators
declarator = self.parse_variable_declarator()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1217, in parse_variable_declarator
identifier = self.parse_identifier()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 232, in parse_identifier
return self.accept(Identifier)
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 133, in accept
self.illegal("Expected %s" % (accept.__name__,))
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 119, in illegal
raise JavaSyntaxError(description, at)
javalang.parser.JavaSyntaxError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/yangchen/Desktop/TransASTNN/predict_pipeline.py", line 251, in <module>
ppl.run()
File "/Users/yangchen/Desktop/TransASTNN/predict_pipeline.py", line 213, in run
self.parse_source(output_file='ast.pkl', option='existing')
File "/Users/yangchen/Desktop/TransASTNN/predict_pipeline.py", line 47, in parse_source
code = parser.parse_member_declaration()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 801, in parse_member_declaration
member = self.parse_void_method_declarator_rest()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 905, in parse_void_method_declarator_rest
body = self.parse_block()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1274, in parse_block
statement = self.parse_block_statement()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1349, in parse_block_statement
return self.parse_statement()
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 1521, in parse_statement
self.accept(';')
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 131, in accept
self.illegal("Expected '%s'" % (accept,))
File "/Users/yangchen/opt/anaconda3/envs/debug/lib/python3.6/site-packages/javalang/parser.py", line 119, in illegal
raise JavaSyntaxError(description, at)
javalang.parser.JavaSyntaxError
Hello,
After trying to parse the file "apache/apache-ant-1.10.9/src/main/org/apache/tools/ant/DirectoryScanner.java"
I got these lines below. (I tried to debug but I couldn't find the problem. Could you tell what is wrong?)
===============
File "d:\dev\python3\lib\site-packages\javalang\parse.py", line 53, in parse
return parser.parse()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 110, in parse
return self.parse_compilation_unit()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 303, in parse_compilation_unit
type_declaration = self.parse_type_declaration()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 348, in parse_type_declaration
return self.parse_class_or_interface_declaration()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 360, in parse_class_or_interface_declaration
type_declaration = self.parse_normal_class_declaration()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 403, in parse_normal_class_declaration
body = self.parse_class_body()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 780, in parse_class_body
declaration = self.parse_class_body_declaration()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 803, in parse_class_body_declaration
return self.parse_member_declaration()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 814, in parse_member_declaration
member = self.parse_void_method_declarator_rest()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 921, in parse_void_method_declarator_rest
body = self.parse_block()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1290, in parse_block
statement = self.parse_block_statement()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1355, in parse_block_statement
return self.parse_statement()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1410, in parse_statement
else_statement = self.parse_statement()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1384, in parse_statement
block = self.parse_block()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1290, in parse_block
statement = self.parse_block_statement()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1355, in parse_block_statement
return self.parse_statement()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1557, in parse_statement
expression = self.parse_expression()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1795, in parse_expression
assignment_expression = self.parse_expression()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1789, in parse_expression
expressionl = self.parse_expressionl()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1804, in parse_expressionl
expression_2 = self.parse_expression_2()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1830, in parse_expression_2
expression_3 = self.parse_expression_3()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1893, in parse_expression_3
selector = self.parse_selector()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 2276, in parse_selector
arguments = self.parse_arguments()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 2062, in parse_arguments
expression = self.parse_expression()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1789, in parse_expression
expressionl = self.parse_expressionl()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1804, in parse_expressionl
expression_2 = self.parse_expression_2()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1830, in parse_expression_2
expression_3 = self.parse_expression_3()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1886, in parse_expression_3
primary = self.parse_primary()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 2012, in parse_primary
identifier_suffix = self.parse_identifier_suffix()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 2196, in parse_identifier_suffix
self.accept('.', 'class')
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 131, in accept
self.illegal("Expected '%s'" % (accept,))
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 119, in illegal
raise JavaSyntaxError(description, at)
Hello, After trying to parse the file "apache/apache-ant-1.10.9/src/main/org/apache/tools/ant/DirectoryScanner.java" I got these lines below. (I tried to debug but I couldn't find the problem. Could you tell what is wrong?)
===============
File "d:\dev\python3\lib\site-packages\javalang\parse.py", line 53, in parse return parser.parse()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 110, in parse return self.parse_compilation_unit()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 303, in parse_compilation_unit type_declaration = self.parse_type_declaration()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 348, in parse_type_declaration return self.parse_class_or_interface_declaration()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 360, in parse_class_or_interface_declaration type_declaration = self.parse_normal_class_declaration()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 403, in parse_normal_class_declaration body = self.parse_class_body()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 780, in parse_class_body declaration = self.parse_class_body_declaration()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 803, in parse_class_body_declaration return self.parse_member_declaration()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 814, in parse_member_declaration member = self.parse_void_method_declarator_rest()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 921, in parse_void_method_declarator_rest body = self.parse_block()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1290, in parse_block statement = self.parse_block_statement()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1355, in parse_block_statement return self.parse_statement()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1410, in parse_statement else_statement = self.parse_statement()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1384, in parse_statement block = self.parse_block()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1290, in parse_block statement = self.parse_block_statement()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1355, in parse_block_statement return self.parse_statement()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1557, in parse_statement expression = self.parse_expression()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1795, in parse_expression assignment_expression = self.parse_expression()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1789, in parse_expression expressionl = self.parse_expressionl()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1804, in parse_expressionl expression_2 = self.parse_expression_2()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1830, in parse_expression_2 expression_3 = self.parse_expression_3()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1893, in parse_expression_3 selector = self.parse_selector()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 2276, in parse_selector arguments = self.parse_arguments()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 2062, in parse_arguments expression = self.parse_expression()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1789, in parse_expression expressionl = self.parse_expressionl()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1804, in parse_expressionl expression_2 = self.parse_expression_2()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1830, in parse_expression_2 expression_3 = self.parse_expression_3()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 1886, in parse_expression_3 primary = self.parse_primary()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 2012, in parse_primary identifier_suffix = self.parse_identifier_suffix()
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 2196, in parse_identifier_suffix self.accept('.', 'class')
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 131, in accept self.illegal("Expected '%s'" % (accept,))
File "d:\dev\python3\lib\site-packages\javalang\parser.py", line 119, in illegal raise JavaSyntaxError(description, at)
I face the same problem.