Documentation
¶
Index ¶
- Constants
- func AssertDeclCount(t *testing.T, file *ast.File, expected int)
- func AssertErrorCount(t *testing.T, p *Parser, expected int)
- func AssertFuncCall(t *testing.T, expr ast.Expr) *ast.FuncCall
- func AssertFuncDecl(t *testing.T, node ast.Node, expectedName string) *ast.FuncDecl
- func AssertIdentifier(t *testing.T, expr ast.Expr, expectedName string)
- func AssertList(t *testing.T, expr ast.Expr) *ast.List
- func AssertListLength(t *testing.T, expr ast.Expr, expectedLen int) *ast.List
- func AssertListType(t *testing.T, typ ast.Type) ast.Type
- func AssertLiteralBool(t *testing.T, expr ast.Expr, expected bool)
- func AssertLiteralFloat(t *testing.T, expr ast.Expr, expected float64)
- func AssertLiteralInt(t *testing.T, expr ast.Expr, expected int)
- func AssertLiteralString(t *testing.T, expr ast.Expr, expected string)
- func AssertNoErrors(t *testing.T, p *Parser)
- func AssertSimpleType(t *testing.T, typ ast.Type, expectedName string)
- func AssertTokenPosition(t *testing.T, p *Parser, expectedCur, expectedPeek lexer.TokenType)
- func AssertTypeDecl(t *testing.T, node ast.Node, expectedName string) *ast.TypeDecl
- type Parser
- type ParserError
Constants ¶
const ( LOWEST = 0 LAMBDA = 1 // \x. (lowest precedence) LogicalOr = 2 // || LogicalAnd = 3 // && BitwiseXor = 5 // ^ (4 reserved for future bitwise OR |) BitwiseAnd = 6 // & EQUALS = 7 // ==, != LESSGREATER = 8 // >, <, >=, <= SHIFT = 9 // <<, >> CONS = 10 // :: (list cons - right associative) APPEND = 11 // ++ SUM = 12 // +, - PRODUCT = 13 // *, /, % PREFIX = 14 // -x, !x, ~x (unary) CALL = 15 // f(x) (application) DotAccess = 16 // r.field (field access - highest) HIGHEST = 17 )
Precedence levels — C-standard dedicated bands. These MUST match the values returned by token.Precedence().
Variables ¶
This section is empty.
Functions ¶
func AssertDeclCount ¶
AssertDeclCount verifies that a file has the expected number of declarations.
Example:
file := p.ParseFile() AssertDeclCount(t, file, 3)
func AssertErrorCount ¶
AssertErrorCount verifies that the parser has exactly the expected number of errors.
Example:
p := New(lexer.New("invalid syntax"))
p.ParseFile()
AssertErrorCount(t, p, 1)
func AssertFuncCall ¶
AssertFuncCall verifies that an expression is a function call and returns it for further inspection.
Example:
expr := p.parseExpression(LOWEST)
call := AssertFuncCall(t, expr)
if call != nil {
AssertIdentifier(t, call.Func, "add")
if len(call.Args) != 2 { ... }
}
func AssertFuncDecl ¶
AssertFuncDecl verifies that a node is a function declaration and returns it.
Example:
file := p.ParseFile()
fn := AssertFuncDecl(t, file.Decls[0], "factorial")
if fn != nil {
// Check function properties
}
func AssertIdentifier ¶
AssertIdentifier verifies that an expression is an identifier with the expected name.
Example:
expr := p.parseExpression(LOWEST) AssertIdentifier(t, expr, "x")
func AssertList ¶
AssertList verifies that an expression is a list and returns it for further inspection.
Example:
expr := p.parseExpression(LOWEST)
list := AssertList(t, expr)
if list != nil {
if len(list.Elements) != 3 { ... }
}
func AssertListLength ¶
AssertListLength verifies that an expression is a list with the expected length.
func AssertListType ¶
AssertListType verifies that a type is a list type and returns the element type. DX-17 Phase 2: [T] syntax now parses to TypeApp("list", [T])
func AssertLiteralBool ¶
AssertLiteralBool verifies that an expression is a boolean literal with the expected value.
func AssertLiteralFloat ¶
AssertLiteralFloat verifies that an expression is a float literal with the expected value.
func AssertLiteralInt ¶
AssertLiteralInt verifies that an expression is an integer literal with the expected value.
Example:
expr := p.parseExpression(LOWEST) AssertLiteralInt(t, expr, 42)
func AssertLiteralString ¶
AssertLiteralString verifies that an expression is a string literal with the expected value.
func AssertNoErrors ¶
AssertNoErrors verifies that the parser has no errors. If there are errors, it prints them before failing the test.
Example:
p := New(lexer.New(input)) file := p.ParseFile() AssertNoErrors(t, p)
func AssertSimpleType ¶
AssertSimpleType verifies that a type is a simple type with the expected name.
func AssertTokenPosition ¶
AssertTokenPosition helps debug token position issues in tests. It verifies that the parser is at the expected current and peek tokens.
Example:
p.nextToken() expr := p.parseExpression(LOWEST) AssertTokenPosition(t, p, lexer.INT, lexer.COMMA) // cur=INT, peek=COMMA
Types ¶
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses AILANG source code into an AST
func (*Parser) SetStrictSyntaxMode ¶
SetStrictSyntaxMode enables or disables strict syntax mode. When strict mode is enabled, all syntactic sugar is rejected with helpful errors.
type ParserError ¶
type ParserError struct {
Code string
Message string
Pos ast.Pos
NearToken lexer.Token
Expected []lexer.TokenType
Fix string // Deprecated: use Suggestions instead
Suggestions []string
HelpURL string
Confidence float64
}
ParserError represents a structured parser error with fix suggestions
func NewParserError ¶
func NewParserError(code string, pos ast.Pos, nearToken lexer.Token, message string, expected []lexer.TokenType, fix string) *ParserError
NewParserError creates a structured parser error with fix suggestion
func NewSuggestionError ¶
func NewSuggestionError(code string, pos ast.Pos, nearToken lexer.Token, message string, suggestions []string, helpURL string) *ParserError
NewSuggestionError creates a parser error with multiple suggestions and optional help URL
func (*ParserError) Error ¶
func (e *ParserError) Error() string