Constructors capitalized

This commit is contained in:
Dmitry Boulytchev 2019-03-07 19:06:04 +03:00
parent 3bf36ae719
commit 4879a02753
18 changed files with 147 additions and 145 deletions

View file

@ -15,8 +15,7 @@
32 32
51 51
93 93
96 67
99
111 111
110 110
115 115
@ -25,8 +24,7 @@
49 49
44 44
32 32
96 67
99
111 111
110 110
115 115
@ -35,8 +33,7 @@
50 50
44 44
32 32
96 78
110
105 105
108 108
41 41

View file

@ -1,21 +1,21 @@
fun append (x, y) { fun append (x, y) {
case x of case x of
`nil -> return y Nil -> return y
| `cons (h, t) -> return `cons (h, append (t, y)) | Cons (h, t) -> return Cons (h, append (t, y))
esac esac
} }
fun printList (x) { fun printList (x) {
case x of case x of
`nil -> skip Nil -> skip
| `cons (h, t) -> write (h); printList (t) | Cons (h, t) -> write (h); printList (t)
esac esac
} }
n := read (); n := read ();
x := `cons (1, `cons (2, `nil)); x := Cons (1, Cons (2, Nil));
y := `cons (3, `cons (4, `nil)); y := Cons (3, Cons (4, Nil));
printList (x); printList (x);
printList (y); printList (y);

View file

@ -1,17 +1,17 @@
fun insert (t, x) { fun insert (t, x) {
case t of case t of
`leaf -> return `node (x, `leaf, `leaf) Leaf -> return Node (x, Leaf, Leaf)
| `node (y, l, r) -> if x > y | Node (y, l, r) -> if x > y
then return `node (y, insert (l, x), r) then return Node (y, insert (l, x), r)
else return `node (y, l, insert (r, x)) else return Node (y, l, insert (r, x))
fi fi
esac esac
} }
fun find (t, x) { fun find (t, x) {
case t of case t of
`leaf -> return 0 Leaf -> return 0
| `node (y, l, r) -> if x == y then return 1 | Node (y, l, r) -> if x == y then return 1
elif x > y then return find (l, x) elif x > y then return find (l, x)
else return find (r, x) else return find (r, x)
fi fi
@ -20,7 +20,7 @@ fun find (t, x) {
n := read (); n := read ();
t := insert (insert (insert (insert (`leaf, 5), 4), 6), 3); t := insert (insert (insert (insert (Leaf, 5), 4), 6), 3);
write (find (t, 5)); write (find (t, 5));
write (find (t, 4)); write (find (t, 4));

View file

@ -1,15 +1,15 @@
fun f (x) { fun f (x) {
case x of case x of
`a -> write (1) A -> write (1)
| `b -> write (2) | B -> write (2)
| `c -> write (3) | C -> write (3)
| _ -> write (4) | _ -> write (4)
esac esac
} }
x := read (); x := read ();
f (`a); f (A);
f (`b); f (B);
f (`c); f (C);
f (`d) f (D)

View file

@ -1,11 +1,11 @@
fun f (a) { fun f (a) {
case a of case a of
`a (x, y, z) -> write (x + y + z) A (x, y, z) -> write (x + y + z)
| `b (x, y, z) -> write (x + y + z) | B (x, y, z) -> write (x + y + z)
esac esac
} }
x := read (); x := read ();
f (`a (100, 200, 300)); f (A (100, 200, 300));
f (`b (500, 600, 700)) f (B (500, 600, 700))

View file

@ -1,17 +1,17 @@
fun f (x) { fun f (x) {
case x of case x of
`nil -> write (0) Nil -> write (0)
| `cons (_, `nil) -> write (1) | Cons (_, Nil) -> write (1)
| `cons (_, `cons (_, `nil)) -> write (2) | Cons (_, Cons (_, Nil)) -> write (2)
| `cons (_, `cons (_, `cons (_, `nil))) -> write (3) | Cons (_, Cons (_, Cons (_, Nil))) -> write (3)
| _ -> write (4) | _ -> write (4)
esac esac
} }
x := read (); x := read ();
y := `nil; y := Nil;
for i := 0, i < 10, i := i + 1 do for i := 0, i < 10, i := i + 1 do
f (y); f (y);
y := `cons (i, y) y := Cons (i, y)
od od

View file

@ -1,12 +1,12 @@
fun sum (x) { fun sum (x) {
case x of case x of
`nil -> return 0 Nil -> return 0
| `cons (x, tl) -> return x + sum (tl) | Cons (x, tl) -> return x + sum (tl)
esac esac
} }
x := read (); x := read ();
write (sum (`nil)); write (sum (Nil));
write (sum (`cons (100, `nil))); write (sum (Cons (100, Nil)));
write (sum (`cons (100, `cons (200, `nil)))) write (sum (Cons (100, Cons (200, Nil))))

View file

@ -1,10 +1,10 @@
fun zip (x) { fun zip (x) {
case x of `pair (x, y) -> case x of Pair (x, y) ->
case x of case x of
`nil -> return `nil Nil -> return Nil
| `cons (x, xs) -> case y of | Cons (x, xs) -> case y of
`nil -> return `nil Nil -> return Nil
| `cons (y, ys) -> return `cons (`pair (x, y), zip (`pair (xs, ys))) | Cons (y, ys) -> return Cons (Pair (x, y), zip (Pair (xs, ys)))
esac esac
esac esac
esac esac
@ -12,26 +12,26 @@ fun zip (x) {
fun unzip (x) { fun unzip (x) {
case x of case x of
`nil -> return `pair (`nil, `nil) Nil -> return Pair (Nil, Nil)
| `cons (`pair (x, y), tl) -> | Cons (Pair (x, y), tl) ->
case unzip (tl) of case unzip (tl) of
`pair (xs, ys) -> return `pair (`cons (x, xs), `cons (y, ys)) Pair (xs, ys) -> return Pair (Cons (x, xs), Cons (y, ys))
esac esac
esac esac
} }
fun printList (l) { fun printList (l) {
case l of case l of
`nil -> skip Nil -> skip
| `cons (x, xs) -> write (x); printList (xs) | Cons (x, xs) -> write (x); printList (xs)
esac esac
} }
z := read (); z := read ();
x := `cons (1, `cons (2, `cons (3, `nil))); x := Cons (1, Cons (2, Cons (3, Nil)));
y := `cons (100, `cons (200, `cons (300, `nil))); y := Cons (100, Cons (200, Cons (300, Nil)));
case unzip (zip (`pair (x, y))) of case unzip (zip (Pair (x, y))) of
`pair (x, y) -> printList (x); printList (y) Pair (x, y) -> printList (x); printList (y)
esac esac

View file

@ -9,4 +9,4 @@ printString (1.string);
printString ("abc".string); printString ("abc".string);
printString ([].string); printString ([].string);
printString ([1, 2, 3].string); printString ([1, 2, 3].string);
printString (`cons (1, `cons (2, `nil)).string) printString (Cons (1, Cons (2, Nil)).string)

View file

@ -13,26 +13,26 @@ case 3 of
a@_ -> write (a) a@_ -> write (a)
esac; esac;
case `a (1, 2, 3) of case A (1, 2, 3) of
`a -> write (1) A -> write (1)
| a@`a (_, _, _) -> case a of | a@A (_, _, _) -> case a of
`a (x, y, z) -> write (x); write (y); write (z) A (x, y, z) -> write (x); write (y); write (z)
esac esac
esac; esac;
case `a (1, 2, 3, 4, 5) of case A (1, 2, 3, 4, 5) of
`a -> write (0) A -> write (0)
| `a (_) -> write (1) | A (_) -> write (1)
| `a (_, _) -> write (2) | A (_, _) -> write (2)
| `a (_, _, _) -> write (3) | A (_, _, _) -> write (3)
| `a (_, _, _, _) -> write (4) | A (_, _, _, _) -> write (4)
| `a (_, _, _, _, _) -> write (5) | A (_, _, _, _, _) -> write (5)
esac; esac;
write (`a (1, 2, 3, 4, 5).length); write (A (1, 2, 3, 4, 5).length);
write (`a (1, 2, 3, 4, 5)[0]); write (A (1, 2, 3, 4, 5)[0]);
write (`a (1, 2, 3, 4, 5)[1]); write (A (1, 2, 3, 4, 5)[1]);
write (`a (1, 2, 3, 4, 5)[2]); write (A (1, 2, 3, 4, 5)[2]);
write (`a (1, 2, 3, 4, 5)[3]); write (A (1, 2, 3, 4, 5)[3]);
write (`a (1, 2, 3, 4, 5)[4]) write (A (1, 2, 3, 4, 5)[4])

View file

@ -1,6 +1,6 @@
fun collect_ints_acc (v, tail) local i { fun collect_ints_acc (v, tail) local i {
case v of case v of
a@#unboxed -> return `cons (a, tail) a@#unboxed -> return Cons (a, tail)
| #string -> return tail | #string -> return tail
| _ -> | _ ->
for i := 0, i < v.length, i := i + 1 do for i := 0, i < v.length, i := i + 1 do
@ -11,13 +11,13 @@ fun collect_ints_acc (v, tail) local i {
} }
fun collect_ints (v) { fun collect_ints (v) {
return collect_ints_acc (v, `nil) return collect_ints_acc (v, Nil)
} }
fun print_list (l) { fun print_list (l) {
case l of case l of
`nil -> skip Nil -> skip
| `cons (n, t) -> write (n); print_list (t) | Cons (n, t) -> write (n); print_list (t)
esac esac
} }
@ -41,11 +41,11 @@ case 1 of
| a@0 -> write (a) | a@0 -> write (a)
esac; esac;
case `a (1, 2, 3) of case A (1, 2, 3) of
`a (1, 3, 5) -> write (0) A (1, 3, 5) -> write (0)
| `a (3, 4, 5) -> write (0) | A (3, 4, 5) -> write (0)
| `a (1, 2, 3) -> write (1) | A (1, 2, 3) -> write (1)
| `a (6, 7, 8) -> write (0) | A (6, 7, 8) -> write (0)
esac; esac;
case "abc" of case "abc" of
@ -69,4 +69,4 @@ case [1, 2, 3] of
| [a, b, c] -> write (a); write (b); write (c) | [a, b, c] -> write (a); write (b); write (c)
esac; esac;
print_list (collect_ints ([1, 2, 3, [4, 5, 6, `cons (1, 2, 3)]])) print_list (collect_ints ([1, 2, 3, [4, 5, 6, Cons (1, 2, 3)]]))

View file

@ -1,12 +1,12 @@
`Empty Empty
`Node (0, `Empty, `Empty) Node (0, Empty, Empty)
`Node (0, `Empty, `Node (1, `Empty, `Empty)) Node (0, Empty, Node (1, Empty, Empty))
`Node (0, `Empty, `Node (1, `Empty, `Node (2, `Empty, `Empty))) Node (0, Empty, Node (1, Empty, Node (2, Empty, Empty)))
`Node (0, `Empty, `Node (1, `Empty, `Node (2, `Empty, `Node (3, `Empty, `Empty)))) Node (0, Empty, Node (1, Empty, Node (2, Empty, Node (3, Empty, Empty))))
`Node (0, `Empty, `Node (1, `Empty, `Node (2, `Empty, `Node (3, `Empty, `Node (4, `Empty, `Empty))))) Node (0, Empty, Node (1, Empty, Node (2, Empty, Node (3, Empty, Node (4, Empty, Empty)))))
`Node (0, `Empty, `Node (1, `Empty, `Node (2, `Empty, `Node (3, `Empty, `Node (4, `Empty, `Node (5, `Empty, `Empty)))))) Node (0, Empty, Node (1, Empty, Node (2, Empty, Node (3, Empty, Node (4, Empty, Node (5, Empty, Empty))))))
`Node (0, `Empty, `Node (1, `Empty, `Node (2, `Empty, `Node (3, `Empty, `Node (4, `Empty, `Node (5, `Empty, `Node (6, `Empty, `Empty))))))) Node (0, Empty, Node (1, Empty, Node (2, Empty, Node (3, Empty, Node (4, Empty, Node (5, Empty, Node (6, Empty, Empty)))))))
`Node (0, `Empty, `Node (1, `Empty, `Node (2, `Empty, `Node (3, `Empty, `Node (4, `Empty, `Node (5, `Empty, `Node (6, `Empty, `Node (7, `Empty, `Empty)))))))) Node (0, Empty, Node (1, Empty, Node (2, Empty, Node (3, Empty, Node (4, Empty, Node (5, Empty, Node (6, Empty, Node (7, Empty, Empty))))))))
`Node (0, `Empty, `Node (1, `Empty, `Node (2, `Empty, `Node (3, `Empty, `Node (4, `Empty, `Node (5, `Empty, `Node (6, `Empty, `Node (7, `Empty, `Node (8, `Empty, `Empty))))))))) Node (0, Empty, Node (1, Empty, Node (2, Empty, Node (3, Empty, Node (4, Empty, Node (5, Empty, Node (6, Empty, Node (7, Empty, Node (8, Empty, Empty)))))))))
`Node (0, `Empty, `Node (1, `Empty, `Node (2, `Empty, `Node (3, `Empty, `Node (4, `Empty, `Node (5, `Empty, `Node (6, `Empty, `Node (7, `Empty, `Node (8, `Empty, `Node (9, `Empty, `Empty)))))))))) Node (0, Empty, Node (1, Empty, Node (2, Empty, Node (3, Empty, Node (4, Empty, Node (5, Empty, Node (6, Empty, Node (7, Empty, Node (8, Empty, Node (9, Empty, Empty))))))))))
`Node (0, `Empty, `Node (1, `Empty, `Node (2, `Empty, `Node (3, `Empty, `Node (4, `Empty, `Node (5, `Empty, `Node (6, `Empty, `Node (7, `Empty, `Node (8, `Empty, `Node (9, `Empty, `Node (10, `Empty, `Empty))))))))))) Node (0, Empty, Node (1, Empty, Node (2, Empty, Node (3, Empty, Node (4, Empty, Node (5, Empty, Node (6, Empty, Node (7, Empty, Node (8, Empty, Node (9, Empty, Node (10, Empty, Empty)))))))))))

View file

@ -6,4 +6,4 @@
2 2
3 3
100 100
`cons (3, `cons (2, `cons (1, `cons (6, `cons (5, `cons (4, `cons (3, `cons (2, `cons (1, `nil))))))))) Cons (3, Cons (2, Cons (1, Cons (6, Cons (5, Cons (4, Cons (3, Cons (2, Cons (1, Nil)))))))))

View file

@ -1,15 +1,15 @@
fun insert (tree, value) { fun insert (tree, value) {
case tree of case tree of
`Empty -> return `Node (value, `Empty, `Empty) Empty -> return Node (value, Empty, Empty)
| `Node (x, left, right) -> | Node (x, left, right) ->
if x > value if x > value
then return `Node (x, insert (left, value), right) then return Node (x, insert (left, value), right)
else return `Node (x, left, insert (right, value)) else return Node (x, left, insert (right, value))
fi fi
esac esac
} }
tree := `Empty; tree := Empty;
for i := 0, i <= 10, i := i+1 do for i := 0, i <= 10, i := i+1 do
printf ("%s\n", tree.string); printf ("%s\n", tree.string);

View file

@ -1,6 +1,6 @@
fun collect_ints_acc (v, tail) local i { fun collect_ints_acc (v, tail) local i {
case v of case v of
a@#unboxed -> return `cons (a, tail) a@#unboxed -> return Cons (a, tail)
| #string -> return tail | #string -> return tail
| _ -> | _ ->
for i := 0, i < v.length, i := i + 1 do for i := 0, i < v.length, i := i + 1 do
@ -11,7 +11,7 @@ fun collect_ints_acc (v, tail) local i {
} }
fun collect_ints (v) { fun collect_ints (v) {
return collect_ints_acc (v, `nil) return collect_ints_acc (v, Nil)
} }
case 1 of case 1 of
@ -32,11 +32,11 @@ case 1 of
| a@0 -> write (a) | a@0 -> write (a)
esac; esac;
case `a (1, 2, 3) of case A (1, 2, 3) of
`a (1, 3, 5) -> write (0) A (1, 3, 5) -> write (0)
| `a (3, 4, 5) -> write (0) | A (3, 4, 5) -> write (0)
| `a (1, 2, 3) -> write (1) | A (1, 2, 3) -> write (1)
| `a (6, 7, 8) -> write (0) | A (6, 7, 8) -> write (0)
esac; esac;
case "abc" of case "abc" of
@ -60,4 +60,4 @@ case [1, 2, 3] of
| [a, b, c] -> write (a); write (b); write (c) | [a, b, c] -> write (a); write (b); write (c)
esac; esac;
printf ("%s\n", collect_ints ([1, 2, 3, [4, 5, 6, `cons (1, 2, 3)]]).string) printf ("%s\n", collect_ints ([1, 2, 3, [4, 5, 6, Cons (1, 2, 3)]]).string)

View file

@ -135,7 +135,7 @@ static void printValue (void *p) {
break; break;
case SEXP_TAG: case SEXP_TAG:
printStringBuf ("`%s", de_hash (TO_SEXP(p)->tag)); printStringBuf ("%s", de_hash (TO_SEXP(p)->tag));
if (LEN(a->tag)) { if (LEN(a->tag)) {
printStringBuf (" ("); printStringBuf (" (");
for (i = 0; i < LEN(a->tag); i++) { for (i = 0; i < LEN(a->tag); i++) {

View file

@ -1,23 +1,27 @@
open Ostap open Ostap
let parse infile = let parse infile =
let s = Util.read infile in let s = Util.read infile in
let kws = [
"skip";
"if"; "then"; "else"; "elif"; "fi";
"while"; "do"; "od";
"repeat"; "until";
"for";
"fun"; "local"; "return";
"length";
"string";
"case"; "of"; "esac"; "when";
"boxed"; "unboxed"; "string"; "sexp"; "array"]
in
Util.parse Util.parse
(object (object
inherit Matcher.t s inherit Matcher.t s
inherit Util.Lexers.decimal s inherit Util.Lexers.decimal s
inherit Util.Lexers.string s inherit Util.Lexers.string s
inherit Util.Lexers.char s inherit Util.Lexers.char s
inherit Util.Lexers.ident ["skip"; inherit Util.Lexers.lident kws s
"if"; "then"; "else"; "elif"; "fi"; inherit Util.Lexers.uident kws s
"while"; "do"; "od";
"repeat"; "until";
"for";
"fun"; "local"; "return";
"length";
"string";
"case"; "of"; "esac"; "when";
"boxed"; "unboxed"; "string"; "sexp"; "array"] s
inherit Util.Lexers.skip [ inherit Util.Lexers.skip [
Matcher.Skip.whitespaces " \t\n"; Matcher.Skip.whitespaces " \t\n";
Matcher.Skip.lineComment "--"; Matcher.Skip.lineComment "--";

View file

@ -46,7 +46,7 @@ module Value =
| Array a -> let n = Array.length a in | Array a -> let n = Array.length a in
append "["; Array.iteri (fun i a -> (if i > 0 then append ", "); inner a) a; append "]" append "["; Array.iteri (fun i a -> (if i > 0 then append ", "); inner a) a; append "]"
| Sexp (t, a) -> let n = List.length a in | Sexp (t, a) -> let n = List.length a in
append "`"; append t; (if n > 0 then (append " ("; List.iteri (fun i a -> (if i > 0 then append ", "); inner a) a; append ")")) append t; (if n > 0 then (append " ("; List.iteri (fun i a -> (if i > 0 then append ", "); inner a) a; append ")"))
in in
inner v; inner v;
Bytes.of_string @@ Buffer.contents buf Bytes.of_string @@ Buffer.contents buf
@ -132,7 +132,7 @@ module Builtin =
) )
| ".length" -> (st, i, o, Some (Value.of_int (match List.hd args with Value.Sexp (_, a) -> List.length a | Value.Array a -> Array.length a | Value.String s -> Bytes.length s))) | ".length" -> (st, i, o, Some (Value.of_int (match List.hd args with Value.Sexp (_, a) -> List.length a | Value.Array a -> Array.length a | Value.String s -> Bytes.length s)))
| ".array" -> (st, i, o, Some (Value.of_array @@ Array.of_list args)) | ".array" -> (st, i, o, Some (Value.of_array @@ Array.of_list args))
| ".stringval" -> let [a] = args in (st, i, o, Some (Value.of_string @@ Value.string_val a)) | ".stringval" -> let [a] = args in (st, i, o, Some (Value.of_string @@ Value.string_val a))
end end
@ -240,7 +240,8 @@ module Expr =
(* Expression parser. You can use the following terminals: (* Expression parser. You can use the following terminals:
IDENT --- a non-empty identifier a-zA-Z[a-zA-Z0-9_]* as a string LIDENT --- a non-empty identifier a-z[a-zA-Z0-9_]* as a string
UIDENT --- a non-empty identifier A-Z[a-zA-Z0-9_]* as a string
DECIMAL --- a decimal constant [0-9]+ as a string DECIMAL --- a decimal constant [0-9]+ as a string
*) *)
ostap ( ostap (
@ -268,12 +269,12 @@ module Expr =
primary: b:base is:(-"[" i:parse -"]" {`Elem i} | -"." (%"length" {`Len} | %"string" {`Str})) * primary: b:base is:(-"[" i:parse -"]" {`Elem i} | -"." (%"length" {`Len} | %"string" {`Str})) *
{List.fold_left (fun b -> function `Elem i -> Elem (b, i) | `Len -> Length b | `Str -> StringVal b) b is}; {List.fold_left (fun b -> function `Elem i -> Elem (b, i) | `Len -> Length b | `Str -> StringVal b) b is};
base: base:
n:DECIMAL {Const n} n:DECIMAL {Const n}
| s:STRING {String (String.sub s 1 (String.length s - 2))} | s:STRING {String (String.sub s 1 (String.length s - 2))}
| c:CHAR {Const (Char.code c)} | c:CHAR {Const (Char.code c)}
| "[" es:!(Util.list0)[parse] "]" {Array es} | "[" es:!(Util.list0)[parse] "]" {Array es}
| "`" t:IDENT args:(-"(" !(Util.list)[parse] -")")? {Sexp (t, match args with None -> [] | Some args -> args)} | t:UIDENT args:(-"(" !(Util.list)[parse] -")")? {Sexp (t, match args with None -> [] | Some args -> args)}
| x:IDENT s:("(" args:!(Util.list0)[parse] ")" {Call (x, args)} | empty {Var x}) {s} | x:LIDENT s:("(" args:!(Util.list0)[parse] ")" {Call (x, args)} | empty {Var x}) {s}
| -"(" parse -")" | -"(" parse -")"
) )
@ -306,17 +307,17 @@ module Stmt =
ostap ( ostap (
parse: parse:
%"_" {Wildcard} %"_" {Wildcard}
| "`" t:IDENT ps:(-"(" !(Util.list)[parse] -")")? {Sexp (t, match ps with None -> [] | Some ps -> ps)} | t:UIDENT ps:(-"(" !(Util.list)[parse] -")")? {Sexp (t, match ps with None -> [] | Some ps -> ps)}
| "[" ps:(!(Util.list0)[parse]) "]" {Array ps} | "[" ps:(!(Util.list0)[parse]) "]" {Array ps}
| x:IDENT y:(-"@" parse)? {match y with None -> Named (x, Wildcard) | Some y -> Named (x, y)} | x:LIDENT y:(-"@" parse)? {match y with None -> Named (x, Wildcard) | Some y -> Named (x, y)}
| c:DECIMAL {Const c} | c:DECIMAL {Const c}
| s:STRING {String (String.sub s 1 (String.length s - 2))} | s:STRING {String (String.sub s 1 (String.length s - 2))}
| c:CHAR {Const (Char.code c)} | c:CHAR {Const (Char.code c)}
| "#" %"boxed" {Boxed} | "#" %"boxed" {Boxed}
| "#" %"unboxed" {UnBoxed} | "#" %"unboxed" {UnBoxed}
| "#" %"string" {StringTag} | "#" %"string" {StringTag}
| "#" %"sexp" {SexpTag} | "#" %"sexp" {SexpTag}
| "#" %"array" {ArrayTag} | "#" %"array" {ArrayTag}
) )
let vars p = transform(t) (fun f -> object inherit [string list, _] @t[foldl] f method c_Named s _ name p = name :: f s p end) [] p let vars p = transform(t) (fun f -> object inherit [string list, _] @t[foldl] f method c_Named s _ name p = name :: f s p end) [] p
@ -437,7 +438,7 @@ module Stmt =
| %"repeat" s:parse %"until" e:!(Expr.parse) {Repeat (s, e)} | %"repeat" s:parse %"until" e:!(Expr.parse) {Repeat (s, e)}
| %"return" e:!(Expr.parse)? {Return e} | %"return" e:!(Expr.parse)? {Return e}
| %"case" e:!(Expr.parse) %"of" bs:!(Util.listBy)[ostap ("|")][ostap (!(Pattern.parse) -"->" parse)] %"esac" {Case (e, bs)} | %"case" e:!(Expr.parse) %"of" bs:!(Util.listBy)[ostap ("|")][ostap (!(Pattern.parse) -"->" parse)] %"esac" {Case (e, bs)}
| x:IDENT | x:LIDENT
s:(is:(-"[" !(Expr.parse) -"]")* ":=" e :!(Expr.parse) {Assign (x, is, e)} | s:(is:(-"[" !(Expr.parse) -"]")* ":=" e :!(Expr.parse) {Assign (x, is, e)} |
"(" args:!(Util.list0)[Expr.parse] ")" {Call (x, args)} "(" args:!(Util.list0)[Expr.parse] ")" {Call (x, args)}
) {s} ) {s}
@ -453,8 +454,8 @@ module Definition =
type t = string * (string list * string list * Stmt.t) type t = string * (string list * string list * Stmt.t)
ostap ( ostap (
arg : IDENT; arg : LIDENT;
parse: %"fun" name:IDENT "(" args:!(Util.list0 arg) ")" parse: %"fun" name:LIDENT "(" args:!(Util.list0 arg) ")"
locs:(%"local" !(Util.list arg))? locs:(%"local" !(Util.list arg))?
"{" body:!(Stmt.parse) "}" { "{" body:!(Stmt.parse) "}" {
(name, (args, (match locs with None -> [] | Some l -> l), body)) (name, (args, (match locs with None -> [] | Some l -> l), body))