1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-07-15 01:25:00 +02:00

New type system (#232)

* New type system

* Fixed dot notation for HTML elements
This commit is contained in:
Tim Voronov
2019-02-13 12:31:18 -05:00
committed by GitHub
parent b3bcbda3b9
commit 1af8b37a0f
185 changed files with 1379 additions and 820 deletions

View File

@ -7,6 +7,7 @@ import (
"sort"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values/types"
)
type (
@ -32,7 +33,7 @@ func (t *Array) MarshalJSON() ([]byte, error) {
}
func (t *Array) Type() core.Type {
return core.ArrayType
return types.Array
}
func (t *Array) String() string {
@ -45,22 +46,23 @@ func (t *Array) String() string {
return string(marshaled)
}
func (t *Array) Compare(other core.Value) int {
switch other.Type() {
case core.ArrayType:
func (t *Array) Compare(other core.Value) int64 {
if other.Type() == types.Array {
other := other.(*Array)
if t.Length() == 0 && other.Length() == 0 {
return 0
}
if t.Length() < other.Length() {
return -1
}
if t.Length() > other.Length() {
return 1
}
var res = 0
var res int64
var val core.Value
other.ForEach(func(otherVal core.Value, idx int) bool {
@ -71,11 +73,9 @@ func (t *Array) Compare(other core.Value) int {
})
return res
case core.ObjectType:
return -1
default:
return 1
}
return types.Compare(types.Array, other.Type())
}
func (t *Array) Unwrap() interface{} {
@ -216,9 +216,13 @@ func (t *Array) Clone() core.Cloneable {
var value core.Value
for idx := NewInt(0); idx < t.Length(); idx++ {
value = t.Get(idx)
if IsCloneable(value) {
value = value.(core.Cloneable).Clone()
cloneable, ok := value.(core.Cloneable)
if ok {
value = cloneable.Clone()
}
cloned.Push(value)
}