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. // ToArray returns Parser items as an array.
// When an error occurs during scanning, a partial result will be // When an error occurs during scanning, a partial result will be
// returned, accompanied by the error that occurred. // 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 var items []parsekit.Item
for { for {
item, err, more := p.Next() 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)) t.Errorf("[%s] Unexpected number of parser items:\nexpected: %d\nactual: %d\n", c.name, len(expected), len(l))
} }
for i, e := range expected { for i, e := range expected {
v := ParserItemToString(l[i]) v := parserItemToString(l[i])
if v != e { if v != e {
t.Errorf("[%s] Unexpected parser item at index %d:\nexpected: %s\nactual: %s\n", c.name, i, e, v) 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: case string:
a := make([]string, len(l)) a := make([]string, len(l))
for _, v := range l { for _, v := range l {
a = append(a, ParserItemToString(v)) a = append(a, parserItemToString(v))
} }
actual := strings.Join(a, "") actual := strings.Join(a, "")
if actual != expected { if actual != expected {
@ -71,8 +71,8 @@ func runStatesT(t *testing.T, c statesT) {
} }
} }
// ParserItemToString returns a string representation of the parsekit.Item. // parserItemToString returns a string representation of the parsekit.Item.
func ParserItemToString(i parsekit.Item) string { func parserItemToString(i parsekit.Item) string {
switch i.Type { switch i.Type {
case parser.ItemComment: case parser.ItemComment:
return fmt.Sprintf("#(%s)", i.Value) return fmt.Sprintf("#(%s)", i.Value)
@ -85,6 +85,6 @@ func ParserItemToString(i parsekit.Item) string {
case parser.ItemAssignment: case parser.ItemAssignment:
return "=" return "="
default: 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 // NewParser creates a new parser, using the provided input string
// as the data to parse. // as the data to parse.
func NewParser(input string) *parsekit.P { func NewParser(input string) *parsekit.Run {
return parsekit.New(input, startKeyValuePair) return parsekit.New(startKeyValuePair).Parse(input)
} }