|
| 1 | +use nom::{Err, ErrorKind, IResult, Needed}; |
| 2 | + |
| 3 | +use std::str; |
| 4 | + |
| 5 | +named!(keyword_follow_char<&[u8], char>, |
| 6 | + peek!(one_of!(" \n;()\t,=")) |
| 7 | +); |
| 8 | + |
| 9 | +named!(keyword_a_to_c<&[u8], &[u8]>, |
| 10 | + alt_complete!( |
| 11 | + terminated!(caseless_tag!("ABORT"), keyword_follow_char) |
| 12 | + | terminated!(caseless_tag!("ACTION"), keyword_follow_char) |
| 13 | + | terminated!(caseless_tag!("ADD"), keyword_follow_char) |
| 14 | + | terminated!(caseless_tag!("AFTER"), keyword_follow_char) |
| 15 | + | terminated!(caseless_tag!("ALL"), keyword_follow_char) |
| 16 | + | terminated!(caseless_tag!("ALTER"), keyword_follow_char) |
| 17 | + | terminated!(caseless_tag!("ANALYZE"), keyword_follow_char) |
| 18 | + | terminated!(caseless_tag!("AND"), keyword_follow_char) |
| 19 | + | terminated!(caseless_tag!("AS"), keyword_follow_char) |
| 20 | + | terminated!(caseless_tag!("ASC"), keyword_follow_char) |
| 21 | + | terminated!(caseless_tag!("ATTACH"), keyword_follow_char) |
| 22 | + | terminated!(caseless_tag!("AUTOINCREMENT"), keyword_follow_char) |
| 23 | + | terminated!(caseless_tag!("BEFORE"), keyword_follow_char) |
| 24 | + | terminated!(caseless_tag!("BEGIN"), keyword_follow_char) |
| 25 | + | terminated!(caseless_tag!("BETWEEN"), keyword_follow_char) |
| 26 | + | terminated!(caseless_tag!("BY"), keyword_follow_char) |
| 27 | + | terminated!(caseless_tag!("CASCADE"), keyword_follow_char) |
| 28 | + | terminated!(caseless_tag!("CASE"), keyword_follow_char) |
| 29 | + | terminated!(caseless_tag!("CAST"), keyword_follow_char) |
| 30 | + | terminated!(caseless_tag!("CHECK"), keyword_follow_char) |
| 31 | + | terminated!(caseless_tag!("COLLATE"), keyword_follow_char) |
| 32 | + | terminated!(caseless_tag!("COLUMN"), keyword_follow_char) |
| 33 | + | terminated!(caseless_tag!("COMMIT"), keyword_follow_char) |
| 34 | + | terminated!(caseless_tag!("CONFLICT"), keyword_follow_char) |
| 35 | + | terminated!(caseless_tag!("CONSTRAINT"), keyword_follow_char) |
| 36 | + | terminated!(caseless_tag!("CREATE"), keyword_follow_char) |
| 37 | + | terminated!(caseless_tag!("CROSS"), keyword_follow_char) |
| 38 | + | terminated!(caseless_tag!("CURRENT_DATE"), keyword_follow_char) |
| 39 | + | terminated!(caseless_tag!("CURRENT_TIME"), keyword_follow_char) |
| 40 | + | terminated!(caseless_tag!("CURRENT_TIMESTAMP"), keyword_follow_char) |
| 41 | + ) |
| 42 | +); |
| 43 | + |
| 44 | +named!(keyword_d_to_i<&[u8], &[u8]>, |
| 45 | + alt_complete!( |
| 46 | + terminated!(caseless_tag!("DATABASE"), keyword_follow_char) |
| 47 | + | terminated!(caseless_tag!("DEFAULT"), keyword_follow_char) |
| 48 | + | terminated!(caseless_tag!("DEFERRABLE"), keyword_follow_char) |
| 49 | + | terminated!(caseless_tag!("DEFERRED"), keyword_follow_char) |
| 50 | + | terminated!(caseless_tag!("DELETE"), keyword_follow_char) |
| 51 | + | terminated!(caseless_tag!("DESC"), keyword_follow_char) |
| 52 | + | terminated!(caseless_tag!("DETACH"), keyword_follow_char) |
| 53 | + | terminated!(caseless_tag!("DISTINCT"), keyword_follow_char) |
| 54 | + | terminated!(caseless_tag!("DROP"), keyword_follow_char) |
| 55 | + | terminated!(caseless_tag!("EACH"), keyword_follow_char) |
| 56 | + | terminated!(caseless_tag!("ELSE"), keyword_follow_char) |
| 57 | + | terminated!(caseless_tag!("END"), keyword_follow_char) |
| 58 | + | terminated!(caseless_tag!("ESCAPE"), keyword_follow_char) |
| 59 | + | terminated!(caseless_tag!("EXCEPT"), keyword_follow_char) |
| 60 | + | terminated!(caseless_tag!("EXCLUSIVE"), keyword_follow_char) |
| 61 | + | terminated!(caseless_tag!("EXISTS"), keyword_follow_char) |
| 62 | + | terminated!(caseless_tag!("EXPLAIN"), keyword_follow_char) |
| 63 | + | terminated!(caseless_tag!("FAIL"), keyword_follow_char) |
| 64 | + | terminated!(caseless_tag!("FOR"), keyword_follow_char) |
| 65 | + | terminated!(caseless_tag!("FOREIGN"), keyword_follow_char) |
| 66 | + | terminated!(caseless_tag!("FROM"), keyword_follow_char) |
| 67 | + | terminated!(caseless_tag!("FULL"), keyword_follow_char) |
| 68 | + | terminated!(caseless_tag!("GLOB"), keyword_follow_char) |
| 69 | + | terminated!(caseless_tag!("GROUP"), keyword_follow_char) |
| 70 | + | terminated!(caseless_tag!("HAVING"), keyword_follow_char) |
| 71 | + | terminated!(caseless_tag!("IF"), keyword_follow_char) |
| 72 | + | terminated!(caseless_tag!("IGNORE"), keyword_follow_char) |
| 73 | + | terminated!(caseless_tag!("IMMEDIATE"), keyword_follow_char) |
| 74 | + | terminated!(caseless_tag!("IN"), keyword_follow_char) |
| 75 | + | terminated!(caseless_tag!("INDEX"), keyword_follow_char) |
| 76 | + | terminated!(caseless_tag!("INDEXED"), keyword_follow_char) |
| 77 | + | terminated!(caseless_tag!("INITIALLY"), keyword_follow_char) |
| 78 | + | terminated!(caseless_tag!("INNER"), keyword_follow_char) |
| 79 | + | terminated!(caseless_tag!("INSERT"), keyword_follow_char) |
| 80 | + | terminated!(caseless_tag!("INSTEAD"), keyword_follow_char) |
| 81 | + | terminated!(caseless_tag!("INTERSECT"), keyword_follow_char) |
| 82 | + | terminated!(caseless_tag!("INTO"), keyword_follow_char) |
| 83 | + | terminated!(caseless_tag!("IS"), keyword_follow_char) |
| 84 | + | terminated!(caseless_tag!("ISNULL"), keyword_follow_char) |
| 85 | + ) |
| 86 | +); |
| 87 | + |
| 88 | +named!(keyword_j_to_s<&[u8], &[u8]>, |
| 89 | + alt_complete!( |
| 90 | + terminated!(caseless_tag!("ORDER"), keyword_follow_char) |
| 91 | + | terminated!(caseless_tag!("JOIN"), keyword_follow_char) |
| 92 | + | terminated!(caseless_tag!("KEY"), keyword_follow_char) |
| 93 | + | terminated!(caseless_tag!("LEFT"), keyword_follow_char) |
| 94 | + | terminated!(caseless_tag!("LIKE"), keyword_follow_char) |
| 95 | + | terminated!(caseless_tag!("LIMIT"), keyword_follow_char) |
| 96 | + | terminated!(caseless_tag!("MATCH"), keyword_follow_char) |
| 97 | + | terminated!(caseless_tag!("NATURAL"), keyword_follow_char) |
| 98 | + | terminated!(caseless_tag!("NO"), keyword_follow_char) |
| 99 | + | terminated!(caseless_tag!("NOT"), keyword_follow_char) |
| 100 | + | terminated!(caseless_tag!("NOTNULL"), keyword_follow_char) |
| 101 | + | terminated!(caseless_tag!("NULL"), keyword_follow_char) |
| 102 | + | terminated!(caseless_tag!("OF"), keyword_follow_char) |
| 103 | + | terminated!(caseless_tag!("OFFSET"), keyword_follow_char) |
| 104 | + | terminated!(caseless_tag!("ON"), keyword_follow_char) |
| 105 | + | terminated!(caseless_tag!("OR"), keyword_follow_char) |
| 106 | + | terminated!(caseless_tag!("OUTER"), keyword_follow_char) |
| 107 | + | terminated!(caseless_tag!("PLAN"), keyword_follow_char) |
| 108 | + | terminated!(caseless_tag!("PRAGMA"), keyword_follow_char) |
| 109 | + | terminated!(caseless_tag!("PRIMARY"), keyword_follow_char) |
| 110 | + | terminated!(caseless_tag!("QUERY"), keyword_follow_char) |
| 111 | + | terminated!(caseless_tag!("RAISE"), keyword_follow_char) |
| 112 | + | terminated!(caseless_tag!("RECURSIVE"), keyword_follow_char) |
| 113 | + | terminated!(caseless_tag!("REFERENCES"), keyword_follow_char) |
| 114 | + | terminated!(caseless_tag!("REGEXP"), keyword_follow_char) |
| 115 | + | terminated!(caseless_tag!("REINDEX"), keyword_follow_char) |
| 116 | + | terminated!(caseless_tag!("RELEASE"), keyword_follow_char) |
| 117 | + | terminated!(caseless_tag!("RENAME"), keyword_follow_char) |
| 118 | + | terminated!(caseless_tag!("REPLACE"), keyword_follow_char) |
| 119 | + | terminated!(caseless_tag!("RESTRICT"), keyword_follow_char) |
| 120 | + | terminated!(caseless_tag!("RIGHT"), keyword_follow_char) |
| 121 | + | terminated!(caseless_tag!("ROLLBACK"), keyword_follow_char) |
| 122 | + | terminated!(caseless_tag!("ROW"), keyword_follow_char) |
| 123 | + | terminated!(caseless_tag!("SAVEPOINT"), keyword_follow_char) |
| 124 | + | terminated!(caseless_tag!("SELECT"), keyword_follow_char) |
| 125 | + | terminated!(caseless_tag!("SET"), keyword_follow_char) |
| 126 | + ) |
| 127 | +); |
| 128 | + |
| 129 | +named!(keyword_t_to_z<&[u8], &[u8]>, |
| 130 | + alt_complete!( |
| 131 | + terminated!(caseless_tag!("TABLE"), keyword_follow_char) |
| 132 | + | terminated!(caseless_tag!("TEMP"), keyword_follow_char) |
| 133 | + | terminated!(caseless_tag!("TEMPORARY"), keyword_follow_char) |
| 134 | + | terminated!(caseless_tag!("THEN"), keyword_follow_char) |
| 135 | + | terminated!(caseless_tag!("TO"), keyword_follow_char) |
| 136 | + | terminated!(caseless_tag!("TRANSACTION"), keyword_follow_char) |
| 137 | + | terminated!(caseless_tag!("TRIGGER"), keyword_follow_char) |
| 138 | + | terminated!(caseless_tag!("UNION"), keyword_follow_char) |
| 139 | + | terminated!(caseless_tag!("UNIQUE"), keyword_follow_char) |
| 140 | + | terminated!(caseless_tag!("UPDATE"), keyword_follow_char) |
| 141 | + | terminated!(caseless_tag!("USING"), keyword_follow_char) |
| 142 | + | terminated!(caseless_tag!("VACUUM"), keyword_follow_char) |
| 143 | + | terminated!(caseless_tag!("VALUES"), keyword_follow_char) |
| 144 | + | terminated!(caseless_tag!("VIEW"), keyword_follow_char) |
| 145 | + | terminated!(caseless_tag!("VIRTUAL"), keyword_follow_char) |
| 146 | + | terminated!(caseless_tag!("WHEN"), keyword_follow_char) |
| 147 | + | terminated!(caseless_tag!("WHERE"), keyword_follow_char) |
| 148 | + | terminated!(caseless_tag!("WITH"), keyword_follow_char) |
| 149 | + | terminated!(caseless_tag!("WITHOUT"), keyword_follow_char) |
| 150 | + ) |
| 151 | +); |
| 152 | + |
| 153 | +/// Matches any SQL reserved keyword |
| 154 | +named!(pub sql_keyword<&[u8], &[u8]>, |
| 155 | + complete!(chain!( |
| 156 | + kw: alt_complete!( |
| 157 | + keyword_a_to_c |
| 158 | + | keyword_d_to_i |
| 159 | + | keyword_j_to_s |
| 160 | + | keyword_t_to_z), |
| 161 | + || { kw } |
| 162 | + )) |
| 163 | +); |
0 commit comments