Compatibility with the latest parsekit module.

This commit is contained in:
Maurice Makaay 2019-05-23 00:02:53 +00:00
parent 234bbdf30f
commit 6af770a918
2 changed files with 8 additions and 8 deletions

View File

@ -25,7 +25,7 @@ func runStatesTs(t *testing.T, tests []statesT) {
// ToArray returns Parser items as an array.
// When an error occurs during scanning, a partial result will be
// returned, accompanied by the error that occurred.
func parseItemsToArray(p *parsekit.P) ([]parsekit.Item, *parsekit.Error) {
func parseItemsToArray(p *parsekit.Run) ([]parsekit.Item, *parsekit.Error) {
var items []parsekit.Item
for {
item, err, more := p.Next()
@ -54,7 +54,7 @@ func runStatesT(t *testing.T, c statesT) {
t.Errorf("[%s] Unexpected number of parser items:\nexpected: %d\nactual: %d\n", c.name, len(expected), len(l))
}
for i, e := range expected {
v := ParserItemToString(l[i])
v := parserItemToString(l[i])
if v != e {
t.Errorf("[%s] Unexpected parser item at index %d:\nexpected: %s\nactual: %s\n", c.name, i, e, v)
}
@ -62,7 +62,7 @@ func runStatesT(t *testing.T, c statesT) {
case string:
a := make([]string, len(l))
for _, v := range l {
a = append(a, ParserItemToString(v))
a = append(a, parserItemToString(v))
}
actual := strings.Join(a, "")
if actual != expected {
@ -71,8 +71,8 @@ func runStatesT(t *testing.T, c statesT) {
}
}
// ParserItemToString returns a string representation of the parsekit.Item.
func ParserItemToString(i parsekit.Item) string {
// parserItemToString returns a string representation of the parsekit.Item.
func parserItemToString(i parsekit.Item) string {
switch i.Type {
case parser.ItemComment:
return fmt.Sprintf("#(%s)", i.Value)
@ -85,6 +85,6 @@ func ParserItemToString(i parsekit.Item) string {
case parser.ItemAssignment:
return "="
default:
panic(fmt.Sprintf("No string representation available for parsekit.Item id %d", i.Type))
panic(fmt.Sprintf("parsekit bug: no string formatting exists for parsekit.Item id %d", i.Type))
}
}

View File

@ -19,6 +19,6 @@ var (
// NewParser creates a new parser, using the provided input string
// as the data to parse.
func NewParser(input string) *parsekit.P {
return parsekit.New(input, startKeyValuePair)
func NewParser(input string) *parsekit.Run {
return parsekit.New(startKeyValuePair).Parse(input)
}