|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + * |
| 19 | + */ |
| 20 | + |
| 21 | +#pragma once |
| 22 | + |
| 23 | +#include <tao/pegtl.hpp> |
| 24 | + |
| 25 | +namespace kqir { |
| 26 | + |
| 27 | +namespace peg = tao::pegtl; |
| 28 | + |
| 29 | +struct True : peg::string<'t', 'r', 'u', 'e'> {}; |
| 30 | +struct False : peg::string<'f', 'a', 'l', 's', 'e'> {}; |
| 31 | +struct Boolean : peg::sor<True, False> {}; |
| 32 | + |
| 33 | +struct Digits : peg::plus<peg::digit> {}; |
| 34 | +struct NumberExp : peg::seq<peg::one<'e', 'E'>, peg::opt<peg::one<'-', '+'>>, Digits> {}; |
| 35 | +struct NumberFrac : peg::seq<peg::one<'.'>, Digits> {}; |
| 36 | +struct Number : peg::seq<peg::opt<peg::one<'-'>>, Digits, peg::opt<NumberFrac>, peg::opt<NumberExp>> {}; |
| 37 | + |
| 38 | +struct UnicodeXDigit : peg::list<peg::seq<peg::one<'u'>, peg::rep<4, peg::xdigit>>, peg::one<'\\'>> {}; |
| 39 | +struct EscapedSingleChar : peg::one<'"', '\\', 'b', 'f', 'n', 'r', 't'> {}; |
| 40 | +struct EscapedChar : peg::sor<EscapedSingleChar, UnicodeXDigit> {}; |
| 41 | +struct UnescapedChar : peg::utf8::range<0x20, 0x10FFFF> {}; |
| 42 | +struct Char : peg::if_then_else<peg::one<'\\'>, EscapedChar, UnescapedChar> {}; |
| 43 | + |
| 44 | +struct StringContent : peg::until<peg::at<peg::one<'"'>>, Char> {}; |
| 45 | +struct String : peg::seq<peg::one<'"'>, StringContent, peg::any> {}; |
| 46 | + |
| 47 | +struct Identifier : peg::identifier {}; |
| 48 | + |
| 49 | +struct WhiteSpace : peg::one<' ', '\t', '\n', '\r'> {}; |
| 50 | +template <typename T> |
| 51 | +struct WSPad : peg::pad<T, WhiteSpace> {}; |
| 52 | + |
| 53 | +struct UnsignedInteger : Digits {}; |
| 54 | +struct Integer : peg::seq<peg::opt<peg::one<'-'>>, Digits> {}; |
| 55 | + |
| 56 | +} // namespace kqir |
0 commit comments