Skip to main content

Module parser

Module parser 

Source
Expand description

Recursive-descent parser for the pic drawing core.

Follows dpic’s grammar.txt. Implemented: pictures (.PS … .PE), primitives with the full attribute set, positions (pairs, places, corners, ordinals, between, ± shifts), expressions with proper precedence, [ … ] blocks, { … } groups, labels, assignments, macros, includes, conditionals, loops, print and exec.

Structs§

ParseError
A parse error with source location. file (via ParseError::span) is None for the user’s own input, or the copy include / library name the position is relative to.

Functions§

parse
Parse a full source string into a Picture with no filesystem context. copy "file" includes are unavailable (they require a base directory).
parse_body_tokens
Parse a deferred body (the raw tokens of an if/for block) with the macro table in scope, expanding macro calls (and copy includes) along this executed path. Used by the evaluator so dead branches and recursive macros are never parsed.
parse_in_dir
Parse pic source, resolving copy "file" includes relative to base with the default (unrestricted) include policy.
parse_with_prelude
Parse pic source with optional preludes: circuits loads the embedded circuit-element library and texlabels injects texlabels = 1 — the library equivalents of the CLI -c / -t flags. Each prelude is lexed as its own named source unit (not text glued in front of src), so every diagnostic position stays relative to the source it belongs to: the user’s own input reports user lines, and library problems name the library.