Skip to content

Commit

Permalink
Merge pull request #109 from flowchartsman/to_any
Browse files Browse the repository at this point in the history
interface{} -> any
  • Loading branch information
breml authored Jun 7, 2023
2 parents ef65bd5 + 22b8424 commit 8ce987b
Show file tree
Hide file tree
Showing 68 changed files with 5,579 additions and 5,499 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ var ops = map[string]func(int, int) int {
},
}
func toIfaceSlice(v interface{}) []interface{} {
func toAnySlice(v any) []any {
if v == nil {
return nil
}
return v.([]interface{})
return v.([]any)
}
func eval(first, rest interface{}) int {
func eval(first, rest any) int {
l := first.(int)
restSl := toIfaceSlice(rest)
restSl := toAnySlice(rest)
for _, v := range restSl {
restExpr := toIfaceSlice(v)
restExpr := toAnySlice(v)
r := restExpr[3].(int)
op := restExpr[1].(string)
l = ops[op](l, r)
Expand Down
16 changes: 8 additions & 8 deletions ast/ast_optimize.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,14 @@ func escapeRune(r rune) string {

// Optimize walks a given grammar and optimizes the grammar in regards
// of parsing performance. This is done with several optimizations:
// * removal of unreferenced rules
// * replace rule references with a copy of the referenced Rule, if the
// referenced rule it self has no references.
// * resolve nested choice expressions
// * resolve choice expressions with only one alternative
// * resolve nested sequences expression
// * resolve sequence expressions with only one element
// * combine character class matcher and literal matcher, where possible
// - removal of unreferenced rules
// - replace rule references with a copy of the referenced Rule, if the
// referenced rule it self has no references.
// - resolve nested choice expressions
// - resolve choice expressions with only one alternative
// - resolve nested sequences expression
// - resolve sequence expressions with only one element
// - combine character class matcher and literal matcher, where possible
func Optimize(g *Grammar, alternateEntrypoints ...string) {
entrypoints := alternateEntrypoints
if len(g.Rules) > 0 {
Expand Down
1 change: 0 additions & 1 deletion ast/ast_walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type Visitor interface {
// v.Visit(expr) is not nil, Walk is invoked recursively with visitor
// w for each of the non-nil children of Expression, followed by a call of
// w.Visit(nil).
//
func Walk(v Visitor, expr Expression) {
if v = v.Visit(expr); v == nil {
return
Expand Down
Loading

0 comments on commit 8ce987b

Please sign in to comment.