From 9243ed87815247b67da3bd1ea4a0ff98f3285971 Mon Sep 17 00:00:00 2001 From: Alhadis Date: Wed, 14 Oct 2020 13:59:56 +1100 Subject: [PATCH] Add support for Lark grammar files --- grammars.yml | 1 + lib/linguist/languages.yml | 11 ++++++ samples/Lark/ebl_atf.lark | 16 +++++++++ samples/Lark/ebl_atf_common.lark | 18 ++++++++++ samples/Lark/lark.lark | 58 ++++++++++++++++++++++++++++++++ vendor/README.md | 1 + 6 files changed, 105 insertions(+) create mode 100644 samples/Lark/ebl_atf.lark create mode 100644 samples/Lark/ebl_atf_common.lark create mode 100644 samples/Lark/lark.lark diff --git a/grammars.yml b/grammars.yml index 2ed7dd5786..fcc0e9e74e 100644 --- a/grammars.yml +++ b/grammars.yml @@ -481,6 +481,7 @@ vendor/grammars/language-grammars: - source.abnf - source.bnf - source.ebnf +- source.lark - source.lex - source.lex.regexp - source.yacc diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index f6cf9973c6..3e3f4e27f1 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -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" diff --git a/samples/Lark/ebl_atf.lark b/samples/Lark/ebl_atf.lark new file mode 100644 index 0000000000..a9e32decd8 --- /dev/null +++ b/samples/Lark/ebl_atf.lark @@ -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) diff --git a/samples/Lark/ebl_atf_common.lark b/samples/Lark/ebl_atf_common.lark new file mode 100644 index 0000000000..3d46e46e76 --- /dev/null +++ b/samples/Lark/ebl_atf_common.lark @@ -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 diff --git a/samples/Lark/lark.lark b/samples/Lark/lark.lark new file mode 100644 index 0000000000..474b8198c2 --- /dev/null +++ b/samples/Lark/lark.lark @@ -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 diff --git a/vendor/README.md b/vendor/README.md index 962d82e444..2031a777e7 100644 --- a/vendor/README.md +++ b/vendor/README.md @@ -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)