blob: 43a7b8cfd1fc650fb308d612fcbd7e3fee774d13 [file] [log] [blame]
Henri Chataing5a53f3d2022-02-08 11:29:28 +01001// 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
10string = { "abc" }
11insensitive = { ^"abc" }
12range = { '0'..'9' }
13ident = { string }
14pos_pred = { &string }
15neg_pred = { !string }
16double_neg_pred = { !!string }
17sequence = !{ string ~ string }
18sequence_compound = ${ string ~ string }
19sequence_atomic = @{ string ~ string }
20sequence_non_atomic = @{ sequence }
21sequence_atomic_compound = @{ sequence_compound }
22sequence_nested = { string ~ string }
23sequence_compound_nested = ${ sequence_nested }
24choice = { string | range }
25optional = { string? }
26repeat = { string* }
27repeat_atomic = @{ string* }
28repeat_once = { string+ }
29repeat_once_atomic = @{ string+ }
30repeat_min_max = { string{2, 3} }
31repeat_min_max_atomic = @{ string{2, 3} }
32repeat_exact = { string{2} }
33repeat_min = { string{2,} }
34repeat_min_atomic = @{ string{2,} }
35repeat_max = { string{, 2} }
36repeat_max_atomic = @{ string{, 2} }
37soi_at_start = { SOI ~ string }
38repeat_mutate_stack = { (PUSH('a'..'c') ~ ",")* ~ POP ~ POP ~ POP }
39peek_ = { PUSH(range) ~ PUSH(range) ~ PEEK ~ PEEK }
40peek_all = { PUSH(range) ~ PUSH(range) ~ PEEK_ALL }
41peek_slice_23 = { PUSH(range) ~ PUSH(range) ~ PUSH(range) ~ PUSH(range) ~ PUSH(range) ~ PEEK[1..-2] }
42pop_ = { PUSH(range) ~ PUSH(range) ~ POP ~ POP }
43pop_all = { PUSH(range) ~ PUSH(range) ~ POP_ALL }
44pop_fail = { PUSH(range) ~ !POP ~ range ~ POP }
45checkpoint_restore = ${
46 PUSH("") ~ (PUSH("a") ~ "b" ~ POP | DROP ~ "b" | POP ~ "a") ~ EOI
47}
48ascii_digits = { ASCII_DIGIT+ }
49ascii_nonzero_digits = { ASCII_NONZERO_DIGIT+ }
50ascii_bin_digits = { ASCII_BIN_DIGIT+ }
51ascii_oct_digits = { ASCII_OCT_DIGIT+ }
52ascii_hex_digits = { ASCII_HEX_DIGIT+ }
53ascii_alpha_lowers = { ASCII_ALPHA_LOWER+ }
54ascii_alpha_uppers = { ASCII_ALPHA_UPPER+ }
55ascii_alphas = { ASCII_ALPHA+ }
56ascii_alphanumerics = { ASCII_ALPHANUMERIC+ }
57asciis = { ASCII+ }
58newline = { NEWLINE+ }
59unicode = { XID_START ~ XID_CONTINUE* }
60SYMBOL = { "shadows builtin" }
61
62WHITESPACE = _{ " " }
63COMMENT = _{ "$"+ }
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*/