Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,12 @@ func (o *Bool) IsFalsy() bool {
// Equals returns true if the value of the type is equal to the value of
// another object.
func (o *Bool) Equals(x Object) bool {
return o == x
switch i:=x.(type) {
casse *Bool:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo?

return o.value==i.value
default:
return o == x
}
}

// GobDecode decodes bool value from input bytes.
Expand Down
24 changes: 24 additions & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,30 @@ func (p *Parser) ParseFile() (file *File, err error) {
return nil, p.errors.Err()
}

var nass [][]string
for i := 0; i < len(stmts); i += 1 {
nas := regexFindAll(stmts[i].String(), "[A-Za-z][a-zA-Z0-9]*(_[a-zA-Z0-9]+)*\\s*[:()]")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parser logic based on regex looks quite brittle to me.

nass = append(nass, nas)
}
for i := 0; i < len(nass); i += 1 {
for j := 0; j < len(nass[i]); j += 1 {
i1 := i + 1
bdo := false
for ; i1 < len(nass); i1 += 1 {
if strings.HasSuffix(nass[i1][0], ":") && strings.HasSuffix(nass[i][j], "(") && nass[i1][0][:len(nass[i1][0])-1] == nass[i][j][:len(nass[i][j])-1] {
nass = AppendManyNew[[]string](nass[:i], nass[i1], nass[i:i1], nass[i1+1:])
stmts = AppendManyNew[Stmt](stmts[:i], stmts[i1], stmts[i:i1], stmts[i1+1:])
bdo = true
break
}
}
if bdo {
i -= 1
break
}
}
}

file = &File{
InputFile: p.file,
Stmts: stmts,
Expand Down
38 changes: 38 additions & 0 deletions parser/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package parser

import (
"reflect"
"regexp"
)

func AppendManyNew[T any](v []T, as ...any) []T {
l := len(v)
for _, a := range as {
switch a.(type) {
case T:
l += 1
case []T:
l += len(a.([]T))
default:
panic("type error:" + reflect.TypeOf(a).String())
}
}
n := make([]T, l)
n = n[:0]
n = append(n, v...)
for _, a := range as {
switch a.(type) {
case T:
n = append(n, a.(T))
case []T:
n = append(n, a.([]T)...)
default:
panic("type error:" + reflect.TypeOf(a).String())
}
}
return n
}

func regexFindAll(s0, frx s) []s {
return regexp.MustCompile(frx).FindAllString(s0, -1)
}