1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
b0VIM 7.4 �U]~ erickt Erick-Tryzelaar-MBP.local ~erickt/projects/rust/rust-syntex/syntex_syntax/src/ext/tt/macro_parser.rs utf-8
3210 #"! U tp X v Y i � T 8 O � M � ad 3 � X � { X U � � M ) ( �
�
5
� � I � � c �
�
�
�
�
<
� � � D @ � � N � � v r / +
� � � � � � b 0 , � � � L H � � � � � B > � � � � N J & "
� � � � � � � e 8 � � � � use parse::attr::ParserAttr; use parse::ParseSess; use parse::lexer::*; //resolve bug? use codemap; use codemap::{BytePos, mk_sp, Span}; use ast::{TtDelimited, TtSequence, TtToken}; use ast::{TokenTree, Ident}; use ast; use self::TokenTreeOrTokenTreeVec::*; pub use self::ParseResult::*; pub use self::NamedMatch::*; //! eof: [a $( a )* a b ·] //! Remaining input: `` //! //! - - - Advance over a `b`. - - - //! //! next: [a $( a )* · a b] [a $( · a )* a b] //! Finish/Repeat (first item) //! cur: [a $( a · )* a b] next: [a $( a )* a · b] //! Remaining input: `b` //! //! - - - Advance over an `a`. - - - (this looks exactly like the last step) //! //! next: [a $( a )* · a b] [a $( · a )* a b] [a $( a )* a · b] //! Finish/Repeat (first item) //! cur: [a $( a · )* a b] next: [a $( a )* a · b] //! Remaining input: `a b` //! //! - - - Advance over an `a`. - - - (this looks exactly like the last step) //! //! next: [a $( a )* · a b] [a $( · a )* a b] [a $( a )* a · b] //! Finish/Repeat (first item) //! cur: [a $( a · )* a b] next: [a $( a )* a · b] //! Remaining input: `a a b` //! //! - - - Advance over an `a`. - - - //! //! next: [a $( · a )* a b] [a $( a )* · a b]. //! Descend/Skip (first item). //! cur: [a · $( a )* a b] //! Remaining input: `a a a b` //! //! - - - Advance over an `a`. - - - //! //! next_eis: [· a $( a )* a b] //! Remaining input: `a a a a b` //! //! Example: Start parsing `a a a a b` against [· a $( a )* a b]. //! //! real Rust parser when no `cur_eis` items remain //! repetitions indicated by Kleene stars. It only advances or calls out to the //! on the a particular token. Most of the logic concerns moving the · through the //! a Rust nonterminal like `$e:expr`, and `next_eis` with items that are waiting //! the macro invocation is now over, `bb_eis` with items that are waiting on //! As it processes them, it fills up `eof_eis` with items that would be valid if //! //! of items consistent with the current position in the input string: `cur_eis`. //! The parser walks through the input a character at a time, maintaining a list //! //! dot. For example `· a $( a )* a b` is a position, as is `a $( · a )* a b`. //! A 'position' is a dot in the middle of a matcher, usually represented as a //! //! Quick intro to how the parser works: //! //! overhead) //! and require more memory to keep around old items, but it would also save //! construct the resulting `NamedMatch`es at the very end. It'd be a pain, //! lower. (In order to prevent the pathological case, we'd need to lazily //! easier fit for Macro-by-Example-style rules, and I think the overhead is //! pathological cases, is worse than traditional Earley parsing, but it's an //! ones. Instead of NTs, we have a special case for Kleene star. The big-O, in //! token: instead, there's a set of current Earley items and a set of next //! completer or predictor rules, and therefore no need to store one column per //! commits to fully when it hits one in a grammar). This means that there are no //! only by calling out to the main rust parser for named nonterminals (which it //! This is an Earley-like parser, without support for in-grammar nonterminals, // except according to those terms. // option. This file may not be copied, modified, or distributed // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or //