GetTypeName in CST

This commit is contained in:
John Kerl 2020-09-07 21:51:49 -04:00
parent a96310d875
commit eef5549994
5 changed files with 25 additions and 4 deletions

View file

@ -58,6 +58,7 @@ func NewAssignmentNode(
func (this *AssignmentNode) Execute(state *State) {
rvalue := this.rvalue.Evaluate(state)
if !rvalue.IsAbsent() {
// xxx need to propagate the error coming back in the Execute() API
this.lvalue.Assign(&rvalue, state)
}
}

View file

@ -98,9 +98,10 @@ func (this *IndirectFieldNameLvalueNode) Assign(
lhsFieldName := this.lhsFieldNameExpression.Evaluate(state)
if !lhsFieldName.IsString() {
// xxx make and use a Mlrval GetTypeName()
return errors.New(
"Miller DSL: computed field name [%s] should be a string but is not.",
"Miller DSL: computed field name [%s] should be a string but was " +
lhsFieldName.GetTypeName() +
".",
)
}

View file

@ -93,3 +93,15 @@ const (
// function pointers which is MT_DIM x MT_DIM.
MT_DIM = 9
)
var TYPE_NAMES = [MT_DIM]string{
"error",
"absent",
"void",
"string",
"int",
"float",
"bool",
"array",
"map",
}

View file

@ -4,6 +4,10 @@ func (this *Mlrval) GetType() MVType {
return this.mvtype
}
func (this *Mlrval) GetTypeName() string {
return TYPE_NAMES[this.mvtype]
}
func (this *Mlrval) IsError() bool {
return this.mvtype == MT_ERROR
}

View file

@ -2,9 +2,7 @@
TOP OF LIST:
* monday:
o lib.GetTypeName
o rename MlrvalOrFunction in the DSL
! tags file
? ENV
* array/map
@ -60,8 +58,13 @@ TOP OF LIST:
o begin/end blocks
o oosvars
o indirect field names, at LHS and RHS
o full indexable at LHS/RHS -- e.g. $*["a"] = $b
o support the filter verb
! the DSL needs a full, written-down-and-published spell-out of reference/copy semantics
* then careful CST impl
! likewise error-eval semantics
----------------------------------------------------------------
MAYBE: