Skip to content

Commit 18a5755

Browse files
committed
Fix minor issues in Java Grammar
1 parent 270a7b0 commit 18a5755

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

syncode/parsers/grammars/java.lark

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
11
start: compilation_unit
22

3-
%import common.CNAME
4-
%import common.DIGIT
5-
%import common.WS
6-
7-
%ignore WS
8-
9-
LINE_COMMENT: /\/\/[^\n\r]*/
10-
BLOCK_COMMENT: /\/\*[\s\S]*?\*\//
11-
123
type_parameters: "<" type_parameter ("," type_parameter)* ">"
134
type_parameter: CNAME type_bound?
145
type_bound: "extends" type ("&" type)*
156

16-
%ignore LINE_COMMENT
17-
%ignore BLOCK_COMMENT
18-
197
compilation_unit: package_declaration? import_declarations? type_declarations?
208

219
package_declaration: "package" name ";"
@@ -188,7 +176,7 @@ floating_point_literal: DIGIT+ "." DIGIT+
188176

189177
boolean_literal: "true" | "false"
190178

191-
character_literal: "'" /[^\\'\n\r]/ "'"
179+
character_literal: /'([^'\r\n\\]|\\([btnfr"'\\0-7]|[0-3]?[0-7]{2})|\\u[0-9a-fA-f]{4})'/
192180

193181
string_literal: /".*?"/
194182

@@ -206,8 +194,6 @@ dim_expr: "[" expression "]"
206194

207195
dims: "[" "]"+
208196

209-
210-
211197
field_access: primary "." CNAME | "super" "." CNAME
212198

213199
method_invocation: name "(" argument_list? ")" | primary "." CNAME "(" argument_list? ")" | "super" "." CNAME "(" argument_list? ")"
@@ -289,3 +275,12 @@ reference_type: class_or_interface_type | array_type
289275

290276
array_type: primitive_type dims | name dims | array_type dims
291277

278+
LINE_COMMENT: /\/\/[^\n\r]*/
279+
BLOCK_COMMENT: /\/\*[\s\S]*?\*\//
280+
281+
%import common.CNAME
282+
%import common.DIGIT
283+
%import common.WS
284+
%ignore WS
285+
%ignore LINE_COMMENT
286+
%ignore BLOCK_COMMENT

tests/parser/test_grammar_java.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,4 +388,8 @@ def test_java_parser26(self):
388388
public """
389389
r = inc_parser.get_acceptable_next_terminals(partial_code)
390390
assert AcceptSequence(['CLASS']) in r.accept_sequences
391-
assert r.remainder_state == RemainderState.COMPLETE
391+
assert r.remainder_state == RemainderState.COMPLETE
392+
393+
if __name__ == '__main__':
394+
unittest.main()
395+

0 commit comments

Comments
 (0)