-
-
Notifications
You must be signed in to change notification settings - Fork 446
Make lark.lark parse the same grammar as load_grammar.py, and make grammar.md document it more fully. #1388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
db1a5a5
9493f81
7a2880f
83a374f
fdffb5f
95c5742
200d6b5
0fb28f9
2ec5ef3
e9c026e
9bf7ddf
7f02bd1
4f7a5eb
40576d2
daac65d
5f37365
697841b
654e102
33d7088
0d01fe2
20302ca
ff01d96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,70 @@ | ||
# Lark grammar of Lark's syntax | ||
# Note: Lark is not bootstrapped, its parser is implemented in load_grammar.py | ||
# This grammar matches that one, but does not enforce some rules that it does. | ||
# If you want to enforce those, you can pass the "LarkValidator" over | ||
# the parse tree, like this: | ||
|
||
# from lark import Lark | ||
# from lark.lark_validator import LarkValidator | ||
# | ||
# lark_parser = Lark.open_from_package("lark", "grammars/lark.lark", parser="lalr") | ||
# parse_tree = lark_parser.parse(my_grammar) | ||
# LarkValidator.validate(parse_tree) | ||
|
||
start: (_item? _NL)* _item? | ||
|
||
_item: rule | ||
| token | ||
| statement | ||
|
||
rule: RULE rule_params priority? ":" expansions | ||
token: TOKEN token_params priority? ":" expansions | ||
rule: rule_modifiers RULE rule_params priority ":" expansions | ||
token: TOKEN priority? ":" expansions | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but It's different for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @erezsh If my comment of 2024-06-20 is acceptable, let's resolve this point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think what I meant was that priority can already be an empty rule, so no point in making it optional. |
||
|
||
rule_modifiers: RULE_MODIFIERS? | ||
|
||
rule_params: ["{" RULE ("," RULE)* "}"] | ||
token_params: ["{" TOKEN ("," TOKEN)* "}"] | ||
|
||
priority: "." NUMBER | ||
priority: ("." NUMBER)? | ||
|
||
statement: "%ignore" expansions -> ignore | ||
| "%import" import_path ["->" name] -> import | ||
| "%import" import_path name_list -> multi_import | ||
| "%override" rule -> override_rule | ||
| "%override" (rule | token) -> override | ||
| "%declare" name+ -> declare | ||
| "%extend" (rule | token) -> extend | ||
|
||
!import_path: "."? name ("." name)* | ||
name_list: "(" name ("," name)* ")" | ||
|
||
?expansions: alias (_VBAR alias)* | ||
expansions: alias (_VBAR alias)* | ||
|
||
?alias: expansion ["->" RULE] | ||
?alias: expansion ("->" RULE)? | ||
|
||
?expansion: expr* | ||
expansion: expr* | ||
|
||
?expr: atom [OP | "~" NUMBER [".." NUMBER]] | ||
?expr: atom (OP | "~" NUMBER (".." NUMBER)?)? | ||
|
||
?atom: "(" expansions ")" | ||
| "[" expansions "]" -> maybe | ||
| value | ||
|
||
?value: STRING ".." STRING -> literal_range | ||
value: STRING ".." STRING -> literal_range | ||
| name | ||
| (REGEXP | STRING) -> literal | ||
| name "{" value ("," value)* "}" -> template_usage | ||
| RULE "{" value ("," value)* "}" -> template_usage | ||
|
||
name: RULE | ||
| TOKEN | ||
|
||
_VBAR: _NL? "|" | ||
OP: /[+*]|[?](?![a-z])/ | ||
RULE: /!?[_?]?[a-z][_a-z0-9]*/ | ||
RULE_MODIFIERS: /(!|![?]?|[?]!?)(?=[_a-z])/ | ||
RULE: /_?[a-z][_a-z0-9]*/ | ||
TOKEN: /_?[A-Z][_A-Z0-9]*/ | ||
STRING: _STRING "i"? | ||
REGEXP: /\/(?!\/)(\\\/|\\\\|[^\/])*?\/[imslux]*/ | ||
_NL: /(\r?\n)+\s*/ | ||
BACKSLASH: /\\[ ]*\n/ | ||
|
||
%import common.ESCAPED_STRING -> _STRING | ||
%import common.SIGNED_INT -> NUMBER | ||
|
@@ -60,3 +74,4 @@ COMMENT: /\s*/ "//" /[^\n]/* | /\s*/ "#" /[^\n]/* | |
|
||
%ignore WS_INLINE | ||
%ignore COMMENT | ||
%ignore BACKSLASH |
Uh oh!
There was an error while loading. Please reload this page.