Add menhir support (#781)

* Add menhir support

* Add menhir support

* Fixed bug with Menhir

---------

Co-authored-by: XAMPPRocky <4464295+XAMPPRocky@users.noreply.github.com>
Co-authored-by: Basile Pesin <basile.pesin@vertmo.org>
This commit is contained in:
pjmkrpg 2024-08-16 12:59:32 +02:00 committed by GitHub
parent 913df079c2
commit 099092fa1b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 58 additions and 1 deletions

View File

@ -940,6 +940,16 @@
"Max": {
"extensions": ["maxpat"]
},
"Menhir": {
"nested": true,
"quotes": [["\\\"", "\\\""]],
"line_comment": ["//"],
"multi_line_comments": [
["(*", "*)"],
["/*", "*/"]
],
"extensions": ["mll", "mly", "vy"]
},
"Meson": {
"line_comment": ["#"],
"quotes": [["'", "'"], ["'''", "'''"]],
@ -1042,7 +1052,7 @@
"OCaml": {
"quotes": [["\\\"", "\\\""]],
"multi_line_comments": [["(*", "*)"]],
"extensions": ["ml", "mli", "mll", "mly", "re", "rei"]
"extensions": ["ml", "mli", "re", "rei"]
},
"Odin": {
"extensions": ["odin"],

47
tests/data/menhir.mly Normal file
View File

@ -0,0 +1,47 @@
// 47 lines 31 code 7 comments 9 blanks
(* Example from the menhir development with instrumented comments.
* (* Note: nested C style comments are not allowed. *)
* https://gitlab.inria.fr/fpottier/menhir/-/tree/master/demos/calc-alias *)
%token<int> INT "42"
%token PLUS "+"
%token MINUS "-"
%token TIMES "*"
%token DIV "/"
%token LPAREN "("
%token RPAREN ")"
%token EOL
(* Token aliases can be used throughout the rest of the grammar. E.g.,
they can be used in precedence declarations: *)
%left "+" "-" /* lowest " precedence */
%left "*" "/" /* medium precedence */
%nonassoc UMINUS // highest "precedence"
%start <int> main
%%
main:
| e = expr EOL
{ e }
(* Token aliases can also be used inside rules: *)
expr:
| i = "42"
{ i }
| "(" e = expr ")"
{ e }
| e1 = expr "+" e2 = expr
{ e1 + e2 }
| e1 = expr "-" e2 = expr
{ e1 - e2 }
| e1 = expr "*" e2 = expr
{ e1 * e2 }
| e1 = expr "/" e2 = expr
{ e1 / e2 }
| "-" e = expr %prec UMINUS
{ - e }