romshark / llparser

A universal LL top-down parser written in Go
BSD 3-Clause "New" or "Revised" License
45 stars 1 forks source link

[FTR] Grammar test suite #6

Closed romshark closed 4 years ago

romshark commented 4 years ago

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:

// TestFoolangGrammar tests the grammar of the Foo language for semantic errors
func TestFoolangGrammar(t *testing.T) {
  llparser.TestGrammar(t, foolang.Grammar())
}
Semantic grammar errors

Current Workaround

Currently, there's no simple way to check a grammar for potential errors.

romshark commented 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)