@promptc/parser
v0.0.2
Published
Parsers (markdown / XML / plain) into promptc IR.
Downloads
262
Readme
@promptc/parser
The front end of the promptc
compiler — turns markdown, XML, or plain-text prompts into a typed
PromptIR (defined in @promptc/ir).
Every entry point is a pure function of the input string: same bytes in produces the same IR out. No I/O, no RNG. This is the basis for the compile path's overall determinism guarantee.
Install
bun add @promptc/parser
# or
npm install @promptc/parserQuick API
import { parse, parseAuto, parseMarkdown, parseXml, parsePlain } from "@promptc/parser";
// Format-routed:
const ir1 = parse(source, { format: "markdown" });
const ir2 = parse(source, { format: "auto" });
// Direct:
const ir3 = parseMarkdown(source);
const ir4 = parseXml(source); // throws ParseError on malformed input
const ir5 = parsePlain(source);parse(source, { format: "auto" }) runs the lightweight format detector
(no LM, no heuristics that depend on locale or environment) and dispatches
to the right per-format parser.
What's in here
parseMarkdown— heading-and-list driven layout, fenced code, simple example/output-schema markers.parseXml—<task>,<context>,<example>, etc. tag layout. ThrowsParseErroron malformed input.parsePlain— minimal plain-text fallback (one big task section).parseAuto— format detector + dispatch.- Errors —
ParseErrorwith byte/line/column location info.
Errors
Malformed XML or invalid plain-text shapes throw ParseError, which
carries a location field ({ line, column, byteOffset }) suitable for
piping into editor diagnostics.
Links
- Main repo:
promptc - Design contract:
DESIGN.md - IR reference:
docs/IR.md
License
Apache-2.0. See LICENSE.
