2
2
//!
3
3
//! # Example
4
4
//!
5
- //! ```ignore
6
- //! # //TODO Unignore this once it stops ICEing
5
+ //! ```
7
6
//! # extern crate combine;
8
7
//! # extern crate combine_language;
9
- //! # use combine::* ;
10
- //! # use combine_language::* ;
8
+ //! # use combine::{alpha_num, letter, satisfy, string, Parser, ParserExt} ;
9
+ //! # use combine_language::{Identifier, LanguageEnv, LanguageDef} ;
11
10
//! # fn main() {
12
11
//! let env = LanguageEnv::new(LanguageDef {
13
12
//! ident: Identifier {
16
15
//! reserved: ["if", "then", "else", "let", "in", "type"].iter().map(|x| (*x).into()).collect()
17
16
//! },
18
17
//! op: Identifier {
19
- //! start: satisfy(|c| "+-*/".chars().find (|x| * x == c).is_some( )),
20
- //! rest: satisfy(|c| "+-*/".chars().find (|x| * x == c).is_some( )),
18
+ //! start: satisfy(|c| "+-*/".chars().any (|x| x == c)),
19
+ //! rest: satisfy(|c| "+-*/".chars().any (|x| x == c)),
21
20
//! reserved: ["+", "-", "*", "/"].iter().map(|x| (*x).into()).collect()
22
21
//! },
23
- //! comment_start: "/*",
24
- //! comment_end: "*/",
25
- //! comment_line: "//"
22
+ //! comment_start: string( "/*").map(|_| ()) ,
23
+ //! comment_end: string( "*/").map(|_| ()) ,
24
+ //! comment_line: string( "//").map(|_| ())
26
25
//! });
27
26
//! let id = env.identifier();//An identifier parser
28
27
//! let integer = env.integer();//An integer parser
29
- //! let result = (id, integer).parse_state ("this /* Skips comments */ 42");
28
+ //! let result = (id, integer).parse ("this /* Skips comments */ 42");
30
29
//! assert_eq!(result, Ok(((String::from("this"), 42), "")));
31
30
//! # }
32
31
//! ```
@@ -36,11 +35,14 @@ extern crate combine;
36
35
use std:: cell:: RefCell ;
37
36
use std:: marker:: PhantomData ;
38
37
use std:: borrow:: Cow ;
39
- use combine:: * ;
40
- use combine:: primitives as prim;
41
38
use combine:: char as pc;
42
39
use combine:: combinator:: { Between , NotFollowedBy , Skip , Try , Token } ;
43
40
use combine:: primitives:: { Consumed , Error , Stream } ;
41
+ use combine:: {
42
+ any, between, char, digit, optional, many, many1, not_followed_by,
43
+ parser, satisfy, skip_many, skip_many1, space, string, try, unexpected,
44
+ Parser , ParserExt , ParseError , ParseResult , State
45
+ } ;
44
46
45
47
///A language parser
46
48
pub struct LanguageParser < ' a : ' b , ' b , I : ' b , T >
@@ -52,8 +54,9 @@ pub struct LanguageParser<'a: 'b, 'b, I: 'b, T>
52
54
53
55
impl < ' a , ' b , I , O > Parser for LanguageParser < ' a , ' b , I , O >
54
56
where I : Stream < Item =char > {
55
- type Output = O ;
56
57
type Input = I ;
58
+ type Output = O ;
59
+
57
60
fn parse_lazy ( & mut self , input : State < I > ) -> ParseResult < O , I > {
58
61
( self . parser ) ( self . env , input)
59
62
}
@@ -73,8 +76,9 @@ pub struct Lex<'a: 'b, 'b, P>
73
76
impl < ' a , ' b , P > Parser for Lex < ' a , ' b , P >
74
77
where P : Parser
75
78
, P :: Input : Stream < Item =char > + ' b {
76
- type Output = P :: Output ;
77
79
type Input = P :: Input ;
80
+ type Output = P :: Output ;
81
+
78
82
fn parse_state ( & mut self , input : State < P :: Input > ) -> ParseResult < P :: Output , P :: Input > {
79
83
self . parser . parse_state ( input)
80
84
}
@@ -95,8 +99,8 @@ pub struct WhiteSpace<'a: 'b, 'b, I>
95
99
96
100
impl < ' a , ' b , I > Parser for WhiteSpace < ' a , ' b , I >
97
101
where I : Stream < Item =char > + ' b {
98
- type Output = ( ) ;
99
102
type Input = I ;
103
+ type Output = ( ) ;
100
104
fn parse_state ( & mut self , input : State < I > ) -> ParseResult < ( ) , I > {
101
105
let mut comment_start = self . env . comment_start . borrow_mut ( ) ;
102
106
let mut comment_end = self . env . comment_end . borrow_mut ( ) ;
@@ -140,8 +144,8 @@ pub struct Reserved<'a: 'b, 'b, I>
140
144
141
145
impl < ' a , ' b , I > Parser for Reserved < ' a , ' b , I >
142
146
where I : Stream < Item =char > + ' b {
143
- type Output = & ' static str ;
144
147
type Input = I ;
148
+ type Output = & ' static str ;
145
149
fn parse_state ( & mut self , input : State < I > ) -> ParseResult < & ' static str , I > {
146
150
self . parser . parse_state ( input)
147
151
}
@@ -163,8 +167,8 @@ pub struct BetweenChar<'a: 'b, 'b, P>
163
167
impl < ' a , ' b , I , P > Parser for BetweenChar < ' a , ' b , P >
164
168
where I : Stream < Item =char > + ' b
165
169
, P : Parser < Input =I > {
166
- type Output = P :: Output ;
167
170
type Input = I ;
171
+ type Output = P :: Output ;
168
172
fn parse_state ( & mut self , input : State < I > ) -> ParseResult < P :: Output , I > {
169
173
self . parser . parse_state ( input)
170
174
}
@@ -553,7 +557,7 @@ impl <O, P, F, T> Expression<O, P, F>
553
557
, F : Fn ( P :: Output , T , P :: Output ) -> P :: Output {
554
558
555
559
fn parse_expr ( & mut self , min_precedence : i32 , mut l : P :: Output , mut input : Consumed < State < P :: Input > > )
556
- -> prim :: ParseResult < P :: Output , P :: Input > {
560
+ -> ParseResult < P :: Output , P :: Input > {
557
561
558
562
loop {
559
563
let ( ( op, op_assoc) , rest) = tryb ! ( self . op. parse_lazy( input. clone( ) . into_inner( ) ) ) ;
@@ -585,7 +589,8 @@ impl <O, P, F, T> Parser for Expression<O, P, F>
585
589
, F : Fn ( P :: Output , T , P :: Output ) -> P :: Output {
586
590
type Input = P :: Input ;
587
591
type Output = P :: Output ;
588
- fn parse_lazy ( & mut self , input : State < Self :: Input > ) -> prim:: ParseResult < Self :: Output , Self :: Input > {
592
+
593
+ fn parse_lazy ( & mut self , input : State < Self :: Input > ) -> ParseResult < Self :: Output , Self :: Input > {
589
594
let ( l, input) = try!( self . term . parse_lazy ( input) ) ;
590
595
self . parse_expr ( 0 , l, input)
591
596
}
@@ -597,12 +602,11 @@ impl <O, P, F, T> Parser for Expression<O, P, F>
597
602
///Constructs an expression parser out of a term parser, an operator parser and a function which
598
603
///combines a binary expression to new expressions.
599
604
///
600
- /// ```ignore
601
- /// //TODO unignore once its stops ICEing
602
- /// # extern crate combine as pc;
603
- /// # extern crate combine_language as pcl;
604
- /// # use pc::*;
605
- /// # use pcl::*;
605
+ /// ```
606
+ /// # extern crate combine;
607
+ /// # extern crate combine_language;
608
+ /// # use combine::{letter, many, spaces, string, Parser, ParserExt};
609
+ /// # use combine_language::{expression_parser, Assoc, Fixity};
606
610
/// use self::Expr::*;
607
611
/// #[derive(PartialEq, Debug)]
608
612
/// enum Expr {
0 commit comments