1
1
use nom:: character:: complete:: { alphanumeric1, multispace0, multispace1} ;
2
2
3
- use common:: { integer_literal, sql_identifier, string_literal, ws_sep_comma} ;
3
+ use common:: { integer_literal, sql_identifier, string_literal, ws_sep_comma,
4
+ ws_sep_equals} ;
4
5
use nom:: branch:: alt;
5
6
use nom:: bytes:: complete:: { tag, tag_no_case} ;
6
7
use nom:: combinator:: { map, opt} ;
7
8
use nom:: multi:: separated_list;
8
- use nom:: sequence:: { preceded , tuple} ;
9
+ use nom:: sequence:: tuple;
9
10
use nom:: IResult ;
10
11
11
12
pub fn table_options ( i : & [ u8 ] ) -> IResult < & [ u8 ] , ( ) > {
@@ -35,58 +36,55 @@ fn create_option(i: &[u8]) -> IResult<&[u8], ()> {
35
36
) ) ( i)
36
37
}
37
38
39
+
40
+ /// Helper to parse equals-separated create option pairs.
41
+ /// Throws away the create option and value
42
+ pub fn create_option_equals_pair < ' a , I , O1 , O2 , F , G > ( first : F , second : G ) -> impl Fn ( I ) -> IResult < I , ( ) >
43
+ where
44
+ F : Fn ( I ) -> IResult < I , O1 > ,
45
+ G : Fn ( I ) -> IResult < I , O2 > ,
46
+ I : nom:: InputTakeAtPosition + nom:: InputTake + nom:: Compare < & ' a str > ,
47
+ <I as nom:: InputTakeAtPosition >:: Item : nom:: AsChar + Clone ,
48
+ {
49
+ move |i : I | {
50
+ let ( i, _o1) = first ( i) ?;
51
+ let ( i, _) = ws_sep_equals ( i) ?;
52
+ let ( i, _o2) = second ( i) ?;
53
+ Ok ( ( i, ( ) ) )
54
+ }
55
+ }
56
+
38
57
fn create_option_type ( i : & [ u8 ] ) -> IResult < & [ u8 ] , ( ) > {
39
- map (
40
- preceded (
41
- tag_no_case ( "type" ) ,
42
- preceded (
43
- multispace0,
44
- preceded ( tag ( "=" ) , preceded ( multispace0, alphanumeric1) ) ,
45
- ) ,
46
- ) ,
47
- |_| ( ) ,
58
+ create_option_equals_pair (
59
+ tag_no_case ( "type" ) ,
60
+ alphanumeric1
48
61
) ( i)
49
62
}
50
63
51
64
fn create_option_pack_keys ( i : & [ u8 ] ) -> IResult < & [ u8 ] , ( ) > {
52
- let ( remaining_input , ( _ , _ , _ , _ , _ ) ) = tuple ( (
65
+ create_option_equals_pair (
53
66
tag_no_case ( "pack_keys" ) ,
54
- multispace0,
55
- tag ( "=" ) ,
56
- multispace0,
57
- alt ( ( tag ( "0" ) , tag ( "1" ) ) ) ,
58
- ) ) ( i) ?;
59
- Ok ( ( remaining_input, ( ) ) )
67
+ alt ( ( tag ( "0" ) , tag ( "1" ) ) )
68
+ ) ( i)
60
69
}
61
70
62
71
fn create_option_engine ( i : & [ u8 ] ) -> IResult < & [ u8 ] , ( ) > {
63
- let ( remaining_input , ( _ , _ , _ , _ , _ ) ) = tuple ( (
72
+ create_option_equals_pair (
64
73
tag_no_case ( "engine" ) ,
65
- multispace0,
66
- tag ( "=" ) ,
67
- multispace0,
68
- opt ( alphanumeric1) ,
69
- ) ) ( i) ?;
70
- Ok ( ( remaining_input, ( ) ) )
74
+ opt ( alphanumeric1)
75
+ ) ( i)
71
76
}
72
77
73
78
fn create_option_auto_increment ( i : & [ u8 ] ) -> IResult < & [ u8 ] , ( ) > {
74
- let ( remaining_input , ( _ , _ , _ , _ , _ ) ) = tuple ( (
79
+ create_option_equals_pair (
75
80
tag_no_case ( "auto_increment" ) ,
76
- multispace0,
77
- tag ( "=" ) ,
78
- multispace0,
79
81
integer_literal,
80
- ) ) ( i) ?;
81
- Ok ( ( remaining_input, ( ) ) )
82
+ ) ( i)
82
83
}
83
84
84
85
fn create_option_default_charset ( i : & [ u8 ] ) -> IResult < & [ u8 ] , ( ) > {
85
- let ( remaining_input , ( _ , _ , _ , _ , _ ) ) = tuple ( (
86
+ create_option_equals_pair (
86
87
tag_no_case ( "default charset" ) ,
87
- multispace0,
88
- tag ( "=" ) ,
89
- multispace0,
90
88
alt ( (
91
89
tag ( "utf8mb4" ) ,
92
90
tag ( "utf8" ) ,
@@ -95,55 +93,39 @@ fn create_option_default_charset(i: &[u8]) -> IResult<&[u8], ()> {
95
93
tag ( "ucs2" ) ,
96
94
tag ( "latin1" ) ,
97
95
) ) ,
98
- ) ) ( i) ?;
99
- Ok ( ( remaining_input, ( ) ) )
96
+ ) ( i)
100
97
}
101
98
102
99
fn create_option_collate ( i : & [ u8 ] ) -> IResult < & [ u8 ] , ( ) > {
103
- let ( remaining_input , ( _ , _ , _ , _ , _ ) ) = tuple ( (
100
+ create_option_equals_pair (
104
101
tag_no_case ( "collate" ) ,
105
- multispace0,
106
- tag ( "=" ) ,
107
- multispace0,
108
102
// TODO(malte): imprecise hack, should not accept everything
109
103
sql_identifier,
110
- ) ) ( i) ?;
111
- Ok ( ( remaining_input, ( ) ) )
104
+ ) ( i)
112
105
}
113
106
114
107
fn create_option_comment ( i : & [ u8 ] ) -> IResult < & [ u8 ] , ( ) > {
115
- let ( remaining_input , ( _ , _ , _ , _ , _ ) ) = tuple ( (
108
+ create_option_equals_pair (
116
109
tag_no_case ( "comment" ) ,
117
- multispace0,
118
- tag ( "=" ) ,
119
- multispace0,
120
110
string_literal,
121
- ) ) ( i) ?;
122
- Ok ( ( remaining_input, ( ) ) )
111
+ ) ( i)
123
112
}
124
113
125
114
fn create_option_max_rows ( i : & [ u8 ] ) -> IResult < & [ u8 ] , ( ) > {
126
- let ( remaining_input , ( _ , _ , _ , _ , _ ) ) = tuple ( (
115
+ create_option_equals_pair (
127
116
tag_no_case ( "max_rows" ) ,
128
- multispace0,
129
- opt ( tag ( "=" ) ) ,
130
- multispace0,
131
- integer_literal,
132
- ) ) ( i) ?;
133
- Ok ( ( remaining_input, ( ) ) )
117
+ integer_literal
118
+ ) ( i)
134
119
}
135
120
136
121
fn create_option_avg_row_length ( i : & [ u8 ] ) -> IResult < & [ u8 ] , ( ) > {
137
- let ( remaining_input , ( _ , _ , _ , _ , _ ) ) = tuple ( (
122
+ create_option_equals_pair (
138
123
tag_no_case ( "avg_row_length" ) ,
139
- multispace0,
140
- opt ( tag ( "=" ) ) ,
141
- multispace0,
142
- integer_literal,
143
- ) ) ( i) ?;
144
- Ok ( ( remaining_input, ( ) ) )
124
+ integer_literal
125
+ ) ( i)
145
126
}
146
127
128
+
147
129
fn create_option_row_format ( i : & [ u8 ] ) -> IResult < & [ u8 ] , ( ) > {
148
130
let ( remaining_input, ( _, _, _, _, _) ) = tuple ( (
149
131
tag_no_case ( "row_format" ) ,
0 commit comments