mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-06 06:48:48 +00:00
Cosmetics in stdlib/spec
This commit is contained in:
parent
50fc2e9f2a
commit
78305d22b3
6 changed files with 12 additions and 12 deletions
BIN
lama-spec.pdf
BIN
lama-spec.pdf
Binary file not shown.
|
|
@ -333,7 +333,8 @@ The unit describes some primitive parsers and combinators which allow to constru
|
|||
|
||||
\descr{\lstinline|fun memo (f)|}{Takes a parser "\lstinline|a|" and returns its memoized version. Needed for some parsers (for expamle, left-recursive ones).}
|
||||
|
||||
\descr{\lstinline|fun token (x)|}{Takes a string and returns a parser which recognizes exactly this string.}
|
||||
\descr{\lstinline|fun token (x)|}{Takes a string or a representation of regular expression, returned by "\lstinline|createRegexp|" (see unit \texttt{Matcher}),
|
||||
and returns a parser which recognizes exactly this string/regular expression.}
|
||||
|
||||
\descr{\lstinline|fun eof (k)|}{A parser which recognizes the end of stream.}
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
let version = "Version 1.00, a44ccbf2, Fri Feb 28 01:11:40 2020 +0300"
|
||||
let version = "Version 1.00, 50fc2e9f, Fri Feb 28 18:32:19 2020 +0300"
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ fun createMatcher (buf, pos, line, col) {
|
|||
fun matchRegexp (r) {
|
||||
local n;
|
||||
|
||||
if (n := regexpMatch (r[0], buf, pos)) > 0
|
||||
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)
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -64,11 +64,10 @@ public fun memo (f) {
|
|||
}
|
||||
|
||||
public fun token (x) {
|
||||
fun (k) {
|
||||
fun (s) {
|
||||
k $ matchString (s, x)
|
||||
}
|
||||
}
|
||||
case x of
|
||||
#string -> fun (k) {fun (s) {k $ matchString (s, x)}}
|
||||
| _ -> fun (k) {fun (s) {k $ matchRegexp (s, x)}}
|
||||
esac
|
||||
}
|
||||
|
||||
public fun eof (k) {
|
||||
|
|
@ -130,8 +129,8 @@ public fun bypass (f) {
|
|||
public fun opt (a) {empty @ lift (None) | a @ fun (x) {Some (x)}}
|
||||
|
||||
public fun rep0 (a) {
|
||||
--memo
|
||||
(empty @ lift({}) | a |> fun (x) {rep0 (a) @ fun (as) {x : as}})
|
||||
memo
|
||||
(empty @ lift({}) | a |> fun (x) {rep0 (a) @ fun (as) {x : as}})
|
||||
}
|
||||
|
||||
public fun rep (a) {
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ printf ("if, case, for, while, repeat etc. are all expressions.\n");
|
|||
|
||||
printf ("Case-expression: %s\n", case A (1, 2, 3) of A (x, y, z) -> z esac.string);
|
||||
|
||||
printf ("If-expression: %s\n", if true then 2 else 3 fi +
|
||||
if false then 6 else 7 fi.string);
|
||||
printf ("If-expression: %s\n", (if true then 2 else 3 fi +
|
||||
if false then 6 else 7 fi).string);
|
||||
|
||||
printf ("Scope-expression: %s\n", {local i, s = 0;
|
||||
for i := 0, i < 10, i := i + 1 do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue