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 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 } 24node_tag = { #string = string } 25choice = { string | range } 26choice_prefix = { | string | range } 27optional = { string? } 28repeat = { string* } 29repeat_atomic = @{ string* } 30repeat_once = { string+ } 31repeat_once_atomic = @{ string+ } 32repeat_min_max = { string{2, 3} } 33repeat_min_max_atomic = @{ string{2, 3} } 34repeat_exact = { string{2} } 35repeat_min = { string{2,} } 36repeat_min_atomic = @{ string{2,} } 37repeat_max = { string{, 2} } 38repeat_max_atomic = @{ string{, 2} } 39soi_at_start = { SOI ~ string } 40repeat_mutate_stack = { (PUSH('a'..'c') ~ ",")* ~ POP ~ POP ~ POP } 41repeat_mutate_stack_pop_all = { (PUSH('a'..'c') ~ ",")* ~ POP_ALL } 42will_fail = { repeat_mutate_stack_pop_all ~ "FAIL" } 43stack_resume_after_fail = { will_fail | repeat_mutate_stack_pop_all } 44peek_ = { PUSH(range) ~ PUSH(range) ~ PEEK ~ PEEK } 45peek_all = { PUSH(range) ~ PUSH(range) ~ PEEK_ALL } 46peek_slice_23 = { PUSH(range) ~ PUSH(range) ~ PUSH(range) ~ PUSH(range) ~ PUSH(range) ~ PEEK[1..-2] } 47pop_ = { PUSH(range) ~ PUSH(range) ~ POP ~ POP } 48pop_all = { PUSH(range) ~ PUSH(range) ~ POP_ALL } 49pop_fail = { PUSH(range) ~ !POP ~ range ~ POP } 50checkpoint_restore = ${ 51 PUSH("") ~ (PUSH("a") ~ "b" ~ POP | DROP ~ "b" | POP ~ "a") ~ EOI 52} 53ascii_digits = { ASCII_DIGIT+ } 54ascii_nonzero_digits = { ASCII_NONZERO_DIGIT+ } 55ascii_bin_digits = { ASCII_BIN_DIGIT+ } 56ascii_oct_digits = { ASCII_OCT_DIGIT+ } 57ascii_hex_digits = { ASCII_HEX_DIGIT+ } 58ascii_alpha_lowers = { ASCII_ALPHA_LOWER+ } 59ascii_alpha_uppers = { ASCII_ALPHA_UPPER+ } 60ascii_alphas = { ASCII_ALPHA+ } 61ascii_alphanumerics = { ASCII_ALPHANUMERIC+ } 62asciis = { ASCII+ } 63newline = { NEWLINE+ } 64unicode = { XID_START ~ XID_CONTINUE* } 65SYMBOL = { "shadows builtin" } 66 67han = { HAN+ } 68hangul = { HANGUL+ } 69hiragana = { HIRAGANA+ } 70arabic = { ARABIC+ } 71emoji = { EMOJI+ } 72 73WHITESPACE = _{ " " } 74COMMENT = _{ "$"+ } 75 76// Line comment 77 78/* 1-line multiline comment */ 79 80/* 81 N-line multiline comment 82*/ 83 84/* 85 // Line comment inside multiline 86 87 /* 88 (Multiline inside) multiline 89 */ 90 91 Invalid segment of grammar below (repeated rule) 92 93 WHITESPACE = _{ "hi" } 94*/ 95