@@ -12,42 +12,6 @@ use nom::{
12
12
13
13
use crate :: path:: Expression ;
14
14
15
- fn raw_ident ( i : & str ) -> IResult < & str , String > {
16
- map (
17
- is_a (
18
- "abcdefghijklmnopqrstuvwxyz \
19
- ABCDEFGHIJKLMNOPQRSTUVWXYZ \
20
- 0123456789 \
21
- _-",
22
- ) ,
23
- ToString :: to_string,
24
- ) ( i)
25
- }
26
-
27
- fn integer ( i : & str ) -> IResult < & str , isize > {
28
- map_res (
29
- delimited ( space0, recognize ( pair ( opt ( tag ( "-" ) ) , digit1) ) , space0) ,
30
- FromStr :: from_str,
31
- ) ( i)
32
- }
33
-
34
- fn ident ( i : & str ) -> IResult < & str , Expression > {
35
- map ( raw_ident, Expression :: Identifier ) ( i)
36
- }
37
-
38
- fn postfix < ' a > ( expr : Expression ) -> impl FnMut ( & ' a str ) -> IResult < & ' a str , Expression > {
39
- let e2 = expr. clone ( ) ;
40
- let child = map ( preceded ( tag ( "." ) , raw_ident) , move |id| {
41
- Expression :: Child ( Box :: new ( expr. clone ( ) ) , id)
42
- } ) ;
43
-
44
- let subscript = map ( delimited ( char ( '[' ) , integer, char ( ']' ) ) , move |num| {
45
- Expression :: Subscript ( Box :: new ( e2. clone ( ) ) , num)
46
- } ) ;
47
-
48
- alt ( ( child, subscript) )
49
- }
50
-
51
15
pub ( crate ) fn from_str ( input : & str ) -> Result < Expression , ErrorKind > {
52
16
match ident ( input) {
53
17
Ok ( ( mut rem, mut expr) ) => {
@@ -73,7 +37,43 @@ pub(crate) fn from_str(input: &str) -> Result<Expression, ErrorKind> {
73
37
}
74
38
}
75
39
76
- pub ( crate ) fn to_error_kind ( e : Err < nom:: error:: Error < & str > > ) -> ErrorKind {
40
+ fn ident ( i : & str ) -> IResult < & str , Expression > {
41
+ map ( raw_ident, Expression :: Identifier ) ( i)
42
+ }
43
+
44
+ fn postfix < ' a > ( expr : Expression ) -> impl FnMut ( & ' a str ) -> IResult < & ' a str , Expression > {
45
+ let e2 = expr. clone ( ) ;
46
+ let child = map ( preceded ( tag ( "." ) , raw_ident) , move |id| {
47
+ Expression :: Child ( Box :: new ( expr. clone ( ) ) , id)
48
+ } ) ;
49
+
50
+ let subscript = map ( delimited ( char ( '[' ) , integer, char ( ']' ) ) , move |num| {
51
+ Expression :: Subscript ( Box :: new ( e2. clone ( ) ) , num)
52
+ } ) ;
53
+
54
+ alt ( ( child, subscript) )
55
+ }
56
+
57
+ fn raw_ident ( i : & str ) -> IResult < & str , String > {
58
+ map (
59
+ is_a (
60
+ "abcdefghijklmnopqrstuvwxyz \
61
+ ABCDEFGHIJKLMNOPQRSTUVWXYZ \
62
+ 0123456789 \
63
+ _-",
64
+ ) ,
65
+ ToString :: to_string,
66
+ ) ( i)
67
+ }
68
+
69
+ fn integer ( i : & str ) -> IResult < & str , isize > {
70
+ map_res (
71
+ delimited ( space0, recognize ( pair ( opt ( tag ( "-" ) ) , digit1) ) , space0) ,
72
+ FromStr :: from_str,
73
+ ) ( i)
74
+ }
75
+
76
+ fn to_error_kind ( e : Err < nom:: error:: Error < & str > > ) -> ErrorKind {
77
77
match e {
78
78
Err :: Incomplete ( _) => ErrorKind :: Complete ,
79
79
Err :: Failure ( e) | Err :: Error ( e) => e. code ,
0 commit comments