On Sat, Feb 28, 2026 at 5:34 PM C. Stroppel <[email protected]> wrote:
>
> In response to Werner’s question,
>
> > * How do you ensure that your parser stays in sync with the one
> > LilyPond uses?
>
> I wanted to add a short note from the perspective of my current work on
> a modular lexer and parser for LilyPond. While exploring the internals,
> I ran into the same issue Werner mentioned: LilyPond has a very complete
> /semantic/ layer (contexts, engravers, grobs, music types), but the
> /syntax/ is only defined implicitly in |parser.yy| and |lexer.ll|. That
> makes it difficult for external tools to rely on a stable description of
> what is syntactically valid.
> ..
> Before I go further in this direction for my own project, I’d like to
> ask whether the community sees value in such a shared grammar source and
> whether this is something we might want to maintain collectively.
>
>
parser.yy and lexer.ll are machine readable descriptions of the syntax, so
IMO, they are superior to EBNF or a YAML based grammar.
The real difficulty with the LilyPond syntax is that it is innately
intertwined with the embedded Scheme interpreter, eg. things like
#(define foo 22.9)
\paper {
paper-width = \foo \cm
}
means that you can only make sense of a snippet of lilypond if you have a
working Scheme interpreter with a module system on board.
--
Han-Wen Nienhuys - [email protected] - http://www.xs4all.nl/~hanwen