tags:

views:

20

answers:

1

Hi, I've been trying to learn OMeta using OMeta/JS and I seem to be getting stuck on something that should be really straightforward. If I have a grammar

ometa L <: Parser {
  l letter:l -> l
}
L.match('h', 'l')

It produces the expected output

h

I can also use

ometa W1 <: Parser {
  ls letter*:ls -> ls
}
W1.matchAll('hi', 'ls')

Which produces

[h, i]

But when I try to parse an entire word using

ometa W2 <: Parser {
  word letter:l word:w -> (l + w)
     | letter:l -> l
}
W2.match('hi', 'word')
//Also tried W2.matchAll('hi', 'word')

I get an error

match failed { errorPos=61 }

What am I misunderstanding, and how do I fix the W2 grammer to output 'hi'?

A: 

Well, I figured out how to get the result I wanted. The answer is here, although I still don't understand why W2 doesn't work. I will leave this open for the time being and hope someone can come along to answer that.

ometa W3 <: Parser {
  word letter*:w -> w.join('')
}
W3.matchAll('hi', 'word')

Back again: it seems that maybe using the shorthand to leave off the equal sign was causing an error. Adding it in produces the correct answer.

ometa W2 <: Parser {
  word = letter:l word:w -> (l + w)
       | letter:l -> l
}
W2.matchAll('hi', 'word')
bmavity