Skip to content

Commit bb822b5

Browse files
authored
Merge pull request #217 from structuredllm/fix9
Fix minor issues in Java Grammar
2 parents 270a7b0 + b55a351 commit bb822b5

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Define your own grammar using simple EBNF syntax. Check out our [notebooks direc
4444
| 🔥 Fast grammar-guided generation (as little as 10% generation overhead with Python and Go!) |
4545
| 🤖 Seamlessly work with any HuggingFace Language Model, including Code, Chat, and Instruct models |
4646
| 🖍️ Pass in any CFG in the EBNF format (even large grammars for programming languages like Python and Go!) |
47-
| 📝 Built-in CFGs for **Python, Go, SQL, Math, JSON**, and more! |
47+
| 📝 Built-in CFGs for **Python, Go, Java, SQL, Math, JSON**, and more! |
4848
| 🎲 Sample with any existing decoding strategy (eg. greedy, beam search, nucleus sampling) |
4949

5050

@@ -148,7 +148,7 @@ print(f"SynCode output:\n{output}")
148148
# }
149149
```
150150

151-
Check more examples of using Python, Go, and other grammars in <a href="#-example-usage">Notebooks</a> and a quick example at
151+
Check more examples of using Python, Go, Java and other grammars in <a href="#-example-usage">Notebooks</a> and a quick example at
152152
&nbsp; [<img align="center" src="https://colab.research.google.com/assets/colab-badge.svg" />](https://colab.research.google.com/drive/1rYm8iehx_qYdtgWmqLkmhIjizhUVTb9E?usp=sharing)
153153

154154
#### Instuct-tuned Models

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)