Skip to content

Commit

Permalink
Add support for Lark grammar files (#5049)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alhadis authored Oct 14, 2020
1 parent 3d39c1c commit b3664e4
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 0 deletions.
1 change: 1 addition & 0 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ vendor/grammars/language-grammars:
- source.abnf
- source.bnf
- source.ebnf
- source.lark
- source.lex
- source.lex.regexp
- source.yacc
Expand Down
11 changes: 11 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2823,6 +2823,17 @@ LabVIEW:
codemirror_mode: xml
codemirror_mime_type: text/xml
language_id: 194
Lark:
type: data
group: EBNF
color: "#0b130f"
extensions:
- ".lark"
tm_scope: source.lark
ace_mode: text
codemirror_mode: ebnf
codemirror_mime_type: text/x-ebnf
language_id: 758480799
Lasso:
type: programming
color: "#999999"
Expand Down
16 changes: 16 additions & 0 deletions samples/Lark/ebl_atf.lark
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
?start: line

?line: empty_line
| note_line
| text_line
| dollar_line
| at_line
| control_line

empty_line: /\s+/?

!control_line.-2: ("=:" | "&" | "#") /.+/?

%import .ebl_atf_text_line (text_line, any_word, note_line)
%import .ebl_atf_dollar_line (dollar_line)
%import .ebl_atf_at_line (at_line)
18 changes: 18 additions & 0 deletions samples/Lark/ebl_atf_common.lark
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
%import common.DIGIT
%import common.INT
%import common.LCASE_LETTER

seal : "seal " INT

free_text.-2 : /./+ " "*

?object: OBJECT | generic_object | fragment
OBJECT: "tablet" | "envelope" | "prism" | "bulla"
fragment: "fragment " free_text
generic_object : "object " free_text

?surface: SURFACE | generic_surface | face | edge
SURFACE: "obverse" | "reverse" | "left" | "right" | "top" | "bottom"
face: "face " LCASE_LETTER
edge: "edge" (" " LCASE_LETTER)?
generic_surface : "surface " free_text
58 changes: 58 additions & 0 deletions samples/Lark/lark.lark
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
start: (_item? _NL)* _item?

_item: rule
| token
| statement

rule: RULE rule_params priority? ":" expansions
token: TOKEN token_params priority? ":" expansions

rule_params: ["{" RULE ("," RULE)* "}"]
token_params: ["{" TOKEN ("," TOKEN)* "}"]

priority: "." NUMBER

statement: "%ignore" expansions -> ignore
| "%import" import_path ["->" name] -> import
| "%import" import_path name_list -> multi_import
| "%declare" name+ -> declare

!import_path: "."? name ("." name)*
name_list: "(" name ("," name)* ")"

?expansions: alias (_VBAR alias)*

?alias: expansion ["->" RULE]

?expansion: expr*

?expr: atom [OP | "~" NUMBER [".." NUMBER]]

?atom: "(" expansions ")"
| "[" expansions "]" -> maybe
| value

?value: STRING ".." STRING -> literal_range
| name
| (REGEXP | STRING) -> literal
| name "{" value ("," value)* "}" -> template_usage

name: RULE
| TOKEN

_VBAR: _NL? "|"
OP: /[+*]|[?](?![a-z])/
RULE: /!?[_?]?[a-z][_a-z0-9]*/
TOKEN: /_?[A-Z][_A-Z0-9]*/
STRING: _STRING "i"?
REGEXP: /\/(?!\/)(\\\/|\\\\|[^\/\n])*?\/[imslux]*/
_NL: /(\r?\n)+\s*/

%import common.ESCAPED_STRING -> _STRING
%import common.SIGNED_INT -> NUMBER
%import common.WS_INLINE

COMMENT: /\s*/ "//" /[^\n]/*

%ignore WS_INLINE
%ignore COMMENT
1 change: 1 addition & 0 deletions vendor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting
- **LSL:** [textmate/secondlife-lsl.tmbundle](https://github.com/textmate/secondlife-lsl.tmbundle)
- **LTspice Symbol:** [Alhadis/language-pcb](https://github.com/Alhadis/language-pcb)
- **LabVIEW:** [textmate/xml.tmbundle](https://github.com/textmate/xml.tmbundle)
- **Lark:** [Alhadis/language-grammars](https://github.com/Alhadis/language-grammars)
- **Lasso:** [bfad/Sublime-Lasso](https://github.com/bfad/Sublime-Lasso)
- **Latte:** [textmate/php-smarty.tmbundle](https://github.com/textmate/php-smarty.tmbundle)
- **Lean:** [leanprover/vscode-lean](https://github.com/leanprover/vscode-lean)
Expand Down

0 comments on commit b3664e4

Please sign in to comment.