Skip to content
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

Add menhir support #781

Merged
merged 7 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }
Loading