From 4879a027530e2e99c6596e2ac5e2b58e21577900 Mon Sep 17 00:00:00 2001 From: Dmitry Boulytchev Date: Thu, 7 Mar 2019 19:06:04 +0300 Subject: [PATCH] Constructors capitalized --- regression/orig/test045.log | 9 ++---- regression/test038.expr | 12 ++++---- regression/test039.expr | 14 ++++----- regression/test040.expr | 14 ++++----- regression/test041.expr | 8 ++--- regression/test042.expr | 14 ++++----- regression/test043.expr | 10 +++--- regression/test044.expr | 28 ++++++++--------- regression/test045.expr | 2 +- regression/test046.expr | 34 ++++++++++----------- regression/test047.expr | 20 ++++++------ regression/x86only/orig/test001.log | 24 +++++++-------- regression/x86only/orig/test002.log | 2 +- regression/x86only/test001.expr | 10 +++--- regression/x86only/test002.expr | 16 +++++----- runtime/runtime.c | 2 +- src/Driver.ml | 26 +++++++++------- src/Language.ml | 47 +++++++++++++++-------------- 18 files changed, 147 insertions(+), 145 deletions(-) diff --git a/regression/orig/test045.log b/regression/orig/test045.log index 5a4da1720..cd95b0ffd 100644 --- a/regression/orig/test045.log +++ b/regression/orig/test045.log @@ -15,8 +15,7 @@ 32 51 93 -96 -99 +67 111 110 115 @@ -25,8 +24,7 @@ 49 44 32 -96 -99 +67 111 110 115 @@ -35,8 +33,7 @@ 50 44 32 -96 -110 +78 105 108 41 diff --git a/regression/test038.expr b/regression/test038.expr index e13e88c87..e5787a21b 100644 --- a/regression/test038.expr +++ b/regression/test038.expr @@ -1,21 +1,21 @@ fun append (x, y) { case x of - `nil -> return y - | `cons (h, t) -> return `cons (h, append (t, y)) + Nil -> return y + | Cons (h, t) -> return Cons (h, append (t, y)) esac } fun printList (x) { case x of - `nil -> skip - | `cons (h, t) -> write (h); printList (t) + Nil -> skip + | Cons (h, t) -> write (h); printList (t) esac } n := read (); -x := `cons (1, `cons (2, `nil)); -y := `cons (3, `cons (4, `nil)); +x := Cons (1, Cons (2, Nil)); +y := Cons (3, Cons (4, Nil)); printList (x); printList (y); diff --git a/regression/test039.expr b/regression/test039.expr index 1075d8de7..a3e8fe05f 100644 --- a/regression/test039.expr +++ b/regression/test039.expr @@ -1,17 +1,17 @@ fun insert (t, x) { case t of - `leaf -> return `node (x, `leaf, `leaf) - | `node (y, l, r) -> if x > y - then return `node (y, insert (l, x), r) - else return `node (y, l, insert (r, x)) + Leaf -> return Node (x, Leaf, Leaf) + | Node (y, l, r) -> if x > y + then return Node (y, insert (l, x), r) + else return Node (y, l, insert (r, x)) fi esac } fun find (t, x) { case t of - `leaf -> return 0 - | `node (y, l, r) -> if x == y then return 1 + Leaf -> return 0 + | Node (y, l, r) -> if x == y then return 1 elif x > y then return find (l, x) else return find (r, x) fi @@ -20,7 +20,7 @@ fun find (t, x) { 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, 4)); diff --git a/regression/test040.expr b/regression/test040.expr index 766857331..aa2933f32 100644 --- a/regression/test040.expr +++ b/regression/test040.expr @@ -1,15 +1,15 @@ fun f (x) { case x of - `a -> write (1) - | `b -> write (2) - | `c -> write (3) + A -> write (1) + | B -> write (2) + | C -> write (3) | _ -> write (4) esac } x := read (); -f (`a); -f (`b); -f (`c); -f (`d) \ No newline at end of file +f (A); +f (B); +f (C); +f (D) \ No newline at end of file diff --git a/regression/test041.expr b/regression/test041.expr index 36d947f35..a6299d630 100644 --- a/regression/test041.expr +++ b/regression/test041.expr @@ -1,11 +1,11 @@ fun f (a) { case a of - `a (x, y, z) -> write (x + y + z) - | `b (x, y, z) -> write (x + y + z) + A (x, y, z) -> write (x + y + z) + | B (x, y, z) -> write (x + y + z) esac } x := read (); -f (`a (100, 200, 300)); -f (`b (500, 600, 700)) \ No newline at end of file +f (A (100, 200, 300)); +f (B (500, 600, 700)) \ No newline at end of file diff --git a/regression/test042.expr b/regression/test042.expr index 1029c9eb9..a45a732cc 100644 --- a/regression/test042.expr +++ b/regression/test042.expr @@ -1,17 +1,17 @@ fun f (x) { case x of - `nil -> write (0) - | `cons (_, `nil) -> write (1) - | `cons (_, `cons (_, `nil)) -> write (2) - | `cons (_, `cons (_, `cons (_, `nil))) -> write (3) - | _ -> write (4) + Nil -> write (0) + | Cons (_, Nil) -> write (1) + | Cons (_, Cons (_, Nil)) -> write (2) + | Cons (_, Cons (_, Cons (_, Nil))) -> write (3) + | _ -> write (4) esac } x := read (); -y := `nil; +y := Nil; for i := 0, i < 10, i := i + 1 do f (y); - y := `cons (i, y) + y := Cons (i, y) od \ No newline at end of file diff --git a/regression/test043.expr b/regression/test043.expr index 88bab7941..fa1031048 100644 --- a/regression/test043.expr +++ b/regression/test043.expr @@ -1,12 +1,12 @@ fun sum (x) { case x of - `nil -> return 0 - | `cons (x, tl) -> return x + sum (tl) + Nil -> return 0 + | Cons (x, tl) -> return x + sum (tl) esac } x := read (); -write (sum (`nil)); -write (sum (`cons (100, `nil))); -write (sum (`cons (100, `cons (200, `nil)))) \ No newline at end of file +write (sum (Nil)); +write (sum (Cons (100, Nil))); +write (sum (Cons (100, Cons (200, Nil)))) \ No newline at end of file diff --git a/regression/test044.expr b/regression/test044.expr index 78bc10dfd..cd5baf59d 100644 --- a/regression/test044.expr +++ b/regression/test044.expr @@ -1,10 +1,10 @@ fun zip (x) { - case x of `pair (x, y) -> + case x of Pair (x, y) -> case x of - `nil -> return `nil - | `cons (x, xs) -> case y of - `nil -> return `nil - | `cons (y, ys) -> return `cons (`pair (x, y), zip (`pair (xs, ys))) + Nil -> return Nil + | Cons (x, xs) -> case y of + Nil -> return Nil + | Cons (y, ys) -> return Cons (Pair (x, y), zip (Pair (xs, ys))) esac esac esac @@ -12,26 +12,26 @@ fun zip (x) { fun unzip (x) { case x of - `nil -> return `pair (`nil, `nil) - | `cons (`pair (x, y), tl) -> + Nil -> return Pair (Nil, Nil) + | Cons (Pair (x, y), tl) -> 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 } fun printList (l) { case l of - `nil -> skip - | `cons (x, xs) -> write (x); printList (xs) + Nil -> skip + | Cons (x, xs) -> write (x); printList (xs) esac } z := read (); -x := `cons (1, `cons (2, `cons (3, `nil))); -y := `cons (100, `cons (200, `cons (300, `nil))); +x := Cons (1, Cons (2, Cons (3, Nil))); +y := Cons (100, Cons (200, Cons (300, Nil))); -case unzip (zip (`pair (x, y))) of - `pair (x, y) -> printList (x); printList (y) +case unzip (zip (Pair (x, y))) of + Pair (x, y) -> printList (x); printList (y) esac \ No newline at end of file diff --git a/regression/test045.expr b/regression/test045.expr index 246780277..0b6d2ac72 100644 --- a/regression/test045.expr +++ b/regression/test045.expr @@ -9,4 +9,4 @@ printString (1.string); printString ("abc".string); printString ([].string); printString ([1, 2, 3].string); -printString (`cons (1, `cons (2, `nil)).string) \ No newline at end of file +printString (Cons (1, Cons (2, Nil)).string) \ No newline at end of file diff --git a/regression/test046.expr b/regression/test046.expr index 9a0a8d106..a0fc12a9d 100644 --- a/regression/test046.expr +++ b/regression/test046.expr @@ -13,26 +13,26 @@ case 3 of a@_ -> write (a) esac; -case `a (1, 2, 3) of - `a -> write (1) -| a@`a (_, _, _) -> case a of - `a (x, y, z) -> write (x); write (y); write (z) +case A (1, 2, 3) of + A -> write (1) +| a@A (_, _, _) -> case a of + A (x, y, z) -> write (x); write (y); write (z) esac esac; -case `a (1, 2, 3, 4, 5) of - `a -> write (0) -| `a (_) -> write (1) -| `a (_, _) -> write (2) -| `a (_, _, _) -> write (3) -| `a (_, _, _, _) -> write (4) -| `a (_, _, _, _, _) -> write (5) +case A (1, 2, 3, 4, 5) of + A -> write (0) +| A (_) -> write (1) +| A (_, _) -> write (2) +| A (_, _, _) -> write (3) +| A (_, _, _, _) -> write (4) +| A (_, _, _, _, _) -> write (5) 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)[1]); -write (`a (1, 2, 3, 4, 5)[2]); -write (`a (1, 2, 3, 4, 5)[3]); -write (`a (1, 2, 3, 4, 5)[4]) +write (A (1, 2, 3, 4, 5)[0]); +write (A (1, 2, 3, 4, 5)[1]); +write (A (1, 2, 3, 4, 5)[2]); +write (A (1, 2, 3, 4, 5)[3]); +write (A (1, 2, 3, 4, 5)[4]) diff --git a/regression/test047.expr b/regression/test047.expr index 37516ac0b..ef53c9593 100644 --- a/regression/test047.expr +++ b/regression/test047.expr @@ -1,6 +1,6 @@ fun collect_ints_acc (v, tail) local i { case v of - a@#unboxed -> return `cons (a, tail) + a@#unboxed -> return Cons (a, tail) | #string -> return tail | _ -> 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) { - return collect_ints_acc (v, `nil) + return collect_ints_acc (v, Nil) } fun print_list (l) { case l of - `nil -> skip - | `cons (n, t) -> write (n); print_list (t) + Nil -> skip + | Cons (n, t) -> write (n); print_list (t) esac } @@ -41,11 +41,11 @@ case 1 of | a@0 -> write (a) esac; -case `a (1, 2, 3) of - `a (1, 3, 5) -> write (0) -| `a (3, 4, 5) -> write (0) -| `a (1, 2, 3) -> write (1) -| `a (6, 7, 8) -> write (0) +case A (1, 2, 3) of + A (1, 3, 5) -> write (0) +| A (3, 4, 5) -> write (0) +| A (1, 2, 3) -> write (1) +| A (6, 7, 8) -> write (0) esac; case "abc" of @@ -69,4 +69,4 @@ case [1, 2, 3] of | [a, b, c] -> write (a); write (b); write (c) 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)]])) diff --git a/regression/x86only/orig/test001.log b/regression/x86only/orig/test001.log index b89fb7132..823fbc829 100644 --- a/regression/x86only/orig/test001.log +++ b/regression/x86only/orig/test001.log @@ -1,12 +1,12 @@ -`Empty -`Node (0, `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, `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, `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, `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, `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))))))))))) +Empty +Node (0, 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, 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, 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, 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, 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))))))))))) diff --git a/regression/x86only/orig/test002.log b/regression/x86only/orig/test002.log index 047d48e6c..0460887d8 100644 --- a/regression/x86only/orig/test002.log +++ b/regression/x86only/orig/test002.log @@ -6,4 +6,4 @@ 2 3 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))))))))) diff --git a/regression/x86only/test001.expr b/regression/x86only/test001.expr index 50c3333a7..3e1dca2d7 100644 --- a/regression/x86only/test001.expr +++ b/regression/x86only/test001.expr @@ -1,15 +1,15 @@ fun insert (tree, value) { case tree of - `Empty -> return `Node (value, `Empty, `Empty) - | `Node (x, left, right) -> + Empty -> return Node (value, Empty, Empty) + | Node (x, left, right) -> if x > value - then return `Node (x, insert (left, value), right) - else return `Node (x, left, insert (right, value)) + then return Node (x, insert (left, value), right) + else return Node (x, left, insert (right, value)) fi esac } -tree := `Empty; +tree := Empty; for i := 0, i <= 10, i := i+1 do printf ("%s\n", tree.string); diff --git a/regression/x86only/test002.expr b/regression/x86only/test002.expr index cbfcab27b..c0c5b5dc9 100644 --- a/regression/x86only/test002.expr +++ b/regression/x86only/test002.expr @@ -1,6 +1,6 @@ fun collect_ints_acc (v, tail) local i { case v of - a@#unboxed -> return `cons (a, tail) + a@#unboxed -> return Cons (a, tail) | #string -> return tail | _ -> 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) { - return collect_ints_acc (v, `nil) + return collect_ints_acc (v, Nil) } case 1 of @@ -32,11 +32,11 @@ case 1 of | a@0 -> write (a) esac; -case `a (1, 2, 3) of - `a (1, 3, 5) -> write (0) -| `a (3, 4, 5) -> write (0) -| `a (1, 2, 3) -> write (1) -| `a (6, 7, 8) -> write (0) +case A (1, 2, 3) of + A (1, 3, 5) -> write (0) +| A (3, 4, 5) -> write (0) +| A (1, 2, 3) -> write (1) +| A (6, 7, 8) -> write (0) esac; case "abc" of @@ -60,4 +60,4 @@ case [1, 2, 3] of | [a, b, c] -> write (a); write (b); write (c) 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) diff --git a/runtime/runtime.c b/runtime/runtime.c index 7e379befe..f6fdebf75 100644 --- a/runtime/runtime.c +++ b/runtime/runtime.c @@ -135,7 +135,7 @@ static void printValue (void *p) { break; case SEXP_TAG: - printStringBuf ("`%s", de_hash (TO_SEXP(p)->tag)); + printStringBuf ("%s", de_hash (TO_SEXP(p)->tag)); if (LEN(a->tag)) { printStringBuf (" ("); for (i = 0; i < LEN(a->tag); i++) { diff --git a/src/Driver.ml b/src/Driver.ml index 2239a6693..4d9d87846 100644 --- a/src/Driver.ml +++ b/src/Driver.ml @@ -1,23 +1,27 @@ open Ostap 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 (object inherit Matcher.t s inherit Util.Lexers.decimal s inherit Util.Lexers.string s inherit Util.Lexers.char s - inherit Util.Lexers.ident ["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"] s + inherit Util.Lexers.lident kws s + inherit Util.Lexers.uident kws s inherit Util.Lexers.skip [ Matcher.Skip.whitespaces " \t\n"; Matcher.Skip.lineComment "--"; diff --git a/src/Language.ml b/src/Language.ml index 5d50c6703..618e00720 100644 --- a/src/Language.ml +++ b/src/Language.ml @@ -46,7 +46,7 @@ module Value = | Array a -> let n = Array.length a in append "["; Array.iteri (fun i a -> (if i > 0 then append ", "); inner a) a; append "]" | 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 inner v; 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))) | ".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 @@ -240,7 +240,8 @@ module Expr = (* 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 *) ostap ( @@ -268,12 +269,12 @@ module Expr = 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}; base: - n:DECIMAL {Const n} - | s:STRING {String (String.sub s 1 (String.length s - 2))} - | c:CHAR {Const (Char.code c)} - | "[" es:!(Util.list0)[parse] "]" {Array es} - | "`" t:IDENT 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} + n:DECIMAL {Const n} + | s:STRING {String (String.sub s 1 (String.length s - 2))} + | c:CHAR {Const (Char.code c)} + | "[" es:!(Util.list0)[parse] "]" {Array es} + | t:UIDENT args:(-"(" !(Util.list)[parse] -")")? {Sexp (t, match args with None -> [] | Some args -> args)} + | x:LIDENT s:("(" args:!(Util.list0)[parse] ")" {Call (x, args)} | empty {Var x}) {s} | -"(" parse -")" ) @@ -306,17 +307,17 @@ module Stmt = ostap ( parse: %"_" {Wildcard} - | "`" t:IDENT ps:(-"(" !(Util.list)[parse] -")")? {Sexp (t, match ps with None -> [] | Some ps -> ps)} - | "[" ps:(!(Util.list0)[parse]) "]" {Array ps} - | x:IDENT y:(-"@" parse)? {match y with None -> Named (x, Wildcard) | Some y -> Named (x, y)} - | c:DECIMAL {Const c} - | s:STRING {String (String.sub s 1 (String.length s - 2))} - | c:CHAR {Const (Char.code c)} - | "#" %"boxed" {Boxed} - | "#" %"unboxed" {UnBoxed} - | "#" %"string" {StringTag} - | "#" %"sexp" {SexpTag} - | "#" %"array" {ArrayTag} + | t:UIDENT ps:(-"(" !(Util.list)[parse] -")")? {Sexp (t, match ps with None -> [] | Some ps -> ps)} + | "[" ps:(!(Util.list0)[parse]) "]" {Array ps} + | x:LIDENT y:(-"@" parse)? {match y with None -> Named (x, Wildcard) | Some y -> Named (x, y)} + | c:DECIMAL {Const c} + | s:STRING {String (String.sub s 1 (String.length s - 2))} + | c:CHAR {Const (Char.code c)} + | "#" %"boxed" {Boxed} + | "#" %"unboxed" {UnBoxed} + | "#" %"string" {StringTag} + | "#" %"sexp" {SexpTag} + | "#" %"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 @@ -437,7 +438,7 @@ module Stmt = | %"repeat" s:parse %"until" e:!(Expr.parse) {Repeat (s, e)} | %"return" e:!(Expr.parse)? {Return e} | %"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)} | "(" args:!(Util.list0)[Expr.parse] ")" {Call (x, args)} ) {s} @@ -453,8 +454,8 @@ module Definition = type t = string * (string list * string list * Stmt.t) ostap ( - arg : IDENT; - parse: %"fun" name:IDENT "(" args:!(Util.list0 arg) ")" + arg : LIDENT; + parse: %"fun" name:LIDENT "(" args:!(Util.list0 arg) ")" locs:(%"local" !(Util.list arg))? "{" body:!(Stmt.parse) "}" { (name, (args, (match locs with None -> [] | Some l -> l), body))