array-index iterate

This commit is contained in:
John Kerl 2020-09-03 18:20:44 -04:00
parent 83bffc1bc1
commit 93a230cd1f
8 changed files with 30362 additions and 26635 deletions

View file

@ -17,6 +17,7 @@ const (
NodeTypeArrayLiteral = "ArrayLiteral"
NodeTypeMapLiteral = "MapLiteral"
NodeTypeMapLiteralKeyValuePair = "MapLiteralKeyValuePair"
NodeTypeArrayOrMapIndexAccess = "ArrayOrMapIndexAccess"
NodeTypeDirectFieldName = "DirectFieldName"
NodeTypeIndirectFieldName = "IndirectFieldName"

View file

@ -17,6 +17,8 @@ func BuildArrayLiteralNode(
) (IEvaluable, error) {
lib.InternalCodingErrorIf(astNode.Type != dsl.NodeTypeArrayLiteral)
// xxx assert children not nil (0-length non-nil ok, nil not ok)
// xxx temp
return BuildPanicNode(), nil
@ -25,14 +27,15 @@ func BuildArrayLiteralNode(
//// ----------------------------------------------------------------
//type ArrayLiteralNode struct {
// literal lib.Mlrval
// elements []IEvaluable
//}
//
//func BuildArrayLiteralNode(literal string) *ArrayLiteralNode {
// return &ArrayLiteral{
// literal: lib.MlrvalFromString(literal),
//func BuildArrayLiteralNode(astChildren []*dsl.ASTNode) *ArrayLiteralNode {
// ...
// return &ArrayLiteralNode{
// elements: ...
// }
//}
//func (this *ArrayLiteralNode) Evaluate(state *State) lib.Mlrval {
// return this.literal
// return ...
//}

View file

@ -2526,6 +2526,9 @@ PowTerm
| MlrvalOrFunction
;
// Please Excuse My Dear Aunt Sally! :) We've gotten to the 'P' so we're done
// with the operator-precedence chain. :)
MlrvalOrFunction
: "(" RHS ")"
<< dsl.Nestable($1) >>
@ -2902,6 +2905,21 @@ ArrayLiteralElement
: RHS
;
// ----------------------------------------------------------------
// For Array or Map -- which one, to be determined at runtime.
MlrvalOrFunction : ArrayOrMapIndexAccess ;
ArrayOrMapIndexAccess
: MlrvalOrFunction "[" RHS "]"
<< dsl.NewASTNodeBinary(
dsl.NewASTToken("[]", $1),
$0,
$2,
dsl.NodeTypeArrayOrMapIndexAccess,
)>>
;
// ================================================================
// Map literals in Miller are JSON-ish.

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -11,9 +11,9 @@ import (
)
const (
numProductions = 113
numStates = 816
numSymbols = 111
numProductions = 115
numStates = 840
numSymbols = 112
)
// Stack

View file

@ -851,9 +851,9 @@ var productionsTable = ProdTab{
NumSymbols: 1,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return dsl.NewASTNodeStripDoubleQuotePairPlease(
X[0],
dsl.NodeTypeStringLiteral,
)
X[0],
dsl.NodeTypeStringLiteral,
)
},
},
ProdTabEntry{
@ -1037,9 +1037,9 @@ var productionsTable = ProdTab{
NumSymbols: 2,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return dsl.NewASTNodeZary(
dsl.NewASTToken("[]", X[0]),
dsl.NodeTypeArrayLiteral,
)
dsl.NewASTToken("[]", X[0]),
dsl.NodeTypeArrayLiteral,
)
},
},
ProdTabEntry{
@ -1056,12 +1056,12 @@ var productionsTable = ProdTab{
NumSymbols: 3,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return dsl.AdoptChildren(
dsl.NewASTNodeNestable(
dsl.NewASTToken("[]", X[0]),
dsl.NodeTypeArrayLiteral,
),
X[1],
)
dsl.NewASTNodeNestable(
dsl.NewASTToken("[]", X[0]),
dsl.NodeTypeArrayLiteral,
),
X[1],
)
},
},
ProdTabEntry{
@ -1076,10 +1076,10 @@ var productionsTable = ProdTab{
NumSymbols: 1,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return dsl.NewASTNodeUnary(
nil,
X[0],
dsl.NodeTypeArrayLiteral,
)
nil,
X[0],
dsl.NodeTypeArrayLiteral,
)
},
},
ProdTabEntry{
@ -1094,10 +1094,10 @@ var productionsTable = ProdTab{
NumSymbols: 2,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return dsl.NewASTNodeUnary(
nil,
X[0],
dsl.NodeTypeArrayLiteral,
)
nil,
X[0],
dsl.NodeTypeArrayLiteral,
)
},
},
ProdTabEntry{
@ -1111,9 +1111,9 @@ var productionsTable = ProdTab{
NumSymbols: 3,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return dsl.PrependChild(
X[2],
X[0],
)
X[2],
X[0],
)
},
},
ProdTabEntry{
@ -1127,7 +1127,7 @@ var productionsTable = ProdTab{
},
},
ProdTabEntry{
String: `MlrvalOrFunction : MapLiteral << >>`,
String: `MlrvalOrFunction : ArrayOrMapIndexAccess << >>`,
Id: "MlrvalOrFunction",
NTType: 22,
Index: 106,
@ -1136,20 +1136,50 @@ var productionsTable = ProdTab{
return X[0], nil
},
},
ProdTabEntry{
String: `ArrayOrMapIndexAccess : MlrvalOrFunction "[" RHS "]" << dsl.NewASTNodeBinary(
dsl.NewASTToken("[]", X[1]),
X[0],
X[2],
dsl.NodeTypeArrayOrMapIndexAccess,
) >>`,
Id: "ArrayOrMapIndexAccess",
NTType: 30,
Index: 107,
NumSymbols: 4,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return dsl.NewASTNodeBinary(
dsl.NewASTToken("[]", X[1]),
X[0],
X[2],
dsl.NodeTypeArrayOrMapIndexAccess,
)
},
},
ProdTabEntry{
String: `MlrvalOrFunction : MapLiteral << >>`,
Id: "MlrvalOrFunction",
NTType: 22,
Index: 108,
NumSymbols: 1,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return X[0], nil
},
},
ProdTabEntry{
String: `MapLiteral : "{" "}" << dsl.NewASTNodeZary(
dsl.NewASTToken("{}", X[0]),
dsl.NodeTypeMapLiteral,
) >>`,
Id: "MapLiteral",
NTType: 30,
Index: 107,
NTType: 31,
Index: 109,
NumSymbols: 2,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return dsl.NewASTNodeZary(
dsl.NewASTToken("{}", X[0]),
dsl.NodeTypeMapLiteral,
)
dsl.NewASTToken("{}", X[0]),
dsl.NodeTypeMapLiteral,
)
},
},
ProdTabEntry{
@ -1161,17 +1191,17 @@ var productionsTable = ProdTab{
X[1],
) >>`,
Id: "MapLiteral",
NTType: 30,
Index: 108,
NTType: 31,
Index: 110,
NumSymbols: 3,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return dsl.AdoptChildren(
dsl.NewASTNodeNestable(
dsl.NewASTToken("{}", X[0]),
dsl.NodeTypeMapLiteral,
),
X[1],
)
dsl.NewASTNodeNestable(
dsl.NewASTToken("{}", X[0]),
dsl.NodeTypeMapLiteral,
),
X[1],
)
},
},
ProdTabEntry{
@ -1181,15 +1211,15 @@ var productionsTable = ProdTab{
dsl.NodeTypeMapLiteral,
) >>`,
Id: "MapLiteralKeyValuePairs",
NTType: 31,
Index: 109,
NTType: 32,
Index: 111,
NumSymbols: 1,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return dsl.NewASTNodeUnary(
nil,
X[0],
dsl.NodeTypeMapLiteral,
)
nil,
X[0],
dsl.NodeTypeMapLiteral,
)
},
},
ProdTabEntry{
@ -1199,15 +1229,15 @@ var productionsTable = ProdTab{
dsl.NodeTypeMapLiteral,
) >>`,
Id: "MapLiteralKeyValuePairs",
NTType: 31,
Index: 110,
NTType: 32,
Index: 112,
NumSymbols: 2,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return dsl.NewASTNodeUnary(
nil,
X[0],
dsl.NodeTypeMapLiteral,
)
nil,
X[0],
dsl.NodeTypeMapLiteral,
)
},
},
ProdTabEntry{
@ -1216,14 +1246,14 @@ var productionsTable = ProdTab{
X[0],
) >>`,
Id: "MapLiteralKeyValuePairs",
NTType: 31,
Index: 111,
NTType: 32,
Index: 113,
NumSymbols: 3,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return dsl.PrependChild(
X[2],
X[0],
)
X[2],
X[0],
)
},
},
ProdTabEntry{
@ -1234,16 +1264,16 @@ var productionsTable = ProdTab{
dsl.NodeTypeMapLiteralKeyValuePair,
) >>`,
Id: "MapLiteralKeyValuePair",
NTType: 32,
Index: 112,
NTType: 33,
Index: 114,
NumSymbols: 3,
ReduceFunc: func(X []Attrib) (Attrib, error) {
return dsl.NewASTNodeBinary(
X[1],
X[0],
X[2],
dsl.NodeTypeMapLiteralKeyValuePair,
)
X[1],
X[0],
X[2],
dsl.NodeTypeMapLiteralKeyValuePair,
)
},
},
}

View file

@ -3,8 +3,11 @@ TOP OF LIST:
* reg_test/run iterate
! 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 ??? on CST execute
- not much to really do with them until/unless RHS-indexing