Strange parsing behavior for particular syntax on wrong input
With a particular syntax and a wrong input, I get errors and AST’s that are completely wrong and could never be the result of parsing the input.
This syntax:
context-free start-symbols Start context-free syntax Start = ModuleDef ModuleDef.ModuleDef = <<Definition*> <Section*>> Definition.Imports = <imports <MODULEID>> Section.Section = <section <SECTIONID> <Definition*>> Definition = TemplateDefinition TemplateElement = TemplateDefinition TemplateDefinition.TemplateDefine = <template <ID> { <TemplateDefinition*> }> TemplateElement.SelectFromList = <select(<Exp> from <Exp>) { <TemplateElement*> }> Exp = [[ID]] lexical syntax ID = [a-zA-Z][a-zA-Z0-9\_]* MODULEID = {EXTENDEDID "/"}+ EXTENDEDID = [a-zA-Z0-9\_\.\-]+ SECTIONID = ~[\n\r]* LAYOUT = [\ \t\n\r] EOF = lexical restrictions ID -/- [a-zA-Z0-9\_] MODULEID -/- [a-zA-Z0-9\_\.\-\/] EOF -/- ~[] context-free restrictions SECTIONID -/- ~[\n\r] LAYOUT? -/- [\ \t\n\r]
And this input:
template X { select (x from x) { } }
results in these errors:
Syntax error, expected: 'imports' Syntax error, expected: 'imports' Syntax error, expected: 'imports' Syntax error, expected: 'section' Syntax error, expected: 'section' Syntax error, expected: 'section' Syntax error, not expected here: '}'
and this AST:
ModuleDef( [TemplateDefine("X", []), Imports("select"), Imports("x"), Imports("from")] , [Section(")", []), Section("{", []), Section("}", [])] )
That AST could never be the result of that particular input. For example, the
Section()
constructor should only be in the AST when thesection
keyword is present in the input, which it is not. Same forImports()
and theimports
keyword.
However, when I change
Section.Section
from this:Section.Section = <section <SECTIONID> <Definition*>>
to this:
Section.Section = <section <ID> <Definition*>>
then parsing behaves normally again, resulting in this error:
Syntax error, not expected here: select
and this AST, as expected:
ModuleDef([TemplateDefine("X", [])], [])
This is not an issue with SDF3. I have attached a small project (with SDF2 syntax) that demonstrates the issue. (See
Submitted by D. Pelsmaeker on 22 July 2014 at 11:58examples\test.tes
.)
Attachments
Log in to post comments