parser

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package parser is the top-level entry point: source bytes in, ast.Mod out. The package wires the lexer, the pegen runtime, and (eventually) the generated parser table into a single Parse / ParseString surface that mirrors CPython's _PyPegen_run_parser entry point.

Until the generated parser table lands the entry points return a sentinel error; callers can program against the stable shape today and the body will fill in once parser_gen ships.

CPython: Parser/peg_api.c

Index

Constants

This section is empty.

Variables

View Source
var ErrParserNotImplemented = fmt.Errorf("parser: generated rule bodies not yet emitted")

ErrParserNotImplemented is returned by Parse / ParseString while the generated parser table is offline. The lexer and error surfaces still work; downstream code should detect this sentinel and route through a fixture-driven path until the real parser lands.

Functions

func Parse

func Parse(r io.Reader, filename string, mode Mode) (ast.Mod, error)

Parse reads from r. Useful for tokenize.tokenize() over file input where buffered IO is preferable.

CPython: Parser/peg_api.c:31 _PyParser_ASTFromFile

func ParseString

func ParseString(src, filename string, mode Mode) (ast.Mod, error)

ParseString parses src under the given mode and returns the AST root. Filename is used for SyntaxError text.

CPython: Parser/peg_api.c:8 _PyParser_ASTFromString

Types

type Mode

type Mode int

Mode picks the entry rule of the generated parser table.

const (
	ModeFile Mode = iota
	ModeSingle
	ModeEval
)

Parse modes mirror Py_*_input.

Directories

Path Synopsis
Package errors holds the SyntaxError text panel and the helpers that turn (parser, token, message) into a structured *SyntaxError.
Package errors holds the SyntaxError text panel and the helpers that turn (parser, token, message) into a structured *SyntaxError.
Package lexer ports cpython/Parser/lexer/ and cpython/Parser/tokenizer/ to Go.
Package lexer ports cpython/Parser/lexer/ and cpython/Parser/tokenizer/ to Go.
Package pegen ports the runtime half of cpython 3.14 Parser/pegen.c and pegen.h.
Package pegen ports the runtime half of cpython 3.14 Parser/pegen.c and pegen.h.
Package string ports cpython/Parser/string_parser.c.
Package string ports cpython/Parser/string_parser.c.

Jump to

Keyboard shortcuts

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