1// 2// Hoa 3// 4// 5// @license 6// 7// New BSD License 8// 9// Copyright © 2007-2017, Hoa community. All rights reserved. 10// 11// Redistribution and use in source and binary forms, with or without 12// modification, are permitted provided that the following conditions are met: 13// * Redistributions of source code must retain the above copyright 14// notice, this list of conditions and the following disclaimer. 15// * Redistributions in binary form must reproduce the above copyright 16// notice, this list of conditions and the following disclaimer in the 17// documentation and/or other materials provided with the distribution. 18// * Neither the name of the Hoa nor the names of its contributors may be 19// used to endorse or promote products derived from this software without 20// specific prior written permission. 21// 22// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE 26// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32// POSSIBILITY OF SUCH DAMAGE. 33// 34// Grammar \Hoa\Compiler\Llk. 35// 36// Provide grammar for the LL(k) parser. 37// 38// @copyright Copyright © 2007-2017, Hoa community. 39// @license New BSD License 40// 41 42 43%skip space \s 44 45%token or \| 46%token zero_or_one \? 47%token one_or_more \+ 48%token zero_or_more \* 49%token n_to_m \{[0-9]+,[0-9]+\} 50%token zero_to_m \{,[0-9]+\} 51%token n_or_more \{[0-9]+,\} 52%token exactly_n \{[0-9]+\} 53 54%token token [a-zA-Z_][a-zA-Z0-9_]* 55 56%token skipped :: 57%token kept_ < 58%token _kept > 59%token named \(\) 60%token node #[a-zA-Z_][a-zA-Z0-9_]*(:[mM])? 61 62%token capturing_ \( 63%token _capturing \) 64%token unification_ \[ 65%token unification [0-9]+ 66%token _unification \] 67 68#rule: 69 choice() 70 71choice: 72 concatenation() ( ::or:: concatenation() #choice )* 73 74concatenation: 75 repetition() ( repetition() #concatenation )* 76 77repetition: 78 simple() ( quantifier() #repetition )? <node>? 79 80simple: 81 ::capturing_:: choice() ::_capturing:: 82 | ::skipped:: <token> ( ::unification_:: <unification> ::_unification:: )? 83 ::skipped:: #skipped 84 | ::kept_:: <token> ( ::unification_:: <unification> ::_unification:: )? 85 ::_kept:: #kept 86 | <token> ::named:: 87 88quantifier: 89 <zero_or_one> 90 | <one_or_more> 91 | <zero_or_more> 92 | <n_to_m> 93 | <n_or_more> 94 | <exactly_n> 95