How do I combine a word with OMetaJS?

I tried to learn OMeta using OMeta / JS and I seem to be fixated on something that should be very simple. If i have 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') 

What produces

 [h, i] 

But when I try to parse a whole 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 I don’t understand, and how to fix W2 grammars for hi output?

+4
source share
1 answer

Well, I figured out how to get the result that I wanted. The answer is here, although I still don't understand why W2 is not working. I will leave this open for a while and hope that someone can come to answer this question.

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

Back again: it seems that perhaps using the abbreviation to leave an equal sign caused an error. By adding it, you will get the correct answer.

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

All Articles