mirror of
https://github.com/johnkerl/miller.git
synced 2026-08-01 20:12:19 +00:00
no-filter-in-filter validation from C to Go
This commit is contained in:
parent
c73bad41bd
commit
b8924e6bec
4 changed files with 25 additions and 5 deletions
|
|
@ -2,7 +2,8 @@
|
|||
BUG:
|
||||
|
||||
rrv ./reg-test/cases/case-c-dsl-context-specific-validation.sh
|
||||
* subr and more ... also needs check for filter statement within filter commands
|
||||
* also needs check for filter statement within filter commands
|
||||
* subr and more
|
||||
|
||||
rrv ./reg-test/cases/case-c-dsl-forbind-typedecl.sh
|
||||
rrv ./reg-test/cases/case-c-dsl-localvar-typedecl.sh
|
||||
|
|
|
|||
2
go/reg-test/cases/case-no-filter-in-filter.sh
Normal file
2
go/reg-test/cases/case-no-filter-in-filter.sh
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
run_mlr put 'filter NR > 2' $indir/s.dkvp
|
||||
mlr_expect_fail filter 'filter NR > 2' $indir/s.dkvp
|
||||
7
go/reg-test/expected/case-no-filter-in-filter.sh.out
Normal file
7
go/reg-test/expected/case-no-filter-in-filter.sh.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
mlr put filter NR > 2 ./reg-test/input/s.dkvp
|
||||
a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776
|
||||
a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463
|
||||
|
||||
mlr filter filter NR > 2 ./reg-test/input/s.dkvp
|
||||
|
||||
|
|
@ -39,6 +39,7 @@ func ValidateAST(
|
|||
for _, astChild := range ast.RootNode.Children {
|
||||
return validateASTAux(
|
||||
astChild,
|
||||
isFilter,
|
||||
atTopLevel,
|
||||
inLoop,
|
||||
inBeginOrEnd,
|
||||
|
|
@ -57,6 +58,7 @@ func ValidateAST(
|
|||
// ----------------------------------------------------------------
|
||||
func validateASTAux(
|
||||
astNode *dsl.ASTNode,
|
||||
isFilter bool,
|
||||
atTopLevel bool,
|
||||
inLoop bool,
|
||||
inBeginOrEnd bool,
|
||||
|
|
@ -66,6 +68,7 @@ func validateASTAux(
|
|||
isAssignmentLHS bool,
|
||||
isUnset bool,
|
||||
) error {
|
||||
nextIsFilter := isFilter
|
||||
nextAtTopLevel := false
|
||||
nextInLoop := inLoop
|
||||
nextInBeginOrEnd := inBeginOrEnd
|
||||
|
|
@ -74,6 +77,16 @@ func validateASTAux(
|
|||
nextIsAssignmentLHS := isAssignmentLHS
|
||||
nextIsUnset := isUnset
|
||||
|
||||
if astNode.Type == dsl.NodeTypeFilterStatement {
|
||||
if isFilter {
|
||||
return errors.New(
|
||||
"Miller: filter expressions must not also contain the \"filter\" keyword.",
|
||||
)
|
||||
}
|
||||
nextIsFilter = true
|
||||
nextInUDS = true
|
||||
}
|
||||
|
||||
// Check: begin/end/func/subr must be at top-level
|
||||
if astNode.Type == dsl.NodeTypeBeginBlock {
|
||||
if !atTopLevel {
|
||||
|
|
@ -206,10 +219,6 @@ func validateASTAux(
|
|||
}
|
||||
}
|
||||
|
||||
// Check: ENV disallowed at left-hand side of assignment? or nah?
|
||||
// Needs to be supported for system() ...
|
||||
// * TODO
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Treewalk
|
||||
|
||||
|
|
@ -219,6 +228,7 @@ func validateASTAux(
|
|||
nextIsUnset = astNode.Type == dsl.NodeTypeUnset
|
||||
err := validateASTAux(
|
||||
astChild,
|
||||
nextIsFilter,
|
||||
nextAtTopLevel,
|
||||
nextInLoop,
|
||||
nextInBeginOrEnd,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue