! / 0 0 0 0 4 ` / 0 0 0 0 16 ` O// 56 ` peg-7fe48a6c661aa89d.peg.e8a853274d6787a6-cgu.0.rcgu.o lib.rmeta/ 0 0 0 644 20107 ` duN.rmeta9N<rust L#rustc 1.81.0 (eeb90cda1 2024-09-04) 4< Y_-759718a9bb18a1234ae'7`/Ж-89ef43c30f9b928exvA١Q-1426abde5263ac46rustc_std_workspace_coreXP\VB*Di-d08e4e7d05aff086PF}iJ dT-bcbe36736b9f0af2,O\;&TZ-93dda7487230aedacfg_ife7C?ubrj -814df84e64e9c749 hashbrowniVE K-1128f34f910afc3arustc_std_workspace_alloc -+/u8h-ec2cabfc22cdef7d std_detectuMChO.-67d9d7b318bd750drustc_demangle"Qb`8;kw-13c5a35fb3626718 x@8^#,%-7da375a7ca1e9a5e peg_macrosӺ1w\i)MWB-5751bd063bbc34d0 peg_runtimeY5h>-d3962009be6b7746 runtime Tv Parse-Y ParseElemMa ParseLiterale e ParseSliceU g RuleResultUvK `rust-peg` is a simple yet flexible parser generator that makes it easy toN7 write robust parsers. Based on the [Parsing ExpressionO:J Grammar][wikipedia-peg] formalism, it provides a Rust macro that builds aMC recursive descent parser from a concise definition of the grammar.FJ [wikipedia-peg]: https://en.wikipedia.org/wiki/Parsing_expression_grammarM ## Features|H * Parse input from `&str`, `&[u8]`, `&[T]` or custom types implementingK traitsd) * Customizable reporting of parse errors,? * Rules can accept arguments to create reusable rule templatesB; * Precedence climbing for prefix/postfix/infix expressions>M * Helpful `rustc` error messages for errors in the grammar definition or theP Rust code embedded within it"' * Rule-level tracing to debug grammars* ## Overview|K The `peg::parser!{}` macro encloses a `grammar NAME() for INPUT_TYPE { ...NG }` definition containing a set of rules which match components of yourJ language.lJ Rules are defined with `rule NAME(PARAMETERS) -> RETURN_TYPE = PEG_EXPR`.MM The body of the rule, following the `=`, is a PEG expression, definining howP) the input is matched to produce a value. , M PEG expressions are evaluated at a particular position of the input. When an PM expression matches, it advances the position and optionally returns a value. P2 The expression syntax and behavior is [documented 5 below](#expression-reference). " M The macro expands to a Rust `mod` containing a function for each rule marked PD `pub` in the grammar. To parse an input sequence, call one of these GJ functions. The call returns a `Result` carrying either the MM successfully parsed value returned by the rule, or a `ParseError` containing P; the failure position and the set of tokens expected there. > ## ExampletR Parse a comma-separated list of numbers surrounded by brackets into a `Vec`:U ```rust\ peg::parser!{" grammar list_parser() for str {% rule number() -> u328 = n:$(['0'..='9']+) {? n.parse().or(Err("u32")) }; pub rule list() -> Vec#* = "[" l:(number() ** ",") "]" { l }- }< }, pub fn main() {P assert_eq!(list_parser::list("[1,1,2,3,5,8]"), Ok(vec![1, 1, 2, 3, 5, 8]));S, ```< ## Expression Referenceܪ ### Atomsl5 * `"keyword"` - _Literal:_ match a literal string.8Y * `['0'..='9']` - _Pattern:_ match a single element that matches a Rust `match`-style\/ pattern. [(details)](#pattern-expressions)2k * `[^ '0'..='9']` - _Inverted pattern:_ match a single element that does not match a Rust `match`-stylen2Y * `some_rule()` - _Rule:_ match a rule defined elsewhere in the grammar and return its\? result. Arguments in the parentheses are Rust expressions.BN * `_` or `__` or `___` - _Rule (underscore):_ As a special case, rule namesQX consisting of underscores can be defined and invoked without parentheses. These are[< conventionally used to match whitespace between tokens.?G * `(e)` - _Parentheses:_ wrap an expression into a group to overrideJL normal precedence. Returns the same value as the inner expression. (UseO? an _Action_ block to set the return value for a sequence).B ### Combining^ * `e1 e2 e3` - _Sequence:_ match expressions in sequence (`e1` followed by `e2` followed bya' `e3`), ignoring the return values.*M * `a:e1 e2 b:e3 c:e4 { rust }` - _Action:_ match `e1`, `e2`, `e3`, `e4` inPK sequence, like above. If they match successfully, run the Rust code inNI the block and return its return value. The variable names before theL; colons in the sequence are bound to the results of the>K corresponding expressions. It is important that the Rust code embeddedNK in the grammar is deterministic and free of side effects, as it may beN called multiple times.K * `a:e1 b:e2 c:e3 {? rust }` - _Conditional action:_ Like above, but theNK Rust block returns a `Result` instead of a value directly. On NM `Ok(v)`, it matches successfully and returns `v`. On `Err(e)`, the match PJ of the entire expression fails and it tries alternatives or reports a!M' parse failure with the `&str` `e`."*\ * `e1 / e2 / e3` - _Ordered choice:_ try to match `e1`. If the match succeeds, return its"_+ result, otherwise try `e2`, and so on.#.# ### Repetition#Z * `expression?` - _Optional:_ match zero or one repetitions of `expression`. Returns an#] `Option`.$\ * `expression*` - _Repeat:_ match zero or more repetitions of `expression` and return the$_ results as a `Vec`.ܡ%` * `expression+` - _One-or-more:_ match one or more repetitions of `expression` and return the%c1ܡ&_ * `expression*` - _Range repeat:_ match between `n` and `m` repetitions of `expression`&b? return the results as a `Vec`. [(details)](#repeat-ranges)'B_ * `expression ** delim` - _Delimited repeat:_ match zero or more repetitions of `expression`'b> delimited with `delim` and return the results as a `Vec`.(As * `expression ** delim` - _Delimited repeat (range):_ match between `n` and `m` repetitions of `expression`)vZ delimited with `delim` and return the results as a `Vec`. [(details)](#repeat-ranges))]l * `expression ++ delim` - _Delimited repeat (one or more):_ match one or more repetitions of `expression`*o5+A, ### Special,R * `$(e)` - _Slice:_ match the expression `e`, and return the slice of the input,U corresponding to the match.,#M * `&e` - _Positive lookahead:_ Match only if `e` matches at this position,-P& without consuming any characters.-)J * `!e` - _Negative lookahead:_ Match only if `e` does not match at this.M0 position, without consuming any characters..3J * `position!()` - return a `usize` representing the current offset into/M* the input without consuming anything./-c * `quiet!{ e }` - match the expression `e`, but don't report literals within it as "expected" in0f error messages.0Z * `expected!("something")` - fail to match, and report the specified string as expected1] at the current location.1 _ * `precedence!{ ... }` - Parse infix, prefix, or postfix expressions by precedence climbing.2b& [(details)](#precedence-climbing)2)3 ## Expression detailș33 ### Pattern expressions330 The `[pat]` syntax expands into a [Rust `match`33` pattern](https://doc.rust-lang.org/book/ch18-03-pattern-syntax.html) against the next character4c (or element) of the input.4 $5E When the pattern begins with `^`, the matching behavior is inverted:5H> the expression succeeds only if the pattern does *not* match.5A3 `[^' ']` matches any character other than a space.666F To match sets of characters, use Rust's `..=` inclusive range pattern6I\ syntax and `|` to match multiple patterns. For example `['a'..='z' | 'A'..='Z']` matches an7_. upper or lower case ASCII alphabet character.818Z If your input type is a slice of an enum type, a pattern could match an enum variant like8] `[Token::Operator('+')]`.99H Variables captured by the pattern are accessible in a subsequent action9K$ block: `[Token::Integer(i)] { i }`.:'C$:K The pattern expression also evaluates to the matched element, which can be:NO captured into a variable or used as the return value of a rule: `c:['+'|'-']`.;RC$;B Like Rust `match`, pattern expressions support guard expressions:;E `[c if c.is_ascii_digit()]`.< <] `[_]` matches any single element. As this always matches except at end-of-file, combining it<`H with negative lookahead as `![_]` is the idiom for matching EOF in PEG.=KC$= ### Repeat ranges>>\ The repeat operators `*` and `**` can be followed by an optional range specification of the>_~ form `` (exact), `` (min-inclusive), `<,m>` (max-inclusive) or `` (range-inclusive), where `n` and `m` are either>9 integers, or a Rust `usize` expression enclosed in `{}`.?<@ ### Precedence climbing@@X `precedence!{ rules... }` provides a convenient way to parse infix, prefix, and postfix@[ operators using the [precedenceA#^ climbing](http://eli.thegreenplace.net/2012/08/02/parsing-expressions-by-precedence-climbing)Aa algorithm.tBB ```rust,no_runB' # peg::parser!{grammar doc() for str {B*) # pub rule number() -> i64 = "..." { 0 }C,, pub rule arithmetic() -> i64 = precedence!{C/ x:(@) "+" y:@ { x + y }C x:(@) "-" y:@ { x - y }D --DD x:(@) "*" y:@ { x * y }D x:(@) "/" y:@ { x / y }DTDD$ x:@ "^" y:(@) { x.pow(y as u32) }D'TDE n:number() { n }E "(" e:arithmetic() ")" { e }E",E # }}DE # fn main() {}EI ## Input typesIIH The first line of the grammar declares an input type. This is normallyIKL `str`, but `rust-peg` handles input types through a series of traits. TheJOM library comes with implementations for `str`, `[u8]`, and `[T]`. Define theKP@ traits below to use your own types as input to `peg` grammars:KCLa * [`Parse`] is the base trait required for all inputs. The others are only required to use theLd corresponding expressions.M"b * [`ParseElem`] implements the `[_]` pattern operator, with a method returning the next item ofMe the input to match.ܢNG * [`ParseLiteral`] implements matching against a `"string"` literal.NJ\ * [`ParseSlice`] implements the `$()` operator, returning a slice from a span of indexes.O_OL As a more complex example, the body of the `peg::parser!{}` macro itself isOOL parsed with `peg`, using a [definition of these traits][gh-flat-token-tree]PO* for a type that wraps Rust's `TokenTree`.Q-Q_ [gh-flat-token-tree]: https://github.com/kevinmehall/rust-peg/blob/master/peg-macros/tokens.rsQbR ## End-of-file handlingܦRRa Normally, parsers report an error if the top-level rule matches without consuming all the input.RdZ To allow matching a prefix of the input, add the `#[no_eof]` attribute before `pub rule`.S]Z Take care to not miss a malformed `x` at the last position if the rule ends with a `x()*`T] repeat expression.TT ## Rule parametersUUX Rules can be parameterized with types, lifetimes, and values, just like Rust functions.U[Ua In addition to Rust values, rules can also accept PEG expression fragments as arguments by usingUda `rule` as a parameter type. When calling such a rule, use `<>` around a PEG expression in theVdA argument list to capture the expression and pass it to the rule.WDX For example:XXRXRX*" rule num_radix(radix: u32) -> u32X%K = n:$(['0'..='9']+) {? u32::from_str_radix(n, radix).or(Err("number")) }YNYE rule list(x: rule) -> Vec = "[" v:(x() ** ",") ","? "]" {v}YHZ9 pub rule octal_list() -> Vec = list()Z<VDZVZ<[[ ## Failure reportingĎ[[V When a match fails, position information is automatically recorded to report a set of[YI "expected" tokens that would have allowed the parser to advance further.\L\Z Some rules should never appear in error messages, and can be suppressed with `quiet!{e}`:\]R]R]*1 rule whitespace() = quiet!{[' ' | '\n' | '\t']+}]4VD^V^<^^_ If you want the "expected" set to contain a more helpful string instead of character sets, you^b/ can use `quiet!{}` and `expected!()` together:_2_R_R_* rule identifier()`J = quiet!{[ 'a'..='z' | 'A'..='Z']['a'..='z' | 'A'..='Z' | '0'..='9' ]*}`M / expected!("identifier")aVDaVa Vec = "[...]" { vec![] }g5VDgVgYaeguv#0vHP7]̝L$\=q#rE4AJ4XS`S@1 EXEEP7]4XSqMQf qMQf XC:\Users\Admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\peg-0.8.4\src\lib.rs DV6p{n*I淶)ch΁vO;NGNL -C?Q#+OKNQ-QQ6#QHNQ?V &<$.T9]3o3]CR\@KPCb+QOM?OOOOQN+`/^`dcCcBw^pBV$Q*N4N.g^!c*4dIB7J`2^L(OSF!aL`=\$b+-0  ( # a\`a?LPQDe#fK`PP.ce^^\eeE+&OI= ZM^+5 c3+N )\cCc+#6 b"PQ@HPNQP;U8S,OL %)784%xKzJx86_64-pc-windows-msvc-e%ɩLpeg-7fe48a6c661aa89dgM'Sȑ8Yrust-end-file@feat.00 /0 0 0 0 644 1996 ` d.text 0`.data@0.bss0.debug$S@0B.debug$T@0BjC:\Proga\Rust\my_parser\target\debug\deps\peg-7fe48a6c661aa89d.peg.e8a853274d6787a6-cgu.0.rcgu.oR<QaFclang LLVM (rustc version 1.81.0 (eeb90cda1 2024-09-04))LVC:\Users\Admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\peg-0.8.4~C:\Users\Admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\peg-0.8.4\src\lib.rs\@\peg.e8a853274d6787a6-cgu.0 VC:\Users\Admin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin\rustc.exe"-cc1" "--crate-name" "peg" "--edition=2018" "C:\\Users\\Admin\\.cargo\\registry\\src\\index.crates.io-6f17d22bba15001f\\peg-0.8.4\\src\\lib.rs" "--error-format=json" "--json=diagnostic-rendered-ansi,artifacts,future-incompat" "--crate-type" "lib" "--emit=dep-info,metadata,link" "-C" "embed-bitcode=no" "-C" "debuginfo=2" "--cfg" "feature=\"default\"" "--cfg" "feature=\"std\"" "--check-cfg" "cfg(docsrs)" "--check-cfg" "cfg(feature, values(\"default\", \"std\", \"trace\", \"unstable\"))" "-C" "metadata=7fe48a6c661aa89d" "-C" "extra-filename=-7fe48a6c661aa89d" "--out-dir" "C:\\Proga\\Rust\\my_parser\\target\\debug\\deps" "-L" "dependency=C:\\Proga\\Rust\\my_parser\\target\\debug\\deps" "--extern" "peg_macros=C:\\Proga\\Rust\\my_parser\\target\\debug\\deps\\peg_macros-5751bd063bbc34d0.dll" "--extern" "peg_runtime=C:\\Proga\\Rust\\my_parser\\target\\debug\\deps\\libpeg_runtime-d3962009be6b7746.rmeta" "--cap-lints" "allow".text.data.bss.debug$SL.debug$T+ӈ@feat.00.filegpeg.e8a853274d6787a6-cgu.0