mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-08 15:58:47 +00:00
More Ostap tests
This commit is contained in:
parent
9163747ff3
commit
ff197744f6
3 changed files with 45 additions and 4 deletions
|
|
@ -11,7 +11,11 @@ public fun initOstap () {
|
||||||
hct := emptyMemo ()
|
hct := emptyMemo ()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun memo (f) {
|
public fun cleanupOstap () {
|
||||||
|
initOstap ()
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun memo (f) {
|
||||||
local t;
|
local t;
|
||||||
|
|
||||||
f := lookupMemo (hct, f);
|
f := lookupMemo (hct, f);
|
||||||
|
|
@ -148,7 +152,7 @@ public fun observe (name, f) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun createResult () {
|
fun createResult () {
|
||||||
local errors = ref ({}),
|
local errors = ref ({}),
|
||||||
line = ref (0),
|
line = ref (0),
|
||||||
col = ref (0),
|
col = ref (0),
|
||||||
|
|
@ -192,10 +196,26 @@ public fun createResult () {
|
||||||
[k, get]
|
[k, get]
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun k (acc) {
|
fun k (acc) {
|
||||||
acc [0]
|
acc [0]
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun result (acc) {
|
fun result (acc) {
|
||||||
acc [1] ()
|
acc [1] ()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public fun parse (p, m) {
|
||||||
|
local acc = createResult ();
|
||||||
|
|
||||||
|
p (acc.k) (m);
|
||||||
|
|
||||||
|
acc.result
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun parseString (p, s) {
|
||||||
|
local acc = createResult ();
|
||||||
|
|
||||||
|
p (acc.k) (initMatcher (s));
|
||||||
|
|
||||||
|
acc.result
|
||||||
|
}
|
||||||
2
stdlib/regression/orig/test10.log
Normal file
2
stdlib/regression/orig/test10.log
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
Parsing "aaa" with many ... Succ ({"a", "a", "a"})
|
||||||
|
Parsing "ab" with bad_alter ... Succ ("ab")
|
||||||
19
stdlib/regression/test10.expr
Normal file
19
stdlib/regression/test10.expr
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import Ostap;
|
||||||
|
import List;
|
||||||
|
import Fun;
|
||||||
|
|
||||||
|
fun many (a) {
|
||||||
|
memo (
|
||||||
|
fun (k) {
|
||||||
|
empty @ lift({})
|
||||||
|
| many (a) |> fun (as) {a @ fun (x) {as +++ singleton (x)}} $ k
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
local a = token ("a"), b = token ("b");
|
||||||
|
local bad_alter = a | a |> fun (x) {b @ fun (y) {x ++ y}};
|
||||||
|
|
||||||
|
initOstap ();
|
||||||
|
printf ("Parsing ""aaa"" with many ... %s\n", parseString (many (a) |> bypass (eof), "aaa").string);
|
||||||
|
printf ("Parsing ""ab"" with bad_alter ... %s\n", parseString (bad_alter |> bypass (eof), "ab").string)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue