Commit 48813d9e by POTTIER Francois

Exposed [foreach_terminal] and [foreach_terminal_but_error].

parent 9a72dd36
* Add ways of iterating over all symbols.
* Add left-recursive lists to the standard library.
* Define [print_result].
......
......@@ -194,6 +194,13 @@ module type INSPECTION = sig
val nullable: 'a nonterminal -> bool
(* [foreach_terminal] enumerates the terminal symbols, including [error].
[foreach_terminal_but_error] enumerates the terminal symbols, excluding
[error]. *)
val foreach_terminal: (xsymbol -> 'a -> 'a) -> 'a -> 'a
val foreach_terminal_but_error: (xsymbol -> 'a -> 'a) -> 'a -> 'a
end
(* This signature combines the incremental API and the inspection API. *)
......
......@@ -124,4 +124,29 @@ module Make
let nullable nt =
PackedIntArray.get1 T.nullable (n2i nt) = 1
(* The function [foreach_terminal] exploits the fact that the
first component of [B.error] is [Terminal.n - 1], i.e., the
number of terminal symbols, including [error] but not [#]. *)
let rec foldij i j f accu =
if i = j then
accu
else
foldij (i + 1) j f (f i accu)
let foreach_terminal f accu =
let n, _ = B.error in
foldij 0 n (fun i accu ->
f (T.terminal i) accu
) accu
let foreach_terminal_but_error f accu =
let n, _ = B.error in
foldij 0 n (fun i accu ->
if i = B.error_terminal then
accu
else
f (T.terminal i) accu
) accu
end
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