Friday, October 7, 2011

Cup problem

I again struggled 4 hours with a problem, actually parsing this correctly:
\markup \huge { asdf }

What you need to know about LilyPond parser, that \huge is interpreted in "markup" lexical state. A lexical state allows you to define a different language for parts of the source file. In LilyPond there is notes state, chords state etc. So "c4" input will mean a note in notes state, but a letter and a number in markup state.
The parser achieves this by the following:
\markup { pushMarkupState(); } \huge --> the huge should be interpreted as a markup command and not a normal escaped word (like an identifier)
But CUP, the parser I use always looks ahead one token. So instead of:
"\markup" MARKUPCOMMAND
it parses
"\markup" KEYWORD
Because the action that pushes into the markup state executed after processing the lookahead token.

That means I have to switch the parser implementation (again)... There is an experimental Java backend for Bison. It might work, we will see...

No comments:

Post a Comment