From 73f60075bde8f9bfee0b449fd757cb74eab56cf1 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Tue, 24 Nov 2020 10:27:11 -0500 Subject: [PATCH] comment-neaten --- go/cases-to-do.txt | 13 ++++-------- go/src/miller/dsl/cst/assignments.go | 8 +++---- go/src/miller/dsl/cst/block-exit.go | 14 ++++++------- go/src/miller/dsl/cst/blocks.go | 11 +++++++--- .../dsl/cst/builtin_function_manager.go | 12 +++++------ go/src/miller/dsl/cst/builtin_functions.go | 8 +++---- go/src/miller/dsl/cst/collections.go | 10 ++++----- go/src/miller/dsl/cst/cond.go | 10 ++++----- go/src/miller/dsl/cst/emit.go | 12 +++++------ go/src/miller/dsl/cst/env.go | 14 ++++++------- go/src/miller/dsl/cst/evaluable.go | 12 +++++------ go/src/miller/dsl/cst/filter.go | 8 +++---- go/src/miller/dsl/cst/for.go | 8 +++---- go/src/miller/dsl/cst/functions.go | 14 ++++++------- go/src/miller/dsl/cst/if.go | 8 +++---- go/src/miller/dsl/cst/leaves.go | 8 +++---- go/src/miller/dsl/cst/lvalues.go | 8 ++++--- go/src/miller/dsl/cst/print.go | 8 +++---- go/src/miller/dsl/cst/root.go | 10 ++++----- go/src/miller/dsl/cst/stack.go | 20 +++++++++--------- go/src/miller/dsl/cst/state.go | 6 ++++++ go/src/miller/dsl/cst/statements.go | 10 ++++----- go/src/miller/dsl/cst/types.go | 21 ++++--------------- go/src/miller/dsl/cst/udf.go | 8 +++---- go/src/miller/dsl/cst/validate.go | 12 +++++------ go/src/miller/dsl/cst/while.go | 8 +++---- go/todo.txt | 5 +++++ 27 files changed, 142 insertions(+), 144 deletions(-) diff --git a/go/cases-to-do.txt b/go/cases-to-do.txt index 8437a7252..6dc37cfed 100644 --- a/go/cases-to-do.txt +++ b/go/cases-to-do.txt @@ -1,12 +1,6 @@ -! rrv --show - ================================================================ BUG: -rrv ./reg-test/cases/case-c-dsl-context-specific-validation.sh -* mlr: filter expressions must end in a final boolean statement. --> abandon this requirement? doc if so. - rrv ./reg-test/cases/case-c-dsl-forbind-typedecl.sh rrv ./reg-test/cases/case-c-dsl-localvar-typedecl.sh rrv ./reg-test/cases/case-c-dsl-local-map-variable-typedecl.sh @@ -25,13 +19,10 @@ MULTIPLE ISSUES: rrv ./reg-test/cases/case-c-dsl-functional-tests.sh * bug mlr filter $nosuchfield>.3 ./reg-test/input/abixy * ofmt -* env -> split up this big case-file * typeof prints different things -- regularize ... -* 'x=' -> MT_EMPTY vs MT_STRING - ================================================================ LF/CRLF ETC. @@ -121,6 +112,10 @@ rrv ./reg-test/cases/case-c-barred-pprint.sh ================================================================ BACKWARD INCOMPATIBILITIES: +rrv ./reg-test/cases/case-c-dsl-context-specific-validation.sh +* mlr: filter expressions must end in a final boolean statement. +-> abandon this requirement? doc if so. + rrv ./reg-test/cases/case-c-label.sh * handles old/new clashes differently from C impl :^/ diff --git a/go/src/miller/dsl/cst/assignments.go b/go/src/miller/dsl/cst/assignments.go index 18dda4b7a..9dcb36495 100644 --- a/go/src/miller/dsl/cst/assignments.go +++ b/go/src/miller/dsl/cst/assignments.go @@ -1,3 +1,7 @@ +// ================================================================ +// CST build/execute for assignment and unset statements. +// ================================================================ + package cst import ( @@ -5,10 +9,6 @@ import ( "miller/lib" ) -// ================================================================ -// CST build/execute for assignment and unset statements. -// ================================================================ - // ================================================================ func (this *RootNode) BuildAssignmentNode( astNode *dsl.ASTNode, diff --git a/go/src/miller/dsl/cst/block-exit.go b/go/src/miller/dsl/cst/block-exit.go index 22f8a2c5f..469b0f48d 100644 --- a/go/src/miller/dsl/cst/block-exit.go +++ b/go/src/miller/dsl/cst/block-exit.go @@ -1,3 +1,8 @@ +// ================================================================ +// This is for things that get us out of statement blocks: break, continue, +// return. +// ================================================================ + package cst import ( @@ -7,11 +12,6 @@ import ( "miller/lib" ) -// ================================================================ -// This is for things that get us out of statement blocks: break, continue, -// return. -// ================================================================ - // ---------------------------------------------------------------- type BreakNode struct { } @@ -40,8 +40,6 @@ func (this *RootNode) BuildContinueNode(astNode *dsl.ASTNode) (*ContinueNode, er lib.InternalCodingErrorIf(astNode.Children == nil) lib.InternalCodingErrorIf(len(astNode.Children) != 0) - // TODO: get type-gate mask - return &ContinueNode{}, nil } @@ -81,7 +79,7 @@ func (this *ReturnNode) Execute(state *State) (*BlockExitPayload, error) { nil, }, nil } else { - // This can be of type MT_ERROR but there is no Go-level error return + // This can be of type MT_ERROR but we do not use Go-level error return here returnValue := this.returnValueExpression.Evaluate(state) // TODO: TypeGatedMlrval return &BlockExitPayload{ BLOCK_EXIT_RETURN_VALUE, diff --git a/go/src/miller/dsl/cst/blocks.go b/go/src/miller/dsl/cst/blocks.go index 6e8956371..e7e36c388 100644 --- a/go/src/miller/dsl/cst/blocks.go +++ b/go/src/miller/dsl/cst/blocks.go @@ -1,3 +1,8 @@ +// ================================================================ +// This is for begin and end blocks, but not the main block which is direct +// from the CST root. +// ================================================================ + package cst import ( @@ -5,9 +10,6 @@ import ( "miller/lib" ) -// This is for begin and end blocks, but not the main block which is direct -// from the CST root. - // ---------------------------------------------------------------- func NewStatementBlockNode() *StatementBlockNode { return &StatementBlockNode{ @@ -107,10 +109,13 @@ func (this *StatementBlockNode) Execute(state *State) (*BlockExitPayload, error) return nil, nil } +// ---------------------------------------------------------------- // Assumes the caller has wrapped PushStackFrame() / PopStackFrame(). That // could be done here, but is instead done in the caller to simplify the // binding of for-loop variables. In particular, in +// // 'for (i = 0; i < 10; i += 1) {...}' +// // the 'i = 0' and 'i += 1' are StatementBlocks and if they pushed their // own stack frame then the 'i=0' would be in an evanescent, isolated frame. diff --git a/go/src/miller/dsl/cst/builtin_function_manager.go b/go/src/miller/dsl/cst/builtin_function_manager.go index f7c01b211..1fcb0a1c4 100644 --- a/go/src/miller/dsl/cst/builtin_function_manager.go +++ b/go/src/miller/dsl/cst/builtin_function_manager.go @@ -1,3 +1,9 @@ +// ================================================================ +// Adding a new builtin function: +// * New entry in BUILTIN_FUNCTION_LOOKUP_TABLE +// * Implement the function in mlrval_functions.go +// ================================================================ + package cst import ( @@ -6,12 +12,6 @@ import ( "os" ) -// ================================================================ -// Adding a new builtin function: -// * New entry in BUILTIN_FUNCTION_LOOKUP_TABLE -// * Implement the function in mlrval_functions.go -// ================================================================ - // ================================================================ type BuiltinFunctionInfo struct { name string diff --git a/go/src/miller/dsl/cst/builtin_functions.go b/go/src/miller/dsl/cst/builtin_functions.go index 38822f869..1e67d458f 100644 --- a/go/src/miller/dsl/cst/builtin_functions.go +++ b/go/src/miller/dsl/cst/builtin_functions.go @@ -1,3 +1,7 @@ +// ================================================================ +// Methods for built-in functions +// ================================================================ + package cst import ( @@ -9,10 +13,6 @@ import ( "miller/types" ) -// ================================================================ -// Methods for built-in functions -// ================================================================ - // ---------------------------------------------------------------- func (this *RootNode) BuildBuiltinFunctionCallsiteNode( astNode *dsl.ASTNode, diff --git a/go/src/miller/dsl/cst/collections.go b/go/src/miller/dsl/cst/collections.go index 90c88753b..2fa69480d 100644 --- a/go/src/miller/dsl/cst/collections.go +++ b/go/src/miller/dsl/cst/collections.go @@ -1,3 +1,8 @@ +// ================================================================ +// CST build/execute for AST array-literal, map-literal, index-access, and +// slice-access nodes +// ================================================================ + package cst import ( @@ -6,11 +11,6 @@ import ( "miller/types" ) -// ================================================================ -// CST build/execute for AST array-literal, map-literal, index-access, and -// slice-access nodes -// ================================================================ - // ---------------------------------------------------------------- type ArrayLiteralNode struct { evaluables []IEvaluable diff --git a/go/src/miller/dsl/cst/cond.go b/go/src/miller/dsl/cst/cond.go index 6b2b42e9f..6fabf52a1 100644 --- a/go/src/miller/dsl/cst/cond.go +++ b/go/src/miller/dsl/cst/cond.go @@ -1,3 +1,8 @@ +// ================================================================ +// This is for awkish pattern-action-blocks, like mlr put 'NR > 10 { ... }'. +// Just shorthand for if-statements without elif/else. +// ================================================================ + package cst import ( @@ -8,11 +13,6 @@ import ( "miller/types" ) -// ================================================================ -// This is for awkish pattern-action-blocks, like mlr put 'NR > 10 { ... }'. -// Just shorthand for if-statements without elif/else. -// ================================================================ - type CondBlockNode struct { conditionNode IEvaluable statementBlockNode *StatementBlockNode diff --git a/go/src/miller/dsl/cst/emit.go b/go/src/miller/dsl/cst/emit.go index 4d8f96c13..9e9925ef0 100644 --- a/go/src/miller/dsl/cst/emit.go +++ b/go/src/miller/dsl/cst/emit.go @@ -1,3 +1,7 @@ +// ================================================================ +// This handles emit statements. +// ================================================================ + package cst import ( @@ -6,10 +10,6 @@ import ( "miller/types" ) -// ================================================================ -// This handles emit statements. -// ================================================================ - // ---------------------------------------------------------------- type EmitStatementNode struct { emitEvaluable IEvaluable @@ -46,8 +46,8 @@ func (this *EmitStatementNode) Execute(state *State) (*BlockExitPayload, error) ) } - // xxx wip - // xxx need to reshape rvalue mlvarls -> mlrmaps; publish w/ contexts; method for that + // xxx WIP + // xxx need to reshape rvalue mlrvals -> mlrmaps; publish w/ contexts; method for that // outputChannel <- types.NewRecordAndContext( // mlrmap goes here, diff --git a/go/src/miller/dsl/cst/env.go b/go/src/miller/dsl/cst/env.go index c40d10190..fa892ba7a 100644 --- a/go/src/miller/dsl/cst/env.go +++ b/go/src/miller/dsl/cst/env.go @@ -1,3 +1,10 @@ +// ================================================================ +// This handles ENV["FOO"] on the right-hand side of an assignment. Note that +// environment variables aren't arbitrarily indexable like maps are -- they're +// only a single-level map from string to string, managed indirectly through +// library routines. +// ================================================================ + package cst import ( @@ -8,13 +15,6 @@ import ( "miller/types" ) -// ================================================================ -// This handles ENV["FOO"] on the right-hand side of an assignment. Note that -// environment variables aren't arbitrarily indexable like maps are -- they're -// only a single-level map from string to string, managed indirectly through -// library routines. -// ================================================================ - type EnvironmentVariableNode struct { nameEvaluable IEvaluable } diff --git a/go/src/miller/dsl/cst/evaluable.go b/go/src/miller/dsl/cst/evaluable.go index 63129748c..c92e3e35e 100644 --- a/go/src/miller/dsl/cst/evaluable.go +++ b/go/src/miller/dsl/cst/evaluable.go @@ -1,3 +1,9 @@ +// ================================================================ +// This handles anything on the right-hand sides of assignment statements. +// (Also, computed field names on the left-hand sides of assignment +// statements.) +// ================================================================ + package cst import ( @@ -10,12 +16,6 @@ import ( "miller/types" ) -// ================================================================ -// This handles anything on the right-hand sides of assignment statements. -// (Also, computed field names on the left-hand sides of assignment -// statements.) -// ================================================================ - // ---------------------------------------------------------------- func (this *RootNode) BuildEvaluableNode(astNode *dsl.ASTNode) (IEvaluable, error) { diff --git a/go/src/miller/dsl/cst/filter.go b/go/src/miller/dsl/cst/filter.go index 3bba381ca..c778ba00e 100644 --- a/go/src/miller/dsl/cst/filter.go +++ b/go/src/miller/dsl/cst/filter.go @@ -1,3 +1,7 @@ +// ================================================================ +// This handles filter statements. +// ================================================================ + package cst import ( @@ -7,10 +11,6 @@ import ( "miller/lib" ) -// ================================================================ -// This handles filter statements. -// ================================================================ - // ---------------------------------------------------------------- type FilterStatementNode struct { filterEvaluable IEvaluable diff --git a/go/src/miller/dsl/cst/for.go b/go/src/miller/dsl/cst/for.go index 2214dd66e..be5c3d25f 100644 --- a/go/src/miller/dsl/cst/for.go +++ b/go/src/miller/dsl/cst/for.go @@ -1,3 +1,7 @@ +// ================================================================ +// This is for various flavors of for-loop +// ================================================================ + package cst import ( @@ -8,10 +12,6 @@ import ( "miller/types" ) -// ================================================================ -// This is for various flavors of for-loop -// ================================================================ - // ---------------------------------------------------------------- // Sample AST: diff --git a/go/src/miller/dsl/cst/functions.go b/go/src/miller/dsl/cst/functions.go index bc0dbde5d..2c1305260 100644 --- a/go/src/miller/dsl/cst/functions.go +++ b/go/src/miller/dsl/cst/functions.go @@ -1,10 +1,3 @@ -package cst - -import ( - "miller/dsl" - "miller/lib" -) - // ================================================================ // CST build/execute for AST operator/function nodes // @@ -13,6 +6,13 @@ import ( // prefix, like 'max(1,2)'. Both parse to the same AST shape. // ================================================================ +package cst + +import ( + "miller/dsl" + "miller/lib" +) + // ---------------------------------------------------------------- // Function lookup: // diff --git a/go/src/miller/dsl/cst/if.go b/go/src/miller/dsl/cst/if.go index 53aeaea2c..8adce8cfc 100644 --- a/go/src/miller/dsl/cst/if.go +++ b/go/src/miller/dsl/cst/if.go @@ -1,3 +1,7 @@ +// ================================================================ +// This is for if/elif/elif/else chains. +// ================================================================ + package cst import ( @@ -8,10 +12,6 @@ import ( "miller/types" ) -// ================================================================ -// This is for if/elif/elif/else chains. -// ================================================================ - // ---------------------------------------------------------------- type IfChainNode struct { ifItems []*IfItem diff --git a/go/src/miller/dsl/cst/leaves.go b/go/src/miller/dsl/cst/leaves.go index 169de64ec..a60fc8f2a 100644 --- a/go/src/miller/dsl/cst/leaves.go +++ b/go/src/miller/dsl/cst/leaves.go @@ -1,3 +1,7 @@ +// ================================================================ +// CST build/execute for AST leaf nodes +// ================================================================ + package cst import ( @@ -9,10 +13,6 @@ import ( "miller/types" ) -// ================================================================ -// CST build/execute for AST leaf nodes -// ================================================================ - // ---------------------------------------------------------------- func (this *RootNode) BuildLeafNode( astNode *dsl.ASTNode, diff --git a/go/src/miller/dsl/cst/lvalues.go b/go/src/miller/dsl/cst/lvalues.go index 7db9ab517..44efb5b8e 100644 --- a/go/src/miller/dsl/cst/lvalues.go +++ b/go/src/miller/dsl/cst/lvalues.go @@ -1,3 +1,8 @@ +// ================================================================ +// This is for Lvalues, i.e. things on the left-hand-side of an assignment +// statement. +// ================================================================ + package cst import ( @@ -10,9 +15,6 @@ import ( "miller/types" ) -// This is for Lvalues, i.e. things on the left-hand-side of an assignment -// statement. - // ---------------------------------------------------------------- func (this *RootNode) BuildAssignableNode( astNode *dsl.ASTNode, diff --git a/go/src/miller/dsl/cst/print.go b/go/src/miller/dsl/cst/print.go index 6969a058e..3137dde1b 100644 --- a/go/src/miller/dsl/cst/print.go +++ b/go/src/miller/dsl/cst/print.go @@ -1,3 +1,7 @@ +// ================================================================ +// This handles print and dump statements. +// ================================================================ + package cst import ( @@ -8,10 +12,6 @@ import ( "miller/lib" ) -// ================================================================ -// This handles print and dump statements. -// ================================================================ - // ================================================================ type DumpStatementNode struct { // TODO: redirect options diff --git a/go/src/miller/dsl/cst/root.go b/go/src/miller/dsl/cst/root.go index d401e8076..43cf6c83e 100644 --- a/go/src/miller/dsl/cst/root.go +++ b/go/src/miller/dsl/cst/root.go @@ -1,3 +1,8 @@ +// ================================================================ +// Top-level entry point for building a CST from an AST at parse time, and for +// executing the CST at runtime. +// ================================================================ + package cst import ( @@ -8,11 +13,6 @@ import ( "miller/types" ) -// ================================================================ -// Top-level entry point for building a CST from an AST at parse time, and for -// executing the CST at runtime. -// ================================================================ - // ---------------------------------------------------------------- func NewEmptyRoot() *RootNode { return &RootNode{ diff --git a/go/src/miller/dsl/cst/stack.go b/go/src/miller/dsl/cst/stack.go index bec76840c..9ee7fc80a 100644 --- a/go/src/miller/dsl/cst/stack.go +++ b/go/src/miller/dsl/cst/stack.go @@ -1,13 +1,3 @@ -package cst - -import ( - "container/list" - "fmt" - - "miller/lib" - "miller/types" -) - // ================================================================ // Stack frames for begin/end/if/for/function blocks // @@ -33,6 +23,16 @@ import ( // } // ================================================================ +package cst + +import ( + "container/list" + "fmt" + + "miller/lib" + "miller/types" +) + // ================================================================ // STACK METHODS diff --git a/go/src/miller/dsl/cst/state.go b/go/src/miller/dsl/cst/state.go index 9e73f0c2e..c2480bf9b 100644 --- a/go/src/miller/dsl/cst/state.go +++ b/go/src/miller/dsl/cst/state.go @@ -1,3 +1,9 @@ +// ================================================================ +// Tracks everything needed for statement evaluation/assignment in the Miller +// DSL runtimne: current record/context (the latter being NF, NR, etc); +// out-of-stream variables; local-variable stack; etc. +// ================================================================ + package cst import ( diff --git a/go/src/miller/dsl/cst/statements.go b/go/src/miller/dsl/cst/statements.go index b539d9d81..2cd9d1d51 100644 --- a/go/src/miller/dsl/cst/statements.go +++ b/go/src/miller/dsl/cst/statements.go @@ -1,3 +1,8 @@ +// ================================================================ +// CST build/execute for statements: assignments, bare booleans, +// break/continue/return, etc. +// ================================================================ + package cst import ( @@ -6,11 +11,6 @@ import ( "miller/dsl" ) -// ================================================================ -// CST build/execute for statements: assignments, bare booleans, -// break/continue/return, etc. -// ================================================================ - // ---------------------------------------------------------------- func (this *RootNode) BuildStatementNode( astNode *dsl.ASTNode, diff --git a/go/src/miller/dsl/cst/types.go b/go/src/miller/dsl/cst/types.go index 53b62892f..a37fa7257 100644 --- a/go/src/miller/dsl/cst/types.go +++ b/go/src/miller/dsl/cst/types.go @@ -1,3 +1,7 @@ +// ================================================================ +// Main type definitions for CST build/execute +// ================================================================ + package cst import ( @@ -7,23 +11,6 @@ import ( "miller/types" ) -// ================================================================ -// Main type definitions for CST build/execute -// ================================================================ - -// ---------------------------------------------------------------- -// There are three CST roots: begin-block, body-block, and end-block. -// -// Next-level items are: -// * srec assignments -// * oosvar assignments -// * localvar assignments -// * emit et al. -// * bare-boolean -// * break/continue/return -// * statement block (if-body, for-body, etc) -// ---------------------------------------------------------------- - // ---------------------------------------------------------------- // When we do mlr put '...DSL expression here...', this state is what is needed // to execute the expression. That includes the current record, AWK-like variables diff --git a/go/src/miller/dsl/cst/udf.go b/go/src/miller/dsl/cst/udf.go index 0de7039dd..af3133a1a 100644 --- a/go/src/miller/dsl/cst/udf.go +++ b/go/src/miller/dsl/cst/udf.go @@ -1,3 +1,7 @@ +// ================================================================ +// Support for user-defined functions and subroutines +// ================================================================ + package cst import ( @@ -10,10 +14,6 @@ import ( "miller/types" ) -// ================================================================ -// Support for user-defined functions and subroutines -// ================================================================ - // ---------------------------------------------------------------- type Signature struct { functionName string diff --git a/go/src/miller/dsl/cst/validate.go b/go/src/miller/dsl/cst/validate.go index 111e60826..35988dacf 100644 --- a/go/src/miller/dsl/cst/validate.go +++ b/go/src/miller/dsl/cst/validate.go @@ -1,3 +1,9 @@ +// ================================================================ +// Checks for things that are syntax errors but not done in the AST for +// pragmatic reasons. For example, $anything in begin/end blocks; +// begin/end/func not at top level; etc. +// ================================================================ + package cst import ( @@ -7,12 +13,6 @@ import ( "miller/dsl" ) -// ================================================================ -// Checks for things that are syntax errors but not done in the AST for -// pragmatic reasons. For example, $anything in begin/end blocks; -// begin/end/func not at top level; etc. -// ================================================================ - // ---------------------------------------------------------------- func ValidateAST( ast *dsl.AST, diff --git a/go/src/miller/dsl/cst/while.go b/go/src/miller/dsl/cst/while.go index 1227c6813..199094712 100644 --- a/go/src/miller/dsl/cst/while.go +++ b/go/src/miller/dsl/cst/while.go @@ -1,3 +1,7 @@ +// ================================================================ +// This is for while/do-while loops +// ================================================================ + package cst import ( @@ -7,10 +11,6 @@ import ( "miller/lib" ) -// ================================================================ -// This is for while/do-while loops -// ================================================================ - // ================================================================ type WhileLoopNode struct { conditionNode IEvaluable diff --git a/go/todo.txt b/go/todo.txt index 67e5f947a..c2db75244 100644 --- a/go/todo.txt +++ b/go/todo.txt @@ -19,14 +19,19 @@ no need to bootstrap a parser for the parser-generator language ! still need functional put -S / put -F ... sigh. +! subr +! emitp/emitf + ! bug on set-var/bind-var - 'int x = 1; x = "abc"' doesn't gate -- needs type-mask within the stack. +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ! int map keys: what to do with: o '{1:2}' treat as '{"1":2}' o 'm[1]' treat as 'm["1"]' o positional indexing for maps -- use [[]] [[[]]] ? o pothole: auto-extend of foo[NR] -- this now creates an array not a map +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ! --jvstack as no-op ! reconsider OFMT -- %.6f is not really OK when inputs have far more digits.