Simon Génier pushed to branch main at Stefan / Typer
Commits: 8b7e3b1f by Simon Génier at 2023-02-19T14:08:42-05:00 Get rid of empty_args_are_not_args.
This configuration was used to toggle the behaviour of the sexp parser for a transition in syntax that was completed years ago. Today it is always false and we can get rid of it to simplify the maintenance of the parser.
- - - - -
1 changed file:
- src/sexp.ml
Changes:
===================================== src/sexp.ml ===================================== @@ -119,13 +119,6 @@ let sexp_name s =
(*************** The Sexp Parser *********************)
- -(* If true, infix symbols like "_;_" will be turned into ";_" or "_;" - * if they had no right or left argument. - * If false, "_;_" will stay as it is, and receive Epsilon arguments - * as appropriate. *) -let empty_args_are_not_args = false - (* `op' is the operator being parsed. E.g. for let...in... * it would be either ["let"] or ["in";"let"] depending on which * part we've parsed already. @@ -173,14 +166,12 @@ let rec sexp_parse (g : grammar) (rest : sexp list) | (None, Some rl) (* Open paren or prefix. *) -> let (e, rest) = sexp_parse rest' rl [s] [] [] in sexp_parse rest level op largs (e::rargs) + + (* A symbol that closes the currently parsed element. *) | (Some ll, _) when ll < level - (* A symbol that closes the currently parsed element. *) - -> ((if empty_args_are_not_args then - mk_node (match rargs with [] -> op | _ -> ((l,"")::op)) - largs rargs false - else - mk_node ((l,"")::op) largs rargs true), - rest) + -> let node = mk_node ((l, "") :: op) largs rargs true in + (node, rest) + | (Some ll, None) when ll > level (* A closer without matching opener or a postfix symbol that binds very tightly. Previously, we signaled an @@ -194,18 +185,14 @@ let rec sexp_parse (g : grammar) (rest : sexp list) constructor. *) -> sexp_parse rest' level op largs [mk_node [(l,name);(l,"")] [] rargs true] + + (* A new infix which binds more tightly, i.e. does not close the + current `op' but takes its `rargs' instead. *) | (Some ll, Some rl) when ll > level - (* A new infix which binds more tightly, i.e. does not close - * the current `op' but takes its `rargs' instead. *) - -> let (e, rest) - = if empty_args_are_not_args then - sexp_parse rest' rl - (match rargs with [] -> [s] | _ -> [s;(l,"")]) - (push_largs [] rargs false) [] - else - sexp_parse rest' rl [s;(l,"")] - (push_largs [] rargs true) [] - in sexp_parse rest level op largs [e] + -> let largs' = push_largs [] rargs true in + let (e, rest'') = sexp_parse rest' rl [s; (l, "")] largs' [] in + sexp_parse rest'' level op largs [e] + | (Some ll, Some rl) -> sexp_parse rest' rl (if ll == rl @@ -213,6 +200,7 @@ let rec sexp_parse (g : grammar) (rest : sexp list) | _ -> false then op else (s::op)) (push_largs largs rargs true) [] + | (Some _ll, None) -> (mk_node (s::op) largs rargs true, rest') with Not_found ->
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/8b7e3b1f8de6d6720a4fe600ca549d6853...
Afficher les réponses par date