Cosmetics; probably a fix for regexps

This commit is contained in:
Dmitry Boulytchev 2020-05-04 02:45:34 +03:00
parent 423e4e7724
commit 9d0b8e811a
6 changed files with 72 additions and 54 deletions

View file

@ -310,9 +310,10 @@ public fun lookupMemo (m, v) {
case v of
#string -> m ::= addMap (deref (m), v, v); v
| _ ->
local vc = clone (v), i = case vc of #fun -> 1 | _ -> 0 esac;
local vc = clone (v), i = case vc of #fun -> 1 | _ -> 0 esac;
for skip, i < v.length, i := i + 1 do
vc [i] := lookupMemo (m, vc [i])
local vci = lookupMemo (m, vc [i]);
vc [i] := vci
od;
m ::= addMap (deref (m), vc, vc);
vc

View file

@ -9,7 +9,7 @@
-- reporting
public fun createRegexp (r, name) {
local l = [regexp (r), name];
--printf ("Created regexp %s: %x, %x\n", name, l, l[0]);
-- printf ("Created regexp %s: %x, %x\n", name, l, l[0]);
l
}

View file

@ -173,6 +173,15 @@ public fun observe (name, f) {
}
}
public fun showStream (name) {
fun (k) {
fun (s) {
printf ("%s: %s\n", name, showMatcher (s));
k (Succ ({}, s))
}
}
}
fun createResult () {
local errors = ref ({}),
line = ref (0),
@ -182,8 +191,10 @@ fun createResult () {
hasValue = ref (false);
fun k (x) {
if log then printf ("Result: %s\n", x.string) fi;
case x of
Succ (val, _) ->
Succ (val, s) ->
if log then printf ("Result stream: %s\n", showMatcher (s)) fi;
if deref (hasValue)
then failure (sprintf ("Ostap: ambiguous parsing (%s vs. %s)", deref (value).string, val.string))
else