mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-06 06:48:48 +00:00
Fixed chop-suffix
This commit is contained in:
parent
e5c5f914bd
commit
98804770e6
5 changed files with 20 additions and 4 deletions
|
|
@ -108,7 +108,7 @@ class options args =
|
|||
| Some name -> name
|
||||
method get_help = !help
|
||||
method get_include_paths = !paths
|
||||
method basename = Filename.chop_suffix (Filename.basename self#get_infile) ".expr"
|
||||
method basename = Filename.chop_suffix (Filename.basename self#get_infile) ".lama"
|
||||
method topname =
|
||||
match !mode with
|
||||
| `Compile -> "init" ^ self#basename
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
let path = "/home/db/.opam/4.13.1+flambda/share/Lama"
|
||||
let path = "/home/db/.opam/4.14.0+flambda/share/Lama"
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
let version = "Version 1.10, 33b082f21, Thu Apr 14 17:40:35 2022 +0300"
|
||||
let version = "Version 1.10, e5c5f914b, Thu Apr 14 17:41:56 2022 +0300"
|
||||
|
|
|
|||
|
|
@ -46,6 +46,14 @@ fun createMatcher (buf, pos, line, col) {
|
|||
}
|
||||
|
||||
fun matchString (s) {
|
||||
|
||||
|
||||
fun min (x, y) {
|
||||
if x < y then x else y fi
|
||||
}
|
||||
|
||||
-- printf ("Matching string %s against %s...\n", s, substring (buf, pos, min (10, buf.length - pos)));
|
||||
|
||||
if s.length > rest ()
|
||||
then Fail (sprintf ("""%s"" expected", s), line, col)
|
||||
elif matchSubString (buf, s, pos) then Succ (s, shift (s.length))
|
||||
|
|
@ -55,7 +63,13 @@ fun createMatcher (buf, pos, line, col) {
|
|||
|
||||
fun matchRegexp (r) {
|
||||
var n;
|
||||
|
||||
fun min (x, y) {
|
||||
if x < y then x else y fi
|
||||
}
|
||||
|
||||
-- printf ("Matching regexp %s against %s...\n", r.string, substring (buf, pos, min (10, buf.length - pos)));
|
||||
|
||||
if (n := regexpMatch (r[0], buf, pos)) >= 0
|
||||
then Succ (substring (buf, pos, n), shift (n))
|
||||
else Fail (sprintf ("%s expected", r[1]), line, col)
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ public fun memo (f) {
|
|||
if log then printf ("Applying memoized parser to %s\n", s.string) fi;
|
||||
case findMap (deref (t), s) of
|
||||
None ->
|
||||
if log then printf ("New stream item\n") fi;
|
||||
t ::= addMap (deref (t), s, [addSet (emptySet (compare), k), emptySet (fun (r1, r2) {
|
||||
case [r1, r2] of
|
||||
[Fail (_, _, _), Fail (_, _, _)] -> 0
|
||||
|
|
@ -51,7 +52,7 @@ public fun memo (f) {
|
|||
esac
|
||||
})]);
|
||||
f (fun (r) {
|
||||
r := lookupMemo (restab, r);
|
||||
--r := lookupMemo (restab, r);
|
||||
if log then printf ("Running continuation with result %s\n", r.string) fi;
|
||||
case findMap (deref (t), s) of
|
||||
Some ([ks, rs]) ->
|
||||
|
|
@ -74,6 +75,7 @@ public fun memo (f) {
|
|||
}
|
||||
|
||||
public fun token (x) {
|
||||
-- printf ("token: %s\n", x.string);
|
||||
case x of
|
||||
#str -> memo $ fun (k) {fun (s) {k $ matchString (s, x)}}
|
||||
| _ -> memo $ fun (k) {fun (s) {k $ matchRegexp (s, x)}}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue