Skip to content

Releases: weaweawe01/ParserSpel

V1.0.7

Choose a tag to compare

@weaweawe01 weaweawe01 released this 24 Oct 12:36

修复复杂的语句存在的错误

V1.0.6

Choose a tag to compare

@weaweawe01 weaweawe01 released this 20 Oct 03:57

更新版本

V1.0.5

Choose a tag to compare

@weaweawe01 weaweawe01 released this 20 Oct 03:50

修复部分错误

Full Changelog: v1.0.3...v1.0.5

V1.0.4

Choose a tag to compare

@weaweawe01 weaweawe01 released this 19 Oct 12:01
v1.0.4

修复错误,新增测试文件-升级到V1.0.4

V1.0.3

Choose a tag to compare

@weaweawe01 weaweawe01 released this 19 Oct 12:00
v1.0.3

修复错误,新增测试文件-升级到V1.0.4

V1.0.2

V1.0.2 Pre-release
Pre-release

Choose a tag to compare

@weaweawe01 weaweawe01 released this 17 Oct 16:07
v1.0.2

V1.0.2

V1.0.1

V1.0.1 Pre-release
Pre-release

Choose a tag to compare

@weaweawe01 weaweawe01 released this 17 Oct 15:51

Go SpEL Parser

这是完整的 Spring Expression Language (SpEL) 解析器的 Go 语言版本,从 Java 原版转换而来。包含完整的词法分析和语法分析功能。
基于(spring-expression-6.2.11.jar)版本开发

安装

go get github.com/weaweawe01/ParserSpel/ast

使用案例

package main

import (
	"fmt"
	"github.com/weaweawe01/ParserSpel/ast"
)

func main() {
	parser := ast.NewSpelExpressionParser()
	// 测试普通表达式
	normalExpressions := []string{
		"{1,2,3,4}",
	}
	for i, expr := range normalExpressions {
		tokenizer := ast.NewTokenizer(expr)
		tokens, err := tokenizer.Process()
		if err != nil {
			fmt.Errorf("tokenization failed: %v", err)
			return
		}
		fmt.Println("词法序列Token:")
		for count, token := range tokens {
			fmt.Printf("[%d] %s\n", count, token)
		}
		fmt.Printf("\n=== 词法解析: %d ===", i+1)
		result, err := parser.ParseExpressionWithContext(expr, nil)
		if err != nil {
			fmt.Printf("❌ 解析错误: %v\n", err)
		} else {
			ast.PrintASTWithTitle(result.AST, "完整 AST 树形结构")
		}
	}
}

执行结果

root@hcss-ecs-5ed3:/tools/terst66# go run .
词法序列Token:
[0] [LCURLY({)](0,1)
[1] [LITERAL_INT:1](1,2)
[2] [COMMA(,)](2,3)
[3] [LITERAL_INT:2](3,4)
[4] [COMMA(,)](4,5)
[5] [LITERAL_INT:3](5,6)
[6] [COMMA(,)](6,7)
[7] [LITERAL_INT:4](7,8)
[8] [RCURLY(})](8,9)

=== 词法解析: 1 ===
=== 完整 AST 树形结构 ===
节点类型: InlineList, 表达式片段: '{1,2,3,4}'
  节点类型: Literal, 表达式片段: '1'
  节点类型: Literal, 表达式片段: '2'
  节点类型: Literal, 表达式片段: '3'
  节点类型: Literal, 表达式片段: '4'

V1.0.0

V1.0.0 Pre-release
Pre-release

Choose a tag to compare

@weaweawe01 weaweawe01 released this 17 Oct 12:11

安装

go get github.com/weaweawe01/ParserSpel/ast

使用案例

package main

import (
	"fmt"
	"github.com/weaweawe01/ParserSpel/ast"
)

func main() {
	parser := ast.NewSpelExpressionParser()
	// 测试普通表达式
	normalExpressions := []string{
		"T(java.lang.Runtime).getRuntime().exec('id')",
	}
	for i, expr := range normalExpressions {
		fmt.Printf("\n=== 表达式测试 %d ===\n", i+1)
		fmt.Printf("表达式: %s\n", expr)
		result, err := parser.ParseExpressionWithContext(expr, nil)
		if err != nil {
			fmt.Printf("❌ 解析错误: %v\n", err)
		} else {
			fmt.Printf("   ✅ 解析成功!\n")
			ast.PrintASTWithTitle(result.AST, "完整 AST 树形结构")
		}
	}
}