On Fri 2010-11-12 at 12:38h, Etienne M. Gagnon wrote on sablecc-discussion:
> Hi,
>
> The theory for implementing an efficient lookback operator (similar to
> the lookahead operator) is ready. Remains the problem of selecting a
> syntax for it.
>
> Here are two alternatives:
>
> // a keyword is the identifier on a line
> keyword = identifier Lookback (Start | eol) blank*;
>
> OR
>
> keyword = Back (Start | eol) blank* Then identifier;
>
> Which one do you prefer (and why)?
An operand order like in the second alternative, where the order
corresponds to the textual order in the input, is generally
preferable, as otherwise it's more difficult to remember which is
which, in the absence of further hints. But with a "fluent" [1]
syntax, the reverse order can be fine too. The first alternative
above isn't particularly fluent though (and neither is "Back" in the
second).
The following would be quite readable:
keyword = identifier Behind (Start | eol) blank*
The lookahead syntax could be designed in correspondance to it:
eolword = identifier Before blank* (End | eol)
Or maybe:
keyword = identifier Following (Start | eol) blank*
eolword = identifier Preceding blank* (End | eol)
By the way, isn't "lookbehind" the usual term?
I don't remember having seen "lookback" used for this before.
Another possible consideration is how the combination of lookahead and
lookbehind works. E.g. is it clear that
foo = bar Following prefix Preceding suffix
would mean (it probably should)
foo = (bar Following prefix) Preceding suffix
and not
foo = bar Following (prefix Preceding suffix)
(and is the latter actually supported?)
A syntax that would preserve order *and* be fluent would be best of
course, but I can't think of any.
-- Niklas Matthies
[1] "fluent" in the spirit of http://martinfowler.com/bliki/FluentInterface.html
_______________________________________________
SableCC-Discussion mailing list
[email protected]
http://lists.sablecc.org/listinfo/sablecc-discussion