From 17b2f1b728a5bf3ccabcdb0159959a4da00b955e Mon Sep 17 00:00:00 2001 From: Patrick Ferris Date: Thu, 25 Jun 2026 13:15:48 +0100 Subject: [PATCH] Fix arith parsing --- dune-project | 2 ++ merry.opam | 2 ++ src/lib/arith_lexer.mll | 2 +- src/lib/ast.ml | 13 ++++++++++--- src/lib/eval.ml | 4 ++-- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/dune-project b/dune-project index 2a03236..350e517 100644 --- a/dune-project +++ b/dune-project @@ -30,7 +30,9 @@ xdge globlon logs + memtrace (mdx :with-test) + (bechamel :with-test) (menhir (= 20250912)) (yojson diff --git a/merry.opam b/merry.opam index d8937a9..2adcbf5 100644 --- a/merry.opam +++ b/merry.opam @@ -17,7 +17,9 @@ depends: [ "xdge" "globlon" "logs" + "memtrace" "mdx" {with-test} + "bechamel" {with-test} "menhir" {= "20250912"} "yojson" {= "2.2.2"} "ppxlib" {>= "0.37.0"} diff --git a/src/lib/arith_lexer.mll b/src/lib/arith_lexer.mll index 2a5b3a9..8d149fb 100644 --- a/src/lib/arith_lexer.mll +++ b/src/lib/arith_lexer.mll @@ -7,7 +7,7 @@ let oct_digit = ['0'-'7'] let hex_digit = ['0'-'9' 'a'-'f' 'A'-'F'] let alpha = ['a'-'z' 'A'-'Z' '_'] let ident = alpha (alpha | digit)* -let enclosed = '{' (alpha | digit | '#' | '*' | '%' | ' ' | '-')* '}' +let enclosed = '{' (alpha | digit | '#' | '*' | '%' | ' ' | '-' | ':' | '+' | '?')* '}' let var = ident diff --git a/src/lib/ast.ml b/src/lib/ast.ml index acbf7ea..80bbc99 100644 --- a/src/lib/ast.ml +++ b/src/lib/ast.ml @@ -592,10 +592,17 @@ and word_component : CST.word_component -> word_component = WordVariable a | WordGlobAll -> WordGlobAll | WordGlobAny -> WordGlobAny - | WordArithmeticExpression s -> - let expr = word_components_to_strings (word s) |> String.concat "" in + | WordArithmeticExpression (Word (expr, _)) -> + let lexbuf = Lexing.from_string expr in let aexpr = - Arith_parser.main Arith_lexer.read (Lexing.from_string expr) + try Arith_parser.main Arith_lexer.read lexbuf + with Failure msg -> + let pos = lexbuf.Lexing.lex_curr_p in + let line = pos.Lexing.pos_lnum in + (* pos_bol is the absolute character offset of the beginning of the current line *) + let col = pos.Lexing.pos_cnum - pos.Lexing.pos_bol + 1 in + Fmt.epr "Error at line %d, column %d -- %s\n" line col expr; + raise (Failure msg) in WordArithmeticExpression aexpr | WordReBracketExpression a -> diff --git a/src/lib/eval.ml b/src/lib/eval.ml index 2388611..56de308 100644 --- a/src/lib/eval.ml +++ b/src/lib/eval.ml @@ -135,8 +135,8 @@ module Make (S : Types.State) (E : Types.Exec) = struct Fmt.field "rdrs" (fun t -> t.rdrs) Fmt.(lst Types.pp_redirect); Fmt.field "argv" (fun t -> Array.to_list t.argv) Fmt.(lst string); Fmt.field "functions" - (fun t -> t.functions |> List.map (fun (k, v) -> (k, v))) - Fmt.(lst (pair ~sep:(any "=") string Ast_pp.compound_command)); + (fun t -> t.functions |> List.map fst) + Fmt.(lst string); ]) ppf -- 2.51.2