Fix bug on DSL comment with no final newline (#1216)

This commit is contained in:
John Kerl 2023-03-03 21:42:10 -05:00 committed by GitHub
parent 40b1d22684
commit 1c5e97b93c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 0 deletions

View file

@ -127,6 +127,14 @@ func buildASTFromString(dslString string) (*dsl.AST, error) {
dslString = dslString[1 : len(dslString)-1]
}
// The comment-stripping lex expression in Miller's GOCC grammar matches from '#' to '\n' ... in
// the case where there is a '#', then comment text, then end-of-string without any final
// newline, the comment text does _not_ get stripped out and is a parse error.
// It's simplest to ensure, here, that DSL-expression strings have a final newline.
if !strings.HasSuffix(dslString, "\n") {
dslString += "\n"
}
theLexer := lexer.NewLexer([]byte(dslString))
theParser := parser.NewParser()
interfaceAST, err := theParser.Parse(theLexer)

View file

@ -0,0 +1 @@
mlr --from test/input/abixy put '$z = NR # test'

View file

View file

@ -0,0 +1,10 @@
a=pan,b=pan,i=1,x=0.34679014,y=0.72680286,z=1
a=eks,b=pan,i=2,x=0.75867996,y=0.52215111,z=2
a=wye,b=wye,i=3,x=0.20460331,y=0.33831853,z=3
a=eks,b=wye,i=4,x=0.38139939,y=0.13418874,z=4
a=wye,b=pan,i=5,x=0.57328892,y=0.86362447,z=5
a=zee,b=pan,i=6,x=0.52712616,y=0.49322129,z=6
a=eks,b=zee,i=7,x=0.61178406,y=0.18788492,z=7
a=zee,b=wye,i=8,x=0.59855401,y=0.97618139,z=8
a=hat,b=wye,i=9,x=0.03144188,y=0.74955076,z=9
a=pan,b=wye,i=10,x=0.50262601,y=0.95261836,z=10