parser

package
v1.0.0-beta.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package parser 提供多语言代码解析功能

Package parser 提供多语言代码解析功能

Package parser 提供多语言代码解析功能

Package parser 提供多语言代码解析功能

Package parser 提供多语言代码解析功能

Package parser 提供多语言代码解析功能

Package parser 提供多语言代码解析功能 创建者:Done-0

Package parser 提供多语言代码解析功能

Package parser 提供多语言代码解析功能

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseParseResult

type BaseParseResult struct {
	Functions    []Function          // 函数列表
	CommentLines int                 // 注释行数
	TotalLines   int                 // 总行数
	Language     common.LanguageType // 语言类型
	ASTRoot      interface{}         // AST根节点
}

BaseParseResult 基础解析结果实现

func (*BaseParseResult) GetASTRoot

func (r *BaseParseResult) GetASTRoot() interface{}

GetASTRoot 获取AST根节点

func (*BaseParseResult) GetCommentLines

func (r *BaseParseResult) GetCommentLines() int

GetCommentLines 获取注释行数

func (*BaseParseResult) GetFunctions

func (r *BaseParseResult) GetFunctions() []Function

GetFunctions 获取解析出的所有函数

func (*BaseParseResult) GetLanguage

func (r *BaseParseResult) GetLanguage() common.LanguageType

GetLanguage 获取语言类型

func (*BaseParseResult) GetTotalLines

func (r *BaseParseResult) GetTotalLines() int

GetTotalLines 获取总行数

type CParser

type CParser struct{}

CParser C/C++语言解析器

func (*CParser) Parse

func (p *CParser) Parse(filePath string, content []byte) (ParseResult, error)

Parse 解析C/C++代码

func (*CParser) SupportedLanguages

func (p *CParser) SupportedLanguages() []common.LanguageType

SupportedLanguages 返回支持的语言类型

type CSharpParser

type CSharpParser struct{}

CSharpParser C#语言解析器

func (*CSharpParser) Parse

func (p *CSharpParser) Parse(filePath string, content []byte) (ParseResult, error)

Parse 解析C#代码

func (*CSharpParser) SupportedLanguages

func (p *CSharpParser) SupportedLanguages() []common.LanguageType

SupportedLanguages 返回支持的语言类型

type ElifClause

type ElifClause struct {
	Condition *Expression       `parser:"'elif' @@"`
	Body      []PythonStatement `parser:"':' @@ EOL*"`
}

ElifClause 表示elif子句

type ElseClause

type ElseClause struct {
	Body []PythonStatement `parser:"'else' ':' @@ EOL*"`
}

ElseClause 表示else子句

type ExceptClause

type ExceptClause struct {
	Body []PythonStatement `parser:"'except' ':' @@ EOL*"`
}

ExceptClause 表示except子句

type Expression

type Expression struct {
	Ident  *string `parser:"@Ident"`
	Number *string `parser:"| @Number"`
	String *string `parser:"| @String"`
}

Expression 表示表达式

type FinallyClause

type FinallyClause struct {
	Body []PythonStatement `parser:"'finally' ':' @@ EOL*"`
}

FinallyClause 表示finally子句

type ForStmt

type ForStmt struct {
	Target   string            `parser:"'for' @Ident"`
	Iterable *Expression       `parser:"'in' @@"`
	Body     []PythonStatement `parser:"':' @@ EOL*"`
}

ForStmt 表示for循环

type Function

type Function struct {
	Name       string      // 函数名
	StartLine  int         // 开始行
	EndLine    int         // 结束行
	Complexity int         // 复杂度
	Parameters int         // 参数数量
	Node       interface{} // AST节点(可选)
}

Function 函数信息

type FunctionDef

type FunctionDef struct {
	Pos        lexer.Position
	Name       string            `parser:"'def' @Ident"`
	Parameters *ParameterList    `parser:"'(' @@? ')'"`
	Body       []PythonStatement `parser:"':' @@ EOL*"`
}

FunctionDef 表示函数定义

type GenericParser

type GenericParser struct{}

GenericParser 通用文本解析器,适用于任何语言

func (*GenericParser) Parse

func (p *GenericParser) Parse(filePath string, content []byte) (ParseResult, error)

Parse 通过文本分析解析代码

func (*GenericParser) SupportedLanguages

func (p *GenericParser) SupportedLanguages() []common.LanguageType

SupportedLanguages 返回支持的语言类型

type GoParser

type GoParser struct{}

GoParser Go语言解析器

func (*GoParser) Parse

func (p *GoParser) Parse(filePath string, content []byte) (ParseResult, error)

Parse 解析Go代码

func (*GoParser) SupportedLanguages

func (p *GoParser) SupportedLanguages() []common.LanguageType

SupportedLanguages 返回支持的语言类型

type IfStmt

type IfStmt struct {
	Condition   *Expression       `parser:"'if' @@"`
	Body        []PythonStatement `parser:"':' @@ EOL*"`
	ElifClauses []ElifClause      `parser:"@@*"`
	ElseClause  *ElseClause       `parser:"@@?"`
}

IfStmt 表示if语句

type JavaParser

type JavaParser struct{}

JavaParser Java语言解析器

func (*JavaParser) Parse

func (p *JavaParser) Parse(filePath string, content []byte) (ParseResult, error)

