Closed romshark closed 4 years ago
This test should probably be done automatically in the Parser constructor function to prevent malformed grammar from being accepted by llparser.NewParser
. Following changes would be necessary:
type Parser struct{
rule *Rule
errRule *Rule
}
func NewParser(rule *Rule, errRule *Rule) Parser
func (pr Parser) Parse(source *SourceFile) (Fragment, error)
Proposal
Provide a simple test-helper function like
llparser.TestGrammar(t *testing.T, mainRule *llparser.Rule)
which automatically performs several semantic tests on the specified grammar. The user would only need to wrap it this way:Semantic grammar errors
Either
Optional
,OneOrMore
andZeroOrMore
Sequence
Rule
Fn
withnil
value inChecked
andLexed
Expectation
inTermExact
Current Workaround
Currently, there's no simple way to check a grammar for potential errors.