Dan Eble <[email protected]> writes: > On 2026-06-16 04:26, C. Stroppel wrote: >> I am currently investigating whether the relationship between >> LilyPond syntax and its internal structures can be extracted >> automatically. >> The question is: In which context can a LilyPond command be >> applied? >> > > Pause. The subject is parsing, but you're using terms that could > easily be misunderstood because there are other areas of LilyPond > apart from parsing where those terms have specific meanings. > > In a discussion of parsing, the natural meaning of "context" is > approximately "the surrounding syntax." For example, a command > appears within a \bookpart, a \score, a music expression, etc. There > is also the translation-time concept of context implemented in > lily/context.cc, which you also discuss a little later in your > message.
The closest to "context" here is one of several _lexer_ states. Those states change how tokens are formed and are defined in lily/lexer.ll . We have here: %x chords %x figures %x incl %x lyrics %x longcomment %x maininput %x markup %x notes %x quote %x commandquote %x sourcefileline %x sourcefilename %x version About half are very specialized and only work in small contexts like strings, particular statements, comments and other tiny things. The others are tied into larger parsing surroundings. The fewer there can be of those, the better. I've tried devising a strategy to fuse chords and notes, for example. There has also been considerable work to make lyrics and markup behave in a way compromising between simple rules and "naïve expectations". The syntactical tie-ins of the parser are harder to mimic. -- David Kastrup