Parse 解析Java代码

func (*JavaParser) SupportedLanguages

func (p *JavaParser) SupportedLanguages() []common.LanguageType

SupportedLanguages 返回支持的语言类型

type JavaScriptParser

type JavaScriptParser struct{}

JavaScriptParser JavaScript语言解析器

func (*JavaScriptParser) Parse

func (p *JavaScriptParser) Parse(filePath string, content []byte) (ParseResult, error)

Parse 解析JavaScript代码

func (*JavaScriptParser) SupportedLanguages

func (p *JavaScriptParser) SupportedLanguages() []common.LanguageType

SupportedLanguages 返回支持的语言类型

type Parameter

type Parameter struct {
	Name string `parser:"@Ident"`
}

Parameter 表示函数参数

type ParameterList

type ParameterList struct {
	Params []Parameter `parser:"@@ (',' @@)*"`
}

ParameterList 表示参数列表

type ParseResult

type ParseResult interface {
	// GetFunctions 获取解析出的所有函数
	GetFunctions() []Function

	// GetCommentLines 获取注释行数
	GetCommentLines() int

	// GetTotalLines 获取总行数
	GetTotalLines() int

	// GetLanguage 获取语言类型
	GetLanguage() common.LanguageType

	// GetASTRoot 获取AST根节点(如果支持)
	GetASTRoot() interface{}
}

ParseResult 解析结果接口

type Parser

type Parser interface {
	// Parse 解析代码内容
	// 参数:
	//   - filePath: 文件路径
	//   - content: 文件内容
	// 返回值:
	//   - ParseResult: 解析结果
	//   - error: 可能的错误
	Parse(filePath string, content []byte) (ParseResult, error)

	// SupportedLanguages 返回支持的语言类型
	SupportedLanguages() []common.LanguageType
}

Parser 代码解析器接口

func CreateParser

func CreateParser(language common.LanguageType) Parser

CreateParser 根据语言类型创建解析器

func CreateParserForFile

func CreateParserForFile(filePath string) Parser

CreateParserForFile 根据文件路径创建解析器

func NewCParser

func NewCParser() Parser

NewCParser 创建新的C/C++语言解析器

func NewCSharpParser

func NewCSharpParser() Parser

NewCSharpParser 创建新的C#语言解析器

func NewGenericParser

func NewGenericParser() Parser

NewGenericParser 创建新的通用文本解析器

func NewGoParser

func NewGoParser() Parser

NewGoParser 创建新的Go语言解析器

func NewJavaParser

func NewJavaParser() Parser

NewJavaParser 创建新的Java语言解析器

func NewJavaScriptParser

func NewJavaScriptParser() Parser

NewJavaScriptParser 创建新的JavaScript语言解析器

func NewPythonParser

func NewPythonParser() Parser

NewPythonParser 创建新的Python语言解析器

func NewTypeScriptParser

func NewTypeScriptParser() Parser

NewTypeScriptParser 创建新的TypeScript语言解析器

type PythonAST

type PythonAST struct {
	Statements []PythonStatement `parser:"@@*"`
}

Python AST结构定义

type PythonParser

type PythonParser struct {
	// contains filtered or unexported fields
}

PythonParser Python语言解析器

func (*PythonParser) Parse

func (p *PythonParser) Parse(filePath string, content []byte) (ParseResult, error)

Parse 解析Python代码

func (*PythonParser) SupportedLanguages

func (p *PythonParser) SupportedLanguages() []common.LanguageType

SupportedLanguages 返回支持的语言类型

type PythonStatement

type PythonStatement struct {
	FunctionDef *FunctionDef `parser:"@@"`
	IfStmt      *IfStmt      `parser:"| @@"`
	ForStmt     *ForStmt     `parser:"| @@"`
	WhileStmt   *WhileStmt   `parser:"| @@"`
	TryStmt     *TryStmt     `parser:"| @@"`
	Expression  *Expression  `parser:"| @@"`
	Comment     *string      `parser:"| @Comment"`
	EOL         *string      `parser:"| @EOL"`
}

PythonStatement 表示Python语句

type RazorCodeBlock

type RazorCodeBlock struct {
	Content   string
	StartLine int
	EndLine   int
	BlockType string // "code", "functions", "inline"
}

RazorCodeBlock 表示Razor文件中的C#代码块

type TryStmt

type TryStmt struct {
	Body          []PythonStatement `parser:"'try' ':' @@ EOL*"`
	ExceptClauses []ExceptClause    `parser:"@@*"`
	FinallyClause *FinallyClause    `parser:"@@?"`
}

TryStmt 表示try语句

type TypeScriptParser

type TypeScriptParser struct {
	JavaScriptParser
}

TypeScriptParser TypeScript语言解析器

func (*TypeScriptParser) Parse

func (p *TypeScriptParser) Parse(filePath string, content []byte) (ParseResult, error)

Parse 解析TypeScript代码

func (*TypeScriptParser) SupportedLanguages

func (p *TypeScriptParser) SupportedLanguages() []common.LanguageType

SupportedLanguages 返回支持的语言类型

type WhileStmt

type WhileStmt struct {
	Condition *Expression       `parser:"'while' @@"`
	Body      []PythonStatement `parser:"':' @@ EOL*"`
}

WhileStmt 表示while循环

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL