basic records support
This commit is contained in:
parent
19011e67da
commit
ff11d7e0ed
11 changed files with 522 additions and 138 deletions
|
|
@ -29,6 +29,7 @@ const (
|
|||
NilNodeType
|
||||
ListNodeType
|
||||
TupleNodeType
|
||||
RecordNodeType
|
||||
BinaryNodeType
|
||||
UnaryNodeType
|
||||
BlockNodeType
|
||||
|
|
@ -93,6 +94,8 @@ func (n NodeType) String() string {
|
|||
return "Alias"
|
||||
case IndexNodeType:
|
||||
return "Index"
|
||||
case RecordNodeType:
|
||||
return "Record"
|
||||
}
|
||||
return "Invalid Node Type"
|
||||
}
|
||||
|
|
@ -237,6 +240,36 @@ func (n TupleNode) Bounds() (Pos, Pos) {
|
|||
return n.start, n.end
|
||||
}
|
||||
|
||||
type RecordNode struct {
|
||||
entries map[string]Node
|
||||
|
||||
start Pos
|
||||
end Pos
|
||||
}
|
||||
|
||||
func (n RecordNode) Type() NodeType {
|
||||
return RecordNodeType
|
||||
}
|
||||
|
||||
func (n RecordNode) String() string {
|
||||
sb := strings.Builder{}
|
||||
|
||||
sb.WriteString("(")
|
||||
for name, item := range n.entries {
|
||||
sb.WriteString(name)
|
||||
sb.WriteString(": ")
|
||||
sb.WriteString(item.String())
|
||||
sb.WriteString(",")
|
||||
}
|
||||
sb.WriteString(")")
|
||||
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func (n RecordNode) Bounds() (Pos, Pos) {
|
||||
return n.start, n.end
|
||||
}
|
||||
|
||||
type AccessNode struct {
|
||||
source Node
|
||||
property *Token
|
||||
|
|
@ -269,6 +302,8 @@ func (n BinaryOperation) String() string {
|
|||
return "multiply"
|
||||
case BinaryDivision:
|
||||
return "divide"
|
||||
case BinaryModulo:
|
||||
return "modulo"
|
||||
case BinaryEquality:
|
||||
return "equality"
|
||||
case BinaryInequality:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue