Interesting work^^. The main problem currently plaguing me is the lack of nice syntax shortcuts. In order to add guards I co-opted the , and ,@ syntaxes already. Hmm. The problem is that there is currently no syntax that supports an <expr><punctuation><expr> or at least <symbol><punctuation><expr>. ! could have been co-opted but the problem is that ! works only for symbols.
Here's a suggestion: add the following bracket-detector stuff (untested):
(let bracket-sample '[a.highly-unlikely!symbol]
(def is-bracket (a)
(is (car a) (car bracket-sample)))
(def bracket-list (a)
((afn (a sample)
(if
(iso sample '(a.highly-unlikely!symbol))
a
(acons a)
(or
(self (car a) (car sample))
(self (cdr a) (cdr sample)))))
a bracket-sample)))
^^ again... code please! Seems pretty nice. Just wondering, does this use the parse combinator library on arc-wiki or is this something else? Haven't studied the parsec lib very well yet. If different, would it be possible to merge it into the arc-wiki lib/parsec.arc?
Here ya go, lib/treeparse.arc. Unlike the sloppy proof of concept hcase, this one might actually be useful.
This is different from parsecomb.arc in a number of ways, one being that it operates on lists and trees while parsecomb takes strings. Parsecomb also appears to be broken...
Incidentally, pg would like to conflate strings as a list of characters, so possibly with a "correct" implementation of treeparse we can still parse strings as well.
Possibly the brokenness in parsecomb currently is from the merge with arc1 and/or arc2
Edit: Hmm. Possibly you think this can be encapsulated using one of the module systems? Most of the components are functions anyway, and the existing macros end up evaluating to functions, so it may be possible to transform them to higher-level functions instead.
It would be nice to put it in a module, seeing as it binds allot of useful words. I like your module1plus, but without macro support it is hard to contain this library.
The macros seq, alt, cant-see, many, and many1 may appear to be expressible as functions, but they need to be macros to reference parsers not yet created.
(= a (alt 'y (many b)))
;; `b' is not bound yet, but will be by the time `a' is used.
(= b (alt 'x (many a)))
(parse a '(x y))
Oh, bummer. I guess I got too used to lazy evaluation in Haskell.
Macro support... dang. It's kind hard to scan through the code looking for macro definitions, and then you need to have them exportable, meaning you need the original list - and exportable macros will not be able to refer to the exporting environment (bummer).
Macros in packages are a hard problem, no doubt. I still wonder if some degree of macrolet hackery might do the trick.
On a brighter note, I decided to make the lazy semantics of "lib/treeparse.arc" a special case, not the default. That way, there only needs to be one macro, delay-parser. Apart from making the code cleaner, this also makes a module more feasible.
Hmm. Maybe export the macros as functions. Hmm. This also means that everything within the module has to be macro-expanded, in case macroexpansion creates a reference to a module-based macro. Aargh.