Expand description
What Parsec’s parsers share, and nothing they don’t: a Span of
input, a LineIndex that turns byte offsets into lines, columns and
UTF-16 offsets, a Diagnostic with a code and a span that
Diagnostic::render prints as a code frame, and the
Limits and Budget that keep hostile input from costing more
than you allow.
Each language keeps its own tokens, tree and error recovery; this crate is only the plumbing under them, and it has no dependencies.
use parsec_base::{Diagnostic, LineIndex, Span};
let src = "let a = 1;\nlet é = 'x\n";
let bad = Diagnostic::error("unterminated-string", Span::new(20, 22), "a string has no closing quote");
let lines = LineIndex::new(src);
assert_eq!(lines.line_col(bad.span.start), (2, 9).into());
assert_eq!(bad.span.text(src), "'x");Structs§
- Budget
- Steps left to spend on a parse. Parsers spend from it on the work whose cost the input controls and stop when it runs out, so the cost of a hostile input is one you chose.
- Diagnostic
- Something a parser has to say about its input: a stable
codeto match on (likeunterminated-string), where, and a sentence for people. With a'staticmessage and no labels, making one allocates nothing. - Exhausted
- A
Budgetran out. - Label
- A second place a
Diagnosticpoints at, with what it is. - Limits
- The most a parse may cost.
Noneis no limit. - LineCol
- A line and a column, both counted from 1.
- Line
Index - Where each line starts in a text, for turning byte offsets into lines and columns, in characters or in UTF-16 code units as editors and the language server protocol count them.
- Render
Options - How
Diagnostic::renderlays a code frame out. - Span
- A byte range in the input,
start..end.
Enums§
- Severity
- How bad a
Diagnosticis.