Skip to content

Commit

Permalink
Add menhir support (#781)
Browse files Browse the repository at this point in the history
* Add menhir support

* Add menhir support

* Fixed bug with Menhir

---------

Co-authored-by: XAMPPRocky <[email protected]>
Co-authored-by: Basile Pesin <[email protected]>
  • Loading branch information
3 people authored Aug 16, 2024
1 parent 913df07 commit 099092f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
12 changes: 11 additions & 1 deletion languages.json
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,16 @@
"Max": {
"extensions": ["maxpat"]
},
"Menhir": {
"nested": true,
"quotes": [["\\\"", "\\\""]],
"line_comment": ["//"],
"multi_line_comments": [
["(*", "*)"],
["/*", "*/"]
],
"extensions": ["mll", "mly", "vy"]
},
"Meson": {
"line_comment": ["#"],
"quotes": [["'", "'"], ["'''", "'''"]],
Expand Down Expand Up @@ -1042,7 +1052,7 @@
"OCaml": {
"quotes": [["\\\"", "\\\""]],
"multi_line_comments": [["(*", "*)"]],
"extensions": ["ml", "mli", "mll", "mly", "re", "rei"]
"extensions": ["ml", "mli", "re", "rei"]
},
"Odin": {
"extensions": ["odin"],
Expand Down
47 changes: 47 additions & 0 deletions tests/data/menhir.mly
Original file line number Diff line number Diff line change
@@ -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 }

0 comments on commit 099092f

Please sign in to comment.