Extend rule structure and nip rule parser (#16)
This commit is contained in:
@@ -45,7 +45,7 @@ func ParseNIPFile(filePath string) ([]Rule, error) {
|
||||
lineNumber := 0
|
||||
for fileScanner.Scan() {
|
||||
lineNumber++
|
||||
rule, err := ParseLine(fileScanner.Text())
|
||||
rule, err := ParseLine(fileScanner.Text(), filePath, lineNumber)
|
||||
if errors.Is(err, errEmptyLine) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ var (
|
||||
propertyNameRegex = regexp.MustCompile(`\[(.*)\]`)
|
||||
)
|
||||
|
||||
func ParseLine(line string) (Rule, error) {
|
||||
func ParseLine(line string, filename string, linenum int) (Rule, error) {
|
||||
line = lineCleanup(line)
|
||||
if line == "" {
|
||||
return Rule{}, errEmptyLine
|
||||
@@ -46,6 +46,9 @@ func ParseLine(line string) (Rule, error) {
|
||||
Properties: properties,
|
||||
Stats: stats,
|
||||
MaxQuantity: maxQuantity,
|
||||
Filename: filename,
|
||||
LineNumber: linenum,
|
||||
Enabled: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
const nipLine = "[type] == boots && [quality] == rare # [frw] >= 10 && [fireresist] >= 10 && ([lightresist]+[coldresist] >= 10 && [dexterity] >= 1 && [fireresist]+[poisonresist] >= 10) // this is a comment"
|
||||
|
||||
func Test_parseLine(t *testing.T) {
|
||||
rules, err := ParseLine(nipLine)
|
||||
rules, err := ParseLine(nipLine, "dummy", 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
expected := Rule{
|
||||
|
||||
@@ -16,6 +16,9 @@ type Rule struct {
|
||||
Properties []Group
|
||||
Stats []Group
|
||||
MaxQuantity []Group
|
||||
Filename string
|
||||
LineNumber int
|
||||
Enabled bool
|
||||
}
|
||||
|
||||
type Keyword string
|
||||
|
||||
Reference in New Issue
Block a user