Documentation
¶
Overview ¶
Package pythongrammar holds the closed Python 3.12 subset lexer and parser. It is deliberately neutral: it carries no request envelope, no fact-output budget, and no dependency on the separately buildable Python analyzer, so Core may reach the grammar without reaching that candidate (PNC-001).
Index ¶
- Constants
- func ContainsPython314ExceptList(content []byte) bool
- func DelimiterPair(open, close byte) bool
- func FString(prefix []byte) bool
- func PythonKeyword(value string) bool
- func SkipString(content []byte, quoteAt int) int
- func StringStart(content []byte, index int) (int, bool)
- func SyntaxName(value string) failure
- type DefinitionSpanSink
- type FactSink
- type Failure
- type Parser
- func (parser *Parser) BinaryConnector(token Token) bool
- func (parser *Parser) CommaSeparated(tokens []Token) ([][]Token, failure)
- func (parser *Parser) Comparison(tokens []Token, index int) bool
- func (parser *Parser) DanglingUnary(tokens []Token) bool
- func (parser *Parser) DefinitionStart(tokens []Token) bool
- func (parser *Parser) EllipsisAt(tokens []Token, index int) bool
- func (parser *Parser) ExpressionBracket(token Token) bool
- func (parser *Parser) HasTopLevel(tokens []Token, want string) bool
- func (parser *Parser) HeaderColon(tokens []Token, start int) int
- func (parser *Parser) KeywordOperator(token Token) bool
- func (parser *Parser) Matching(tokens []Token, open int) int
- func (parser *Parser) Name(token Token, want string) bool
- func (parser *Parser) Operand(token Token) bool
- func (parser *Parser) SpanColon(tokens []Token, start int) int
- func (parser *Parser) StatementEnd(start int) int
- func (parser *Parser) StaticCallee(tokens []Token) (string, int, bool, failure)
- func (parser *Parser) Symbol(token Token, want string) bool
- func (parser *Parser) SymbolByte(token Token, want byte) bool
- func (parser *Parser) Text(token Token) string
- func (parser *Parser) TopLevel(tokens []Token, target int) bool
- func (parser *Parser) TypeAliasStart(tokens []Token) bool
- type SyntaxCheck
- type Token
Constants ¶
const ( KindName byte = iota + 1 KindNumber KindString KindSymbol KindNewline KindIndent KindDedent )
Variables ¶
This section is empty.
Functions ¶
func ContainsPython314ExceptList ¶
ContainsPython314ExceptList reports whether the source uses the 3.14 bare `except` list form, which this 3.12 subset does not accept.
func DelimiterPair ¶
DelimiterPair reports whether close is the delimiter matching open.
func PythonKeyword ¶
func SkipString ¶
SkipString returns the index just past the string literal opening at quoteAt.
func StringStart ¶
StringStart reports whether a string literal opens at index, returning the index of its opening quote.
func SyntaxName ¶
func SyntaxName(value string) failure
Types ¶
type DefinitionSpanSink ¶
type DefinitionSpanSink interface {
DefinitionEnd(startLine, endLine int)
}
DefinitionSpanSink is the optional half of FactSink for callers that need a definition's extent rather than only its position. A fact carries one line, which names where a definition starts and can never name where its suite ends; a collector that implements this interface is told both, and one that does not is unaffected -- the parser reports spans only when the assertion below succeeds.
type FactSink ¶
FactSink receives the grammar's facts. The grammar names only the subject it parsed; identity beyond that belongs to the caller, which closes over it.
type Failure ¶
type Failure string
Failure is a typed rejection reason. The values match the analyzer's wire vocabulary so a caller can pass them straight through.
func ParseChecked ¶
func ParseChecked(subject string, source []byte, collector FactSink, check SyntaxCheck) Failure
ParseChecked is ParsePython312Subset with an additional syntax check applied to the lexed source before the fact grammar runs. A nil check parses exactly as ParsePython312Subset does.
func ParsePython312Subset ¶
Balanced expressions outside the named fact grammar remain opaque. ParsePython312Subset parses the closed Python 3.12 subset, emitting facts to the sink. subject names the parsed unit in every fact it produces.
type Parser ¶
func (*Parser) BinaryConnector ¶
func (*Parser) CommaSeparated ¶
func (*Parser) DanglingUnary ¶
func (*Parser) DefinitionStart ¶
func (*Parser) ExpressionBracket ¶
func (*Parser) KeywordOperator ¶
func (*Parser) StatementEnd ¶
func (*Parser) StaticCallee ¶
func (*Parser) TypeAliasStart ¶
TypeAliasStart reports whether a statement opening with the soft keyword `type` is a PEP 695 alias rather than an ordinary use of the builtin. CPython commits to `type_alias: "type" NAME [type_params] '=' expression` only on that shape, so `type(x)`, `type = 5` and `type(self).calls += 1` stay expressions.
type SyntaxCheck ¶
SyntaxCheck rejects a lexed source whose shape the closed grammar treats as necessarily invalid. It is supplied by the caller rather than held here so this package — and every executable that reaches it for fact extraction alone — carries no syntax-validation route (ACP-009).