Documentation
¶
Index ¶
- Constants
- type FunctionCallInfo
- type LintListener
- func (l *LintListener) EnterAssignment(ctx *grulev3.AssignmentContext)
- func (l *LintListener) EnterComparisonOperator(ctx *grulev3.ComparisonOperatorContext)
- func (l *LintListener) EnterExpression(ctx *grulev3.ExpressionContext)
- func (l *LintListener) EnterFunctionCall(ctx *grulev3.FunctionCallContext)
- func (l *LintListener) EnterRuleDescription(ctx *grulev3.RuleDescriptionContext)
- func (l *LintListener) EnterRuleEntry(ctx *grulev3.RuleEntryContext)
- func (l *LintListener) EnterRuleName(ctx *grulev3.RuleNameContext)
- func (l *LintListener) EnterSalience(ctx *grulev3.SalienceContext)
- func (l *LintListener) EnterThenScope(ctx *grulev3.ThenScopeContext)
- func (l *LintListener) EnterVariable(ctx *grulev3.VariableContext)
- func (l *LintListener) EnterWhenScope(ctx *grulev3.WhenScopeContext)
- func (l *LintListener) ExitRuleEntry(ctx *grulev3.RuleEntryContext)
- func (l *LintListener) ExitThenScope(ctx *grulev3.ThenScopeContext)
- func (l *LintListener) ExitWhenScope(ctx *grulev3.WhenScopeContext)
- type ParseError
- type ParseResult
- type Parser
- type RuleInfo
- type VariableInfo
Constants ¶
const DefaultMaxFileSize = 10 * 1024 * 1024
DefaultMaxFileSize is the default maximum file size for parsing (10MB).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FunctionCallInfo ¶
type FunctionCallInfo struct {
Name string
Position diagnostic.Position
}
type LintListener ¶
type LintListener struct {
*grulev3.Basegrulev3Listener
Rules []RuleInfo
// contains filtered or unexported fields
}
LintListener extracts rule information from the ANTLR parse tree.
func NewLintListener ¶
func NewLintListener() *LintListener
func (*LintListener) EnterAssignment ¶
func (l *LintListener) EnterAssignment(ctx *grulev3.AssignmentContext)
EnterAssignment tracks variable assignments in then clause for unused variable detection.
func (*LintListener) EnterComparisonOperator ¶
func (l *LintListener) EnterComparisonOperator(ctx *grulev3.ComparisonOperatorContext)
EnterComparisonOperator counts comparison operators (==, !=, <, >, <=, >=) in when clause. Only comparison operators are counted as conditions, not logical operators (&&, ||).
func (*LintListener) EnterExpression ¶
func (l *LintListener) EnterExpression(ctx *grulev3.ExpressionContext)
func (*LintListener) EnterFunctionCall ¶
func (l *LintListener) EnterFunctionCall(ctx *grulev3.FunctionCallContext)
func (*LintListener) EnterRuleDescription ¶
func (l *LintListener) EnterRuleDescription(ctx *grulev3.RuleDescriptionContext)
func (*LintListener) EnterRuleEntry ¶
func (l *LintListener) EnterRuleEntry(ctx *grulev3.RuleEntryContext)
func (*LintListener) EnterRuleName ¶
func (l *LintListener) EnterRuleName(ctx *grulev3.RuleNameContext)
func (*LintListener) EnterSalience ¶
func (l *LintListener) EnterSalience(ctx *grulev3.SalienceContext)
func (*LintListener) EnterThenScope ¶
func (l *LintListener) EnterThenScope(ctx *grulev3.ThenScopeContext)
func (*LintListener) EnterVariable ¶
func (l *LintListener) EnterVariable(ctx *grulev3.VariableContext)
func (*LintListener) EnterWhenScope ¶
func (l *LintListener) EnterWhenScope(ctx *grulev3.WhenScopeContext)
func (*LintListener) ExitRuleEntry ¶
func (l *LintListener) ExitRuleEntry(ctx *grulev3.RuleEntryContext)
func (*LintListener) ExitThenScope ¶
func (l *LintListener) ExitThenScope(ctx *grulev3.ThenScopeContext)
func (*LintListener) ExitWhenScope ¶
func (l *LintListener) ExitWhenScope(ctx *grulev3.WhenScopeContext)
type ParseError ¶
ParseError represents a syntax error from the Grule parser.
type ParseResult ¶
type ParseResult struct {
// KnowledgeBase is the parsed AST (nil if parsing failed)
KnowledgeBase *gruleAst.KnowledgeBase
// Rules contains parsed rule information with accurate positions
Rules []RuleInfo
// Errors contains any parse errors encountered
Errors []ParseError
// Source is the original source content
Source string
// File is the file path
File string
}
ParseResult contains the result of parsing a GRL file.
func (*ParseResult) GetRuleInfo ¶
func (r *ParseResult) GetRuleInfo(ruleName string) (*RuleInfo, bool)
GetRuleInfo returns the RuleInfo for a rule by name.
func (*ParseResult) GetRulePosition ¶
func (r *ParseResult) GetRulePosition(ruleName string) (diagnostic.Position, bool)
GetRulePosition returns the position of a rule by name.
func (*ParseResult) Success ¶
func (r *ParseResult) Success() bool
Success returns true if parsing succeeded without errors.
func (*ParseResult) ToDiagnostics ¶
func (r *ParseResult) ToDiagnostics() []diagnostic.Diagnostic
ToDiagnostics converts parse errors to diagnostics.
type Parser ¶
type Parser struct {
// MaxFileSize is the maximum file size allowed for parsing.
// Set to 0 to use DefaultMaxFileSize. Set to -1 for unlimited.
MaxFileSize int64
}
Parser wraps Grule's ANTLR parser for parsing GRL files.
func NewParser ¶
func NewParser() *Parser
NewParser creates a new Parser instance with default settings.
func (*Parser) ParseFile ¶
func (p *Parser) ParseFile(file string) (*ParseResult, error)
ParseFile parses a GRL file from disk.
func (*Parser) ParseString ¶
func (p *Parser) ParseString(file, content string) *ParseResult
ParseString parses GRL content from a string.
type RuleInfo ¶
type RuleInfo struct {
Name string
Description string
Salience string
Position diagnostic.Position
EndPosition diagnostic.Position
WhenPosition diagnostic.Position
ThenPosition diagnostic.Position
FunctionCalls []FunctionCallInfo
ConditionCount int
HasWhenExpression bool
ThenActionCount int
VariableAssignments []VariableInfo
VariableUsages []VariableInfo
WhenExpressionText string
}
RuleInfo contains parsed information about a single GRL rule.
type VariableInfo ¶
type VariableInfo struct {
Name string
Position diagnostic.Position
}