Attention une mise à jour du serveur va être effectuée le vendredi 16 avril entre 12h et 12h30. Cette mise à jour va générer une interruption du service de quelques minutes.

Commit 379675e8 authored by POTTIER Francois's avatar POTTIER Francois

Isolate [find]. Introduce [expand_symbol].

Make it [expand_symbol] the main entry point instead of [expand_rule].
parent 5c029418
......@@ -151,6 +151,15 @@ let is_inline_nonterminal grammar symbol : bool =
(* This is a terminal symbol. *)
(* [find grammar symbol] looks up the definition of [symbol], which must be
a valid nonterminal symbol. *)
let find grammar symbol : rule =
StringMap.find symbol grammar.rules
with Not_found ->
assert false
(* [find_inlining_site grammar (prefix, suffix)] traverses a list of producers
that is already decomposed as [List.rev prefix @ suffix]. It looks for the
first nonterminal symbol that can be inlined away. If it does not find one,
......@@ -352,10 +361,13 @@ let inline grammar =
return caller
| Some ((_prefix, producer, _suffix) as site) ->
let symbol = producer_symbol producer in
let rule = StringMap.find symbol grammar.rules in (* cannot fail *)
let rule = expand_rule symbol rule in
let rule = expand_symbol symbol in
inline_branches caller site rule.branches >>= expand_branch
and expand_symbol symbol : rule =
let rule = find grammar symbol in
expand_rule symbol rule
(* Expand a rule if necessary. *)
and expand_rule k r =
......@@ -387,7 +399,7 @@ let inline grammar =
let rules =
|> StringMap.filter (fun _ r -> not r.inline_flag)
|> StringMap.mapi expand_rule
|> StringMap.mapi (fun symbol _rule -> expand_symbol symbol) (* a little wasteful, but simple *)
let useful (k : string) : bool =
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment