Parser glue symbols

<< Click to Display Table of Contents >>

Navigation:  Details >

Parser glue symbols

Previous pageReturn to chapter overviewNext page

In general, the ANTLR parser is set up to ignore whitespace. This makes the parser grammar much more readable, but it means the the parser does not inherently distinguish between for instance a{%i} and {%i}, note the blank in the last expression. Even though Gekko uses commas to separate elements, blanks/whitespace still has some significance, and therefore, before the parser is called, an expression like a{%i} or {%i} is transformed into a¨{%¨i} and {%¨i}, respectively. The small symbol ¨ is a kind of artificial "glue" character, signifying that the parts are "glued" together.

In the first expression, there is no blank between a and {, and in both expressions there is no blank between % and i. The parser uses this to demand "no-blanks" in some cases, and this logic is a bit complicated.

The glue symbols are added in the method HandleGekkoCommandsGlueSymbols() in Program.cs, where there are quite a lot of comments to explain what is going on.

When errors are printed, we need to remove the glue symbols again. Also, the character number will be wrong, if there are glue symbols, and this is handled (not perfectly though). The glue symbols are removed by the method ReplaceGlueSymbols() in G.cs.