cst array/map iterate

This commit is contained in:
John Kerl 2020-09-03 23:26:51 -04:00
parent 146b51211c
commit bbd12b7b6b
6 changed files with 129 additions and 49 deletions

View file

@ -8,7 +8,8 @@ import (
)
// ================================================================
// CST build/execute for AST array nodes
// CST build/execute for AST array-literal, map-literal, index-access, and
// slice-access nodes
// ================================================================
// ----------------------------------------------------------------
@ -21,8 +22,16 @@ func BuildArrayLiteralNode(
// xxx temp
return BuildPanicNode(), nil
}
return nil, errors.New("CST builder: unhandled AST array node " + string(astNode.Type))
// ----------------------------------------------------------------
func BuildArraySliceAccessNode(
astNode *dsl.ASTNode,
) (IEvaluable, error) {
lib.InternalCodingErrorIf(astNode.Type != dsl.NodeTypeArraySliceAccess)
// xxx temp
return BuildPanicNode(), nil
}
//// ----------------------------------------------------------------
@ -39,3 +48,22 @@ func BuildArrayLiteralNode(
//func (this *ArrayLiteralNode) Evaluate(state *State) lib.Mlrval {
// return ...
//}
//// if astNode.Type == dsl.NodeTypeArraySliceEmptyLowerIndex {
//// return BuildPanicNode(), nil // xxx temp
//// }
//// if astNode.Type == dsl.NodeTypeArraySliceEmptyUpperIndex {
//// return BuildPanicNode(), nil // xxx temp
//// }
// ----------------------------------------------------------------
func BuildMapLiteralNode(
astNode *dsl.ASTNode,
) (IEvaluable, error) {
lib.InternalCodingErrorIf(astNode.Type != dsl.NodeTypeMapLiteral)
// xxx temp
return BuildPanicNode(), nil
return nil, errors.New("CST builder: unhandled AST array node " + string(astNode.Type))
}

View file

@ -14,33 +14,28 @@ import (
// ----------------------------------------------------------------
func BuildEvaluableNode(astNode *dsl.ASTNode) (IEvaluable, error) {
if astNode.Children == nil {
return BuildEvaluableLeafNode(astNode)
return BuildLeafNode(astNode)
}
if astNode.Type == dsl.NodeTypeOperator {
switch astNode.Type {
case dsl.NodeTypeOperator:
return BuildOperatorNode(astNode)
}
if astNode.Type == dsl.NodeTypeArrayLiteral {
case dsl.NodeTypeArrayLiteral:
return BuildArrayLiteralNode(astNode)
}
if astNode.Type == dsl.NodeTypeMapLiteral {
case dsl.NodeTypeMapLiteral:
return BuildMapLiteralNode(astNode)
}
if astNode.Type == dsl.NodeTypeArrayOrMapIndexAccess {
return BuildPanicNode(), nil // xxx temp
}
if astNode.Type == dsl.NodeTypeArraySliceAccess {
return BuildPanicNode(), nil // xxx temp
}
if astNode.Type == dsl.NodeTypeArraySliceEmptyLowerIndex {
return BuildPanicNode(), nil // xxx temp
}
if astNode.Type == dsl.NodeTypeArraySliceEmptyUpperIndex {
case dsl.NodeTypeArrayOrMapIndexAccess:
return BuildPanicNode(), nil // xxx temp
case dsl.NodeTypeArraySliceAccess:
return BuildArraySliceAccessNode(astNode)
}
// xxx if/while/etc

View file

@ -12,7 +12,7 @@ import (
// ================================================================
// ----------------------------------------------------------------
func BuildEvaluableLeafNode(
func BuildLeafNode(
astNode *dsl.ASTNode,
) (IEvaluable, error) {
lib.InternalCodingErrorIf(astNode.Children != nil)

View file

@ -1,24 +0,0 @@
package cst
import (
"errors"
"miller/dsl"
"miller/lib"
)
// ================================================================
// CST build/execute for AST map nodes
// ================================================================
// ----------------------------------------------------------------
func BuildMapLiteralNode(
astNode *dsl.ASTNode,
) (IEvaluable, error) {
lib.InternalCodingErrorIf(astNode.Type != dsl.NodeTypeMapLiteral)
// xxx temp
return BuildPanicNode(), nil
return nil, errors.New("CST builder: unhandled AST array node " + string(astNode.Type))
}

View file

@ -6,11 +6,11 @@ TOP OF LIST:
! makefile for build-dsl: if $bnf newer than productionstable.go
* array/map
o iterate on CST build
o string index access -- ? if i support this people will want ranges ...
better to maybe give them that. or [m:n] slices ...
o slices ...
o ??? on CST execute
- not much to really do with them until/unless RHS-indexing
o array literals and map literals
o indexes and slices
- string index access -- ? along with slices ...
o mlrval Go Copy method and DSL copy function ... or, pass by
reference throughout RHS but always copy on assignment?
* SUMMARY:
o easy: most verbs

View file

@ -472,3 +472,84 @@ RAW AST:
* DirectFieldName "a"
* IntLiteral "1"
DSL EXPRESSION:
$z = $a["index"]
RAW AST:
* StatementBlock
* SrecDirectAssignment "="
* DirectFieldName "z"
* ArrayOrMapIndexAccess "[]"
* DirectFieldName "a"
* StringLiteral "index"
DSL EXPRESSION:
$z = "abcde"[1]
RAW AST:
* StatementBlock
* SrecDirectAssignment "="
* DirectFieldName "z"
* ArrayOrMapIndexAccess "[]"
* StringLiteral "abcde"
* IntLiteral "1"
DSL EXPRESSION:
$z = "abcde"["index"]
RAW AST:
* StatementBlock
* SrecDirectAssignment "="
* DirectFieldName "z"
* ArrayOrMapIndexAccess "[]"
* StringLiteral "abcde"
* StringLiteral "index"
DSL EXPRESSION:
$z = $a[1:2]
RAW AST:
* StatementBlock
* SrecDirectAssignment "="
* DirectFieldName "z"
* ArraySliceAccess "[]"
* DirectFieldName "a"
* IntLiteral "1"
* IntLiteral "2"
DSL EXPRESSION:
$z = $a[:2]
RAW AST:
* StatementBlock
* SrecDirectAssignment "="
* DirectFieldName "z"
* ArraySliceAccess "[]"
* DirectFieldName "a"
* ArraySliceEmptyLowerIndex ":"
* IntLiteral "2"
DSL EXPRESSION:
$z = $a[1:]
RAW AST:
* StatementBlock
* SrecDirectAssignment "="
* DirectFieldName "z"
* ArraySliceAccess "[]"
* DirectFieldName "a"
* IntLiteral "1"
* ArraySliceEmptyUpperIndex ":"
DSL EXPRESSION:
$z = $a[:]
RAW AST:
* StatementBlock
* SrecDirectAssignment "="
* DirectFieldName "z"
* ArraySliceAccess "[]"
* DirectFieldName "a"
* ArraySliceEmptyLowerIndex ":"
* ArraySliceEmptyUpperIndex ":"