On Mon, Apr 19, 2004 at 01:06:29AM -0600, Luke Palmer wrote:
: Therefore, the first syntax can be redefined to evaluate the code block
: and assign the result to $0. The example now becomes:
:
: rule list {
: <?term> , <?list> <{ make_node('list', $?term, $?list) }>
: | <?term> <{ $?term }>
: }
Well, I've been thinking about this for a couple of weeks now, and
while I freely admit that "$0 =" is ugly, I also find that I dislike
using <...> for something that is not a pattern assertion, but a
side effect. Plus your proposed notation is almost as long as what
you're replacing. And I don't think it stands out visually enough
for its semantic weight.
: My argument for using this notation stems from the fact that it would
: be a royal pain to write subs like:
:
: sub add ($a, $b) {
: $RET = $a + $b;
: }
:
: Even though it's just a few extra characters. I don't want to think
: about replacing the current parse tree node, I just want the rule to
: represent a value. An assignment has little place there.
Then what you want is something like a "return" keyword, only it returns
from the rule rather than the closure:
rule list {
<?term> , <?list> { succeed make_node('list', $?term, $?list) }
| <?term> { succeed $?term }
}
Or whatever word you like there...
Alternately, you can get rid of the explicit $0 by saying
rule list {
<?term> , <?list> {.= make_node('list', $?term, $?list) }
| <?term> {.= $?term }
}
That at least removes the extraneous "noun" from your thinking, and
".=" can be read as a pure verb if you like. And if you don't like,
translating "succeed" to ".=" via a macro is left as an exercise for
the don't-liker.
Larry