This commit is contained in:
Dmitry Boulytchev 2018-11-04 12:54:26 +03:00
parent 584e7a998b
commit be89ee983a

View file

@ -246,15 +246,15 @@ module Expr =
DECIMAL --- a decimal constant [0-9]+ as a string DECIMAL --- a decimal constant [0-9]+ as a string
*) *)
ostap ( ostap (
parse: parse:
!(Ostap.Util.expr !(Ostap.Util.expr
(fun x -> x) (fun x -> x)
(Array.map (fun (a, s) -> a, (Array.map (fun (a, s) -> a,
List.map (fun s -> ostap(- $(s)), List.map (fun s -> ostap(- $(s)),
(fun x y -> (fun x y ->
match s with match s with
"++" -> Call ("strcat", [x; y]) | "++" -> Call ("strcat", [x; y])
| _ -> Binop (s, x, y) | _ -> Binop (s, x, y)
) )
) s ) s
) )
@ -266,17 +266,17 @@ module Expr =
`Lefta, ["*" ; "/"; "%"]; `Lefta, ["*" ; "/"; "%"];
|] |]
) )
primary); primary);
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: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} | x:IDENT s:("(" args:!(Util.list0)[parse] ")" {Call (x, args)} | empty {Var x}) {s}
| -"(" parse -")" | -"(" parse -")"
) )
end end