c/reg_test/run reorg

This commit is contained in:
John Kerl 2020-09-10 09:08:01 -04:00
parent 0659ca30f4
commit 4e62cf477d
7 changed files with 1064 additions and 1017 deletions

File diff suppressed because it is too large Load diff

View file

@ -124,7 +124,8 @@ nil through the reader/mapper/writer sequence.
* If a mapper drops a record (`mlr filter` in false cases, for example, or `mlr nothing`) it will be GCed.
* One caveat is any mapper which produces multiples, e.g. `mlr repeat` -- this needs to explicitly copy records instead of producing multiple pointers to the same record.
* Right-hand-sides of DSL expressions all pass around pointers to records and Mlrvals.
* Copy-on-write is done on map/array put -- for example, in the assignment phase of a DSL statement.
* Lvalue expressions return pointed `*lib.Mlrmap` so they can be assigned to; rvalue expressions return non-pointed `lib.Mlrval` but these are very shallow copies -- the int/string/etc types are copied but maps/arrays are passed by reference in the rvalue expression-evaluators.
* Copy-on-write is done on map/array put -- for example, in the assignment phase of a DSL statement, where an rvalue is assigned to an lvalue.
# More about mlrvals

View file

@ -96,7 +96,6 @@ func BuildIndirectFieldValueLvalueNode(astNode *dsl.ASTNode) (IAssignable, error
lib.InternalCodingErrorIf(astNode.Type != dsl.NodeTypeIndirectFieldValue)
lib.InternalCodingErrorIf(astNode == nil)
lib.InternalCodingErrorIf(len(astNode.Children) != 1)
lhsFieldNameExpression, err := BuildEvaluableNode(astNode.Children[0])
if err != nil {
return nil, err
@ -385,7 +384,6 @@ func BuildIndexedLvalueNode(astNode *dsl.ASTNode) (IAssignable, error) {
break
}
}
return NewIndexedLvalueNode(baseLvalue, indexEvaluables), nil
}

View file

@ -101,7 +101,7 @@ func (this *RootNode) ExecuteBeginBlocks(state *State) error {
func (this *RootNode) ExecuteMainBlock(state *State) (outrec *lib.Mlrmap, err error) {
err = this.mainBlock.Execute(state)
return state.Inrec, nil
return state.Inrec, err
}
// ----------------------------------------------------------------

View file

@ -110,6 +110,7 @@ func (this *Mlrmap) PutIndexedKeyless(indices []*Mlrval, rvalue *Mlrval) error {
}
baseIndex := indices[0]
// yyy string/positional-int
if !baseIndex.IsString() {
skey := baseIndex.String()
return errors.New("Non-string key " + skey) // xxx needs better wording
@ -117,10 +118,13 @@ func (this *Mlrmap) PutIndexedKeyless(indices []*Mlrval, rvalue *Mlrval) error {
baseKey := baseIndex.printrep
if n == 1 {
// yyy PutCopy w/ Mlrval flavor
// yyy sigh ... doc that positional indices on maps don't auto-extend.
this.PutCopy(&baseKey, rvalue) // E.g. mlr put '$*["a"] = 3'
return nil
}
// yyy Get w/ Mlrval flavor
baseValue := this.Get(&baseKey)
if baseValue == nil {
baseValue := MlrvalEmptyMap()

View file

@ -1,7 +1,7 @@
----------------------------------------------------------------
TOP OF LIST:
* wednesday:
* thursday:
! array-assigns with auto-extend
k API:
k mlrmap.GetWithPositionalIndex
@ -10,7 +10,8 @@ TOP OF LIST:
k code/test '$new = $*[1]'
o code/test '$[1] = "new"'
o code/test '$*[1] = "new"'
o this needs to work: '@records[FILENAME][NR]=$*'
o this auto-extend needs to work: '@records[FILENAME][NR]=$*'
o c/reg_test/run reorgs
! unbork pprint writer
o indexed-lvalue assignment ops -- need ints too
- $[1] is easier now; needn't $[[[1]]]
@ -108,6 +109,7 @@ PARSER/LEXER PLAN:
NITS/NON-IMMEDIATE:
* address all manner of xxx and TODO comments
* throughout -- 'map' used too much -- 'mapping/mapper' -> 'transform' or something?
* AST insertions: make a simple NodeFromToken & have all interface{} be *ASTNode, not *token.Token
* mlr --help-for w/ stdout redirect for manpage -- ?
* mlr verb -h -> stdout & exit 0
@ -141,3 +143,8 @@ NITS/NON-IMMEDIATE:
* support 0b0101 et al.? mlrdoc if so
? dsl/ast.go -> parsing/ast.go? then, put new-ast ctor -> parsing package
o if so, update r.mds
* mlrdoc the confusing fact that arrays are 0-up but positionals are 1-up (b/c unix toolkit)
o -n..-1 aliased to 0..n-1 vs -n..-1 aliased to 1..n
o also $1 vs $[1] -- the former 'sticks' with input-data ordering
o moral: miller is a name-indexed tool as its primary purpose. positional
indexing is supported but it can be confusing.

View file

@ -4,3 +4,11 @@ wc -l \
$(find src/miller -name \*.go | grep -v src/miller/parsing) \
src/miller/parsing/mlr.bnf \
| sort -n
echo
wc -c \
$(find src/miller -name \*.go | grep -v src/miller/parsing) \
src/miller/parsing/mlr.bnf \
| sort -n \
| tail -n 5