Henri Chataing | 5a53f3d | 2022-02-08 11:29:28 +0100 | [diff] [blame] | 1 | // pest. The Elegant Parser |
| 2 | // Copyright (c) 2018 DragoČ™ Tiselice |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 |
| 5 | // <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT |
| 6 | // license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 7 | // option. All files in the project carrying such notice may not be copied, |
| 8 | // modified, or distributed except according to those terms. |
| 9 | |
| 10 | string = { "abc" } |
| 11 | insensitive = { ^"abc" } |
| 12 | range = { '0'..'9' } |
| 13 | ident = { string } |
| 14 | pos_pred = { &string } |
| 15 | neg_pred = { !string } |
| 16 | double_neg_pred = { !!string } |
| 17 | sequence = !{ string ~ string } |
| 18 | sequence_compound = ${ string ~ string } |
| 19 | sequence_atomic = @{ string ~ string } |
| 20 | sequence_non_atomic = @{ sequence } |
| 21 | sequence_atomic_compound = @{ sequence_compound } |
| 22 | sequence_nested = { string ~ string } |
| 23 | sequence_compound_nested = ${ sequence_nested } |
| 24 | choice = { string | range } |
| 25 | optional = { string? } |
| 26 | repeat = { string* } |
| 27 | repeat_atomic = @{ string* } |
| 28 | repeat_once = { string+ } |
| 29 | repeat_once_atomic = @{ string+ } |
| 30 | repeat_min_max = { string{2, 3} } |
| 31 | repeat_min_max_atomic = @{ string{2, 3} } |
| 32 | repeat_exact = { string{2} } |
| 33 | repeat_min = { string{2,} } |
| 34 | repeat_min_atomic = @{ string{2,} } |
| 35 | repeat_max = { string{, 2} } |
| 36 | repeat_max_atomic = @{ string{, 2} } |
| 37 | soi_at_start = { SOI ~ string } |
| 38 | repeat_mutate_stack = { (PUSH('a'..'c') ~ ",")* ~ POP ~ POP ~ POP } |
| 39 | peek_ = { PUSH(range) ~ PUSH(range) ~ PEEK ~ PEEK } |
| 40 | peek_all = { PUSH(range) ~ PUSH(range) ~ PEEK_ALL } |
| 41 | peek_slice_23 = { PUSH(range) ~ PUSH(range) ~ PUSH(range) ~ PUSH(range) ~ PUSH(range) ~ PEEK[1..-2] } |
| 42 | pop_ = { PUSH(range) ~ PUSH(range) ~ POP ~ POP } |
| 43 | pop_all = { PUSH(range) ~ PUSH(range) ~ POP_ALL } |
| 44 | pop_fail = { PUSH(range) ~ !POP ~ range ~ POP } |
| 45 | checkpoint_restore = ${ |
| 46 | PUSH("") ~ (PUSH("a") ~ "b" ~ POP | DROP ~ "b" | POP ~ "a") ~ EOI |
| 47 | } |
| 48 | ascii_digits = { ASCII_DIGIT+ } |
| 49 | ascii_nonzero_digits = { ASCII_NONZERO_DIGIT+ } |
| 50 | ascii_bin_digits = { ASCII_BIN_DIGIT+ } |
| 51 | ascii_oct_digits = { ASCII_OCT_DIGIT+ } |
| 52 | ascii_hex_digits = { ASCII_HEX_DIGIT+ } |
| 53 | ascii_alpha_lowers = { ASCII_ALPHA_LOWER+ } |
| 54 | ascii_alpha_uppers = { ASCII_ALPHA_UPPER+ } |
| 55 | ascii_alphas = { ASCII_ALPHA+ } |
| 56 | ascii_alphanumerics = { ASCII_ALPHANUMERIC+ } |
| 57 | asciis = { ASCII+ } |
| 58 | newline = { NEWLINE+ } |
| 59 | unicode = { XID_START ~ XID_CONTINUE* } |
| 60 | SYMBOL = { "shadows builtin" } |
| 61 | |
| 62 | WHITESPACE = _{ " " } |
| 63 | COMMENT = _{ "$"+ } |
| 64 | |
| 65 | // Line comment |
| 66 | |
| 67 | /* 1-line multiline comment */ |
| 68 | |
| 69 | /* |
| 70 | N-line multiline comment |
| 71 | */ |
| 72 | |
| 73 | /* |
| 74 | // Line comment inside multiline |
| 75 | |
| 76 | /* |
| 77 | (Multiline inside) multiline |
| 78 | */ |
| 79 | |
| 80 | Invalid segment of grammar below (repeated rule) |
| 81 | |
| 82 | WHITESPACE = _{ "hi" } |
| 83 | */ |