pax_global_header00006660000000000000000000000064127013006720014510gustar00rootroot0000000000000052 comment=5b137f3c2f7fa5fa833f2c3a5ea8d5fb21d2a3b7 PEGTL-1.3.1/000077500000000000000000000000001270130067200123655ustar00rootroot00000000000000PEGTL-1.3.1/.gitignore000066400000000000000000000000321270130067200143500ustar00rootroot00000000000000.svn build manual private PEGTL-1.3.1/.travis.yml000066400000000000000000000047721270130067200145100ustar00rootroot00000000000000language: cpp matrix: include: - os: linux compiler: gcc addons: apt: sources: ['ubuntu-toolchain-r-test'] packages: ['g++-4.8'] env: COMPILER=g++-4.8 - os: linux compiler: gcc addons: apt: sources: ['ubuntu-toolchain-r-test'] packages: ['g++-4.9'] env: COMPILER=g++-4.9 - os: linux compiler: gcc addons: apt: sources: ['ubuntu-toolchain-r-test'] packages: ['g++-5'] env: COMPILER=g++-5 - os: linux compiler: clang env: COMPILER=clang++ V='3.4' - os: linux compiler: clang addons: apt: sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.5'] packages: ['clang-3.5'] env: COMPILER=clang++-3.5 - os: linux compiler: clang addons: apt: sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.6'] packages: ['clang-3.6'] env: COMPILER=clang++-3.6 - os: linux compiler: clang addons: apt: sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.7'] packages: ['clang-3.7'] env: COMPILER=clang++-3.7 - os: linux compiler: clang addons: apt: sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.8'] packages: ['clang-3.8'] env: COMPILER=clang++-3.8 - os: osx compiler: clang env: COMPILER=clang++ V='Apple LLVM 6.0' # Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn) - os: osx osx_image: xcode6.4 compiler: clang env: COMPILER=clang++ - os: osx osx_image: xcode7 compiler: clang env: COMPILER=clang++ V='Apple LLVM 7.0.0' # Apple LLVM version 7.0.0 (clang-700.0.72) - os: osx osx_image: xcode7.1 compiler: clang env: COMPILER=clang++ - os: osx osx_image: xcode7.2 compiler: clang env: COMPILER=clang++ - os: osx osx_image: xcode7.3 compiler: clang env: COMPILER=clang++ - os: linux compiler: gcc addons: apt: sources: ['ubuntu-toolchain-r-test'] packages: ['g++-5'] env: - COMPILER=g++-5 - PEGTL_CXXFLAGS="-O0 --coverage" before_script: - pip install --user cpp-coveralls after_success: - coveralls --gcov gcov-5 --gcov-options '\-lp' --exclude unit_tests --exclude examples script: make CXX=$COMPILER -j3 PEGTL-1.3.1/LICENSE000066400000000000000000000021211270130067200133660ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014-2016 Dr. Colin Hirsch and Daniel Frey Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PEGTL-1.3.1/Makefile000066400000000000000000000030101270130067200140170ustar00rootroot00000000000000# Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey # Please see LICENSE for license or visit https://github.com/ColinH/PEGTL ifeq ($(OS),Windows_NT) UNAME_S := $(OS) ifeq ($(shell gcc -dumpmachine),mingw32) MINGW_CXXFLAGS = -U__STRICT_ANSI__ endif else UNAME_S := $(shell uname -s) endif # For Darwin (Mac OS X) we assume that the default compiler # clang++ is used; when $(CXX) is some version of g++, then # $(PEGTL_CXXSTD) has to be set to -std=c++11 (or newer) so # that -stdlib=libc++ is not automatically added. ifeq ($(PEGTL_CXXSTD),) PEGTL_CXXSTD := -std=c++11 ifeq ($(UNAME_S),Darwin) PEGTL_CXXSTD += -stdlib=libc++ endif endif # Ensure strict standard compliance and no warnings, can be # changed if desired. PEGTL_CPPFLAGS ?= -pedantic PEGTL_CXXFLAGS ?= -Wall -Wextra -Werror -O3 $(MINGW_CXXFLAGS) .PHONY: all clean SOURCES := $(wildcard */*.cc) DEPENDS := $(SOURCES:%.cc=build/%.d) BINARIES := $(SOURCES:%.cc=build/%) UNIT_TESTS := $(filter build/unit_tests/%,$(BINARIES)) all: $(BINARIES) @echo "Built with '$(CXX) $(PEGTL_CXXSTD) -I. $(PEGTL_CPPFLAGS) $(PEGTL_CXXFLAGS)'." @set -e; for T in $(UNIT_TESTS); do echo $$T; $$T > /dev/null; done @echo "All $(words $(UNIT_TESTS)) unit tests passed." clean: rm -rf build/* .SECONDARY: build/%.d: %.cc Makefile @mkdir -p $(@D) $(CXX) $(PEGTL_CXXSTD) -I. $(PEGTL_CPPFLAGS) -MM -MQ $@ $< -o $@ build/%: %.cc build/%.d $(CXX) $(PEGTL_CXXSTD) -I. $(PEGTL_CPPFLAGS) $(PEGTL_CXXFLAGS) $< -o $@ ifeq ($(findstring $(MAKECMDGOALS),clean),) -include $(DEPENDS) endif PEGTL-1.3.1/README.md000066400000000000000000000250151270130067200136470ustar00rootroot00000000000000## Welcome to the PEGTL [![Release](https://img.shields.io/github/release/ColinH/PEGTL.svg)](https://github.com/ColinH/PEGTL/releases/latest) [![License](https://img.shields.io/github/license/ColinH/PEGTL.svg)](#license) [![TravisCI](https://travis-ci.org/ColinH/PEGTL.svg)](https://travis-ci.org/ColinH/PEGTL) [![Coverage](https://img.shields.io/coveralls/ColinH/PEGTL.svg)](https://coveralls.io/github/ColinH/PEGTL) [![Issues](https://img.shields.io/github/issues/ColinH/PEGTL.svg)](https://github.com/ColinH/PEGTL/issues) The Parsing Expression Grammar Template Library (PEGTL) is a zero-dependency C++11 header-only library for creating parsers according to a [Parsing Expression Grammar](http://en.wikipedia.org/wiki/Parsing_expression_grammar) (PEG). #### Introduction Grammars are written as regular C++ code, created with template programming (not template meta programming), i.e. nested template instantiations that naturally correspond to the inductive definition of PEGs or other parser combinator approaches. A comprehensive set of parser rules that can be combined and extended by the user is included, as are mechanisms for debugging grammars and attaching user-defined actions to grammar rules. Here is an example of how a PEG grammar rule is implemented as C++ class with the PEGTL. ```c++ // PEG rule for integers consisting of a non-empty // sequence of digits with an optional sign: // integer ::= ( '+' / '-' )? digit+ // The same parsing rule implemented with the PEGTL: struct integer : pegtl::seq< pegtl::opt< pegtl::one< '+', '-' > >, pegtl::plus< pegtl::digit > > {}; ``` PEGs are superficially similar to Context-Free Grammars (CFGs), however the more deterministic nature of PEGs gives rise to some very important differences. The included [grammar analysis](https://github.com/ColinH/PEGTL/wiki/Grammar-Analysis) finds several typical errors in PEGs, including left recursion. #### Design The PEGTL is mostly concerned with parsing combinators and grammar rules, and with giving the user control over what else happens during a parsing run. The PEGTL is designed to be "lean and mean". The actual core library has about 3000 lines of code. Emphasis is on simplicity and efficiency but without adding any large constructions for optimising parsers. Whether and which actions are taken, and which data structures are created during a parsing run, is entirely up to the user of the library, however we provide some [examples](https://github.com/ColinH/PEGTL/wiki/Contrib-and-Examples#examples) for typical situation like unescaping escape sequences in strings, building a generic [JSON](http://www.json.org/) data structure, and on-the-fly evaluation of arithmetic expressions. Through the use of template programming and template specialisations it is possible to write a grammar once, and use it in multiple ways with different (semantic) actions in different (or the same) parsing runs. Unlike [Antlr](http://www.antlr.org/) and Yacc/[Bison](http://www.gnu.org/software/bison/), the grammar is expressed in C++ and is part of the C++ source code. Also, with the PEG formalism the separation into lexer and parser stages is usually dropped -- everything is done in a single grammar. Unlike [Spirit](http://boost-spirit.com/), the grammar is implemented with compile-time template instantiations rather than run-time operator calls. This leads to slightly increased compile times as the C++ compiler is given the task of optimising PEGTL grammars. #### Status The master branch of the PEGTL is stable in the sense that all known bugs are fixed and all unit tests run without errors. Each commit is automatically tested with multiple operating systems, compilers and versions, currently: * Linux, GCC (4.8, 4.9, 5) with libstdc++ * Linux, Clang (3.4, 3.5, 3.6, 3.7, 3.8) with libstdc++ * MacOS X, XCode (6, 7) with libc++ (Visual Studio 2015 on Windows is *not* automatically tested, *yet*.) The coverage is also automatically measured. Our unit tests cover 100% of the core library code. Releases are not stable in the sense that incompatible API changes can happen, but only between major versions. [Releases](https://github.com/ColinH/PEGTL/releases) are done in accordance with [Semantic Versioning](http://semver.org/). For details see the [changelog](https://github.com/ColinH/PEGTL/wiki/Changelog). ## Documentation * [Getting Started](https://github.com/ColinH/PEGTL/wiki/Getting-Started) * [Hello, world!](https://github.com/ColinH/PEGTL/wiki/Getting-Started#hello-world) * [Requirements](https://github.com/ColinH/PEGTL/wiki/Getting-Started#requirements) * [Compilation](https://github.com/ColinH/PEGTL/wiki/Getting-Started#compilation) * [Limitations](https://github.com/ColinH/PEGTL/wiki/Getting-Started#limitations) * [Rules and Grammars](https://github.com/ColinH/PEGTL/wiki/Rules-and-Grammars) * [Combining Existing Rules](https://github.com/ColinH/PEGTL/wiki/Rules-and-Grammars#combining-existing-rules) * [Actions and States](https://github.com/ColinH/PEGTL/wiki/Actions-and-States) * [Actions](https://github.com/ColinH/PEGTL/wiki/Actions-and-States#actions) * [States](https://github.com/ColinH/PEGTL/wiki/Actions-and-States#states) * [Action Specialisation](https://github.com/ColinH/PEGTL/wiki/Actions-and-States#action-specialisation) * [Changing Actions](https://github.com/ColinH/PEGTL/wiki/Actions-and-States#changing-actions) * [Errors and Exceptions](https://github.com/ColinH/PEGTL/wiki/Errors-and-Exceptions) * [Failure](https://github.com/ColinH/PEGTL/wiki/Errors-and-Exceptions#failure) * [Error Messages](https://github.com/ColinH/PEGTL/wiki/Errors-and-Exceptions#error-messages) * [Rule Reference](https://github.com/ColinH/PEGTL/wiki/Rule-Reference) * [Meta Rules](https://github.com/ColinH/PEGTL/wiki/Rule-Reference#meta-rules) * [Combinators](https://github.com/ColinH/PEGTL/wiki/Rule-Reference#combinators) * [Convenience](https://github.com/ColinH/PEGTL/wiki/Rule-Reference#convenience) * [Atomic Rules](https://github.com/ColinH/PEGTL/wiki/Rule-Reference#atomic-rules) * [ASCII Rules](https://github.com/ColinH/PEGTL/wiki/Rule-Reference#ascii-rules) * [UTF-8 Rules](https://github.com/ColinH/PEGTL/wiki/Rule-Reference#utf-8-rules) * [UTF-16 Rules](https://github.com/ColinH/PEGTL/wiki/Rule-Reference#utf-16-rules) * [UTF-32 Rules](https://github.com/ColinH/PEGTL/wiki/Rule-Reference#utf-32-rules) * [Full Index](https://github.com/ColinH/PEGTL/wiki/Rule-Reference#full-index) * [Parser Reference](https://github.com/ColinH/PEGTL/wiki/Parser-Reference) * [Input and Errors](https://github.com/ColinH/PEGTL/wiki/Parser-Reference#input-and-errors) * [Parser Functions](https://github.com/ColinH/PEGTL/wiki/Parser-Reference#parser-functions) * [Tracer Functions](https://github.com/ColinH/PEGTL/wiki/Parser-Reference#tracer-functions) * [Parser Classes](https://github.com/ColinH/PEGTL/wiki/Parser-Reference#parser-classes) * [Contrib and Examples](https://github.com/ColinH/PEGTL/wiki/Contrib-and-Examples) * [Contrib](https://github.com/ColinH/PEGTL/wiki/Contrib-and-Examples#contrib) * [Examples](https://github.com/ColinH/PEGTL/wiki/Contrib-and-Examples#examples) * [Control Hooks](https://github.com/ColinH/PEGTL/wiki/Control-Hooks) * [Normal Control](https://github.com/ColinH/PEGTL/wiki/Control-Hooks#normal-control) * [Debug Functions](https://github.com/ColinH/PEGTL/wiki/Control-Hooks#debug-functions) * [Exception Throwing](https://github.com/ColinH/PEGTL/wiki/Control-Hooks#exception-throwing) * [Debugging and Tracing](https://github.com/ColinH/PEGTL/wiki/Control-Hooks#debugging-and-tracing) * [Advanced Control](https://github.com/ColinH/PEGTL/wiki/Control-Hooks#advanced-control) * [Changing Control](https://github.com/ColinH/PEGTL/wiki/Control-Hooks#changing-control) * [Advanced Rules](https://github.com/ColinH/PEGTL/wiki/Advanced-Rules) * [Simple Rules](https://github.com/ColinH/PEGTL/wiki/Advanced-Rules#simple-rules) * [Complex Rules](https://github.com/ColinH/PEGTL/wiki/Advanced-Rules#complex-rules) * [Switching Style](https://github.com/ColinH/PEGTL/wiki/Switching-Style) * [Grammar Analysis](https://github.com/ColinH/PEGTL/wiki/Grammar-Analysis) * [Calculator Example](https://github.com/ColinH/PEGTL/wiki/Calculator-Example) * [Changelog](https://github.com/ColinH/PEGTL/wiki/Changelog) * [2014 Refactoring](https://github.com/ColinH/PEGTL/wiki/2014-Refactoring) #### Thank You * Christopher Diggins and the YARD parser for the general idea. * Stephan Beal for the bug reports, suggestions and discussions. * Johannes Overmann for his invaluable [`streplace`](https://code.google.com/p/streplace/) command-line tool. * Sam Hocevar for contributing Visual Studio 2015 compatibility. * George Makrydakis for the [inspiration](https://github.com/irrequietus/typestring) to `pegtl_string_t`. * Kenneth Geisshirt for Android compatibility. ## License The PEGTL is certified [Open Source](http://www.opensource.org/docs/definition.html) software. It may be used for any purpose, including commercial purposes, at absolutely no cost. It is distributed under the terms of the [MIT license](http://www.opensource.org/licenses/mit-license.html) reproduced here. > Copyright (c) 2014-2016 Dr. Colin Hirsch and Daniel Frey > > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: > > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. > > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. This site and software is not affiliated with or endorsed by the Open Source Initiative. For questions and suggestions about the PEGTL please contact the authors at `pegtl(at)colin-hirsch.net`. PEGTL-1.3.1/examples/000077500000000000000000000000001270130067200142035ustar00rootroot00000000000000PEGTL-1.3.1/examples/abnf.abnf000066400000000000000000000040631270130067200157440ustar00rootroot00000000000000; grammar for ABNFs taken from RFC 5234 + RFC 7405, ; slightly adapted and extended to PEGs rulelist = 1*( rule / (*c-wsp c-nl) ) rule = rulename defined-as elements c-nl ; continues if next line starts ; with white space rulename = ALPHA *(ALPHA / DIGIT / "-") defined-as = *c-wsp ("=/" / "=") *c-wsp ; basic rules definition and ; incremental alternatives ; different order due to PEG elements = alternation *c-wsp c-wsp = WSP / (c-nl WSP) c-nl = comment / CRLF ; comment or newline comment = ";" *(WSP / VCHAR) CRLF alternation = concatenation *(*c-wsp "/" *c-wsp concatenation) concatenation = predicate *(1*c-wsp predicate) predicate = ["&" / "!"] repetition ; extension for PEGs repetition = [repeat] element repeat = (*DIGIT "*" *DIGIT) / 1*DIGIT ; different order due to PEG element = rulename / group / option / char-val / num-val / prose-val group = "(" *c-wsp alternation *c-wsp ")" option = "[" *c-wsp alternation *c-wsp "]" char-val = DQUOTE *(%x20-21 / %x23-7E) DQUOTE ; quoted string of SP and VCHAR ; without DQUOTE num-val = "%" (bin-val / dec-val / hex-val) bin-val = "b" 1*BIT [ 1*("." 1*BIT) / ("-" 1*BIT) ] ; series of concatenated bit values ; or single ONEOF range dec-val = "d" 1*DIGIT [ 1*("." 1*DIGIT) / ("-" 1*DIGIT) ] hex-val = "x" 1*HEXDIG [ 1*("." 1*HEXDIG) / ("-" 1*HEXDIG) ] prose-val = "<" *(%x20-3D / %x3F-7E) ">" ; bracketed string of SP and VCHAR ; without angles ; prose description, to be used as ; last resort PEGTL-1.3.1/examples/abnf2pegtl.cc000066400000000000000000000571141270130067200165460ustar00rootroot00000000000000// Copyright (c) 2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include #include #include #include #include #include #include #include #include #include #include #include #include namespace pegtl { namespace abnf { namespace grammar { // ABNF grammar according to RFC 5234, updated by RFC 7405, with // the following differences: // // To form a C++ identifier from a rulename, all minuses are // replaced with underscores. // // As C++ identifiers are case-sensitive, we remember the "correct" // spelling from the first occurrence of a rulename, all other // occurrences are automatically changed to that. // // Certain rulenames are reserved as their equivalent C++ identifier is // reserved as a keyword, an alternative token, by the standard or // for other, special reasons. // // When using numerical values (num-val, repeat), the values // must be in the range of the corresponsing C++ data type. // // Remember we are defining a PEG, not a CFG. Simply copying some // ABNF from somewhere might lead to surprising results as the // alternations are now sequential, using the pegtl::sor<> rule. // // PEG also require two extensions: the and-predicate and the // not-predicate. They are expressed by '&' and '!' respectively, // being allowed (optionally, only one of them) before the // repetition. You can use braces for more complex expressions. // // Finally, instead of the pre-defined CRLF sequence, we accept // any type of line ending as a convencience extension: struct CRLF : sor< abnf::CRLF, CR, LF > {}; // The rest is according to the RFC(s): struct comment_cont : until< CRLF, sor< WSP, VCHAR > > {}; struct comment : if_must< one< ';' >, comment_cont > {}; struct c_nl : sor< comment, CRLF > {}; struct c_wsp : sor< WSP, seq< c_nl, WSP > > {}; struct rulename : seq< ALPHA, star< ranges< 'a', 'z', 'A', 'Z', '0', '9', '-' > > > {}; struct quoted_string_cont : until< DQUOTE, print > {}; struct quoted_string : if_must< DQUOTE, quoted_string_cont > {}; struct case_insensitive_string : seq< opt< istring< '%', 'i' > >, quoted_string > {}; struct case_sensitive_string : seq< istring< '%', 's' >, quoted_string > {}; struct char_val : sor< case_insensitive_string, case_sensitive_string > {}; struct prose_val_cont : until< one< '>' >, print > {}; struct prose_val : if_must< one< '<' >, prose_val_cont > {}; template< char First, typename Digit > struct gen_val { struct value : plus< Digit > {}; struct range : if_must< one< '-' >, value > {}; struct next_value : must< value > {}; struct type : seq< istring< First >, must< value >, sor< range, star< one< '.' >, next_value > > > {}; }; using hex_val = gen_val< 'x', HEXDIG >; using dec_val = gen_val< 'd', DIGIT >; using bin_val = gen_val< 'b', BIT >; struct num_val_choice : sor< bin_val::type, dec_val::type, hex_val::type > {}; struct num_val : if_must< one< '%' >, num_val_choice > {}; struct alternation; struct option_close : one< ']' > {}; struct option : seq< one< '[' >, pad< must< alternation >, c_wsp >, must< option_close > > {}; struct group_close : one< ')' > {}; struct group : seq< one< '(' >, pad< must< alternation >, c_wsp >, must< group_close > > {}; struct rulename_val : rulename {}; struct element : sor< rulename_val, group, option, char_val, num_val, prose_val > {}; struct repeat : sor< seq< star< DIGIT >, one< '*' >, star< DIGIT > >, plus< DIGIT > > {}; struct repetition : seq< opt< repeat >, element > {}; struct and_predicate : if_must< one< '&' >, repetition > {}; struct not_predicate : if_must< one< '!' >, repetition > {}; struct predicate : sor< and_predicate, not_predicate, repetition > {}; struct push_stack : success {}; struct concatenation : seq< push_stack, list< predicate, plus< c_wsp > > > {}; struct alternation : seq< push_stack, list_must< concatenation, pad< one< '/' >, c_wsp > > > {}; struct defined_as_op : sor< string< '=', '/' >, one< '=' > > {}; struct defined_as : pad< defined_as_op, c_wsp > {}; struct rule : seq< push_stack, if_must< rulename, defined_as, alternation >, star< c_wsp >, must< c_nl > > {}; struct rulelist : until< eof, sor< seq< star< c_wsp >, c_nl >, must< rule > > > {}; // end of grammar template< typename Rule > struct error_control : public normal< Rule > { static const std::string error_message; template< typename Input, typename ... States > static void raise( const Input & in, States && ... ) { throw parse_error( error_message, in ); } }; template<> const std::string error_control< comment_cont >::error_message = "unterminated comment"; template<> const std::string error_control< quoted_string_cont >::error_message = "unterminated string (missing '\"')"; template<> const std::string error_control< prose_val_cont >::error_message = "unterminated prose description (missing '>')"; template<> const std::string error_control< hex_val::value >::error_message = "expected hexadecimal value"; template<> const std::string error_control< dec_val::value >::error_message = "expected decimal value"; template<> const std::string error_control< bin_val::value >::error_message = "expected binary value"; template<> const std::string error_control< num_val_choice >::error_message = "expected base specifier (one of 'bBdDxX')"; template<> const std::string error_control< option_close >::error_message = "unterminated option (missing ']')"; template<> const std::string error_control< group_close >::error_message = "unterminated group (missing ')')"; template<> const std::string error_control< repetition >::error_message = "expected element"; template<> const std::string error_control< concatenation >::error_message = "expected element"; template<> const std::string error_control< alternation >::error_message = "expected element"; template<> const std::string error_control< defined_as >::error_message = "expected '=' or '=/'"; template<> const std::string error_control< c_nl >::error_message = "unterminated rule"; template<> const std::string error_control< rule >::error_message = "expected rule"; } // grammar } // abnf } // pegtl namespace abnf2pegtl { struct data { std::string rulename; std::vector< std::vector< std::string > > elements; using rules_t = std::vector< std::pair< std::string, std::string > >; rules_t rules; rules_t::reverse_iterator find_rule( const std::string& v, const rules_t::reverse_iterator& rbegin ) { return std::find_if( rbegin, rules.rend(), [&]( const rules_t::value_type& p ){ return ::strcasecmp( p.first.c_str(), v.c_str() ) == 0; } ); } rules_t::reverse_iterator find_rule( const std::string& v ) { return find_rule( v, rules.rbegin() ); } }; namespace { std::set< std::string > keywords = { "alignas", "alignof", "and", "and_eq", "asm", "auto", "bitand", "bitor", "bool", "break", "case", "catch", "char", "char16_t", "char32_t", "class", "compl", "const", "constexpr", "const_cast", "continue", "decltype", "default", "delete", "do", "double", "dynamic_cast", "else", "enum", "explicit", "export", "extern", "false", "float", "for", "friend", "goto", "if", "inline", "int", "long", "mutable", "namespace", "new", "noexcept", "not", "not_eq", "nullptr", "operator", "or", "or_eq", "private", "protected", "public", "register", "reinterpret_cast", "return", "short", "signed", "sizeof", "static", "static_assert", "static_cast", "struct", "switch", "template", "this", "thread_local", "throw", "true", "try", "typedef", "typeid", "typename", "union", "unsigned", "using", "virtual", "void", "volatile", "wchar_t", "while", "xor", "xor_eq", "pegtl" // this would not end well :) }; } std::string get_rulename( const pegtl::input & in, data & d ) { std::string v = in.string(); std::replace( v.begin(), v.end(), '-', '_' ); const auto it = d.find_rule( v ); if( it != d.rules.rend() ) { return it->first; } if( keywords.find( v ) != keywords.end() || v.find( "__" ) != std::string::npos ) { throw pegtl::parse_error( "'" + in.string() + "' is a reserved rulename", in ); } return v; } namespace grammar = pegtl::abnf::grammar; template< typename Rule > struct action : pegtl::nothing< Rule > {}; template<> struct action< grammar::push_stack > { static void apply( const pegtl::input &, data & d ) { d.elements.emplace_back(); } }; template<> struct action< grammar::rulename > { static void apply( const pegtl::input & in, data & d ) { d.rulename = get_rulename( in, d ); } }; template<> struct action< grammar::rulename_val > { static void apply( const pegtl::input & in, data & d ) { assert( !d.elements.empty() ); std::string v = get_rulename( in, d ); const auto it = d.find_rule( v ); if( it == d.rules.rend() ) { d.rules.emplace_back( v, "" ); } d.elements.back().push_back( v ); } }; template<> struct action< grammar::quoted_string > { static bool append( std::string& s, const char c ) { if( !s.empty() ) { s += ", "; } s += '\''; if( c == '\'' ) { s += '\\'; } s += c; s += '\''; return std::isalpha( c ); } static void apply( const pegtl::input & in, data & d ) { assert( !d.elements.empty() ); std::string s; bool alpha = append( s, in.peek_char( 1 ) ); for( std::size_t pos = 2; pos < in.size() - 1; ++pos ) { alpha = append( s, in.peek_char( pos ) ) || alpha; } if( alpha ) { d.elements.back().push_back( "pegtl::istring< " + s + " >" ); } else if( in.size() > 3 ) { d.elements.back().push_back( "pegtl::string< " + s + " >" ); } else { d.elements.back().push_back( "pegtl::one< " + s + " >" ); } } }; template<> struct action< grammar::prose_val > { static void apply( const pegtl::input & in, data & d ) { assert( !d.elements.empty() ); const auto v = in.string(); d.elements.back().push_back( "/* " + v.substr( 1, v.size() - 2 ) + " */" ); } }; template<> struct action< grammar::case_sensitive_string > { static void apply( const pegtl::input &, data & d ) { assert( !d.elements.empty() ); assert( !d.elements.back().empty() ); if( d.elements.back().back()[ 7 ] == 'i' ) { d.elements.back().back().erase( 7, 1 ); } } }; template<> struct action< grammar::bin_val::value > { static void apply( const pegtl::input & in, data & d ) { assert( !d.elements.empty() ); const auto v = in.string(); d.elements.back().push_back( "pegtl::one< " + std::to_string( std::strtoull( v.c_str(), nullptr, 2 ) ) + " >" ); } }; template<> struct action< grammar::bin_val::range > { static void apply( const pegtl::input &, data & d ) { assert( !d.elements.empty() ); assert( !d.elements.back().empty() ); const auto end = d.elements.back().back(); d.elements.back().pop_back(); assert( !d.elements.back().empty() ); const auto begin = d.elements.back().back(); d.elements.back().back() = "pegtl::range< " + begin.substr( 12, begin.size() - 14 ) + ", " + end.substr( 12, end.size() - 14 ) + " >"; } }; template<> struct action< grammar::bin_val::next_value > { static void apply( const pegtl::input &, data & d ) { assert( !d.elements.empty() ); assert( !d.elements.back().empty() ); const auto end = d.elements.back().back(); d.elements.back().pop_back(); assert( !d.elements.back().empty() ); d.elements.back().back().replace( d.elements.back().back().size() - 2, 2, ", " + end.substr( 12 ) ); } }; template<> struct action< grammar::dec_val::value > { static void apply( const pegtl::input & in, data & d ) { assert( !d.elements.empty() ); const auto v = in.string(); const auto p = v.find_first_not_of( '0' ); d.elements.back().push_back( "pegtl::one< " + ( ( p == std::string::npos ) ? "0" : v.substr( p ) ) + " >" ); } }; template<> struct action< grammar::dec_val::range > : action< grammar::bin_val::range > {}; template<> struct action< grammar::dec_val::next_value > : action< grammar::bin_val::next_value > {}; template<> struct action< grammar::hex_val::value > { static void apply( const pegtl::input & in, data & d ) { assert( !d.elements.empty() ); d.elements.back().push_back( "pegtl::one< 0x" + in.string() + " >" ); } }; template<> struct action< grammar::hex_val::range > : action< grammar::bin_val::range > {}; template<> struct action< grammar::hex_val::next_value > : action< grammar::bin_val::next_value > {}; template<> struct action< grammar::option > { static void apply( const pegtl::input &, data & d ) { assert( !d.elements.empty() ); assert( !d.elements.back().empty() ); d.elements.back().back() = "pegtl::opt< " + d.elements.back().back() + " >"; } }; template<> struct action< grammar::repeat > { static void apply( const pegtl::input & in, data & d ) { assert( !d.elements.empty() ); d.elements.back().push_back( in.string() ); } }; template<> struct action< grammar::repetition > { static std::string remove_leading_zeroes( const std::string& v ) { const auto pos = v.find_first_not_of( '0' ); if( pos == std::string::npos ) { return ""; } return v.substr( pos ); } static void apply( const pegtl::input & in, data & d ) { assert( !d.elements.empty() ); assert( !d.elements.back().empty() ); const auto size = d.elements.back().size(); if( size > 1 ) { const auto value = d.elements.back()[ size - 2 ]; if( value.find_first_not_of( "0123456789*" ) == std::string::npos ) { const auto element = d.elements.back().back(); d.elements.back().pop_back(); d.elements.back().pop_back(); const auto star = value.find( '*' ); if( star == std::string::npos ) { const auto num = remove_leading_zeroes( value ); if( num == "" ) { throw pegtl::parse_error( "repetition of zero not allowed", in ); } d.elements.back().push_back( "pegtl::rep< " + num + ", " + element + " >" ); } else { const auto min = remove_leading_zeroes( value.substr( 0, star ) ); const auto max = remove_leading_zeroes( value.substr( star + 1 ) ); if( star != value.size() - 1 && max == "" ) { throw pegtl::parse_error( "repetition maximum of zero not allowed", in ); } if( min.empty() && max.empty() ) { d.elements.back().push_back( "pegtl::star< " + element + " >" ); } else if( !min.empty() && max.empty() ) { if( min == "1" ) { d.elements.back().push_back( "pegtl::plus< " + element + " >" ); } else { d.elements.back().push_back( "pegtl::rep_min< " + min + ", " + element + " >" ); } } else if( min.empty() && !max.empty() ) { if( max == "1" ) { d.elements.back().push_back( "pegtl::opt< " + element + " >" ); } else { d.elements.back().push_back( "pegtl::rep_opt< " + max + ", " + element + " >" ); } } else { const auto min_val = std::strtoull( min.c_str(), nullptr, 10 ); const auto max_val = std::strtoull( max.c_str(), nullptr, 10 ); if( min_val > max_val ) { throw pegtl::parse_error( "repetition minimum which is greater than the repetition maximum not allowed", in ); } const auto min_element = ( min_val == 1 ) ? element : "pegtl::rep< " + min + ", " + element + " >"; if( min_val == max_val ) { d.elements.back().push_back( min_element ); } else if( max_val - min_val == 1 ) { const auto max_element = "pegtl::opt< " + element + " >"; d.elements.back().push_back( "pegtl::seq< " + min_element + ", " + max_element + " >" ); } else { const auto max_element = "pegtl::rep_opt< " + std::to_string( max_val - min_val ) + ", " + element + " >"; d.elements.back().push_back( "pegtl::seq< " + min_element + ", " + max_element + " >" ); } } } } } } }; template<> struct action< grammar::and_predicate > { static void apply( const pegtl::input &, data & d ) { assert( !d.elements.empty() ); assert( !d.elements.back().empty() ); d.elements.back().back() = "pegtl::at< " + d.elements.back().back() + " >"; } }; template<> struct action< grammar::not_predicate > { static void apply( const pegtl::input &, data & d ) { assert( !d.elements.empty() ); assert( !d.elements.back().empty() ); d.elements.back().back() = "pegtl::not_at< " + d.elements.back().back() + " >"; } }; template<> struct action< grammar::concatenation > { static void apply( const pegtl::input &, data & d ) { assert( !d.elements.empty() ); if( d.elements.back().size() == 1 ) { assert( d.elements.back().size() == 1 ); const auto v = d.elements.back().back(); d.elements.pop_back(); assert( !d.elements.empty() ); d.elements.back().push_back( v ); } else { std::string s = d.elements.back().front(); for( std::size_t p = 1; p != d.elements.back().size(); ++p ) { s += ", "; s += d.elements.back()[ p ]; } d.elements.pop_back(); assert( !d.elements.empty() ); d.elements.back().push_back( "pegtl::seq< " + s + " >" ); } } }; template<> struct action< grammar::alternation > { static bool is_one( const std::string& v ) { return v.compare( 0, 12, "pegtl::one< " ) == 0; } static void apply( const pegtl::input &, data & d ) { assert( !d.elements.empty() ); if( d.elements.back().size() == 1 ) { assert( d.elements.back().size() == 1 ); const auto v = d.elements.back().back(); d.elements.pop_back(); assert( !d.elements.empty() ); d.elements.back().push_back( v ); } else { std::string s = d.elements.back().front(); bool one = is_one( s ); for( std::size_t p = 1; p != d.elements.back().size(); ++p ) { const auto v = d.elements.back()[ p ]; if( one && is_one( v ) ) { s.replace( s.size() - 2, 2, ", " + v.substr( 12 ) ); } else { one = false; s += ", "; s += v; } } d.elements.pop_back(); assert( !d.elements.empty() ); if( !one ) { s = "pegtl::sor< " + s + " >"; } d.elements.back().push_back( s ); } } }; template<> struct action< grammar::defined_as_op > { static void apply( const pegtl::input & in, data & d ) { assert( !d.elements.empty() ); d.elements.back().push_back( in.string() ); } }; template<> struct action< grammar::rule > { static std::string strip_sor( const std::string& v ) { return ( v.compare( 0, 12, "pegtl::sor< " ) == 0 ) ? v.substr( 12, v.size() - 14 ) : v; } static void apply( const pegtl::input & in, data & d ) { assert( !d.elements.empty() ); assert( d.elements.back().size() == 2 ); auto value = d.elements.back().back(); d.elements.back().pop_back(); const auto op = d.elements.back().back(); d.elements.back().pop_back(); const auto it = d.find_rule( d.rulename ); if( op == "=" ) { if( it != d.rules.rend() && it->second != "" ) { throw pegtl::parse_error( "'" + d.rulename + "' has already been assigned", in ); } } else { assert( op == "=/" ); if( it == d.rules.rend() || it->second == "" ) { throw pegtl::parse_error( "'" + d.rulename + "' has not yet been assigned", in ); } value = "pegtl::sor< " + strip_sor( it->second ) + ", " + strip_sor( value ) + " >"; if( d.find_rule( d.rulename, std::next( it ) ) == d.rules.rend() ) { it->second.clear(); } else { d.rules.erase( --it.base() ); } } d.rules.emplace_back( d.rulename, value ); d.elements.pop_back(); assert( d.elements.empty() ); } }; } // abnf2pegtl int main( int argc, char ** argv ) { using namespace pegtl; if( argc != 2 ) { analyze< abnf::grammar::rulelist >(); std::cerr << "Usage: " << argv[ 0 ] << " SOURCE" << std::endl; return 1; } abnf2pegtl::data d; file_parser( argv[ 1 ] ).parse< abnf::grammar::rulelist, abnf2pegtl::action, abnf::grammar::error_control >( d ); for( const auto& e : d.rules ) { if( e.second.empty() ) { if( !d.find_rule( e.first )->second.empty() ) { std::cout << "struct " << e.first << ";\n"; } } else { std::cout << "struct " << e.first << " : " << e.second << " {};\n"; } } return 0; } PEGTL-1.3.1/examples/calculator.cc000066400000000000000000000256451270130067200166570ustar00rootroot00000000000000// Copyright (c) 2014-2016 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include #include #include #include #include #include // Include the analyze function that checks // a grammar for possible infinite cycles. #include namespace calculator { // This enum is used for the order in which the operators are // evaluated, i.e. the priority of the operators. enum class order : int {}; // The shift-reduce-style approach allows for both left- and // right-associative binary operators, and this enum is used // to indicate the kind of each operator. enum class assoc : bool { LEFT = true, RIGHT = false }; // For each binary operator known to the calculator we need an // instance of the following data structure with the priority, // associativity, and a function that performs the calculation. struct op { order p; assoc a; std::function< long ( long, long ) > f; }; // Class that takes care of an operand and an operator stack for // shift-reduce style handling of operator associativity and // priority; in a reduce-step it calls on the functions contained // in the op instances to perform the calculation. struct stack { void push( const op & b ) { if ( ! m_o.empty() ) { if ( m_o.back().p < b.p ) { reduce(); } else if ( ( m_o.back().p == b.p ) && ( b.a == assoc::LEFT ) ) { reduce(); } } m_o.push_back( b ); } void push( const long l ) { m_l.push_back( l ); } long finish() { while ( ! m_o.empty() ) { reduce(); } assert( m_l.size() == 1 ); const auto r = m_l.back(); m_l.clear(); return r; } private: std::vector< op > m_o; std::vector< long > m_l; void reduce() { assert( m_o.size() > 0 ); assert( m_l.size() > 1 ); const auto r = m_l.back(); m_l.pop_back(); const auto l = m_l.back(); m_l.pop_back(); const auto o = m_o.back(); m_o.pop_back(); m_l.push_back( o.f( l, r ) ); } }; // Additional layer, a "stack of stacks", to clearly show how bracketed // sub-expressions can be easily processed by giving them a stack of // their own. Once a bracketed sub-expression has finished evaluation on // its stack, the result is pushed onto the next higher stack, and the // sub-expression's temporary stack is discarded. The top-level calculation // is handled just like a bracketed sub-expression, on the first stack pushed // by the constructor. struct stacks { stacks() { open(); } void open() { m_v.push_back( stack() ); } template< typename T > void push( const T & t ) { assert( ! m_v.empty() ); m_v.back().push( t ); } void close() { assert( m_v.size() > 1 ); const auto r = m_v.back().finish(); m_v.pop_back(); m_v.back().push( r ); } long finish() { assert( m_v.size() == 1 ); return m_v.back().finish(); } private: std::vector< stack > m_v; }; // A wrapper around the data structures that contain the binary // operators for the calculator. struct operators { operators() { // By default we initialise with all binary operators from the C language that can be // used on integers, all with their usual priority and associativity. insert( "*", order( 5 ), assoc::LEFT, []( const long l, const long r ){ return l * r; } ); insert( "/", order( 5 ), assoc::LEFT, []( const long l, const long r ){ return l / r; } ); insert( "%", order( 5 ), assoc::LEFT, []( const long l, const long r ){ return l % r; } ); insert( "+", order( 6 ), assoc::LEFT, []( const long l, const long r ){ return l + r; } ); insert( "-", order( 6 ), assoc::LEFT, []( const long l, const long r ){ return l - r; } ); insert( "<<", order( 7 ), assoc::LEFT, []( const long l, const long r ){ return l << r; } ); insert( ">>", order( 7 ), assoc::LEFT, []( const long l, const long r ){ return l >> r; } ); insert( "<", order( 8 ), assoc::LEFT, []( const long l, const long r ){ return l < r; } ); insert( ">", order( 8 ), assoc::LEFT, []( const long l, const long r ){ return l > r; } ); insert( "<=", order( 8 ), assoc::LEFT, []( const long l, const long r ){ return l <= r; } ); insert( ">=", order( 8 ), assoc::LEFT, []( const long l, const long r ){ return l >= r; } ); insert( "==", order( 9 ), assoc::LEFT, []( const long l, const long r ){ return l == r; } ); insert( "!=", order( 9 ), assoc::LEFT, []( const long l, const long r ){ return l != r; } ); insert( "&", order( 10 ), assoc::LEFT, []( const long l, const long r ){ return l & r; } ); insert( "^", order( 11 ), assoc::LEFT, []( const long l, const long r ){ return l ^ r; } ); insert( "|", order( 12 ), assoc::LEFT, []( const long l, const long r ){ return l | r; } ); insert( "&&", order( 13 ), assoc::LEFT, []( const long l, const long r ){ return l && r; } ); insert( "||", order( 14 ), assoc::LEFT, []( const long l, const long r ){ return l || r; } ); } // Arbitrary user-defined operators can be added at runtime. void insert( const std::string & name, const order p, const assoc a, const std::function< long( long, long ) > & f ) { assert( ! name.empty() ); const auto i = m_pas.insert( { p, a } ); assert( i.first->second == a ); // Asserts that all operators of the same priority share the same associativity. m_ops.insert( { name, { p, a, f } } ); } const std::map< std::string, op > & ops() const { return m_ops; } private: std::map< order, assoc > m_pas; std::map< std::string, op > m_ops; }; // Here the actual grammar starts. using namespace pegtl; // Comments are introduced by a '#' and proceed to the end-of-line/file. struct comment : if_must< one< '#' >, until< eolf > > {}; // The calculator ignores all spaces and comments; space is a pegtl rule // that matches the usual ascii characters ' ', '\t', '\n' etc. In other // words, everything that is space or a comment is ignored. struct ignored : sor< space, comment > {}; // Since the binary operators are taken from a runtime data structure // (rather than hard-coding them into the grammar), we need a custom // rule that attempts to match the input against the current map of // operators. struct infix { using analyze_t = analysis::generic< analysis::rule_type::ANY >; template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input > static bool match( Input & in, const operators & b, stacks & s ) { // Look for the longest match of the input against the operators in the operator map. return match( in, b, s, std::string() ); } private: template< typename Input > static bool match( Input & in, const operators & b, stacks & s, std::string t ) { if ( in.size() > t.size() ) { t += in.peek_char( t.size() ); const auto i = b.ops().lower_bound( t ); if ( i != b.ops().end() ) { if ( match( in, b, s, t ) ) { return true; } else if ( i->first == t ) { // While we are at it, this rule also performs the task of what would // usually be an associated action: To push the matched operator onto // the operator stack. s.push( i->second ); in.bump( t.size() ); return true; } } } return false; } }; // A number is a non-empty sequence of digits preceeded by an optional sign. struct number : seq< opt< one< '+', '-' > >, plus< digit > > {}; struct expression; // A bracketed expression is introduced by a '(' and, in this grammar, must // proceed with an expression and a ')'. struct bracket : if_must< one< '(' >, expression, one< ')' > > {}; // An atomic expression, i.e. one without operators, is either a number or // a bracketed expression. struct atomic : sor< number, bracket > {}; // An expression is a non-empty list of atomic expressions where each pair // of atomic expressions is separated by an infix operator and we allow // the rule ignored as padding (before and after every singlar expression). struct expression : list< atomic, infix, ignored > {}; // The top-level grammar allows one expression and then expects eof. struct grammar : must< expression, eof > {}; // After the grammar we proceed with the additional actions that are // required to let our calculator actually do something. // The base-case of the class template for the actions must derive from // pegtl::nothing (or, alternatively, define an action that does something // sensible for all rules for which no specialisation exists). template< typename Rule > struct action : pegtl::nothing< Rule > {}; // This action will be called when the number rule matches; it converts the // matched portion of the input to a long and pushes it onto the operand // stack. template<> struct action< number > { static void apply( const input & in, const operators &, stacks & s ) { s.push( std::stol( in.string() ) ); } }; // The actions for the brackets call functions that create, and collect // a temporary additional stack for evaluating the bracketed expression. template<> struct action< one< '(' > > { static void apply( const input &, const operators &, stacks & s ) { s.open(); } }; template<> struct action< one< ')' > > { static void apply( const input &, const operators &, stacks & s ) { s.close(); } }; } // calculator int main( int argc, char ** argv ) { // Check the grammar for some possible issues. pegtl::analyze< calculator::grammar >(); // The objects required as state by the actions. calculator::stacks s; calculator::operators b; for ( int i = 1; i < argc; ++i ) { // Parse and process the command-line arguments as calculator expressions... pegtl::parse< calculator::grammar, calculator::action >( i, argv, b, s ); // ...and print the respective results to std::cout. std::cout << s.finish() << std::endl; } return 0; } PEGTL-1.3.1/examples/double.hh000066400000000000000000000031361270130067200160010ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_EXAMPLES_DOUBLE_HH #define PEGTL_EXAMPLES_DOUBLE_HH #include namespace double_ { // A grammar for doubles suitable for std::stod without locale support. // See also: http://en.cppreference.com/w/cpp/string/basic_string/stof struct plus_minus : pegtl::opt< pegtl::one< '+', '-' > > {}; struct dot : pegtl::one< '.' > {}; struct inf : pegtl::seq< pegtl::istring< 'i', 'n', 'f' >, pegtl::opt< pegtl::istring< 'i', 'n', 'i', 't', 'y' > > > {}; struct nan : pegtl::seq< pegtl::istring< 'n', 'a', 'n' >, pegtl::opt< pegtl::one< '(' >, pegtl::plus< pegtl::alnum >, pegtl::one< ')' > > > {}; template< typename D > struct number : pegtl::if_then_else< dot, pegtl::plus< D >, pegtl::seq< pegtl::plus< D >, dot, pegtl::star< D > > > {}; struct e : pegtl::one< 'e', 'E' > {}; struct p : pegtl::one< 'p', 'P' > {}; struct exponent : pegtl::seq< plus_minus, pegtl::plus< pegtl::digit > > {}; struct decimal : pegtl::seq< number< pegtl::digit >, pegtl::opt< e, exponent > > {}; struct binary : pegtl::seq< pegtl::one< '0' >, pegtl::one< 'x', 'X' >, number< pegtl::xdigit >, pegtl::opt< p, exponent > > {}; struct grammar : pegtl::seq< plus_minus, pegtl::sor< decimal, binary, inf, nan > > {}; } // double_ #endif PEGTL-1.3.1/examples/hello_world.cc000066400000000000000000000016441270130067200170310ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include #include #include namespace hello { struct prefix : pegtl::string< 'H', 'e', 'l', 'l', 'o', ',', ' ' > {}; struct name : pegtl::plus< pegtl::alpha > {}; struct grammar : pegtl::must< prefix, name, pegtl::one< '!' >, pegtl::eof > {}; template< typename Rule > struct action : pegtl::nothing< Rule > {}; template<> struct action< name > { static void apply( const pegtl::input & in, std::string & name ) { name = in.string(); } }; } // hello int main( int argc, char ** argv ) { if ( argc > 1 ) { std::string name; pegtl::parse< hello::grammar, hello::action >( 1, argv, name ); std::cout << "Good bye, " << name << "!" << std::endl; } } PEGTL-1.3.1/examples/json_build_one.cc000066400000000000000000000113451270130067200175070ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include #include #include #include #include "json_errors.hh" #include "json_classes.hh" #include "json_unescape.hh" namespace examples { // Basic state class that stores the result of a JSON parsing run -- a single JSON object. struct result_state { result_state() = default; result_state( const result_state & ) = delete; void operator= ( const result_state & ) = delete; std::shared_ptr< json_base > result; }; // Action class for the simple cases... template< typename Rule > struct value_action : unescape_action< Rule > {}; struct string_state : public unescape_state_base { void success( result_state & result ) { result.result = std::make_shared< string_json >( std::move( unescaped ) ); } }; template<> struct value_action< pegtl::json::null > { static void apply( const pegtl::input &, result_state & result ) { result.result = std::make_shared< null_json >(); } }; template<> struct value_action< pegtl::json::true_ > { static void apply( const pegtl::input &, result_state & result ) { result.result = std::make_shared< boolean_json >( true ); } }; template<> struct value_action< pegtl::json::false_ > { static void apply( const pegtl::input &, result_state & result ) { result.result = std::make_shared< boolean_json >( false ); } }; template<> struct value_action< pegtl::json::number > { static void apply( const pegtl::input & in, result_state & result ) { result.result = std::make_shared< number_json >( std::stold( in.string() ) ); // NOTE: stold() is not quite correct for JSON but we'll use it for this simple example. } }; // State and action classes to accumulate the data for a JSON array. struct array_state : public result_state { std::shared_ptr< array_json > array = std::make_shared< array_json >(); void push_back() { array->data.push_back( std::move( result ) ); result.reset(); } void success( result_state & result ) { if ( this->result ) { push_back(); } result.result = array; } }; template< typename Rule > struct array_action : pegtl::nothing< Rule > {}; template<> struct array_action< pegtl::json::value_separator > { static void apply( const pegtl::input &, array_state & result ) { result.push_back(); } }; // State and action classes to accumulate the data for a JSON object. struct object_state : public result_state { std::string unescaped; std::shared_ptr< object_json > object = std::make_shared< object_json >(); void insert() { object->data.insert( std::make_pair( std::move( unescaped ), std::move( result ) ) ); unescaped.clear(); result.reset(); } void success( result_state & result ) { if ( this->result ) { insert(); } result.result = object; } }; template< typename Rule > struct object_action : unescape_action< Rule > {}; template<> struct object_action< pegtl::json::value_separator > { static void apply( const pegtl::input &, object_state & result ) { result.insert(); } }; // Put together a control class that changes the actions and states as required. template< typename Rule > struct control : errors< Rule > {}; // Inherit from json_errors.hh. template<> struct control< pegtl::json::value > : pegtl::change_action< pegtl::json::value, value_action, errors > {}; template<> struct control< pegtl::json::string::content > : pegtl::change_state< pegtl::json::string::content, string_state, errors > {}; template<> struct control< pegtl::json::array::content > : pegtl::change_state_and_action< pegtl::json::array::content, array_state, array_action, errors > {}; template<> struct control< pegtl::json::object::content > : pegtl::change_state_and_action< pegtl::json::object::content, object_state, object_action, errors > {}; struct grammar : pegtl::must< pegtl::json::text, pegtl::eof > {}; } // examples int main( int argc, char ** argv ) { for ( int i = 1; i < argc; ++i ) { examples::result_state result; pegtl::file_parser( argv[ i ] ).parse< examples::grammar, pegtl::nothing, examples::control >( result ); assert( result.result ); std::cout << result.result << std::endl; } return 0; } PEGTL-1.3.1/examples/json_build_two.cc000066400000000000000000000113131270130067200175320ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include #include #include #include #include "json_errors.hh" #include "json_classes.hh" #include "json_unescape.hh" namespace examples { // State class that stores the result of a JSON parsing run -- a single JSON object. // The other members are used temporarily, at the end of a (successful) parsing run // they are expected to be empty. struct json_state { std::shared_ptr< json_base > result; std::vector< std::string > keys; std::vector< std::shared_ptr< array_json > > arrays; std::vector< std::shared_ptr< object_json > > objects; }; // Action and Control classes template< typename Rule > struct action : unescape_action< Rule > {}; // Inherit from json_unescape.hh. template< typename Rule > struct control : errors< Rule > {}; // Inherit from json_errors.hh. template<> struct action< pegtl::json::null > { static void apply( const pegtl::input &, json_state & state ) { state.result = std::make_shared< null_json >(); } }; template<> struct action< pegtl::json::true_ > { static void apply( const pegtl::input &, json_state & state ) { state.result = std::make_shared< boolean_json >( true ); } }; template<> struct action< pegtl::json::false_ > { static void apply( const pegtl::input &, json_state & state ) { state.result = std::make_shared< boolean_json >( false ); } }; template<> struct action< pegtl::json::number > { static void apply( const pegtl::input & in, json_state & state ) { state.result = std::make_shared< number_json >( std::stold( in.string() ) ); // NOTE: stold() is not quite correct for JSON but we'll use it for this simple example. } }; // To parse a string, we change the state to decouple string parsing/unescaping struct string_state : public unescape_state_base { void success( json_state & state ) { state.result = std::make_shared< string_json >( unescaped ); } }; template<> struct control< pegtl::json::string::content > : pegtl::change_state< pegtl::json::string::content, string_state, errors > {}; template<> struct action< pegtl::json::array::begin > { static void apply( const pegtl::input &, json_state & state ) { state.arrays.push_back( std::make_shared< array_json >() ); } }; template<> struct action< pegtl::json::array::element > { static void apply( const pegtl::input &, json_state & state ) { state.arrays.back()->data.push_back( std::move( state.result ) ); } }; template<> struct action< pegtl::json::array::end > { static void apply( const pegtl::input &, json_state & state ) { state.result = std::move( state.arrays.back() ); state.arrays.pop_back(); } }; template<> struct action< pegtl::json::object::begin > { static void apply( const pegtl::input &, json_state & state ) { state.objects.push_back( std::make_shared< object_json >() ); } }; // To parse a key, we change the state to decouple string parsing/unescaping struct key_state : unescape_state_base { void success( json_state & state ) { state.keys.push_back( std::move( unescaped ) ); } }; template<> struct control< pegtl::json::key::content > : pegtl::change_state< pegtl::json::key::content, key_state, errors > {}; template<> struct action< pegtl::json::object::element > { static void apply( const pegtl::input &, json_state & state ) { state.objects.back()->data[ std::move( state.keys.back() ) ] = std::move( state.result ); state.keys.pop_back(); } }; template<> struct action< pegtl::json::object::end > { static void apply( const pegtl::input &, json_state & state ) { state.result = std::move( state.objects.back() ); state.objects.pop_back(); } }; using grammar = pegtl::must< pegtl::json::text, pegtl::eof >; } int main( int argc, char ** argv ) { if ( argc != 2 ) { std::cerr << "usage: " << argv[ 0 ] << " "; } else { examples::json_state state; pegtl::file_parser( argv[ 1 ] ).parse< examples::grammar, examples::action, examples::control >( state ); assert( state.keys.empty() ); assert( state.arrays.empty() ); assert( state.objects.empty() ); std::cout << state.result << std::endl; } return 0; } PEGTL-1.3.1/examples/json_classes.hh000066400000000000000000000110061270130067200172100ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_EXAMPLES_JSON_CLASSES_HH #define PEGTL_EXAMPLES_JSON_CLASSES_HH #include #include #include #include #include namespace examples { enum class json_type { ARRAY, BOOLEAN, NULL_, NUMBER, OBJECT, STRING }; class json_base { public: const json_type type; virtual void stream( std::ostream & ) const = 0; protected: explicit json_base( const json_type type ) : type( type ) { } ~json_base() { } }; inline std::ostream & operator<< ( std::ostream & o, const json_base & j ) { j.stream( o ); return o; } inline std::ostream & operator<< ( std::ostream & o, const std::shared_ptr< json_base > & j ) { return j ? ( o << * j ) : ( o << "NULL" ); } struct array_json : public json_base { array_json() : json_base( json_type::ARRAY ) { } std::vector< std::shared_ptr< json_base > > data; virtual void stream( std::ostream & o ) const override { o << '['; if ( ! data.empty() ) { auto iter = data.begin(); o << * iter; while ( ++iter != data.end() ) { o << ',' << * iter; } } o << ']'; } }; struct boolean_json : public json_base { explicit boolean_json( const bool data) : json_base( json_type::BOOLEAN ), data( data ) { } bool data; virtual void stream( std::ostream & o ) const override { o << ( data ? "true" : "false" ); } }; struct null_json : public json_base { null_json() : json_base( json_type::NULL_ ) { } virtual void stream( std::ostream & o ) const override { o << "null"; } }; struct number_json : public json_base { explicit number_json( const long double data ) : json_base( json_type::NUMBER ), data( data ) { } long double data; virtual void stream( std::ostream & o ) const override { o << data; } }; inline std::string json_escape( const std::string & data ) { std::string r = "\""; r.reserve( data.size() + 4 ); static const char * h = "0123456789abcdef"; const unsigned char * d = reinterpret_cast< const unsigned char * >( data.data() ); for ( size_t i = 0; i < data.size(); ++i ) { switch ( const auto c = d[ i ] ) { case '\b': r += "\\b"; break; case '\f': r += "\\f"; break; case '\n': r += "\\n"; break; case '\r': r += "\\r"; break; case '\t': r += "\\t"; break; case '\\': r += "\\\\"; break; case '\"': r += "\\\""; break; default: if ( ( c < 32 ) || ( c == 127 ) ) { r += "\\u00"; r += h[ ( c & 0xf0 ) >> 4 ]; r += h[ c & 0x0f ]; continue; } r += c; // Assume valid UTF-8. break; } } r += '"'; return r; } struct string_json : public json_base { explicit string_json( const std::string & data ) : json_base( json_type::STRING ), data( data ) { } std::string data; virtual void stream( std::ostream & o ) const override { o << json_escape( data ); } }; struct object_json : public json_base { object_json() : json_base( json_type::OBJECT ) { } std::map< std::string, std::shared_ptr< json_base > > data; virtual void stream( std::ostream & o ) const override { o << '{'; if ( ! data.empty() ) { auto iter = data.begin(); o << json_escape( iter->first ) << ':' << iter->second; while ( ++iter != data.end() ) { o << ',' << json_escape( iter->first ) << ':' << iter->second; } } o << '}'; } }; } // examples #endif PEGTL-1.3.1/examples/json_errors.hh000066400000000000000000000054051270130067200170750ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_EXAMPLES_JSON_ERRORS_HH #define PEGTL_EXAMPLES_JSON_ERRORS_HH #include #include namespace examples { // This file shows how to throw exceptions with // custom error messages for parse errors. A custom // control class is created that delegates everything // to the PEGTL default control class pegtl::normal<> // except for the throwing of exceptions: template< typename Rule > struct errors : public pegtl::normal< Rule > { static const std::string error_message; template< typename Input, typename ... States > static void raise( const Input & in, States && ... ) { throw pegtl::parse_error( error_message, in ); } }; // The following specialisations of the static string // member are then used in the exception messages: template<> const std::string errors< pegtl::json::text >::error_message = "no valid JSON"; template<> const std::string errors< pegtl::json::end_array >::error_message = "incomplete array, expected ']'"; template<> const std::string errors< pegtl::json::end_object >::error_message = "incomplete object, expected '}'"; template<> const std::string errors< pegtl::json::member >::error_message = "expected member"; template<> const std::string errors< pegtl::json::name_separator >::error_message = "expected ':'"; template<> const std::string errors< pegtl::json::array_element >::error_message = "expected value"; template<> const std::string errors< pegtl::json::value >::error_message = "expected value"; template<> const std::string errors< pegtl::json::digits >::error_message = "expected at least one digit"; template<> const std::string errors< pegtl::json::xdigit >::error_message = "incomplete universal character name"; template<> const std::string errors< pegtl::json::escaped >::error_message = "unknown escape sequence"; template<> const std::string errors< pegtl::json::char_ >::error_message = "invalid character in string"; template<> const std::string errors< pegtl::json::string::content >::error_message = "unterminated string"; template<> const std::string errors< pegtl::json::key::content >::error_message = "unterminated key"; template<> const std::string errors< pegtl::eof >::error_message = "unexpected character after JSON value"; // The raise()-function-template is instantiated exactly // for the specialisations of errors< Rule > for which a // parse error can be generated, therefore the string // error_message needs to be supplied only for these rules // (and the compiler will complain if one is missing). } // examples #endif PEGTL-1.3.1/examples/json_parse.cc000066400000000000000000000006161270130067200166600ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "json_errors.hh" using grammar = pegtl::must< pegtl::json::text, pegtl::eof >; int main( int argc, char ** argv ) { for ( int i = 1; i < argc; ++i ) { pegtl::parse< grammar, pegtl::nothing, examples::errors >( i, argv ); } return 0; } PEGTL-1.3.1/examples/json_unescape.hh000066400000000000000000000023601270130067200173610ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_EXAMPLES_JSON_UNESCAPE_HH #define PEGTL_EXAMPLES_JSON_UNESCAPE_HH #include #include #include #include namespace examples { // State base class to store an unescaped string struct unescape_state_base { unescape_state_base() = default; unescape_state_base( const unescape_state_base & ) = delete; void operator= ( const unescape_state_base & ) = delete; std::string unescaped; }; // Action class for parsing literal strings, uses the PEGTL unescape utilities, cf. unescape.cc. template< typename Rule, template< typename ... > class Base = pegtl::nothing > struct unescape_action : Base< Rule > {}; template<> struct unescape_action< pegtl::json::unicode > : pegtl::unescape::unescape_j {}; template<> struct unescape_action< pegtl::json::escaped_char > : pegtl::unescape::unescape_c< pegtl::json::escaped_char, '"', '\\', '/', '\b', '\f', '\n', '\r', '\t' > {}; template<> struct unescape_action< pegtl::json::unescaped > : pegtl::unescape::append_all {}; } // examples #endif PEGTL-1.3.1/examples/lua53_parse.cc000066400000000000000000000437201270130067200166430ustar00rootroot00000000000000// Copyright (c) 2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include #include #include namespace lua53 { // PEG version of the Lua 5.3.0 lexer and parser. // // The grammar here is not very similar to the grammar // in the Lua reference documentation on which it is based // which is due to multiple causes. // // The PEG approach combines lexer and parser, so the grammar // here really contains "everything" including comments and // everything else that would normally be done by a lexer. // // The second necessary difference is that all left-recursion // was eliminated. // // Also literal constants are included with all their details, // i.e. all forms of numeric constants, and escape sequences // in literal strings are all there. // // The operator precedence and associativity is also reflected // in this grammar which the documented Lua grammar omits. // // In some places the grammar was optimised to require as little // back-tracking as possible, most prominently for expressions. // The original grammar contains the following prodcutions rules: // // prefixexp ::= var | functioncall | ‘(’ exp ‘)’ // functioncall ::= prefixexp args | prefixexp ‘:’ Name args // var ::= Name | prefixexp ‘[’ exp ‘]’ | prefixexp ‘.’ Name // // We need to eliminate the left-recursion, and we also want to // remove the ambiguity between function calls and variables, // i.e. the fact that we can have expressions like // // ( a * b ).c()[ d ].e:f() // // where only the last element decides between function call and // variable. As first step we eliminate prefixexp and obtain: // // functioncall ::= ( var | functioncall | ‘(’ exp ‘)’ ) ( args | ‘:’ Name args ) // var ::= Name | ( var | functioncall | ‘(’ exp ‘)’ ) ( ‘[’ exp ‘]’ | ‘.’ Name ) // // Next we split function_call and variable into a first part, // a "head" or how they can start, and a second part, the "tail" // which, in a sequence like above, is the final deciding part. // // vartail ::= '[' exp ']' | '.' Name // varhead ::= Name | '(' exp ')' vartail // functail ::= args | ':' Name args // funchead ::= Name | '(' exp ')' // // This allows us to rewrite var and function_call as follows. // // var ::= varhead { { functail } vartail } // function_call ::= funchead [ { vartail } functail ] // // Finally we can define a single expression that takes care // of var, function_call, and expressions in a bracket: // // chead ::= '(' exp ')' | Name // combined ::= chead { functail | vartail } // // We have a name or a bracketed expression as head, and can // append arbitrarily many function_call or var tail parts, // all in a single grammar rule without back-tracking. // // The rule expr_thirteen below implements this "combined". // // Another issue of interest when writing a PEG is how to // manage the separators, the white-space and comments that // can occur in many places, and are taken care of by the // lexer when using the two-stage lexer-parser approach. // // In the following grammar most rules adopt the convention // that they take care of "internal padding", i.e. spaces // and comments that can occur within the rule, but not // "external padding", i.e. they don't start or end with // a rule that "eats up" all extra padding (spaces and // comments). In some places, where it is more efficient, // right padding is used. struct short_comment : pegtl::until< pegtl::eolf > {}; struct long_string : pegtl::raw_string< '[', '=', ']' > {}; struct comment : pegtl::disable< pegtl::two< '-' >, pegtl::sor< long_string, short_comment > > {}; struct sep : pegtl::sor< pegtl::ascii::space, comment > {}; struct seps : pegtl::star< sep > {}; struct str_and : pegtl_string_t( "and" ) {}; struct str_break : pegtl_string_t( "break" ) {}; struct str_do : pegtl_string_t( "do" ) {}; struct str_else : pegtl_string_t( "else" ) {}; struct str_elseif : pegtl_string_t( "elseif" ) {}; struct str_end : pegtl_string_t( "end" ) {}; struct str_false : pegtl_string_t( "false" ) {}; struct str_for : pegtl_string_t( "for" ) {}; struct str_function : pegtl_string_t( "function" ) {}; struct str_goto : pegtl_string_t( "goto" ) {}; struct str_if : pegtl_string_t( "if" ) {}; struct str_in : pegtl_string_t( "in" ) {}; struct str_local : pegtl_string_t( "local" ) {}; struct str_nil : pegtl_string_t( "nil" ) {}; struct str_not : pegtl_string_t( "not" ) {}; struct str_or : pegtl_string_t( "or" ) {}; struct str_repeat : pegtl_string_t( "repeat" ) {}; struct str_return : pegtl_string_t( "return" ) {}; struct str_then : pegtl_string_t( "then" ) {}; struct str_true : pegtl_string_t( "true" ) {}; struct str_until : pegtl_string_t( "until" ) {}; struct str_while : pegtl_string_t( "while" ) {}; // Note that 'elseif' precedes 'else' in order to prevent only matching // the "else" part of an "elseif" and running into an error in the // 'keyword' rule. struct str_keyword : pegtl::sor< str_and, str_break, str_do, str_elseif, str_else, str_end, str_false, str_for, str_function, str_goto, str_if, str_in, str_local, str_nil, str_not, str_repeat, str_return, str_then, str_true, str_until, str_while > {}; template< typename Key > struct key : pegtl::seq< Key, pegtl::not_at< pegtl::identifier_other > > {}; struct key_and : key< str_and > {}; struct key_break : key< str_break > {}; struct key_do : key< str_do > {}; struct key_else : key< str_else > {}; struct key_elseif : key< str_elseif > {}; struct key_end : key< str_end > {}; struct key_false : key< str_false > {}; struct key_for : key< str_for > {}; struct key_function : key< str_function > {}; struct key_goto : key< str_goto > {}; struct key_if : key< str_if > {}; struct key_in : key< str_in > {}; struct key_local : key< str_local > {}; struct key_nil : key< str_nil > {}; struct key_not : key< str_not > {}; struct key_or : key< str_or > {}; struct key_repeat : key< str_repeat > {}; struct key_return : key< str_return > {}; struct key_then : key< str_then > {}; struct key_true : key< str_true > {}; struct key_until : key< str_until > {}; struct key_while : key< str_while > {}; struct keyword : key< str_keyword > {}; template< typename R > struct pad : pegtl::pad< R, sep > {}; struct three_dots : pegtl::string< '.', '.', '.' > {}; struct name : pegtl::seq< pegtl::not_at< keyword >, pegtl::identifier > {}; struct single : pegtl::one< 'a', 'b', 'f', 'n', 'r', 't', 'v', '\\', '"', '\'', '0', '\n' > {}; struct spaces : pegtl::seq< pegtl::one< 'z' >, pegtl::star< pegtl::space > > {}; struct hexbyte : pegtl::if_must< pegtl::one< 'x' >, pegtl::xdigit, pegtl::xdigit > {}; struct decbyte : pegtl::if_must< pegtl::digit, pegtl::rep_opt< 2, pegtl::digit > > {}; struct unichar : pegtl::if_must< pegtl::one< 'u' >, pegtl::one< '{' >, pegtl::plus< pegtl::xdigit >, pegtl::one< '}' > > {}; struct escaped : pegtl::if_must< pegtl::one< '\\' >, pegtl::sor< hexbyte, decbyte, unichar, single, spaces > > {}; struct regular : pegtl::not_one< '\r', '\n' > {}; struct character : pegtl::sor< escaped, regular > {}; template< char Q > struct short_string : pegtl::if_must< pegtl::one< Q >, pegtl::until< pegtl::one< Q >, character > > {}; struct literal_string : pegtl::sor< short_string< '"' >, short_string< '\'' >, long_string > {}; template< typename E > struct exponent : pegtl::opt< pegtl::if_must< E, pegtl::opt< pegtl::one< '+', '-' > >, pegtl::plus< pegtl::digit > > > {}; template< typename D, typename E > struct numeral_three : pegtl::seq< pegtl::if_must< pegtl::one< '.' >, pegtl::plus< D > >, exponent< E > > {}; template< typename D, typename E > struct numeral_two : pegtl::seq< pegtl::plus< D >, pegtl::opt< pegtl::one< '.' >, pegtl::star< D > >, exponent< E > > {}; template< typename D, typename E > struct numeral_one : pegtl::sor< numeral_two< D, E >, numeral_three< D, E > > {}; struct decimal : numeral_one< pegtl::digit, pegtl::one< 'e', 'E' > > {}; struct hexadecimal : pegtl::if_must< pegtl::istring< '0', 'x' >, numeral_one< pegtl::xdigit, pegtl::one< 'p', 'P' > > > {}; struct numeral : pegtl::sor< hexadecimal, decimal > {}; struct label_statement : pegtl::if_must< pegtl::two< ':' >, seps, name, seps, pegtl::two< ':' > > {}; struct goto_statement : pegtl::if_must< key_goto, seps, name > {}; struct statement; struct expression; struct name_list : pegtl::list< name, pegtl::one< ',' >, sep > {}; struct name_list_must : pegtl::list_must< name, pegtl::one< ',' >, sep > {}; struct expr_list_must : pegtl::list_must< expression, pegtl::one< ',' >, sep > {}; struct statement_return : pegtl::seq< pegtl::pad_opt< expr_list_must, sep >, pegtl::opt< pegtl::one< ';' >, seps > > {}; template< typename E > struct statement_list : pegtl::seq< seps, pegtl::until< pegtl::sor< E, pegtl::if_must< key_return, statement_return, E > >, statement, seps > > {}; struct table_field_one : pegtl::if_must< pegtl::one< '[' >, seps, expression, seps, pegtl::one< ']' >, seps, pegtl::one< '=' >, seps, expression > {}; struct table_field_two : pegtl::if_must< pegtl::seq< name, seps, pegtl::one< '=' > >, seps, expression > {}; struct table_field : pegtl::sor< table_field_one, table_field_two, expression > {}; struct table_field_list : pegtl::list_tail< table_field, pegtl::one< ',', ';' >, sep > {}; struct table_constructor : pegtl::if_must< pegtl::one< '{' >, pegtl::pad_opt< table_field_list, sep >, pegtl::one< '}' > > {}; struct parameter_list_one : pegtl::seq< name_list, pegtl::opt< pegtl::if_must< pad< pegtl::one< ',' > >, three_dots > > > {}; struct parameter_list : pegtl::sor< three_dots, parameter_list_one > {}; struct function_body : pegtl::seq< pegtl::one< '(' >, pegtl::pad_opt< parameter_list, sep >, pegtl::one< ')' >, seps, statement_list< key_end > > {}; struct function_literal : pegtl::if_must< key_function, seps, function_body > {}; struct bracket_expr : pegtl::if_must< pegtl::one< '(' >, seps, expression, seps, pegtl::one< ')' > > {}; struct function_args_one : pegtl::if_must< pegtl::one< '(' >, pegtl::pad_opt< expr_list_must, sep >, pegtl::one< ')' > > {}; struct function_args : pegtl::sor< function_args_one, table_constructor, literal_string > {}; struct variable_tail_one : pegtl::if_must< pegtl::one< '[' >, seps, expression, seps, pegtl::one< ']' > > {}; struct variable_tail_two : pegtl::if_must< pegtl::seq< pegtl::not_at< pegtl::two< '.' > >, pegtl::one< '.' > >, seps, name > {}; struct variable_tail : pegtl::sor< variable_tail_one, variable_tail_two > {}; struct function_call_tail_one : pegtl::if_must< pegtl::seq< pegtl::not_at< pegtl::two< ':' > >, pegtl::one< ':' > >, seps, name, seps, function_args > {}; struct function_call_tail : pegtl::sor< function_args, function_call_tail_one > {}; struct variable_head_one : pegtl::seq< bracket_expr, seps, variable_tail > {}; struct variable_head : pegtl::sor< name, variable_head_one > {}; struct function_call_head : pegtl::sor< name, bracket_expr > {}; struct variable : pegtl::seq< variable_head, pegtl::star< pegtl::star< seps, function_call_tail >, seps, variable_tail > > {}; struct function_call : pegtl::seq< function_call_head, pegtl::plus< pegtl::until< pegtl::seq< seps, function_call_tail >, seps, variable_tail > > > {}; template< char O, char ... N > struct op_one : pegtl::seq< pegtl::one< O >, pegtl::at< pegtl::not_one< N ... > > > {}; template< char O, char P, char ... N > struct op_two : pegtl::seq< pegtl::string< O, P >, pegtl::at< pegtl::not_one< N ... > > > {}; template< typename S, typename O > struct left_assoc : pegtl::seq< S, seps, pegtl::star< pegtl::if_must< O, seps, S, seps > > > {}; template< typename S, typename O > struct right_assoc : pegtl::seq< S, seps, pegtl::opt< pegtl::if_must< O, seps, right_assoc< S, O > > > > {}; struct unary_operators : pegtl::sor< pegtl::one< '-' >, pegtl::one< '#' >, op_one< '~', '=' >, key_not > {}; struct expr_ten; struct expr_thirteen : pegtl::seq< pegtl::sor< bracket_expr, name >, pegtl::star< seps, pegtl::sor< function_call_tail, variable_tail > > > {}; struct expr_twelve : pegtl::sor< key_nil, key_true, key_false, three_dots, numeral, literal_string, function_literal, expr_thirteen, table_constructor > {}; struct expr_eleven : pegtl::seq< expr_twelve, seps, pegtl::opt< pegtl::one< '^' >, seps, expr_ten, seps > > {}; struct unary_apply : pegtl::if_must< unary_operators, seps, expr_ten, seps > {}; struct expr_ten : pegtl::sor< unary_apply, expr_eleven > {}; struct operators_nine : pegtl::sor< pegtl::two< '/' >, pegtl::one< '/' >, pegtl::one< '*' >, pegtl::one< '%' > > {}; struct expr_nine : left_assoc< expr_ten, operators_nine > {}; struct operators_eight : pegtl::sor< pegtl::one< '+' >, pegtl::one< '-' > > {}; struct expr_eight : left_assoc< expr_nine, operators_eight > {}; struct expr_seven : right_assoc< expr_eight, op_two< '.', '.', '.' > > {}; struct operators_six : pegtl::sor< pegtl::two< '<' >, pegtl::two< '>' > > {}; struct expr_six : left_assoc< expr_seven, operators_six > {}; struct expr_five : left_assoc< expr_six, pegtl::one< '&' > > {}; struct expr_four : left_assoc< expr_five, op_one< '~', '=' > > {}; struct expr_three : left_assoc< expr_four, pegtl::one< '|' > > {}; struct operators_two : pegtl::sor< pegtl::two< '=' >, pegtl::string< '<', '=' >, pegtl::string< '>', '=' >, op_one< '<', '<' >, op_one< '>', '>' >, pegtl::string< '~', '=' > > {}; struct expr_two : left_assoc< expr_three, operators_two > {}; struct expr_one : left_assoc< expr_two, key_and > {}; struct expression : left_assoc< expr_one, key_or > {}; struct do_statement : pegtl::if_must< key_do, statement_list< key_end > > {}; struct while_statement : pegtl::if_must< key_while, seps, expression, seps, key_do, statement_list< key_end > > {}; struct repeat_statement : pegtl::if_must< key_repeat, statement_list< key_until >, seps, expression > {}; struct at_elseif_else_end : pegtl::sor< pegtl::at< key_elseif >, pegtl::at< key_else >, pegtl::at< key_end > > {}; struct elseif_statement : pegtl::if_must< key_elseif, seps, expression, seps, key_then, statement_list< at_elseif_else_end > > {}; struct else_statement : pegtl::if_must< key_else, statement_list< key_end > > {}; struct if_statement : pegtl::if_must< key_if, seps, expression, seps, key_then, statement_list< at_elseif_else_end >, seps, pegtl::until< pegtl::sor< else_statement, key_end >, elseif_statement, seps > > {}; struct for_statement_one : pegtl::seq< name, seps, pegtl::one< '=' >, seps, expression, seps, pegtl::one< ',' >, seps, expression, pegtl::pad_opt< pegtl::if_must< pegtl::one< ',' >, seps, expression >, sep >, key_do, statement_list< key_end > > {}; struct for_statement_two : pegtl::seq< name_list_must, seps, key_in, seps, expr_list_must, seps, key_do, statement_list< key_end > > {}; struct for_statement : pegtl::if_must< key_for, seps, pegtl::sor< for_statement_one, for_statement_two > > {}; struct assignment_variable_list : pegtl::list_must< variable, pegtl::one< ',' >, sep > {}; struct assignments_one : pegtl::if_must< pegtl::one< '=' >, seps, expr_list_must > {}; struct assignments : pegtl::seq< assignment_variable_list, seps, assignments_one > {}; struct function_name : pegtl::seq< pegtl::list< name, pegtl::one< '.' >, sep >, seps, pegtl::opt< pegtl::if_must< pegtl::one< ':' >, seps, name, seps > > > {}; struct function_definition : pegtl::if_must< key_function, seps, function_name, function_body > {}; struct local_function : pegtl::if_must< key_function, seps, name, seps, function_body > {}; struct local_variables : pegtl::if_must< name_list_must, seps, pegtl::opt< assignments_one > > {}; struct local_statement : pegtl::if_must< key_local, seps, pegtl::sor< local_function, local_variables > > {}; struct semicolon : pegtl::one< ';' > {}; struct statement : pegtl::sor< semicolon, assignments, function_call, label_statement, key_break, goto_statement, do_statement, while_statement, repeat_statement, if_statement, for_statement, function_definition, local_statement > {}; struct interpreter : pegtl::seq< pegtl::one< '#' >, pegtl::until< pegtl::eolf > > {}; struct grammar : pegtl::must< pegtl::opt< interpreter >, statement_list< pegtl::eof > > {}; } // lua53 int main( int argc, char ** argv ) { pegtl::analyze< lua53::grammar >(); for ( int i = 1; i < argc; ++i ) { pegtl::file_parser( argv[ i ] ).parse< lua53::grammar >(); } return 0; } PEGTL-1.3.1/examples/modulus_match.cc000066400000000000000000000017031270130067200173570ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include namespace modulus { template< unsigned M, unsigned R = 0 > struct my_rule { using analyze_t = pegtl::analysis::generic< pegtl::analysis::rule_type::ANY >; static_assert( M > 1, "Modulus must be greater than 1" ); static_assert( R < M, "Remainder must be less than modulus" ); template< typename Input > static bool match( Input & in ) { if ( in.size() ) { if ( ( ( * in.begin() ) % M ) == R ) { in.bump( 1 ); return true; } } return false; } }; struct grammar : pegtl::until< pegtl::eolf, pegtl::must< my_rule< 3 > > > {}; } int main( int argc, char ** argv ) { if ( argc > 1 ) { pegtl::parse< modulus::grammar >( 1, argv ); } return 0; } PEGTL-1.3.1/examples/s_expression.cc000066400000000000000000000044471270130067200172440ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include #include #include #include namespace sexpr { using namespace pegtl; struct hash_comment : until< eolf > {}; struct list; struct list_comment : if_must< at< one< '(' > >, disable< list > > {}; struct read_include : seq< one< ' ' >, one< '"' >, plus< not_one< '"' > >, one< '"' > > {}; struct hash_include : if_must< string< 'i', 'n', 'c', 'l', 'u', 'd', 'e' >, read_include > {}; struct hashed : if_must< one< '#' >, sor< hash_include, list_comment, hash_comment > > {}; struct number : plus< digit > {}; struct symbol : identifier {}; struct atom : sor< number, symbol > {}; struct anything; struct list : if_must< one< '(' >, until< one< ')' >, anything > > {}; struct normal : sor< atom, list > {}; struct anything : sor< space, hashed, normal > {}; struct main : until< eof, must< anything > > {}; template< typename Rule > struct action : nothing< Rule > {}; template<> struct action< plus< not_one< '"' > > > { template< typename Input > static void apply( const Input & in, std::string & fn ) { fn = in.string(); } }; template<> struct action< hash_include > { template< typename Input > static void apply( const Input & in, std::string & fn ) { std::string f2; // Here f2 is the state argument for the nested parsing // run (to store the value of the string literal like in // the upper-level parsing run), fn is the value of the // last string literal that we use as filename here, and // the input is passed on for chained error messages (as // in "error in line x file foo included from file bar...) file_parser( fn, in ).parse< main, sexpr::action >( f2 ); } }; } // sexpr int main( int argc, char ** argv ) { pegtl::analyze< sexpr::main >(); for ( int i = 1; i < argc; ++i ) { std::string fn; pegtl::parse< sexpr::main, sexpr::action >( i, argv, fn ); } return 0; } PEGTL-1.3.1/examples/sum.cc000066400000000000000000000025731270130067200153250ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include #include #include #include "double.hh" namespace sum { struct padded_double : pegtl::pad< double_::grammar, pegtl::space > {}; struct double_list : pegtl::list< padded_double, pegtl::one< ',' > > {}; struct grammar : pegtl::seq< double_list, pegtl::eof > {}; template< typename Rule > struct action : pegtl::nothing< Rule > {}; template<> struct action< double_::grammar > { static void apply( const pegtl::input & in, double & sum ) { // assume all values will fit into a C++ double sum += std::stod( in.string() ); } }; } // sum int main() { std::cout << "Give me a comma separated list of numbers.\n"; std::cout << "The numbers are added using the PEGTL.\n"; std::cout << "Type [q or Q] to quit\n\n"; std::string str; while ( std::getline( std::cin, str ) ) { if ( str.empty() || str[ 0 ] == 'q' || str[ 0 ] == 'Q' ) { break; } double d = 0.0; if ( pegtl::parse< sum::grammar, sum::action >( str, "std::cin", d ) ) { std::cout << "parsing OK; sum = " << d << std::endl; } else { std::cout << "parsing failed" << std::endl; } } } PEGTL-1.3.1/examples/unescape.cc000066400000000000000000000047641270130067200163300ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include #include #include namespace unescape { // Grammar for string literals with some escape sequences from the C language: // - \x followed by two hex-digits to insert any byte value. // - \u followed by four hex-digits to insert a Unicode code point. // - \U followed by eight hex-digits to insert any Unicdoe code points. // - A backslash followed by one of the characters listed in the grammar below. struct escaped_x : pegtl::seq< pegtl::one< 'x' >, pegtl::rep< 2, pegtl::must< pegtl::xdigit > > > {}; struct escaped_u : pegtl::seq< pegtl::one< 'u' >, pegtl::rep< 4, pegtl::must< pegtl::xdigit > > > {}; struct escaped_U : pegtl::seq< pegtl::one< 'U' >, pegtl::rep< 8, pegtl::must< pegtl::xdigit > > > {}; struct escaped_c : pegtl::one< '\'', '"', '?', '\\', 'a', 'b', 'f', 'n', 'r', 't', 'v' > {}; struct escaped : pegtl::sor< escaped_x, escaped_u, escaped_U, escaped_c > {}; struct character : pegtl::if_must_else< pegtl::one< '\\' >, escaped, pegtl::utf8::range< 0x20, 0x10FFFF > > {}; struct literal : pegtl::if_must< pegtl::one< '"' >, pegtl::until< pegtl::one< '"' >, character > > {}; struct padded : pegtl::must< pegtl::pad< literal, pegtl::blank >, pegtl::eof > {}; // Action class that uses the actions from pegtl/contrib/unescape.hh to // produce a UTF-8 encoded result string where all escape sequences are // replaced with their intended meaning. template< typename Rule > struct action : pegtl::nothing< Rule > {}; template<> struct action< pegtl::utf8::range< 0x20, 0x10FFFF > > : pegtl::unescape::append_all {}; template<> struct action< escaped_x > : pegtl::unescape::unescape_x {}; template<> struct action< escaped_u > : pegtl::unescape::unescape_u {}; template<> struct action< escaped_U > : pegtl::unescape::unescape_u {}; template<> struct action< escaped_c > : pegtl::unescape::unescape_c< escaped_c, '\'', '"', '?', '\\', '\a', '\b', '\f', '\n', '\r', '\t', '\v' > {}; } // unescape int main( int argc, char ** argv ) { for ( int i = 1; i < argc; ++i ) { pegtl::unescape::state s; pegtl::parse< unescape::padded, unescape::action >( i, argv, s ); std::cout << "argv[ " << i << " ] = " << s.unescaped << std::endl; } return 0; } PEGTL-1.3.1/examples/uri_trace.cc000066400000000000000000000007401270130067200164700ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include #include #include #include using grammar = pegtl::must< pegtl::uri::URI >; int main( int argc, char ** argv ) { for ( int i = 1; i < argc; ++i ) { std::cout << "Parsing " << argv[ i ] << std::endl; pegtl::trace< grammar >( i, argv ); } return 0; } PEGTL-1.3.1/pegtl.hh000066400000000000000000000010371270130067200140220ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_HH #define PEGTL_HH #include "pegtl/input.hh" #include "pegtl/parse.hh" #include "pegtl/rules.hh" #include "pegtl/ascii.hh" #include "pegtl/utf8.hh" #include "pegtl/utf16.hh" #include "pegtl/utf32.hh" // Not included by default; // safe to use when needed: // #include "pegtl/trace.hh" // #include "pegtl/analyze.hh" #include "pegtl/data_parser.hh" #include "pegtl/file_parser.hh" #endif PEGTL-1.3.1/pegtl/000077500000000000000000000000001270130067200135005ustar00rootroot00000000000000PEGTL-1.3.1/pegtl/analysis/000077500000000000000000000000001270130067200153235ustar00rootroot00000000000000PEGTL-1.3.1/pegtl/analysis/analyze_cycles.hh000066400000000000000000000076421270130067200206620ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_ANALYSIS_ANALYZE_CYCLES_HH #define PEGTL_ANALYSIS_ANALYZE_CYCLES_HH #include #include #include #include #include #include "grammar_info.hh" #include "insert_guard.hh" namespace pegtl { namespace analysis { class analyze_cycles_impl { protected: explicit analyze_cycles_impl( const bool verbose ) : m_verbose( verbose ), m_problems( 0 ) { } const bool m_verbose; unsigned m_problems; grammar_info m_info; std::set< std::string > m_stack; std::map< std::string, bool > m_cache; std::map< std::string, bool > m_results; const std::map< std::string, rule_info >::const_iterator find( const std::string & name ) const { const auto iter = m_info.map.find( name ); assert( iter != m_info.map.end() ); return iter; } bool work( const std::map< std::string, rule_info >::const_iterator & start, const bool accum ) { const auto j = m_cache.find( start->first ); if ( j != m_cache.end() ) { return j->second; } if ( const auto g = make_insert_guard( m_stack, start->first ) ) { switch ( start->second.type ) { case rule_type::ANY: { bool a = false; for ( const auto & r : start->second.rules ) { a |= work( find( r ), accum || a ); } return m_cache[ start->first ] = true; } case rule_type::OPT: { bool a = false; for ( const auto & r : start->second.rules ) { a |= work( find( r ), accum || a ); } return m_cache[ start->first ] = false; } case rule_type::SEQ: { bool a = false; for ( const auto & r : start->second.rules ) { a |= work( find( r ), accum || a ); } return m_cache[ start->first ] = a; } case rule_type::SOR: { bool a = true; for ( const auto & r : start->second.rules ) { a &= work( find( r ), accum ); } return m_cache[ start->first ] = a; } } assert( false ); // LCOV_EXCL_LINE } if ( ! accum ) { ++m_problems; if ( m_verbose ) { std::cout << "problem: cycle without progress detected at rule class " << start->first << std::endl; } } return m_cache[ start->first ] = accum; } }; template< typename Grammar > class analyze_cycles : private analyze_cycles_impl { public: explicit analyze_cycles( const bool verbose ) : analyze_cycles_impl( verbose ) { Grammar::analyze_t::template insert< Grammar >( m_info ); } std::size_t problems() { for ( auto i = m_info.map.begin(); i != m_info.map.end(); ++i ) { m_results[ i->first ] = work( i, false ); m_cache.clear(); } return m_problems; } template< typename Rule > bool consumes() const { const auto i = m_results.find( internal::demangle< Rule >() ); assert( i != m_results.end() ); return i->second; } }; } // analysis } // pegtl #endif PEGTL-1.3.1/pegtl/analysis/counted.hh000066400000000000000000000007371270130067200173140ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_ANALYSIS_COUNTED_HH #define PEGTL_ANALYSIS_COUNTED_HH #include "generic.hh" namespace pegtl { namespace analysis { template< rule_type Type, unsigned Count, typename ... Rules > struct counted : generic< Count ? Type : rule_type::OPT, Rules ... > { }; } // analysis } // pegtl #endif PEGTL-1.3.1/pegtl/analysis/generic.hh000066400000000000000000000014071270130067200172620ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_ANALYSIS_GENERIC_HH #define PEGTL_ANALYSIS_GENERIC_HH #include "rule_type.hh" #include "insert_rules.hh" #include "grammar_info.hh" namespace pegtl { namespace analysis { template< rule_type Type, typename ... Rules > struct generic { template< typename Name > static std::string insert( grammar_info & g ) { const auto r = g.insert< Name >( Type ); if ( r.second ) { insert_rules< Rules ... >::insert( g, r.first->second ); } return r.first->first; } }; } // analysis } // pegtl #endif PEGTL-1.3.1/pegtl/analysis/grammar_info.hh000066400000000000000000000014031270130067200203030ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_ANALYSIS_GRAMMAR_INFO_HH #define PEGTL_ANALYSIS_GRAMMAR_INFO_HH #include #include #include #include "../internal/demangle.hh" #include "rule_info.hh" namespace pegtl { namespace analysis { struct grammar_info { using map_t = std::map< std::string, rule_info >; map_t map; template< typename Name > std::pair< map_t::iterator, bool > insert( const rule_type type ) { return map.insert( map_t::value_type( internal::demangle< Name >(), rule_info( type ) ) ); } }; } // analysis } // pegtl #endif PEGTL-1.3.1/pegtl/analysis/insert_guard.hh000066400000000000000000000024121270130067200203310ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_ANALYSIS_INSERT_GUARD_HH #define PEGTL_ANALYSIS_INSERT_GUARD_HH namespace pegtl { namespace analysis { template< typename C > class insert_guard { public: insert_guard( insert_guard && g ) : m_i( g.m_i ), m_c( g.m_c ) { g.m_c = 0; } insert_guard( C & c, const typename C::value_type & t ) : m_i( c.insert( t ) ), m_c( & c ) { } ~insert_guard() { if ( m_c && m_i.second ) { m_c->erase( m_i.first ); } } insert_guard( const insert_guard & ) = delete; void operator= ( const insert_guard & ) = delete; explicit operator bool () const { return m_i.second; } private: const std::pair< typename C::iterator, bool > m_i; C * m_c; }; template< typename C, typename T > insert_guard< C > make_insert_guard( C & c, const T & t ) { return insert_guard< C >( c, t ); } } // analysis } // pegtl #endif PEGTL-1.3.1/pegtl/analysis/insert_rules.hh000066400000000000000000000015511270130067200203640ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_ANALYSIS_INSERT_RULES_HH #define PEGTL_ANALYSIS_INSERT_RULES_HH #include "rule_info.hh" #include "grammar_info.hh" namespace pegtl { namespace analysis { template< typename ... > struct insert_rules; template<> struct insert_rules<> { static void insert( grammar_info &, rule_info & ) { } }; template< typename Rule, typename ... Rules > struct insert_rules< Rule, Rules ... > { static void insert( grammar_info & g, rule_info & r ) { r.rules.push_back( Rule::analyze_t::template insert< Rule >( g ) ); insert_rules< Rules ... >::insert( g, r ); } }; } // analysis } // pegtl #endif PEGTL-1.3.1/pegtl/analysis/rule_info.hh000066400000000000000000000010701270130067200176240ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_ANALYSIS_RULE_INFO_HH #define PEGTL_ANALYSIS_RULE_INFO_HH #include #include #include "rule_type.hh" namespace pegtl { namespace analysis { struct rule_info { explicit rule_info( const rule_type type ) : type( type ) { } rule_type type; std::vector< std::string > rules; }; } // analysis } // pegtl #endif PEGTL-1.3.1/pegtl/analysis/rule_type.hh000066400000000000000000000014741270130067200176620ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_ANALYSIS_RULE_TYPE_HH #define PEGTL_ANALYSIS_RULE_TYPE_HH namespace pegtl { namespace analysis { enum class rule_type : char { ANY, // Consumption-on-success is always true; assumes bounded repetition of conjunction of sub-rules. OPT, // Consumption-on-success not necessarily true; assumes bounded repetition of conjunction of sub-rules. SEQ, // Consumption-on-success depends on consumption of (non-zero bounded repetition of) conjunction of sub-rules. SOR // Consumption-on-success depends on consumption of (non-zero bounded repetition of) disjunction of sub-rules. }; } // analysis } // pegtl #endif PEGTL-1.3.1/pegtl/analyze.hh000066400000000000000000000006511270130067200154660ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_ANALYZE_HH #define PEGTL_ANALYZE_HH #include "analysis/analyze_cycles.hh" namespace pegtl { template< typename Rule > std::size_t analyze( const bool verbose = true ) { return analysis::analyze_cycles< Rule >( verbose ).problems(); } } // pegtl #endif PEGTL-1.3.1/pegtl/apply_mode.hh000066400000000000000000000004761270130067200161610ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_APPLY_MODE_HH #define PEGTL_APPLY_MODE_HH namespace pegtl { enum class apply_mode : bool { ACTION = true, NOTHING = false }; } // pegtl #endif PEGTL-1.3.1/pegtl/ascii.hh000066400000000000000000000056651270130067200151250ustar00rootroot00000000000000// Copyright (c) 2014-2016 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_ASCII_HH #define PEGTL_ASCII_HH #include "internal/rules.hh" #include "internal/result_on_found.hh" namespace pegtl { inline namespace ascii { struct alnum : internal::ranges< internal::peek_char, 'a', 'z', 'A', 'Z', '0', '9' > {}; struct alpha : internal::ranges< internal::peek_char, 'a', 'z', 'A', 'Z' > {}; struct any : internal::any< internal::peek_char > {}; struct blank : internal::one< internal::result_on_found::SUCCESS, internal::peek_char, ' ', '\t' > {}; struct digit : internal::range< internal::result_on_found::SUCCESS, internal::peek_char, '0', '9' > {}; struct eol : internal::eol {}; struct eolf : internal::eolf {}; struct identifier_first : internal::ranges< internal::peek_char, 'a', 'z', 'A', 'Z', '_' > {}; struct identifier_other : internal::ranges< internal::peek_char, 'a', 'z', 'A', 'Z', '0', '9', '_' > {}; struct identifier : internal::seq< identifier_first, internal::star< identifier_other > > {}; template< char ... Cs > struct istring : internal::istring< Cs ... > {}; struct lower : internal::range< internal::result_on_found::SUCCESS, internal::peek_char, 'a', 'z' > {}; template< char ... Cs > struct not_one : internal::one< internal::result_on_found::FAILURE, internal::peek_char, Cs ... > {}; template< char Lo, char Hi > struct not_range : internal::range< internal::result_on_found::FAILURE, internal::peek_char, Lo, Hi > {}; struct nul : internal::one< internal::result_on_found::SUCCESS, internal::peek_char, char( 0 ) > {}; template< char ... Cs > struct one : internal::one< internal::result_on_found::SUCCESS, internal::peek_char, Cs ... > {}; struct print : internal::range< internal::result_on_found::SUCCESS, internal::peek_char, char( 32 ), char( 126 ) > {}; template< char Lo, char Hi > struct range : internal::range< internal::result_on_found::SUCCESS, internal::peek_char, Lo, Hi > {}; template< char ... Cs > struct ranges : internal::ranges< internal::peek_char, Cs ... > {}; struct seven : internal::range< internal::result_on_found::SUCCESS, internal::peek_char, char( 0 ), char( 127 ) > {}; struct shebang : internal::if_must< internal::string< '#', '!' >, internal::until< internal::eolf > > {}; struct space : internal::one< internal::result_on_found::SUCCESS, internal::peek_char, ' ', '\n', '\r', '\t', '\v', '\f' > {}; template< char ... Cs > struct string : internal::string< Cs ... > {}; template< char C > struct two : internal::string< C, C > {}; struct upper : internal::range< internal::result_on_found::SUCCESS, internal::peek_char, 'A', 'Z' > {}; struct xdigit : internal::ranges< internal::peek_char, '0', '9', 'a', 'f', 'A', 'F' > {}; } // ascii } // pegtl #include "internal/pegtl_string.hh" #endif PEGTL-1.3.1/pegtl/contrib/000077500000000000000000000000001270130067200151405ustar00rootroot00000000000000PEGTL-1.3.1/pegtl/contrib/abnf.hh000066400000000000000000000040671270130067200163760ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_CONTRIB_ABNF_HH #define PEGTL_CONTRIB_ABNF_HH #include "../internal/rules.hh" namespace pegtl { namespace abnf { // Core ABNF rules according to RFC 5234, Appendix B struct ALPHA : internal::ranges< internal::peek_char, 'a', 'z', 'A', 'Z' > {}; struct BIT : internal::one< internal::result_on_found::SUCCESS, internal::peek_char, '0', '1' > {}; struct CHAR : internal::range< internal::result_on_found::SUCCESS, internal::peek_char, char( 1 ), char( 127 ) > {}; struct CR : internal::one< internal::result_on_found::SUCCESS, internal::peek_char, '\r' > {}; struct CRLF : internal::string< '\r', '\n' > {}; struct CTL : internal::ranges< internal::peek_char, char( 0 ), char( 31 ), char( 127 ) > {}; struct DIGIT : internal::range< internal::result_on_found::SUCCESS, internal::peek_char, '0', '9' > {}; struct DQUOTE : internal::one< internal::result_on_found::SUCCESS, internal::peek_char, '"' > {}; struct HEXDIG : internal::ranges< internal::peek_char, '0', '9', 'a', 'f', 'A', 'F' > {}; struct HTAB : internal::one< internal::result_on_found::SUCCESS, internal::peek_char, '\t' > {}; struct LF : internal::one< internal::result_on_found::SUCCESS, internal::peek_char, '\n' > {}; struct LWSP : internal::star< internal::sor< internal::string< '\r', '\n' >, internal::one< internal::result_on_found::SUCCESS, internal::peek_char, ' ', '\t' > >, internal::one< internal::result_on_found::SUCCESS, internal::peek_char, ' ', '\t' > > {}; struct OCTET : internal::any< internal::peek_char > {}; struct SP : internal::one< internal::result_on_found::SUCCESS, internal::peek_char, ' ' > {}; struct VCHAR : internal::range< internal::result_on_found::SUCCESS, internal::peek_char, char( 33 ), char( 126 ) > {}; struct WSP : internal::one< internal::result_on_found::SUCCESS, internal::peek_char, ' ', '\t' > {}; } // abnf } // pegtl #endif PEGTL-1.3.1/pegtl/contrib/alphabet.hh000066400000000000000000000036441270130067200172500ustar00rootroot00000000000000// Copyright (c) 2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_CONTRIB_ALPHABET_HH #define PEGTL_CONTRIB_ALPHABET_HH namespace pegtl { inline namespace alphabet { static const int a = 'a'; static const int b = 'b'; static const int c = 'c'; static const int d = 'd'; static const int e = 'e'; static const int f = 'f'; static const int g = 'g'; static const int h = 'h'; static const int i = 'i'; static const int j = 'j'; static const int k = 'k'; static const int l = 'l'; static const int m = 'm'; static const int n = 'n'; static const int o = 'o'; static const int p = 'p'; static const int q = 'q'; static const int r = 'r'; static const int s = 's'; static const int t = 't'; static const int u = 'u'; static const int v = 'v'; static const int w = 'w'; static const int x = 'x'; static const int y = 'y'; static const int z = 'z'; static const int A = 'A'; static const int B = 'B'; static const int C = 'C'; static const int D = 'D'; static const int E = 'E'; static const int F = 'F'; static const int G = 'G'; static const int H = 'H'; static const int I = 'I'; static const int J = 'J'; static const int K = 'K'; static const int L = 'L'; static const int M = 'M'; static const int N = 'N'; static const int O = 'O'; static const int P = 'P'; static const int Q = 'Q'; static const int R = 'R'; static const int S = 'S'; static const int T = 'T'; static const int U = 'U'; static const int V = 'V'; static const int W = 'W'; static const int X = 'X'; static const int Y = 'Y'; static const int Z = 'Z'; } // alphabet } // pegtl #endif PEGTL-1.3.1/pegtl/contrib/changes.hh000066400000000000000000000043241270130067200170740ustar00rootroot00000000000000// Copyright (c) 2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_CONTRIB_CHANGES_HH #define PEGTL_CONTRIB_CHANGES_HH #include #include "../normal.hh" namespace pegtl { namespace internal { struct dummy_disabled_state { template< typename ... Ts > void success( Ts && ... ) { } }; template< pegtl::apply_mode A, typename State > using state_disable_helper = typename std::conditional< A == pegtl::apply_mode::ACTION, State, dummy_disabled_state >::type; } // internal template< typename Rule, typename State, template< typename ... > class Base = pegtl::normal > struct change_state : public Base< Rule > { template< pegtl::apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { internal::state_disable_helper< A, State > s; if ( Base< Rule >::template match< A, Action, Control >( in, s ) ) { s.success( st ... ); return true; } return false; } }; template< typename Rule, template< typename ... > class Action, template< typename ... > class Base = pegtl::normal > struct change_action : public Base< Rule > { template< pegtl::apply_mode A, template< typename ... > class, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { return Base< Rule >::template match< A, Action, Control >( in, st ... ); } }; template< template< typename ... > class Action, template< typename ... > class Base > struct change_both_helper { template< typename T > using change_action = change_action< T, Action, Base >; }; template< typename Rule, typename State, template< typename ... > class Action, template< typename ... > class Base = pegtl::normal > struct change_state_and_action : public change_state< Rule, State, change_both_helper< Action, Base >::template change_action > { }; } // pegtl #endif PEGTL-1.3.1/pegtl/contrib/http.hh000066400000000000000000000135601270130067200164450ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_CONTRIB_HTTP_HH #define PEGTL_CONTRIB_HTTP_HH #include "../rules.hh" #include "../ascii.hh" #include "../utf8.hh" #include "abnf.hh" #include "uri.hh" namespace pegtl { namespace http { // HTTP 1.1 grammar according to RFC 7230. // This grammar is a direct PEG translation of the original HTTP grammar. // It should be considered experimental -- in case of any issues, in particular // missing anchor rules for actions, please contact the developers. using namespace abnf; using OWS = star< WSP >; // optional whitespace using RWS = plus< WSP >; // required whitespace using BWS = OWS; // "bad" whitespace using obs_text = not_range< 0x00, 0x7F >; using obs_fold = seq< CRLF, plus< WSP > >; struct tchar : sor< ALPHA, DIGIT, one< '!', '#', '$', '%', '&', '\'', '*', '+', '-', '.', '^', '_', '`', '|', '~' > > {}; struct token : plus< tchar > {}; struct field_name : token {}; struct field_vchar : sor< VCHAR, obs_text > {}; struct field_content : list< field_vchar, plus< WSP > > {}; struct field_value : star< sor< field_content, obs_fold > > {}; struct header_field : seq< field_name, one< ':' >, OWS, field_value, OWS > {}; struct method : token {}; struct absolute_path : plus< one< '/' >, uri::segment > {}; struct origin_form : seq< absolute_path, uri::opt_query > {}; struct absolute_form : uri::absolute_URI {}; struct authority_form : uri::authority {}; struct asterisk_form : one< '*' > {}; struct request_target : sor< origin_form, absolute_form, authority_form, asterisk_form > {}; struct status_code : rep< 3, DIGIT > {}; struct reason_phrase : star< sor< VCHAR, obs_text, WSP > > {}; struct HTTP_version : if_must< pegtl_string_t( "HTTP/" ), DIGIT, one< '.' >, DIGIT > {}; struct request_line : if_must< method, SP, request_target, SP, HTTP_version, CRLF > {}; struct status_line : if_must< HTTP_version, SP, status_code, SP, reason_phrase, CRLF > {}; struct start_line : sor< request_line, status_line > {}; struct message_body : star< OCTET > {}; struct HTTP_message : seq< start_line, star< header_field, CRLF >, CRLF, opt< message_body > > {}; struct Content_Length : plus< DIGIT > {}; struct uri_host : uri::host {}; struct port : uri::port {}; struct Host : seq< uri_host, opt< one< ':' >, port > > {}; // PEG are different from CFGs! (this replaces ctext and qdtext) using text = sor< HTAB, range< 0x20, 0x7E >, obs_text >; struct quoted_pair : if_must< one< '\\' >, sor< VCHAR, obs_text, WSP > > {}; struct quoted_string : if_must< DQUOTE, until< DQUOTE, sor< quoted_pair, text > > > {}; struct transfer_parameter : seq< token, BWS, one< '=' >, BWS, sor< token, quoted_string > > {}; struct transfer_extension : seq< token, star< OWS, one< ';' >, OWS, transfer_parameter > > {}; struct transfer_coding : sor< pegtl_istring_t( "chunked" ), pegtl_istring_t( "compress" ), pegtl_istring_t( "deflate" ), pegtl_istring_t( "gzip" ), transfer_extension > {}; struct rank : sor< seq< one< '0' >, opt< one< '.' >, rep_opt< 3, DIGIT > > >, seq< one< '1' >, opt< one< '.' >, rep_opt< 3, one< '0' > > > > > {}; struct t_ranking : seq< OWS, one< ';' >, OWS, one< 'q', 'Q' >, one< '=' >, rank > {}; struct t_codings : sor< pegtl_istring_t( "trailers" ), seq< transfer_coding, opt< t_ranking > > > {}; struct TE : opt< sor< one< ',' >, t_codings >, star< OWS, one< ',' >, opt< OWS, t_codings > > > {}; template< typename T > using make_comma_list = seq< star< one< ',' >, OWS >, T, star< OWS, one< ',' >, opt< OWS, T > > >; struct connection_option : token {}; struct Connection : make_comma_list< connection_option > {}; struct Trailer : make_comma_list< field_name > {}; struct Transfer_Encoding : make_comma_list< transfer_coding > {}; struct protocol_name : token {}; struct protocol_version : token {}; struct protocol : seq< protocol_name, opt< one< '/' >, protocol_version > > {}; struct Upgrade : make_comma_list< protocol > {}; struct pseudonym : token {}; struct received_protocol : seq< opt< protocol_name, one< '/' > >, protocol_version > {}; struct received_by : sor< seq< uri_host, opt< one< ':' >, port > >, pseudonym > {}; struct comment : if_must< one< '(' >, until< one< ')' >, sor< comment, quoted_pair, text > > > {}; struct Via : make_comma_list< seq< received_protocol, RWS, received_by, opt< RWS, comment > > > {}; struct http_URI : if_must< pegtl_istring_t( "http://" ), uri::authority, uri::path_abempty, uri::opt_query, uri::opt_fragment > {}; struct https_URI : if_must< pegtl_istring_t( "https://" ), uri::authority, uri::path_abempty, uri::opt_query, uri::opt_fragment > {}; struct partial_URI : seq< uri::relative_part, uri::opt_query > {}; struct chunk_size : plus< HEXDIG > {}; struct chunk_ext_name : token {}; struct chunk_ext_val : sor< quoted_string, token > {}; struct chunk_ext : star< if_must< one< ';' >, chunk_ext_name, if_must< one< '=' >, chunk_ext_val > > > {}; struct chunk_data : until< at< CRLF >, OCTET > {}; struct chunk : seq< chunk_size, opt< chunk_ext >, CRLF, chunk_data, CRLF > {}; struct last_chunk : seq< plus< one< '0' > >, opt< chunk_ext >, CRLF > {}; struct trailer_part : star< header_field, CRLF > {}; struct chunked_body : seq< until< last_chunk, chunk >, trailer_part, CRLF > {}; } // http } // pegtl #endif PEGTL-1.3.1/pegtl/contrib/json.hh000066400000000000000000000060341270130067200164350ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_CONTRIB_JSON_HH #define PEGTL_CONTRIB_JSON_HH #include "../rules.hh" #include "../ascii.hh" #include "../utf8.hh" #include "abnf.hh" namespace pegtl { namespace json { // JSON grammar according to RFC 7159 (for UTF-8 encoded JSON only). struct ws : one< ' ', '\t', '\n', '\r' > {}; template< typename R, typename P = ws > struct padr : internal::seq< R, internal::star< P > > {}; struct begin_array : padr< one< '[' > > {}; struct begin_object : padr< one< '{' > > {}; struct end_array : one< ']' > {}; struct end_object : one< '}' > {}; struct name_separator : pad< one< ':' >, ws > {}; struct value_separator : padr< one< ',' > > {}; struct false_ : pegtl_string_t( "false" ) {}; struct null : pegtl_string_t( "null" ) {}; struct true_ : pegtl_string_t( "true" ) {}; struct digits : plus< abnf::DIGIT > {}; struct exp : seq< one< 'e', 'E' >, opt< one< '-', '+'> >, must< digits > > {}; struct frac : if_must< one< '.' >, digits > {}; struct int_ : sor< one< '0' >, digits > {}; struct number : seq< opt< one< '-' > >, int_, opt< frac >, opt< exp > > {}; struct xdigit : abnf::HEXDIG {}; struct unicode : list< seq< one< 'u' >, rep< 4, must< xdigit > > >, one< '\\' > > {}; struct escaped_char : one< '"', '\\', '/', 'b', 'f', 'n', 'r', 't' > {}; struct escaped : sor< escaped_char, unicode > {}; struct unescaped : utf8::range< 0x20, 0x10FFFF > {}; struct char_ : if_then_else< one< '\\' >, must< escaped >, unescaped > {}; struct string_content : until< at< one< '"' > >, must< char_ > > {}; struct string : seq< one< '"' >, must< string_content >, any > { using content = string_content; }; struct key_content : until< at< one< '"' > >, must< char_ > > {}; struct key : seq< one< '"' >, must< key_content >, any > { using content = key_content; }; struct value; struct array_element; struct array_content : opt< list_must< array_element, value_separator > > {}; struct array : seq< begin_array, array_content, must< end_array > > { using begin = begin_array; using end = end_array; using element = array_element; using content = array_content; }; struct member : if_must< key, name_separator, value > {}; struct object_content : opt< list_must< member, value_separator > > {}; struct object : seq< begin_object, object_content, must< end_object > > { using begin = begin_object; using end = end_object; using element = member; using content = object_content; }; struct value : padr< sor< string, number, object, array, false_, true_, null > > {}; struct array_element : seq< value > {}; struct text : seq< star< ws >, value > {}; } // json } // pegtl #endif PEGTL-1.3.1/pegtl/contrib/raw_string.hh000066400000000000000000000145151270130067200176460ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_CONTRIB_RAW_STRING_HH #define PEGTL_CONTRIB_RAW_STRING_HH #include "../apply_mode.hh" #include "../nothing.hh" #include "../internal/must.hh" #include "../internal/until.hh" #include "../internal/state.hh" #include "../internal/skip_control.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { template< char Open, char Intermediate, char Close > struct raw_string_tag { }; template< typename Tag > struct raw_string_state { template< typename Input, typename ... States > raw_string_state( const Input & in, States && ... ) : line( in.line() ), column( in.column() ), size( in.size() ) { } template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > typename std::enable_if< ( ( A == apply_mode::ACTION ) && ( ! is_nothing< Action, Tag >::value ) ) >::type success( const Input & in, States && ... st ) const { Input content( line, column, in.begin() - ( size - in.size() ), in.begin() - count, in.source() ); const bool skip = ( content.peek_char( count ) == '\n' ); content.bump( count + skip ); Action< Tag >::apply( const_cast< const Input & >( content ), st ... ); } template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > typename std::enable_if< ! ( ( A == apply_mode::ACTION ) && ( ! is_nothing< Action, Tag >::value ) ) >::type success( const Input &, States && ... ) const { } raw_string_state( const raw_string_state & ) = delete; void operator= ( const raw_string_state & ) = delete; std::size_t line; std::size_t column; std::size_t size; std::size_t count = 0; }; template< typename Tag, char Open, char Intermediate > struct raw_string_open { using analyze_t = analysis::generic< analysis::rule_type::ANY >; template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input > static bool match( Input & in, raw_string_state< Tag > & ls ) { if ( in.empty() || ( in.peek_char( 0 ) != Open ) ) { return false; } for ( std::size_t i = 1; i < in.size(); ++i ) { switch ( const auto c = in.peek_char( i ) ) { case Open: ls.count = i + 1; in.bump( ls.count ); return true; case Intermediate: break; default: return false; } } return false; } }; template< typename Tag, char Intermediate, char Close > struct raw_string_close { using analyze_t = analysis::generic< analysis::rule_type::ANY >; template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input > static bool match( Input & in, const raw_string_state< Tag > & ls ) { if ( in.size() < ls.count ) { return false; } if ( in.peek_char( 0 ) != Close ) { return false; } if ( in.peek_char( ls.count - 1 ) != Close ) { return false; } for ( std::size_t i = 0; i < ls.count - 2; ++i ) { if ( in.peek_char( i + 1 ) != Intermediate ) { return false; } } in.bump( ls.count ); return true; } }; template< typename Tag, char Open, char Intermediate > struct skip_control< raw_string_open< Tag, Open, Intermediate > > : std::true_type {}; template< typename Tag, char Intermediate, char Close > struct skip_control< raw_string_close< Tag, Intermediate, Close > > : std::true_type {}; } // internal // raw_string matches Lua-style long literals. // // The following description was taken from the Lua documentation // (see http://www.lua.org/docs.html): // // - An "opening long bracket of level n" is defined as an opening square // bracket followed by n equal signs followed by another opening square // bracket. So, an opening long bracket of level 0 is written as `[[`, // an opening long bracket of level 1 is written as `[=[`, and so on. // - A "closing long bracket" is defined similarly; for instance, a closing // long bracket of level 4 is written as `]====]`. // - A "long literal" starts with an opening long bracket of any level and // ends at the first closing long bracket of the same level. It can // contain any text except a closing bracket of the same level. // - Literals in this bracketed form can run for several lines, do not // interpret any escape sequences, and ignore long brackets of any other // level. // - For convenience, when the opening long bracket is immediately followed // by a newline, the newline is not included in the string. // // Note that unlike Lua's long literal, a raw_string is customizable to use // other characters than `[`, `=` and `]` for matching. Also note that Lua // introduced newline-specific replacements in Lua 5.2, which we do not // support on the grammar level. template< char Open, char Intermediate, char Close, typename Tag = internal::raw_string_tag< Open, Intermediate, Close > > struct raw_string : state< internal::raw_string_state< Tag >, internal::raw_string_open< Tag, Open, Intermediate >, internal::must< internal::until< internal::raw_string_close< Tag, Intermediate, Close > > > > { // This is used to bind an action to the content using content = Tag; // This is used for error-reporting when a raw string is not closed properly using close = internal::until< internal::raw_string_close< Tag, Intermediate, Close > >; }; } // pegtl #endif PEGTL-1.3.1/pegtl/contrib/unescape.hh000066400000000000000000000141351270130067200172700ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_CONTRIB_UNESCAPE_HH #define PEGTL_CONTRIB_UNESCAPE_HH #include #include #include #include namespace pegtl { namespace unescape { struct state { std::string unescaped; }; // Utility functions for the unescape actions. inline bool utf8_append_utf32( std::string & string, const unsigned utf32 ) { if ( utf32 <= 0x7f ) { string += char( utf32 & 0xff ); return true; } else if ( utf32 <= 0x7ff ) { char tmp[] = { char( ( ( utf32 & 0x7c0 ) >> 6 ) | 0xc0 ), char( ( ( utf32 & 0x03f ) ) | 0x80 ) }; string.append( tmp, sizeof( tmp ) ); return true; } else if ( utf32 <= 0xffff ) { char tmp[] = { char( ( ( utf32 & 0xf000 ) >> 12 ) | 0xe0 ), char( ( ( utf32 & 0x0fc0 ) >> 6 ) | 0x80 ), char( ( ( utf32 & 0x003f ) ) | 0x80 ) }; string.append( tmp, sizeof( tmp ) ); return true; } else if ( utf32 <= 0x10ffff ) { char tmp[] = { char( ( ( utf32 & 0x1c0000 ) >> 18 ) | 0xf0 ), char( ( ( utf32 & 0x03f000 ) >> 12 ) | 0x80 ), char( ( ( utf32 & 0x000fc0 ) >> 6 ) | 0x80 ), char( ( ( utf32 & 0x00003f ) ) | 0x80 ) }; string.append( tmp, sizeof( tmp ) ); return true; } return false; } // This function MUST only be called for characters matching pegtl::ascii::xdigit! template< typename I > I unhex_char( const char c ) { switch ( c ) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': return I( c - '0' ); case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': return I( c - 'a' + 10 ); case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': return I( c - 'A' + 10 ); } assert( false ); // LCOV_EXCL_LINE } template< typename I > I unhex_string( const char * begin, const char * const end ) { I r = 0; while ( begin != end ) { r <<= 4; r += unhex_char< I >( *begin++ ); } return r; } // Actions for common unescape situations. struct append_all { template< typename Input, typename State > static void apply( const Input & in, State & st ) { st.unescaped.append( in.begin(), in.size() ); } }; // This function MUST be called for a character matching T which must be pegtl::one< ... >. template< typename T, char ... Rs > struct unescape_c { template< typename Input, typename State > static void apply( const Input & in, State & st ) { assert( in.size() == 1 ); st.unescaped += apply_one( * in.begin(), static_cast< const T * >( nullptr ) ); } template< char ... Qs > static char apply_one( const char c, const one< Qs ... > * ) { static_assert( sizeof ... ( Qs ) == sizeof ... ( Rs ), "size mismatch between escaped characters and their mappings" ); return apply_two( c, { Qs ... }, { Rs ... } ); } static char apply_two( const char c, const std::initializer_list< char > & q, const std::initializer_list< char > & r ) { for ( std::size_t i = 0; i < q.size(); ++i ) { if ( * ( q.begin() + i ) == c ) { return * ( r.begin() + i ); } } assert( false ); // LCOV_EXCL_LINE } }; // See examples/unescape.cc to see why the following two actions // have the convenience of skipping the first input character... struct unescape_u { template< typename Input, typename State > static void apply( const Input & in, State & st ) { assert( ! in.empty() ); // First character MUST be present, usually 'u' or 'U'. if ( ! utf8_append_utf32( st.unescaped, unhex_string< unsigned >( in.begin() + 1, in.end() ) ) ) { throw parse_error( "invalid escaped unicode code point", in ); } } }; struct unescape_x { template< typename Input, typename State > static void apply( const Input & in, State & st ) { assert( ! in.empty() ); // First character MUST be present, usually 'x'. st.unescaped += unhex_string< char >( in.begin() + 1, in.end() ); } }; // Like unescape_u, but (a) assumes 4 hexdigits per code point, // and (b) accepts multiple consecutive escaped 16-bit values. // It encodes UTF-16 surrogate pairs as single UTF-8 sequence // as required for JSON by RFC 7159. struct unescape_j { template< typename Input, typename State > static void apply( const Input & in, State & st ) { assert( ( ( in.size() + 1 ) % 6 ) == 0 ); // Expects multiple "\\u1234" with the first backslash already skipped. for ( const char * b = in.begin() + 1; b < in.end(); b += 6 ) { const auto c = unhex_string< unsigned >( b, b + 4 ); if ( ( 0xd800 <= c ) && ( c <= 0xdbff ) && ( b + 6 < in.end() ) ) { const auto d = unhex_string< unsigned >( b + 6, b + 10 ); if ( ( 0xdc00 <= d ) && ( d <= 0xdfff ) ) { b += 6; utf8_append_utf32( st.unescaped, ( ( ( c & 0x03ff ) << 10 ) | ( d & 0x03ff ) ) + 0x10000 ); continue; } } utf8_append_utf32( st.unescaped, c ); } } }; } // unescape } // pegtl #endif PEGTL-1.3.1/pegtl/contrib/uri.hh000066400000000000000000000121771270130067200162700ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_CONTRIB_URI_HH #define PEGTL_CONTRIB_URI_HH #include "../rules.hh" #include "../ascii.hh" #include "../utf8.hh" #include "abnf.hh" namespace pegtl { namespace uri { // URI grammar according to RFC 3986. // This grammar is a direct PEG translation of the original URI grammar. // It should be considered experimental -- in case of any issues, in particular // missing anchor rules for actions, please contact the developers. // Note that this grammar has multiple top-level rules. using namespace abnf; using dot = one< '.' >; using colon = one< ':' >; struct dec_octet : sor< one< '0' >, rep_min_max< 1, 2, DIGIT >, seq< one< '1' >, DIGIT, DIGIT >, seq< one< '2' >, range< '0', '4' >, DIGIT >, seq< string< '2', '5' >, range< '0', '5' > > > {}; struct IPv4address : seq< dec_octet, dot, dec_octet, dot, dec_octet, dot, dec_octet > {}; struct h16 : rep_min_max< 1, 4, HEXDIG > {}; struct ls32 : sor< seq< h16, colon, h16 >, IPv4address > {}; struct dcolon : two< ':' > {}; struct IPv6address : sor< seq< rep< 6, h16, colon >, ls32 >, seq< dcolon, rep< 5, h16, colon >, ls32 >, seq< opt< h16 >, dcolon, rep< 4, h16, colon >, ls32 >, seq< opt< h16, opt< colon, h16 > >, dcolon, rep< 3, h16, colon >, ls32 >, seq< opt< h16, rep_opt< 2, colon, h16 > >, dcolon, rep< 2, h16, colon >, ls32 >, seq< opt< h16, rep_opt< 3, colon, h16 > >, dcolon, h16, colon, ls32 >, seq< opt< h16, rep_opt< 4, colon, h16 > >, dcolon, ls32 >, seq< opt< h16, rep_opt< 5, colon, h16 > >, dcolon, h16 >, seq< opt< h16, rep_opt< 6, colon, h16 > >, dcolon > > {}; struct gen_delims : one< ':', '/', '?', '#', '[', ']', '@' > {}; struct sub_delims : one< '!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=' > {}; struct unreserved : sor< ALPHA, DIGIT, one< '-', '.', '_', '~' > > {}; struct reserved : sor< gen_delims, sub_delims > {}; struct IPvFuture : if_must< one< 'v' >, plus< HEXDIG >, dot, plus< sor< unreserved, sub_delims, colon > > > {}; struct IP_literal : if_must< one< '[' >, sor< IPvFuture, IPv6address >, one< ']' > > {}; struct pct_encoded : if_must< one< '%' >, HEXDIG, HEXDIG > {}; struct pchar : sor< unreserved, pct_encoded, sub_delims, one< ':', '@' > > {}; struct query : star< sor< pchar, one< '/', '?' > > > {}; struct fragment : star< sor< pchar, one< '/', '?' > > > {}; struct segment : star< pchar > {}; struct segment_nz : plus< pchar > {}; struct segment_nz_nc : plus< sor< unreserved, pct_encoded, sub_delims, one< '@' > > > {}; // non-zero-length segment without any colon ":" struct path_abempty : star< one< '/' >, segment > {}; struct path_absolute : seq< one< '/' >, opt< segment_nz, star< one< '/' >, segment > > > {}; struct path_noscheme : seq< segment_nz_nc, star< one< '/' >, segment > > {}; struct path_rootless : seq< segment_nz, star< one< '/' >, segment > > {}; struct path_empty : success {}; struct path : sor< path_noscheme, // begins with a non-colon segment path_rootless, // begins with a segment path_absolute, // begins with "/" but not "//" path_abempty > {}; // begins with "/" or is empty struct reg_name : star< sor< unreserved, pct_encoded, sub_delims > > {}; struct port : star< DIGIT > {}; struct host : sor< IP_literal, IPv4address, reg_name > {}; struct userinfo : star< sor< unreserved, pct_encoded, sub_delims, colon > > {}; struct authority : seq< opt< userinfo, one< '@' > >, host, opt< colon, port > > {}; struct scheme : seq< ALPHA, star< sor< ALPHA, DIGIT, one< '+', '-', '.' > > > > {}; using dslash = two< '/' >; using opt_query = opt< if_must< one< '?' >, query > >; using opt_fragment = opt< if_must< one< '#' >, fragment > >; struct hier_part : sor< if_must< dslash, authority, path_abempty >, path_rootless, path_absolute, path_empty > {}; struct relative_part : sor< if_must< dslash, authority, path_abempty >, path_noscheme, path_absolute, path_empty > {}; struct relative_ref : seq< relative_part, opt_query, opt_fragment > {}; struct URI : seq< scheme, one< ':' >, hier_part, opt_query, opt_fragment > {}; struct URI_reference : sor< URI, relative_ref > {}; struct absolute_URI : seq< scheme, one< ':' >, hier_part, opt_query > {}; } // uri } // pegtl #endif PEGTL-1.3.1/pegtl/data_parser.hh000066400000000000000000000031131270130067200163040ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_DATA_PARSER_HH #define PEGTL_DATA_PARSER_HH #include #include #include "parse.hh" #include "input.hh" #include "normal.hh" #include "nothing.hh" namespace pegtl { class data_parser { public: data_parser( std::string data, std::string source, const std::size_t line = 1, const std::size_t column = 0 ) : m_data( std::move( data ) ), m_source( std::move( source ) ), m_input( line, column, m_data.data(), m_data.data() + m_data.size(), m_source.c_str() ) { } data_parser( std::string data, std::string source, const pegtl::input & from, const std::size_t line = 1, const std::size_t column = 0 ) : m_data( std::move( data ) ), m_source( std::move( source ) ), m_input( line, column, m_data.data(), m_data.data() + m_data.size(), m_source.c_str(), & from ) { } const std::string & source() const { return m_source; } const pegtl::input & input() const { return m_input; } template< typename Rule, template< typename ... > class Action = nothing, template< typename ... > class Control = normal, typename ... States > bool parse( States && ... st ) { return parse_input< Rule, Action, Control >( m_input, st ... ); } private: std::string m_data; std::string m_source; pegtl::input m_input; }; } // pegtl #endif PEGTL-1.3.1/pegtl/file_parser.hh000066400000000000000000000010771270130067200163210ustar00rootroot00000000000000// Copyright (c) 2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_FILE_PARSER_HH #define PEGTL_FILE_PARSER_HH #include "read_parser.hh" #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) #include // Required for _POSIX_MAPPED_FILES #endif #if defined(_POSIX_MAPPED_FILES) #include "mmap_parser.hh" #endif namespace pegtl { #if defined(_POSIX_MAPPED_FILES) using file_parser = mmap_parser; #else using file_parser = read_parser; #endif } // pegtl #endif PEGTL-1.3.1/pegtl/input.hh000066400000000000000000000054521270130067200151660ustar00rootroot00000000000000// Copyright (c) 2014-2016 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INPUT_HH #define PEGTL_INPUT_HH #include #include #include "internal/input_data.hh" #include "internal/input_mark.hh" namespace pegtl { class input { public: explicit input( const internal::input_data & data ) : m_data( data ) { } input( const internal::input_data & data, const internal::input_mark & mark ) : m_data( mark.m_line, mark.m_column, mark.m_begin, data.begin, data.source, data.from ) { } input( const std::size_t line, const std::size_t column, const char * begin, const char * end, const char * source, const input * from = nullptr ) : m_data( line, column, begin, end, source, from ? ( & from->m_data ) : nullptr ) { } bool empty() const { return m_data.begin == m_data.end; } std::size_t size() const { return m_data.end - m_data.begin; } const char * begin() const { return m_data.begin; } const char * end() const { return m_data.end; } std::size_t line() const { return m_data.line; } std::size_t column() const { return m_data.column; } const char * source() const { return m_data.source; } std::string string() const { return std::string( m_data.begin, m_data.end ); } char peek_char( const std::size_t offset = 0 ) const { return m_data.begin[ offset ]; } unsigned char peek_byte( const std::size_t offset = 0 ) const { return static_cast< unsigned char >( peek_char( offset ) ); } void bump( const std::size_t count = 1 ) { for ( std::size_t i = 0; i < count; ++i ) { bump_unsafe(); } } void bump_in_line( const std::size_t count = 1 ) { m_data.begin += count; m_data.column += count; } void bump_next_line( const std::size_t count = 1 ) { ++m_data.line; m_data.begin += count; m_data.column = 0; } internal::input_mark mark() { return internal::input_mark( m_data ); } const internal::input_data & data() const { return m_data; } private: internal::input_data m_data; void bump_unsafe() { switch ( * m_data.begin ) { case '\n': ++m_data.line; m_data.column = 0; break; default: ++m_data.column; break; } ++m_data.begin; } }; } // pegtl #endif PEGTL-1.3.1/pegtl/input_error.hh000066400000000000000000000017461270130067200164010ustar00rootroot00000000000000// Copyright (c) 2014-2016 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INPUT_ERROR_HH #define PEGTL_INPUT_ERROR_HH #include #include #include namespace pegtl { struct input_error : std::runtime_error { input_error( const std::string & message, const int errorno ) : std::runtime_error( message ), errorno( errorno ) { } int errorno; }; #define PEGTL_THROW_INPUT_ERROR( MESSAGE ) \ do { \ const int errorno = errno; \ std::ostringstream oss; \ oss << "pegtl: " << MESSAGE << " errno " << errorno; \ throw pegtl::input_error( oss.str(), errorno ); \ } while ( false ) } // pegtl #endif PEGTL-1.3.1/pegtl/internal/000077500000000000000000000000001270130067200153145ustar00rootroot00000000000000PEGTL-1.3.1/pegtl/internal/action.hh000066400000000000000000000020631270130067200171130ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_ACTION_HH #define PEGTL_INTERNAL_ACTION_HH #include "skip_control.hh" #include "seq.hh" #include "rule_match_three.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { template< template< typename ... > class Action, typename ... Rules > struct action { using analyze_t = analysis::generic< analysis::rule_type::SEQ, Rules ... >; template< apply_mode A, template< typename ... > class, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { return rule_match_three< seq< Rules ... >, A, Action, Control >::match( in, st ... ); } }; template< template< typename ... > class Action, typename ... Rules > struct skip_control< action< Action, Rules ... > > : std::true_type {}; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/any.hh000066400000000000000000000024621270130067200164300ustar00rootroot00000000000000// Copyright (c) 2014-2016 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_ANY_HH #define PEGTL_INTERNAL_ANY_HH #include "skip_control.hh" #include "peek_char.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { template< typename Peek > struct any; template< typename Peek > struct skip_control< any< Peek > > : std::true_type {}; template<> struct any< peek_char > { using analyze_t = analysis::generic< analysis::rule_type::ANY >; template< typename Input > static bool match( Input & in ) { if ( ! in.empty() ) { in.bump(); return true; } return false; } }; template< typename Peek > struct any { using analyze_t = analysis::generic< analysis::rule_type::ANY >; template< typename Input > static bool match( Input & in ) { if ( ! in.empty() ) { if ( const auto t = Peek::peek( in ) ) { in.bump( t.size ); return true; } } return false; } }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/at.hh000066400000000000000000000022031270130067200162360ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_AT_HH #define PEGTL_INTERNAL_AT_HH #include "skip_control.hh" #include "trivial.hh" #include "rule_conjunction.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { template< typename ... Rules > struct at; template< typename ... Rules > struct skip_control< at< Rules ... > > : std::true_type {}; template<> struct at<> : trivial< true > {}; template< typename ... Rules > struct at { using analyze_t = analysis::generic< analysis::rule_type::OPT, Rules ... >; template< apply_mode, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { auto m = in.mark(); return rule_conjunction< Rules ... >::template match< apply_mode::NOTHING, Action, Control >( in, st ... ); } }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/bump_util.hh000066400000000000000000000023171270130067200176400ustar00rootroot00000000000000// Copyright (c) 2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_BUMP_UTIL_HH #define PEGTL_INTERNAL_BUMP_UTIL_HH #include #include "result_on_found.hh" namespace pegtl { namespace internal { template< bool > struct bump_impl; template<> struct bump_impl< true > { template< typename Input > static void bump( Input & in, const size_t count ) { in.bump( count ); } }; template<> struct bump_impl< false > { template< typename Input > static void bump( Input & in, const size_t count ) { in.bump_in_line( count ); } }; template< bool ... > struct bool_list {}; template< typename Char, Char ... Cs > using no_lf = std::is_same< bool_list< ( Cs != '\n' ) ... >, bool_list< ( Cs || true ) ... > >; template< result_on_found R, typename Input, typename Char, Char ... Cs > void bump( Input & in, const size_t count ) { bump_impl< no_lf< Char, Cs ... >::value != bool( R ) >::bump( in, count ); } } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/bytes.hh000066400000000000000000000014721270130067200167670ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_BYTES_HH #define PEGTL_INTERNAL_BYTES_HH #include "skip_control.hh" #include "../analysis/counted.hh" namespace pegtl { namespace internal { template< unsigned Num > struct bytes { using analyze_t = analysis::counted< analysis::rule_type::ANY, Num >; template< typename Input > static bool match( Input & in ) { if ( in.size() >= Num ) { in.bump( Num ); return true; } return false; } }; template< unsigned Num > struct skip_control< bytes< Num > > : std::true_type {}; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/control.hh000066400000000000000000000020711270130067200173150ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_CONTROL_HH #define PEGTL_INTERNAL_CONTROL_HH #include "skip_control.hh" #include "seq.hh" #include "rule_match_three.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { template< template< typename ... > class Control, typename ... Rules > struct control { using analyze_t = analysis::generic< analysis::rule_type::SEQ, Rules ... >; template< apply_mode A, template< typename ... > class Action, template< typename ... > class, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { return rule_match_three< seq< Rules ... >, A, Action, Control >::match( in, st ... ); } }; template< template< typename ... > class Control, typename ... Rules > struct skip_control< control< Control, Rules ... > > : std::true_type {}; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/demangle.hh000066400000000000000000000012451270130067200174130ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_DEMANGLE_HH #define PEGTL_INTERNAL_DEMANGLE_HH #include #include #if defined(__GLIBCXX__) #include "demangle_cxxabi.hh" #elif defined(__has_include) #if __has_include() #include "demangle_cxxabi.hh" #else #include "demangle_nop.hh" #endif #else #include "demangle_nop.hh" #endif namespace pegtl { namespace internal { template< typename T > std::string demangle() { return demangle( typeid( T ).name() ); } } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/demangle_cxxabi.hh000066400000000000000000000012201270130067200207420ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_DEMANGLE_CXXABI_HH #define PEGTL_INTERNAL_DEMANGLE_CXXABI_HH #include #include #include #include namespace pegtl { namespace internal { inline std::string demangle( const char * symbol ) { const std::unique_ptr< char, decltype( & std::free ) > demangled( abi::__cxa_demangle( symbol, nullptr, nullptr, nullptr ), & std::free ); return demangled ? demangled.get() : symbol; } } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/demangle_nop.hh000066400000000000000000000006371270130067200202730ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_DEMANGLE_NOP_HH #define PEGTL_INTERNAL_DEMANGLE_NOP_HH #include namespace pegtl { namespace internal { inline std::string demangle( const char * symbol ) { return symbol; } } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/disable.hh000066400000000000000000000017701270130067200172450ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_DISABLE_HH #define PEGTL_INTERNAL_DISABLE_HH #include "skip_control.hh" #include "seq.hh" #include "rule_match_three.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { template< typename ... Rules > struct disable { using analyze_t = analysis::generic< analysis::rule_type::SEQ, Rules ... >; template< apply_mode, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { return rule_match_three< seq< Rules ... >, apply_mode::NOTHING, Action, Control >::match( in, st ... ); } }; template< typename ... Rules > struct skip_control< disable< Rules ... > > : std::true_type {}; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/enable.hh000066400000000000000000000017631270130067200170720ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_ENABLE_HH #define PEGTL_INTERNAL_ENABLE_HH #include "skip_control.hh" #include "seq.hh" #include "rule_match_three.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { template< typename ... Rules > struct enable { using analyze_t = analysis::generic< analysis::rule_type::SEQ, Rules ... >; template< apply_mode, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { return rule_match_three< seq< Rules ... >, apply_mode::ACTION, Action, Control >::match( in, st ... ); } }; template< typename ... Rules > struct skip_control< enable< Rules ... > > : std::true_type {}; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/eof.hh000066400000000000000000000012171270130067200164070ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_EOF_HH #define PEGTL_INTERNAL_EOF_HH #include "skip_control.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { struct eof { using analyze_t = analysis::generic< analysis::rule_type::OPT >; template< typename Input > static bool match( Input & in ) { return in.empty(); } }; template<> struct skip_control< eof > : std::true_type {}; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/eol.hh000066400000000000000000000022761270130067200164230ustar00rootroot00000000000000// Copyright (c) 2016 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_EOL_HH #define PEGTL_INTERNAL_EOL_HH #include "skip_control.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { struct eol { using analyze_t = analysis::generic< analysis::rule_type::ANY >; template< typename Input > static bool match( Input & in ) { if ( const auto s = in.size() ) { return match_impl( in, s ); } return false; } template< typename Input > static bool match_impl( Input & in, const std::size_t s ) { const auto a = in.peek_char(); if ( a == '\n' ) { in.bump_next_line(); return true; } if ( ( a == '\r' ) && ( s > 1 ) && ( in.peek_char( 1 ) == '\n' ) ) { in.bump_next_line( 2 ); return true; } return false; } }; template<> struct skip_control< eol > : std::true_type {}; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/eolf.hh000066400000000000000000000014141270130067200165620ustar00rootroot00000000000000// Copyright (c) 2014-2016 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_EOLF_HH #define PEGTL_INTERNAL_EOLF_HH #include "skip_control.hh" #include "../analysis/generic.hh" #include "eol.hh" namespace pegtl { namespace internal { struct eolf { using analyze_t = analysis::generic< analysis::rule_type::OPT >; template< typename Input > static bool match( Input & in ) { if ( const auto s = in.size() ) { return eol::match_impl( in, s ); } return true; } }; template<> struct skip_control< eolf > : std::true_type {}; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/file_mapper.hh000066400000000000000000000040031270130067200201150ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_FILE_MAPPER_HH #define PEGTL_INTERNAL_FILE_MAPPER_HH #include #include #include "file_opener.hh" #include "../input_error.hh" namespace pegtl { namespace internal { class file_mapper { public: explicit file_mapper( const std::string & filename ) : file_mapper( file_opener( filename ) ) { } explicit file_mapper( const file_opener & reader ) : m_size( reader.size() ), m_data( static_cast< const char * >( ::mmap( 0, m_size, PROT_READ, MAP_FILE | MAP_PRIVATE, reader.m_fd, 0 ) ) ) { if ( intptr_t( m_data ) == -1 ) { PEGTL_THROW_INPUT_ERROR( "unable to mmap() file " << reader.m_source << " descriptor " << reader.m_fd ); } } ~file_mapper() { ::munmap( const_cast< char * >( m_data ), m_size ); // Legacy C interface requires pointer-to-mutable but does not write through the pointer. } file_mapper( const file_mapper & ) = delete; void operator= ( const file_mapper & ) = delete; bool empty() const { return m_size == 0; } std::size_t size() const { return m_size; } using iterator = const char *; using const_iterator = const char *; iterator data() const { return m_data; } iterator begin() const { return m_data; } iterator end() const { return m_data + m_size; } std::string string() const { return std::string( m_data, m_size ); } private: const std::size_t m_size; const char * const m_data; }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/file_opener.hh000066400000000000000000000027331270130067200201310ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_FILE_OPENER_HH #define PEGTL_INTERNAL_FILE_OPENER_HH #include #include #include #include #include "../input_error.hh" namespace pegtl { namespace internal { struct file_opener { explicit file_opener( const std::string & filename ) : m_source( filename ), m_fd( open() ) { } ~file_opener() { ::close( m_fd ); } file_opener( const file_opener & ) = delete; void operator= ( const file_opener & ) = delete; std::size_t size() const { struct stat st; errno = 0; if ( ::fstat( m_fd, & st ) < 0 ) { PEGTL_THROW_INPUT_ERROR( "unable to fstat() file " << m_source << " descriptor " << m_fd ); } return std::size_t( st.st_size ); } const std::string m_source; const int m_fd; private: int open() const { errno = 0; const int fd = ::open( m_source.c_str(), O_RDONLY ); if ( fd >= 0 ) { return fd; } PEGTL_THROW_INPUT_ERROR( "unable to open() file " << m_source << " for reading" ); } }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/file_reader.hh000066400000000000000000000043301270130067200200760ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_FILE_READER_HH #define PEGTL_INTERNAL_FILE_READER_HH #include #include #include "../input_error.hh" namespace pegtl { namespace internal { class file_reader { public: explicit file_reader( const std::string & filename ) : m_source( filename ), m_file( open(), & std::fclose ) { } file_reader( const file_reader & ) = delete; void operator= ( const file_reader & ) = delete; std::size_t size() const { errno = 0; if ( std::fseek( m_file.get(), 0, SEEK_END ) ) { PEGTL_THROW_INPUT_ERROR( "unable to fseek() to end of file " << m_source ); // LCOV_EXCL_LINE } errno = 0; const auto s = std::ftell( m_file.get() ); if ( s < 0 ) { PEGTL_THROW_INPUT_ERROR( "unable to ftell() file size of file " << m_source ); // LCOV_EXCL_LINE } errno = 0; if ( std::fseek( m_file.get(), 0, SEEK_SET ) ) { PEGTL_THROW_INPUT_ERROR( "unable to fseek() to beginning of file " << m_source ); // LCOV_EXCL_LINE } return s; } std::string read() const { std::string nrv; nrv.resize( size() ); errno = 0; if ( nrv.size() && ( std::fread( & nrv[ 0 ], nrv.size(), 1, m_file.get() ) != 1 ) ) { PEGTL_THROW_INPUT_ERROR( "unable to fread() file " << m_source << " size " << nrv.size() ); // LCOV_EXCL_LINE } return nrv; } private: const std::string m_source; const std::unique_ptr< std::FILE, decltype( & std::fclose ) > m_file; std::FILE * open() const { errno = 0; if ( auto * file = std::fopen( m_source.c_str(), "rb" ) ) { return file; } PEGTL_THROW_INPUT_ERROR( "unable to fopen() file " << m_source << " for reading" ); } }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/if_must.hh000066400000000000000000000006611270130067200173060ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_IF_MUST_HH #define PEGTL_INTERNAL_IF_MUST_HH #include "seq.hh" #include "must.hh" namespace pegtl { namespace internal { template< typename Cond, typename ... Thens > using if_must = seq< Cond, must< Thens ... > >; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/if_must_else.hh000066400000000000000000000007451270130067200203210ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_IF_MUST_ELSE_HH #define PEGTL_INTERNAL_IF_MUST_ELSE_HH #include "if_then_else.hh" #include "must.hh" namespace pegtl { namespace internal { template< typename Cond, typename Then, typename Else > using if_must_else = if_then_else< Cond, must< Then >, must< Else > >; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/if_then_else.hh000066400000000000000000000025511270130067200202640ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_IF_THEN_ELSE_HH #define PEGTL_INTERNAL_IF_THEN_ELSE_HH #include "sor.hh" #include "seq.hh" #include "not_at.hh" #include "skip_control.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { template< typename Cond, typename Then, typename Else > struct if_then_else { using analyze_t = analysis::generic< analysis::rule_type::SOR, seq< Cond, Then >, seq< not_at< Cond >, Else > >; template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { auto m = in.mark(); if ( Control< Cond >::template match< A, Action, Control >( in, st ... ) ) { return m( Control< Then >::template match< A, Action, Control >( in, st ... ) ); } else { return m( Control< Else >::template match< A, Action, Control >( in, st ... ) ); } } }; template< typename Cond, typename Then, typename Else > struct skip_control< if_then_else< Cond, Then, Else > > : std::true_type {}; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/input_data.hh000066400000000000000000000016131270130067200177660ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_INPUT_DATA_HH #define PEGTL_INTERNAL_INPUT_DATA_HH #include namespace pegtl { namespace internal { struct input_data { input_data( const std::size_t line, const std::size_t column, const char * begin, const char * end, const char * source, const input_data * from = nullptr ) : line( line ), column( column ), begin( begin ), end( end ), source( source ), from( from ) { } std::size_t line; std::size_t column; const char * begin; const char * end; const char * source; const input_data * from; }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/input_mark.hh000066400000000000000000000033341270130067200200110ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_INPUT_MARK_HH #define PEGTL_INTERNAL_INPUT_MARK_HH #include "input_data.hh" namespace pegtl { namespace internal { class input_mark { public: explicit input_mark( input_data & i ) : m_line( i.line ), m_column( i.column ), m_begin( i.begin ), m_input( & i ) { } input_mark( input_mark && i ) : m_line( i.m_line ), m_column( i.m_column ), m_begin( i.m_begin ), m_input( i.m_input ) { i.m_input = nullptr; } ~input_mark() { if ( m_input ) { m_input->line = m_line; m_input->column = m_column; m_input->begin = m_begin; } } input_mark( const input_mark & ) = delete; void operator= ( const input_mark & ) = delete; bool success() { m_input = nullptr; return true; } bool failure() { m_input->line = m_line; m_input->column = m_column; m_input->begin = m_begin; m_input = nullptr; return false; } bool operator() ( const bool result ) { return result ? success() : failure(); } public: const std::size_t m_line; const std::size_t m_column; const char * const m_begin; input_data * m_input; }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/input_pair.hh000066400000000000000000000010351270130067200200060ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_INPUT_PAIR_HH #define PEGTL_INTERNAL_INPUT_PAIR_HH namespace pegtl { namespace internal { template< typename Data > struct input_pair { Data data; unsigned char size; using data_t = Data; explicit operator bool () const { return size > 0; } }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/istring.hh000066400000000000000000000043341270130067200173200ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_ISTRING_HH #define PEGTL_INTERNAL_ISTRING_HH #include #include "result_on_found.hh" #include "skip_control.hh" #include "bump_util.hh" #include "trivial.hh" #include "../analysis/counted.hh" namespace pegtl { namespace internal { template< char C > using is_alpha = std::integral_constant< bool, ( ( 'a' <= C ) && ( C <= 'z' ) ) || ( ( 'A' <= C ) && ( C <= 'Z' ) ) >; template< char C, bool A = is_alpha< C >::value > struct ichar_equal; template< char C > struct ichar_equal< C, true > { static bool match( const char c ) { return ( C | 0x20 ) == ( c | 0x20 ); } }; template< char C > struct ichar_equal< C, false > { static bool match( const char c ) { return c == C; } }; template< char ... Cs > struct istring_equal; template<> struct istring_equal<> { static bool match( const char * ) { return true; } }; template< char C, char ... Cs > struct istring_equal< C, Cs ... > { static bool match( const char * r ) { return ichar_equal< C >::match( * r ) && istring_equal< Cs ... >::match( r + 1 ); } }; template< char ... Cs > struct istring; template< char ... Cs > struct skip_control< istring< Cs ... > > : std::true_type {}; template<> struct istring<> : trivial< true > {}; template< char ... Cs > struct istring { using analyze_t = analysis::counted< analysis::rule_type::ANY, sizeof ... ( Cs ) >; template< typename Input > static bool match( Input & in ) { if ( in.size() >= sizeof ... ( Cs ) ) { if ( istring_equal< Cs ... >::match( in.begin() ) ) { bump< result_on_found::SUCCESS, Input, char, Cs ... >( in, sizeof ... ( Cs ) ); return true; } } return false; } }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/list.hh000066400000000000000000000006421270130067200166120ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_LIST_HH #define PEGTL_INTERNAL_LIST_HH #include "seq.hh" #include "star.hh" namespace pegtl { namespace internal { template< typename Rule, typename Sep > using list = seq< Rule, star< Sep, Rule > >; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/list_must.hh000066400000000000000000000007141270130067200176620ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_LIST_MUST_HH #define PEGTL_INTERNAL_LIST_MUST_HH #include "seq.hh" #include "star.hh" #include "must.hh" namespace pegtl { namespace internal { template< typename Rule, typename Sep > using list_must = seq< Rule, star< Sep, must< Rule > > >; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/list_tail.hh000066400000000000000000000007111270130067200176200ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_LIST_TAIL_HH #define PEGTL_INTERNAL_LIST_TAIL_HH #include "seq.hh" #include "list.hh" #include "opt.hh" namespace pegtl { namespace internal { template< typename Rule, typename Sep > using list_tail = seq< list< Rule, Sep >, opt< Sep > >; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/list_tail_pad.hh000066400000000000000000000010411270130067200204410ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_LIST_TAIL_PAD_HH #define PEGTL_INTERNAL_LIST_TAIL_PAD_HH #include "seq.hh" #include "list.hh" #include "pad.hh" #include "opt.hh" #include "star.hh" namespace pegtl { namespace internal { template< typename Rule, typename Sep, typename Pad > using list_tail_pad = seq< list< Rule, pad< Sep, Pad > >, opt< star< Pad >, Sep > >; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/must.hh000066400000000000000000000027711270130067200166340ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_MUST_HH #define PEGTL_INTERNAL_MUST_HH #include "seq.hh" #include "raise.hh" #include "skip_control.hh" namespace pegtl { namespace internal { // The general case simply applies must<> to each member of the // 'Rules' parameter pack individually, below is the specialization // which implements the case for a single rule. template< typename ... Rules > struct must : seq< must< Rules > ... > {}; // While in theory the implementation for a single rule could // be simplified to must< Rule > = sor< Rule, raise< Rule > >, this // would result in some unnecessary run-time overhead. template< typename Rule > struct must< Rule > { using analyze_t = typename Rule::analyze_t; template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { if ( ! Control< Rule >::template match< A, Action, Control >( in, st ... ) ) { raise< Rule >::template match< A, Action, Control >( in, st ... ); } return true; } }; template< typename ... Rules > struct skip_control< must< Rules ... > > : std::true_type {}; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/not_at.hh000066400000000000000000000022361270130067200171240ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_NOT_AT_HH #define PEGTL_INTERNAL_NOT_AT_HH #include "trivial.hh" #include "skip_control.hh" #include "rule_conjunction.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { template< typename ... Rules > struct not_at; template< typename ... Rules > struct skip_control< not_at< Rules ... > > : std::true_type {}; template<> struct not_at<> : trivial< false > {}; template< typename ... Rules > struct not_at { using analyze_t = analysis::generic< analysis::rule_type::OPT, Rules ... >; template< apply_mode, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { auto m = in.mark(); return ! rule_conjunction< Rules ... >::template match< apply_mode::NOTHING, Action, Control >( in, st ... ); } }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/one.hh000066400000000000000000000040171270130067200164200ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_ONE_HH #define PEGTL_INTERNAL_ONE_HH #include #include #include "bump_util.hh" #include "skip_control.hh" #include "result_on_found.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { template< typename Char > bool contains( const Char c, const std::initializer_list< Char > & l ) { return std::find( l.begin(), l.end(), c ) != l.end(); } template< result_on_found R, typename Peek, typename Peek::data_t ... Cs > struct one { using analyze_t = analysis::generic< analysis::rule_type::ANY >; template< typename Input > static bool match( Input & in ) { if ( ! in.empty() ) { if ( const auto t = Peek::peek( in ) ) { if ( contains( t.data, { Cs ... } ) == bool( R ) ) { bump< R, Input, typename Peek::data_t, Cs ... >( in, t.size ); return true; } } } return false; } }; template< result_on_found R, typename Peek, typename Peek::data_t C > struct one< R, Peek, C > { using analyze_t = analysis::generic< analysis::rule_type::ANY >; template< typename Input > static bool match( Input & in ) { if ( ! in.empty() ) { if ( const auto t = Peek::peek( in ) ) { if ( ( t.data == C ) == bool( R ) ) { bump< R, Input, typename Peek::data_t, C >( in, t.size ); return true; } } } return false; } }; template< result_on_found R, typename Peek, typename Peek::data_t ... Cs > struct skip_control< one< R, Peek, Cs ... > > : std::true_type {}; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/opt.hh000066400000000000000000000021361270130067200164410ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_OPT_HH #define PEGTL_INTERNAL_OPT_HH #include "skip_control.hh" #include "seq.hh" #include "trivial.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { template< typename ... Rules > struct opt; template< typename ... Rules > struct skip_control< opt< Rules ... > > : std::true_type {}; template<> struct opt<> : trivial< true > {}; template< typename ... Rules > struct opt { using analyze_t = analysis::generic< analysis::rule_type::OPT, Rules ... >; template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { return in.empty() || rule_match_three< seq< Rules ... >, A, Action, Control >::match( in, st ... ) || true; } }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/pad.hh000066400000000000000000000006771270130067200164130ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_PAD_HH #define PEGTL_INTERNAL_PAD_HH #include "seq.hh" #include "star.hh" namespace pegtl { namespace internal { template< typename Rule, typename Pad1, typename Pad2 = Pad1 > using pad = seq< star< Pad1 >, Rule, star< Pad2 > >; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/pad_opt.hh000066400000000000000000000007131270130067200172640ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_PAD_OPT_HH #define PEGTL_INTERNAL_PAD_OPT_HH #include "seq.hh" #include "opt.hh" #include "star.hh" namespace pegtl { namespace internal { template< typename Rule, typename Pad > using pad_opt = seq< star< Pad >, opt< Rule, star< Pad > > >; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/peek_char.hh000066400000000000000000000011601270130067200175540ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_PEEK_CHAR_HH #define PEGTL_INTERNAL_PEEK_CHAR_HH #include #include "input_pair.hh" namespace pegtl { namespace internal { struct peek_char { using data_t = char; using pair_t = input_pair< char >; template< typename Input > static pair_t peek( Input & in, const std::size_t o = 0 ) { return { in.peek_char( o ), 1 }; } }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/peek_utf16.hh000066400000000000000000000026101270130067200176050ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_PEEK_UTF16_HH #define PEGTL_INTERNAL_PEEK_UTF16_HH #include #include "input_pair.hh" namespace pegtl { namespace internal { struct peek_utf16 { using data_t = char32_t; using pair_t = input_pair< char32_t >; using short_t = std::make_unsigned< char16_t >::type; static_assert( sizeof( short_t ) == 2, "expected size 2 for 16bit value" ); static_assert( sizeof( char16_t ) == 2, "expected size 2 for 16bit value" ); template< typename Input > static pair_t peek( Input & in ) { const std::size_t s = in.size(); if ( s >= 2 ) { const char32_t t = * reinterpret_cast< const short_t * >( in.begin() ); if ( ( t < 0xd800 ) || ( t > 0xdbff ) || ( s < 4 ) ) { return { t, 2 }; } const char32_t u = * reinterpret_cast< const short_t * >( in.begin() + 2 ); if ( ( u < 0xdc00 ) || ( u > 0xdfff ) ) { return { t, 2 }; } return { ( ( ( t & 0x03ff ) << 10 ) | ( u & 0x03ff ) ) + 0x10000, 4 }; } return { 0, 0 }; } }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/peek_utf32.hh000066400000000000000000000016601270130067200176070ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_PEEK_UTF32_HH #define PEGTL_INTERNAL_PEEK_UTF32_HH #include "input_pair.hh" namespace pegtl { namespace internal { struct peek_utf32 { using data_t = char32_t; using pair_t = input_pair< char32_t >; static_assert( sizeof( char32_t ) == 4, "expected size 4 for 32bit value" ); template< typename Input > static pair_t peek( Input & in ) { const std::size_t s = in.size(); if ( s >= 4 ) { const char32_t t = * reinterpret_cast< const char32_t * >( in.begin() ); if ( ( 0 <= t ) && ( t <= 0x10ffff ) ) { return { t, 4 }; } } return { 0, 0 }; } }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/peek_utf8.hh000066400000000000000000000050171270130067200175320ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_PEEK_UTF8_HH #define PEGTL_INTERNAL_PEEK_UTF8_HH #include "input_pair.hh" namespace pegtl { namespace internal { struct peek_utf8 { using data_t = char32_t; using pair_t = input_pair< char32_t >; template< typename Input > static pair_t peek( Input & in ) { char32_t c0 = in.peek_byte(); if ( ( c0 & 0x80 ) == 0 ) { return { c0, 1 }; } else if ( ( c0 & 0xE0 ) == 0xC0 ) { if ( in.size() >= 2 ) { const char32_t c1 = in.peek_byte( 1 ); if ( ( c1 & 0xC0 ) == 0x80 ) { c0 &= 0x1F; c0 <<= 6; c0 |= ( c1 & 0x3F ); if ( c0 >= 0x80 ) { return { c0, 2 }; } } } } else if ( ( c0 & 0xF0 ) == 0xE0 ) { if ( in.size() >= 3 ) { const char32_t c1 = in.peek_byte( 1 ); const char32_t c2 = in.peek_byte( 2 ); if( ( ( c1 & 0xC0 ) == 0x80 ) && ( ( c2 & 0xC0 ) == 0x80 ) ) { c0 &= 0x0F; c0 <<= 6; c0 |= ( c1 & 0x3F ); c0 <<= 6; c0 |= ( c2 & 0x3F ); if ( c0 >= 0x800 ) { return { c0, 3 }; } } } } else if ( ( c0 & 0xF8 ) == 0xF0 ) { if ( in.size() >= 4 ) { const char32_t c1 = in.peek_byte( 1 ); const char32_t c2 = in.peek_byte( 2 ); const char32_t c3 = in.peek_byte( 3 ); if ( ( ( c1 & 0xC0 ) == 0x80 ) && ( ( c2 & 0xC0 ) == 0x80 ) && ( ( c3 & 0xC0 ) == 0x80 ) ) { c0 &= 0x07; c0 <<= 6; c0 |= ( c1 & 0x3F ); c0 <<= 6; c0 |= ( c2 & 0x3F ); c0 <<= 6; c0 |= ( c3 & 0x3F ); if ( c0 >= 0x10000 && c0 <= 0x10FFFF ) { return { c0, 4 }; } } } } return { 0, 0 }; } }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/pegtl_string.hh000066400000000000000000000050741270130067200203440ustar00rootroot00000000000000// Copyright (c) 2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_PEGTL_STRING_HH #define PEGTL_INTERNAL_PEGTL_STRING_HH #include #include #include "../ascii.hh" namespace pegtl { // Inspired by https://github.com/irrequietus/typestring // Rewritten and reduced to what is needed for the PEGTL // and to work with Visual Studio 2015. namespace internal { template< std::size_t N, std::size_t M > constexpr char string_at( const char(&c)[ M ] ) noexcept { static_assert( M <= 101, "String longer than 100 (excluding terminating \\0)!" ); return ( N < M ) ? c[ N ] : 0; } template< typename, char ... > struct string_builder; template< typename T > struct string_builder< T > { using type = T; }; template< template< char ... > class S, char ... Hs, char C, char ... Cs > struct string_builder< S< Hs ... >, C, Cs ... > : std::conditional< C == '\0', string_builder< S< Hs ... > >, string_builder< S< Hs ..., C >, Cs ... > >::type { }; } // internal } // pegtl #define PEGTL_INTERNAL_STRING_10(n,x) \ pegtl::internal::string_at< n##0 >( x ), \ pegtl::internal::string_at< n##1 >( x ), \ pegtl::internal::string_at< n##2 >( x ), \ pegtl::internal::string_at< n##3 >( x ), \ pegtl::internal::string_at< n##4 >( x ), \ pegtl::internal::string_at< n##5 >( x ), \ pegtl::internal::string_at< n##6 >( x ), \ pegtl::internal::string_at< n##7 >( x ), \ pegtl::internal::string_at< n##8 >( x ), \ pegtl::internal::string_at< n##9 >( x ) #define PEGTL_INTERNAL_STRING_100(x) \ PEGTL_INTERNAL_STRING_10(,x), \ PEGTL_INTERNAL_STRING_10(1,x), \ PEGTL_INTERNAL_STRING_10(2,x), \ PEGTL_INTERNAL_STRING_10(3,x), \ PEGTL_INTERNAL_STRING_10(4,x), \ PEGTL_INTERNAL_STRING_10(5,x), \ PEGTL_INTERNAL_STRING_10(6,x), \ PEGTL_INTERNAL_STRING_10(7,x), \ PEGTL_INTERNAL_STRING_10(8,x), \ PEGTL_INTERNAL_STRING_10(9,x) #define pegtl_string_t(x) \ pegtl::internal::string_builder< pegtl::ascii::string<>, PEGTL_INTERNAL_STRING_100(x) >::type #define pegtl_istring_t(x) \ pegtl::internal::string_builder< pegtl::ascii::istring<>, PEGTL_INTERNAL_STRING_100(x) >::type #endif PEGTL-1.3.1/pegtl/internal/plus.hh000066400000000000000000000025001270130067200166150ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_PLUS_HH #define PEGTL_INTERNAL_PLUS_HH #include "seq.hh" #include "opt.hh" #include "skip_control.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { // While plus<> could easily be implemented with // seq< Rule, Rules ..., star< Rule, Rules ... > > we // provide an explicit implementation to optimize away // the otherwise created input mark. template< typename Rule, typename ... Rules > struct plus { using analyze_t = analysis::generic< analysis::rule_type::SEQ, Rule, Rules ..., opt< plus > >; template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { return rule_match_three< seq< Rule, Rules ... >, A, Action, Control >::match( in, st ... ) && rule_match_three< star< Rule, Rules ... >, A, Action, Control >::match( in, st ... ); } }; template< typename Rule, typename ... Rules > struct skip_control< plus< Rule, Rules ... > > : std::true_type {}; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/raise.hh000066400000000000000000000016711270130067200167450ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_RAISE_HH #define PEGTL_INTERNAL_RAISE_HH #include #include "skip_control.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { template< typename T > struct raise { using analyze_t = analysis::generic< analysis::rule_type::ANY >; template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { Control< T >::raise( const_cast< const Input & >( in ), st ... ); std::abort(); // LCOV_EXCL_LINE } }; template< typename T > struct skip_control< raise< T > > : std::true_type {}; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/range.hh000066400000000000000000000025241270130067200167340ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_RANGE_HH #define PEGTL_INTERNAL_RANGE_HH #include "any.hh" #include "bump_util.hh" #include "skip_control.hh" #include "result_on_found.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { template< result_on_found R, typename Peek, typename Peek::data_t Lo, typename Peek::data_t Hi > struct range { using analyze_t = analysis::generic< analysis::rule_type::ANY >; static constexpr bool can_match_lf = ( ( ( Lo <= '\n' ) && ( '\n' <= Hi ) ) == bool( R ) ); template< typename Input > static bool match( Input & in ) { if ( ! in.empty() ) { if ( const auto t = Peek::peek( in ) ) { if ( ( ( Lo <= t.data ) && ( t.data <= Hi ) ) == bool( R ) ) { bump_impl< can_match_lf >::bump( in, t.size ); return true; } } } return false; } }; template< result_on_found R, typename Peek, typename Peek::data_t Lo, typename Peek::data_t Hi > struct skip_control< range< R, Peek, Lo, Hi > > : std::true_type {}; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/ranges.hh000066400000000000000000000046101270130067200171150ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_RANGES_HH #define PEGTL_INTERNAL_RANGES_HH #include "any.hh" #include "range.hh" #include "bump_util.hh" #include "skip_control.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { template< typename Char, Char ... Cs > struct ranges_impl; template< typename Char > struct ranges_impl< Char > { static constexpr bool can_match_lf = false; static bool match( const Char ) { return false; } }; template< typename Char, Char Eq > struct ranges_impl< Char, Eq > { static constexpr bool can_match_lf = ( Eq == '\n' ); static bool match( const Char c ) { return c == Eq; } }; template< typename Char, Char Lo, Char Hi, Char ... Cs > struct ranges_impl< Char, Lo, Hi, Cs ... > { static constexpr bool can_match_lf = ( ( ( Lo <= '\n' ) && ( '\n' <= Hi ) ) || ranges_impl< Char, Cs ... >::can_match_lf ); static bool match( const Char c ) { return ( ( Lo <= c ) && ( c <= Hi ) ) || ranges_impl< Char, Cs ... >::match( c ); } }; template< typename Peek, typename Peek::data_t ... Cs > struct ranges { using analyze_t = analysis::generic< analysis::rule_type::ANY >; static constexpr bool can_match_lf = ranges_impl< typename Peek::data_t, Cs ... >::can_match_lf; template< typename Input > static bool match( Input & in ) { if ( ! in.empty() ) { if ( const auto t = Peek::peek( in ) ) { if ( ranges_impl< typename Peek::data_t, Cs ... >::match( t.data ) ) { bump_impl< can_match_lf >::bump( in, t.size ); return true; } } } return false; } }; template< typename Peek, typename Peek::data_t Lo, typename Peek::data_t Hi > struct ranges< Peek, Lo, Hi > : range< result_on_found::SUCCESS, Peek, Lo, Hi > {}; template< typename Peek, typename Peek::data_t ... Cs > struct skip_control< ranges< Peek, Cs ... > > : std::true_type {}; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/rep.hh000066400000000000000000000027331270130067200164300ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_REP_HH #define PEGTL_INTERNAL_REP_HH #include "skip_control.hh" #include "trivial.hh" #include "rule_conjunction.hh" #include "../analysis/counted.hh" namespace pegtl { namespace internal { template< unsigned Num, typename ... Rules > struct rep; template< unsigned Num, typename ... Rules > struct skip_control< rep< Num, Rules ... > > : std::true_type {}; template< unsigned Num > struct rep< Num > : trivial< true > {}; template< typename Rule, typename ... Rules > struct rep< 0, Rule, Rules ... > : trivial< true > {}; template< unsigned Num, typename ... Rules > struct rep { using analyze_t = analysis::counted< analysis::rule_type::SEQ, Num, Rules ... >; template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { auto m = in.mark(); for ( unsigned i = 0; i != Num; ++i ) { if ( ! rule_conjunction< Rules ... >::template match< A, Action, Control >( in, st ... ) ) { return m( false ); } } return m( true ); } }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/rep_min.hh000066400000000000000000000007561270130067200172760ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_REP_MIN_HH #define PEGTL_INTERNAL_REP_MIN_HH #include "seq.hh" #include "rep.hh" #include "star.hh" namespace pegtl { namespace internal { template< unsigned Min, typename Rule, typename ... Rules > using rep_min = seq< rep< Min, Rule, Rules ... >, star< Rule, Rules ... > >; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/rep_min_max.hh000066400000000000000000000042331270130067200201350ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_REP_MIN_MAX_HH #define PEGTL_INTERNAL_REP_MIN_MAX_HH #include "trivial.hh" #include "skip_control.hh" #include "seq.hh" #include "not_at.hh" #include "../analysis/counted.hh" namespace pegtl { namespace internal { template< unsigned Min, unsigned Max, typename ... Rules > struct rep_min_max; template< unsigned Min, unsigned Max, typename ... Rules > struct skip_control< rep_min_max< Min, Max, Rules ... > > : std::true_type {}; template< unsigned Min, unsigned Max > struct rep_min_max< Min, Max > : trivial< false > { static_assert( Min <= Max, "illegal rep_min_max rule (maximum number of repetitions smaller than minimum)" ); }; template< typename Rule, typename ... Rules > struct rep_min_max< 0, 0, Rule, Rules ... > : not_at< Rule, Rules ... > { }; template< unsigned Min, unsigned Max, typename ... Rules > struct rep_min_max { using analyze_t = analysis::counted< analysis::rule_type::SEQ, Min, Rules ... >; static_assert( Min <= Max, "illegal rep_min_max rule (maximum number of repetitions smaller than minimum)" ); template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { auto m = in.mark(); for ( unsigned i = 0; i != Min; ++i ) { if ( ! rule_conjunction< Rules ... >::template match< A, Action, Control >( in, st ... ) ) { return m( false ); } } for ( unsigned i = Min; i != Max; ++i ) { if ( ! rule_match_three< seq< Rules ... >, A, Action, Control >::match( in, st ... ) ) { return m( true ); } } return m( rule_match_three< not_at< Rules ... >, A, Action, Control >::match( in, st ... ) ); } }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/rep_opt.hh000066400000000000000000000021121270130067200173010ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_REP_OPT_HH #define PEGTL_INTERNAL_REP_OPT_HH #include "skip_control.hh" #include "rule_match_three.hh" #include "seq.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { template< unsigned Max, typename ... Rules > struct rep_opt { using analyze_t = analysis::generic< analysis::rule_type::OPT, Rules ... >; template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { for ( unsigned i = 0; ( i != Max ) && rule_match_three< seq< Rules ... >, A, Action, Control >::match( in, st ... ); ++i ) {} return true; } }; template< unsigned Max, typename ... Rules > struct skip_control< rep_opt< Max, Rules ... > > : std::true_type {}; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/result_on_found.hh000066400000000000000000000006341270130067200210450ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_RESULT_ON_FOUND_HH #define PEGTL_INTERNAL_RESULT_ON_FOUND_HH namespace pegtl { namespace internal { enum class result_on_found : bool { SUCCESS = true, FAILURE = false }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/rule_conjunction.hh000066400000000000000000000017711270130067200212230ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_RULE_CONJUNCTION_HH #define PEGTL_INTERNAL_RULE_CONJUNCTION_HH #include "../apply_mode.hh" namespace pegtl { namespace internal { template< typename ... Rules > struct rule_conjunction { template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { #ifdef __cpp_fold_expressions return ( Control< Rules >::template match< A, Action, Control >( in, st ... ) && ... ); #else bool result = true; using swallow = bool[]; (void)swallow{ result = result && Control< Rules >::template match< A, Action, Control >( in, st ... ) ..., true }; return result; #endif } }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/rule_match_one.hh000066400000000000000000000026721270130067200206300ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_RULE_MATCH_ONE_HH #define PEGTL_INTERNAL_RULE_MATCH_ONE_HH #include "../apply_mode.hh" #include "skip_control.hh" #include "rule_match_two.hh" #include "rule_match_three.hh" namespace pegtl { namespace internal { // Forward to rule_match_two<> for all user-defined / -visible rules, // but skip rule_match_two<> (which calls the control class' callbacks) // and forward directly to rule_match_three<> when a rule is marked as // an internal rule by skip_control<>. template< typename Rule, apply_mode A, template< typename ... > class Action, template< typename ... > class Control, bool = skip_control< Rule >::value > struct rule_match_one; template< typename Rule, apply_mode A, template< typename ... > class Action, template< typename ... > class Control > struct rule_match_one< Rule, A, Action, Control, false > : rule_match_two< Rule, A, Action, Control > { }; template< typename Rule, apply_mode A, template< typename ... > class Action, template< typename ... > class Control > struct rule_match_one< Rule, A, Action, Control, true > : rule_match_three< Rule, A, Action, Control > { }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/rule_match_three.hh000066400000000000000000000030211270130067200211430ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_RULE_MATCH_THREE_HH #define PEGTL_INTERNAL_RULE_MATCH_THREE_HH #include "../apply_mode.hh" namespace pegtl { namespace internal { // The purpose of rule_match_three<> is to allow for two different // signatures of a rule's match()-method. A more complicated but // more general version which takes the explicit template parameters // for A, Action and Control, and a more simple and limited version // which takes the input as its only parameter. The latter is often // sufficient and helps to keep the overhead smaller. template< typename Rule, apply_mode A, template< typename ... > class Action, template< typename ... > class Control > struct rule_match_three { template< typename Input, typename ... States > static auto match( Input & in, States && ... st ) -> decltype( Rule::template match< A, Action, Control >( in, st ... ), true ) { return Rule::template match< A, Action, Control >( in, st ... ); } // NOTE: The additional "int = 0" is a work-around for missing expression SFINAE in VS2015. template< typename Input, typename ... States, int = 0 > static auto match( Input & in, States && ... ) -> decltype( Rule::match( in ), true ) { return Rule::match( in ); } }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/rule_match_two.hh000066400000000000000000000044541270130067200206600ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_RULE_MATCH_TWO_HH #define PEGTL_INTERNAL_RULE_MATCH_TWO_HH #include "../apply_mode.hh" #include "../nothing.hh" #include "rule_match_three.hh" namespace pegtl { namespace internal { // The purpose of rule_match_two is to call all necessary debug hooks of // the control class and, if applicable, also call the action class' // apply()-method. The latter can be disabled either explicitly (via // disable<>) or implicitly by at<> or not_at<>. template< typename Rule, apply_mode A, template< typename ... > class Action, template< typename ... > class Control, bool apply_here = ( ( A == apply_mode::ACTION ) && ( ! is_nothing< Action, Rule >::value ) ) > struct rule_match_two; template< typename Rule, apply_mode A, template< typename ... > class Action, template< typename ... > class Control > struct rule_match_two< Rule, A, Action, Control, false > { template< typename Input, typename ... States > static bool match( Input & in, States && ... st ) { Control< Rule >::start( const_cast< const Input & >( in ), st ... ); if ( rule_match_three< Rule, A, Action, Control >::match( in, st ... ) ) { Control< Rule >::success( const_cast< const Input & >( in ), st ... ); return true; } Control< Rule >::failure( const_cast< const Input & >( in ), st ... ); return false; } }; template< typename Rule, apply_mode A, template< typename ... > class Action, template< typename ... > class Control > struct rule_match_two< Rule, A, Action, Control, true > { template< typename Input, typename ... States > static bool match( Input & in, States && ... st ) { auto m = in.mark(); if ( rule_match_two< Rule, A, Action, Control, false >::match( in, st ... ) ) { Action< Rule >::apply( Input( in.data(), m ), st ... ); return m( true ); } return false; } }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/rules.hh000066400000000000000000000021151270130067200167660ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_RULES_HH #define PEGTL_INTERNAL_RULES_HH #include "action.hh" #include "any.hh" #include "at.hh" #include "bytes.hh" #include "control.hh" #include "disable.hh" #include "enable.hh" #include "eof.hh" #include "eol.hh" #include "eolf.hh" #include "if_must.hh" #include "if_must_else.hh" #include "if_then_else.hh" #include "istring.hh" #include "list.hh" #include "list_must.hh" #include "list_tail.hh" #include "list_tail_pad.hh" #include "must.hh" #include "not_at.hh" #include "one.hh" #include "opt.hh" #include "pad.hh" #include "pad_opt.hh" #include "plus.hh" #include "range.hh" #include "ranges.hh" #include "raise.hh" #include "rep.hh" #include "rep_min.hh" #include "rep_min_max.hh" #include "rep_opt.hh" #include "seq.hh" #include "skip_control.hh" #include "sor.hh" #include "star.hh" #include "star_must.hh" #include "state.hh" #include "string.hh" #include "trivial.hh" #include "try_catch_type.hh" #include "until.hh" #endif PEGTL-1.3.1/pegtl/internal/seq.hh000066400000000000000000000030761270130067200164330ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_SEQ_HH #define PEGTL_INTERNAL_SEQ_HH #include "trivial.hh" #include "skip_control.hh" #include "rule_conjunction.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { template< typename ... Rules > struct seq; template< typename ... Rules > struct skip_control< seq< Rules ... > > : std::true_type {}; template<> struct seq<> : trivial< true > {}; template< typename Rule > struct seq< Rule > { using analyze_t = typename Rule::analyze_t; template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { return Control< Rule >::template match< A, Action, Control >( in, st ... ); } }; template< typename ... Rules > struct seq { using analyze_t = analysis::generic< analysis::rule_type::SEQ, Rules ... >; template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { auto m = in.mark(); return m( rule_conjunction< Rules ... >::template match< A, Action, Control >( in, st ... ) ); } }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/skip_control.hh000066400000000000000000000014001270130067200203360ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_SKIP_CONTROL_HH #define PEGTL_INTERNAL_SKIP_CONTROL_HH #include namespace pegtl { namespace internal { // This class is a simple tagging mechanism. // By default, skip_control< Rule >::value // is 'false'. Each internal (!) rule that should // be hidden from the control and action class' // callbacks simply specializes skip_control<> // to return 'true' for the above expression. // This is then used in rule_match_one.hh. template< typename Rule > struct skip_control : std::false_type {}; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/sor.hh000066400000000000000000000023201270130067200164350ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_SOR_HH #define PEGTL_INTERNAL_SOR_HH #include "../apply_mode.hh" #include "skip_control.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { template< typename ... Rules > struct sor { using analyze_t = analysis::generic< analysis::rule_type::SOR, Rules ... >; template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { #ifdef __cpp_fold_expressions return ( Control< Rules >::template match< A, Action, Control >( in, st ... ) || ... ); #else bool result = false; using swallow = bool[]; (void)swallow{ result = result || Control< Rules >::template match< A, Action, Control >( in, st ... ) ..., true }; return result; #endif } }; template< typename ... Rules > struct skip_control< sor< Rules ... > > : std::true_type {}; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/star.hh000066400000000000000000000020671270130067200166130ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_STAR_HH #define PEGTL_INTERNAL_STAR_HH #include "seq.hh" #include "opt.hh" #include "skip_control.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { template< typename Rule, typename ... Rules > struct star { using analyze_t = analysis::generic< analysis::rule_type::OPT, Rule, Rules ..., star >; template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { while ( ( ! in.empty() ) && rule_match_three< seq< Rule, Rules ... >, A, Action, Control >::match( in, st ... ) ) {} return true; } }; template< typename Rule, typename ... Rules > struct skip_control< star< Rule, Rules ... > > : std::true_type {}; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/star_must.hh000066400000000000000000000006751270130067200176660ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_STAR_MUST_HH #define PEGTL_INTERNAL_STAR_MUST_HH #include "star.hh" #include "if_must.hh" namespace pegtl { namespace internal { template< typename Cond, typename ... Rules > using star_must = star< if_must< Cond, Rules ... > >; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/state.hh000066400000000000000000000040231270130067200167540ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_STATE_HH #define PEGTL_INTERNAL_STATE_HH #include "seq.hh" #include "rule_match_three.hh" #include "skip_control.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { template< typename State, typename ... Rules > struct state { using analyze_t = analysis::generic< analysis::rule_type::SEQ, Rules ... >; template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static auto success( State & s, const Input & in, States && ... st ) -> decltype( s.template success< A, Action, Control >( in, st ... ), void() ) { s.template success< A, Action, Control >( in, st ... ); } // NOTE: The additional "int = 0" is a work-around for missing expression SFINAE in VS2015. template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States, int = 0 > static auto success( State & s, const Input & in, States && ... st ) -> decltype( s.success( in, st ... ), void() ) { s.success( in, st ... ); } template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { State s( const_cast< const Input & >( in ), st ... ); if ( rule_match_three< seq< Rules ... >, A, Action, Control >::match( in, s ) ) { success< A, Action, Control >( s, in, st ... ); return true; } return false; } }; template< typename State, typename ... Rules > struct skip_control< state< State, Rules ... > > : std::true_type {}; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/string.hh000066400000000000000000000026031270130067200171440ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_STRING_HH #define PEGTL_INTERNAL_STRING_HH #include #include #include "result_on_found.hh" #include "skip_control.hh" #include "bump_util.hh" #include "trivial.hh" #include "../analysis/counted.hh" namespace pegtl { namespace internal { inline bool unsafe_equals( const char * s, const std::initializer_list< char > & l ) { return std::memcmp( s, & * l.begin(), l.size() ) == 0; } template< char ... Cs > struct string; template< char ... Cs > struct skip_control< string< Cs ... > > : std::true_type {}; template<> struct string<> : trivial< true > {}; template< char ... Cs > struct string { using analyze_t = analysis::counted< analysis::rule_type::ANY, sizeof ... ( Cs ) >; template< typename Input > static bool match( Input & in ) { if ( in.size() >= sizeof ... ( Cs ) ) { if ( unsafe_equals( in.begin(), { Cs ... } ) ) { bump< result_on_found::SUCCESS, Input, char, Cs ... >( in, sizeof ... ( Cs ) ); return true; } } return false; } }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/trivial.hh000066400000000000000000000013431270130067200173100ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_TRIVIAL_HH #define PEGTL_INTERNAL_TRIVIAL_HH #include "skip_control.hh" #include "../analysis/counted.hh" namespace pegtl { namespace internal { template< bool Result > struct trivial { using analyze_t = analysis::counted< analysis::rule_type::ANY, unsigned( ! Result ) >; template< typename Input > static bool match( Input & ) { return Result; } }; template< bool Result > struct skip_control< trivial< Result > > : std::true_type {}; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/try_catch_type.hh000066400000000000000000000026151270130067200206620ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_TRY_CATCH_TYPE_HH #define PEGTL_INTERNAL_TRY_CATCH_TYPE_HH #include "skip_control.hh" #include "trivial.hh" #include "seq.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { template< typename Exception, typename ... Rules > struct try_catch_type; template< typename Exception, typename ... Rules > struct skip_control< try_catch_type< Exception, Rules ... > > : std::true_type {}; template< typename Exception > struct try_catch_type< Exception > : trivial< true > {}; template< typename Exception, typename ... Rules > struct try_catch_type { using analyze_t = analysis::generic< analysis::rule_type::SEQ, Rules ... >; template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { auto m = in.mark(); try { return m( rule_match_three< seq< Rules ... >, A, Action, Control >::match( in, st ... ) ); } catch ( const Exception & ) { return false; } } }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/internal/until.hh000066400000000000000000000042351270130067200167740ustar00rootroot00000000000000// Copyright (c) 2014-2016 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_INTERNAL_UNTIL_HH #define PEGTL_INTERNAL_UNTIL_HH #include "eof.hh" #include "star.hh" #include "bytes.hh" #include "not_at.hh" #include "skip_control.hh" #include "rule_conjunction.hh" #include "../analysis/generic.hh" namespace pegtl { namespace internal { template< typename Cond, typename ... Rules > struct until; template< typename Cond, typename ... Rules > struct skip_control< until< Cond, Rules ... > > : std::true_type {}; template< typename Cond > struct until< Cond > { using analyze_t = analysis::generic< analysis::rule_type::SEQ, star< not_at< Cond >, not_at< eof >, bytes< 1 > >, Cond >; template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { auto m = in.mark(); while ( ! Control< Cond >::template match< A, Action, Control >( in, st ... ) ) { if ( in.empty() ) { return false; } in.bump(); } m.success(); return true; } }; template< typename Cond, typename ... Rules > struct until { using analyze_t = analysis::generic< analysis::rule_type::SEQ, star< not_at< Cond >, not_at< eof >, Rules ... >, Cond >; template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { auto m = in.mark(); while ( ! Control< Cond >::template match< A, Action, Control >( in, st ... ) ) { if ( in.empty() || ! rule_conjunction< Rules ... >::template match< A, Action, Control >( in, st ... ) ) { return false; } } m.success(); return true; } }; } // internal } // pegtl #endif PEGTL-1.3.1/pegtl/mmap_parser.hh000066400000000000000000000026311270130067200163310ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_MMAP_PARSER_HH #define PEGTL_MMAP_PARSER_HH #include #include "parse.hh" #include "input.hh" #include "normal.hh" #include "nothing.hh" #include "internal/file_mapper.hh" namespace pegtl { class mmap_parser { public: explicit mmap_parser( const std::string & filename ) : m_file( filename ), m_source( filename ), m_input( 1, 0, m_file.begin(), m_file.end(), m_source.c_str() ) { } mmap_parser( const std::string & filename, const pegtl::input & from ) : m_file( filename ), m_source( filename ), m_input( 1, 0, m_file.begin(), m_file.end(), m_source.c_str(), & from ) { } const std::string & source() const { return m_source; } const pegtl::input & input() const { return m_input; } template< typename Rule, template< typename ... > class Action = nothing, template< typename ... > class Control = normal, typename ... States > bool parse( States && ... st ) { return parse_input< Rule, Action, Control >( m_input, st ... ); } private: internal::file_mapper m_file; std::string m_source; pegtl::input m_input; }; } // pegtl #endif PEGTL-1.3.1/pegtl/normal.hh000066400000000000000000000024341270130067200153140ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_NORMAL_HH #define PEGTL_NORMAL_HH #include "apply_mode.hh" #include "parse_error.hh" #include "internal/demangle.hh" #include "internal/rule_match_one.hh" namespace pegtl { template< typename Rule > struct normal { template< typename Input, typename ... States > static void start( const Input &, States && ... ) { } template< typename Input, typename ... States > static void success( const Input &, States && ... ) { } template< typename Input, typename ... States > static void failure( const Input &, States && ... ) { } template< typename Input, typename ... States > static void raise( const Input & in, States && ... ) { throw pegtl::parse_error( "parse error matching " + internal::demangle< Rule >(), in ); } template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States > static bool match( Input & in, States && ... st ) { return internal::rule_match_one< Rule, A, Action, Control >::match( in, st ... ); } }; } // pegtl #endif PEGTL-1.3.1/pegtl/nothing.hh000066400000000000000000000006711270130067200154730ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_NOTHING_HH #define PEGTL_NOTHING_HH #include namespace pegtl { template< typename Rule > struct nothing {}; template< template< typename ... > class Action, typename Rule > using is_nothing = std::is_base_of< nothing< Rule >, Action< Rule > >; } // pegtl #endif PEGTL-1.3.1/pegtl/parse.hh000066400000000000000000000066111270130067200151370ustar00rootroot00000000000000// Copyright (c) 2014-2016 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_PARSE_HH #define PEGTL_PARSE_HH #include #include #include #include "input.hh" #include "normal.hh" #include "nothing.hh" #include "apply_mode.hh" namespace pegtl { template< typename Rule, template< typename ... > class Action = nothing, template< typename ... > class Control = normal, typename Input, typename ... States > bool parse_input( Input & in, States && ... st ) { return Control< Rule >::template match< apply_mode::ACTION, Action, Control >( in, st ... ); } template< typename Rule, template< typename ... > class Action = nothing, template< typename ... > class Control = normal, typename ... States > bool parse( const int argc, char ** argv, States && ... st ) { std::ostringstream os; os << "argv[" << argc << ']'; const std::string source = os.str(); input in( 1, 0, argv[ argc ], argv[ argc ] + ::strlen( argv[ argc ] ), source.c_str() ); return parse_input< Rule, Action, Control >( in, st ... ); } template< typename Rule, template< typename ... > class Action = nothing, template< typename ... > class Control = normal, typename ... States > bool parse( const char * data, const char * dend, const char * source, States && ... st ) { input in( 1, 0, data, dend, source ); return parse_input< Rule, Action, Control >( in, st ... ); } template< typename Rule, template< typename ... > class Action = nothing, template< typename ... > class Control = normal, typename ... States > bool parse( const char * data, const std::size_t size, const char * source, States && ... st ) { return parse< Rule, Action, Control >( data, data + size, source, st ... ); } template< typename Rule, template< typename ... > class Action = nothing, template< typename ... > class Control = normal, typename ... States > bool parse( const std::string & data, const std::string & source, States && ... st ) { return parse< Rule, Action, Control >( data.data(), data.data() + data.size(), source.c_str(), st ... ); } template< typename Rule, template< typename ... > class Action = nothing, template< typename ... > class Control = normal, typename Input, typename ... States > bool parse_nested( const Input & nest, const char * data, const char * dend, const char * source, States && ... st ) { input in( 1, 0, data, dend, source, & nest ); return parse_input< Rule, Action, Control >( in, st ... ); } template< typename Rule, template< typename ... > class Action = nothing, template< typename ... > class Control = normal, typename Input, typename ... States > bool parse_nested( const Input & nest, const char * data, const std::size_t size, const char * source, States && ... st ) { return parse_nested< Rule, Action, Control >( nest, data, data + size, source, st ... ); } template< typename Rule, template< typename ... > class Action = nothing, template< typename ... > class Control = normal, typename Input, typename ... States > bool parse_nested( const Input & nest, const std::string & data, const std::string & source, States && ... st ) { return parse_nested< Rule, Action, Control >( nest, data.data(), data.data() + data.size(), source.c_str(), st ... ); } } // pegtl #endif PEGTL-1.3.1/pegtl/parse_error.hh000066400000000000000000000026471270130067200163550ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_PARSE_ERROR_HH #define PEGTL_PARSE_ERROR_HH #include #include #include #include "position_info.hh" namespace pegtl { namespace internal { template< typename Input > std::vector< position_info > positions( const Input & in ) { std::vector< position_info > result; for ( const auto * id = & in.data(); id; id = id->from ) { result.push_back( pegtl::position_info( * id ) ); } return result; } template< typename Input > std::string source( const Input & in ) { std::ostringstream oss; oss << pegtl::position_info( in.data() ); return oss.str(); } } // internal struct parse_error : std::runtime_error { parse_error( const std::string & message, std::vector< position_info > && positions ) : std::runtime_error( message ), positions( std::move( positions ) ) { } template< typename Input > parse_error( const std::string & message, const Input & in ) : std::runtime_error( internal::source( in ) + ": " + message ), positions( internal::positions( in ) ) { } std::vector< position_info > positions; }; } // pegtl #endif PEGTL-1.3.1/pegtl/position_info.hh000066400000000000000000000017071270130067200167050ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_POSITION_INFO_HH #define PEGTL_POSITION_INFO_HH #include #include #include #include "input.hh" #include "internal/input_data.hh" namespace pegtl { struct position_info { explicit position_info( const input & in ) : position_info( in.data() ) { } explicit position_info( const internal::input_data & id ) : source( id.source ), line( id.line ), column( id.column ), begin( id.begin ) { } std::string source; std::size_t line; std::size_t column; const char * begin; }; inline std::ostream & operator<< ( std::ostream & o, const position_info & p ) { return o << p.source << ':' << p.line << ':' << p.column; } } // pegtl #endif PEGTL-1.3.1/pegtl/read_parser.hh000066400000000000000000000012731270130067200163130ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_READ_PARSER_HH #define PEGTL_READ_PARSER_HH #include "data_parser.hh" #include "internal/file_reader.hh" namespace pegtl { class read_parser : public data_parser { public: explicit read_parser( const std::string & filename ) : data_parser( internal::file_reader( filename ).read(), filename ) { } read_parser( const std::string & filename, const pegtl::input & from ) : data_parser( internal::file_reader( filename ).read(), filename, from ) { } }; } // pegtl #endif PEGTL-1.3.1/pegtl/rules.hh000066400000000000000000000100421270130067200151500ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_RULES_HH #define PEGTL_RULES_HH #include "parse_error.hh" #include "internal/rules.hh" namespace pegtl { template< template< typename ... > class Action, typename ... Rules > struct action : internal::action< Action, Rules ... > {}; template< typename ... Rules > struct at : internal::at< Rules ... > {}; template< unsigned Num > struct bytes : internal::bytes< Num > {}; template< template< typename ... > class Control, typename ... Rules > struct control : internal::control< Control, Rules ... > {}; template< typename ... Rules > struct disable : internal::disable< Rules ... > {}; template< typename ... Rules > struct enable : internal::enable< Rules ... > {}; struct eof : internal::eof {}; struct failure : internal::trivial< false > {}; template< typename Cond, typename ... Thens > struct if_must : internal::if_must< Cond, Thens ... > {}; template< typename Cond, typename Then, typename Else > struct if_must_else : internal::if_must_else< Cond, Then, Else > {}; template< typename Cond, typename Then, typename Else > struct if_then_else : internal::if_then_else< Cond, Then, Else > {}; template< typename Rule, typename Sep, typename Pad = void > struct list : internal::list< Rule, internal::pad< Sep, Pad > > {}; template< typename Rule, typename Sep > struct list< Rule, Sep, void > : internal::list< Rule, Sep > {}; template< typename Rule, typename Sep, typename Pad = void > struct list_must : internal::list_must< Rule, internal::pad< Sep, Pad > > {}; template< typename Rule, typename Sep > struct list_must< Rule, Sep, void > : internal::list_must< Rule, Sep > {}; template< typename Rule, typename Sep, typename Pad = void > struct list_tail : internal::list_tail_pad< Rule, Sep, Pad > {}; template< typename Rule, typename Sep > struct list_tail< Rule, Sep, void > : internal::list_tail< Rule, Sep > {}; template< typename ... Rules > struct must : internal::must< Rules ... > {}; template< typename ... Rules > struct not_at : internal::not_at< Rules ... > {}; template< typename ... Rules > struct opt : internal::opt< Rules ... > {}; template< typename Rule, typename Pad1, typename Pad2 = Pad1 > struct pad : internal::pad< Rule, Pad1, Pad2 > {}; template< typename Rule, typename Pad > struct pad_opt : internal::pad_opt< Rule, Pad > {}; template< typename Rule, typename ... Rules > struct plus : internal::plus< Rule, Rules ... > {}; template< typename Exception > struct raise : internal::raise< Exception > {}; template< unsigned Num, typename ... Rules > struct rep : internal::rep< Num, Rules ... > {}; template< unsigned Max, typename ... Rules > struct rep_max : internal::rep_min_max< 0, Max, Rules ... > {}; template< unsigned Min, typename Rule, typename ... Rules > struct rep_min : internal::rep_min< Min, Rule, Rules ... > {}; template< unsigned Min, unsigned Max, typename ... Rules > struct rep_min_max : internal::rep_min_max< Min, Max, Rules ... > {}; template< unsigned Max, typename ... Rules > struct rep_opt : internal::rep_opt< Max, Rules ... > {}; template< typename ... Rules > struct seq : internal::seq< Rules ... > {}; template< typename ... Rules > struct sor : internal::sor< Rules ... > {}; template< typename Rule, typename ... Rules > struct star : internal::star< Rule, Rules ... > {}; template< typename Cond, typename ... Rules > struct star_must : internal::star_must< Cond, Rules ... > {}; template< typename State, typename ... Rules > struct state : internal::state< State, Rules ... > {}; struct success : internal::trivial< true > {}; template< typename ... Rules > struct try_catch : internal::try_catch_type< parse_error, Rules ... > {}; template< typename Exception, typename ... Rules > struct try_catch_type : internal::try_catch_type< Exception, Rules ... > {}; template< typename Cond, typename ... Rules > struct until : internal::until< Cond, Rules ... > {}; } // pegtl #endif PEGTL-1.3.1/pegtl/trace.hh000066400000000000000000000031711270130067200151210ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_TRACE_HH #define PEGTL_TRACE_HH #include #include #include "parse.hh" #include "normal.hh" #include "nothing.hh" #include "position_info.hh" #include "internal/demangle.hh" namespace pegtl { template< typename Rule > struct tracer : normal< Rule > { template< typename Input, typename ... States > static void start( const Input & in, States && ... ) { std::cerr << pegtl::position_info( in ) << " start " << internal::demangle< Rule >() << std::endl; } template< typename Input, typename ... States > static void success( const Input & in, States && ... ) { std::cerr << pegtl::position_info( in ) << " success " << internal::demangle< Rule >() << std::endl; } template< typename Input, typename ... States > static void failure( const Input & in, States && ... ) { std::cerr << pegtl::position_info( in ) << " failure " << internal::demangle< Rule >() << std::endl; } }; template< typename Rule, template< typename ... > class Action = nothing, typename Input, typename ... States > bool trace_input( Input & in, States && ... st ) { return parse_input< Rule, Action, tracer >( in, st ... ); } template< typename Rule, template< typename ... > class Action = nothing, typename ... Args > bool trace( Args && ... args ) { return parse< Rule, Action, tracer >( std::forward< Args >( args ) ... ); } } // pegtl #endif PEGTL-1.3.1/pegtl/utf16.hh000066400000000000000000000021011270130067200147600ustar00rootroot00000000000000// Copyright (c) 2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_UTF16_HH #define PEGTL_UTF16_HH #include "internal/rules.hh" #include "internal/peek_utf16.hh" #include "internal/result_on_found.hh" namespace pegtl { namespace utf16 { struct any : internal::any< internal::peek_utf16 > {}; template< char32_t ... Cs > struct not_one : internal::one< internal::result_on_found::FAILURE, internal::peek_utf16, Cs ... > {}; template< char32_t Lo, char32_t Hi > struct not_range : internal::range< internal::result_on_found::FAILURE, internal::peek_utf16, Lo, Hi > {}; template< char32_t ... Cs > struct one : internal::one< internal::result_on_found::SUCCESS, internal::peek_utf16, Cs ... > {}; template< char32_t Lo, char32_t Hi > struct range : internal::range< internal::result_on_found::SUCCESS, internal::peek_utf16, Lo, Hi > {}; template< char32_t ... Cs > struct ranges : internal::ranges< internal::peek_utf16, Cs ... > {}; } // utf16 } // pegtl #endif PEGTL-1.3.1/pegtl/utf32.hh000066400000000000000000000021061270130067200147630ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_UTF32_HH #define PEGTL_UTF32_HH #include "internal/rules.hh" #include "internal/peek_utf32.hh" #include "internal/result_on_found.hh" namespace pegtl { namespace utf32 { struct any : internal::any< internal::peek_utf32 > {}; template< char32_t ... Cs > struct not_one : internal::one< internal::result_on_found::FAILURE, internal::peek_utf32, Cs ... > {}; template< char32_t Lo, char32_t Hi > struct not_range : internal::range< internal::result_on_found::FAILURE, internal::peek_utf32, Lo, Hi > {}; template< char32_t ... Cs > struct one : internal::one< internal::result_on_found::SUCCESS, internal::peek_utf32, Cs ... > {}; template< char32_t Lo, char32_t Hi > struct range : internal::range< internal::result_on_found::SUCCESS, internal::peek_utf32, Lo, Hi > {}; template< char32_t ... Cs > struct ranges : internal::ranges< internal::peek_utf32, Cs ... > {}; } // utf32 } // pegtl #endif PEGTL-1.3.1/pegtl/utf8.hh000066400000000000000000000020731270130067200147110ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_UTF8_HH #define PEGTL_UTF8_HH #include "internal/rules.hh" #include "internal/peek_utf8.hh" #include "internal/result_on_found.hh" namespace pegtl { namespace utf8 { struct any : internal::any< internal::peek_utf8 > {}; template< char32_t ... Cs > struct not_one : internal::one< internal::result_on_found::FAILURE, internal::peek_utf8, Cs ... > {}; template< char32_t Lo, char32_t Hi > struct not_range : internal::range< internal::result_on_found::FAILURE, internal::peek_utf8, Lo, Hi > {}; template< char32_t ... Cs > struct one : internal::one< internal::result_on_found::SUCCESS, internal::peek_utf8, Cs ... > {}; template< char32_t Lo, char32_t Hi > struct range : internal::range< internal::result_on_found::SUCCESS, internal::peek_utf8, Lo, Hi > {}; template< char32_t ... Cs > struct ranges : internal::ranges< internal::peek_utf8, Cs ... > {}; } // utf8 } // pegtl #endif PEGTL-1.3.1/unit_tests/000077500000000000000000000000001270130067200145665ustar00rootroot00000000000000PEGTL-1.3.1/unit_tests/actions.cc000066400000000000000000000066671270130067200165540ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { namespace test1 { struct fiz : if_must< at< one< 'a' > >, two< 'a' > > {}; struct foo : sor< fiz, one< 'b' > > {}; struct bar : until< eof, foo > {}; void test_result() { TEST_ASSERT( applied.size() == 10 ); TEST_ASSERT( applied[ 0 ].first == internal::demangle< one< 'b' > >() ); TEST_ASSERT( applied[ 1 ].first == internal::demangle< foo >() ); TEST_ASSERT( applied[ 2 ].first == internal::demangle< at< one< 'a' > > >() ); TEST_ASSERT( applied[ 3 ].first == internal::demangle< two< 'a' > >() ); TEST_ASSERT( applied[ 4 ].first == internal::demangle< fiz >() ); TEST_ASSERT( applied[ 5 ].first == internal::demangle< foo >() ); TEST_ASSERT( applied[ 6 ].first == internal::demangle< one< 'b' > >() ); TEST_ASSERT( applied[ 7 ].first == internal::demangle< foo >() ); TEST_ASSERT( applied[ 8 ].first == internal::demangle< eof >() ); TEST_ASSERT( applied[ 9 ].first == internal::demangle< bar >() ); TEST_ASSERT( applied[ 0 ].second == "b" ); TEST_ASSERT( applied[ 1 ].second == "b" ); TEST_ASSERT( applied[ 2 ].second == "" ); TEST_ASSERT( applied[ 3 ].second == "aa" ); TEST_ASSERT( applied[ 4 ].second == "aa" ); TEST_ASSERT( applied[ 5 ].second == "aa" ); TEST_ASSERT( applied[ 6 ].second == "b" ); TEST_ASSERT( applied[ 7 ].second == "b" ); TEST_ASSERT( applied[ 8 ].second == "" ); TEST_ASSERT( applied[ 9 ].second == "baab" ); } struct state1 { char c; template< typename Input > state1( const Input &, std::string & ) { } template< typename Input > void success( const Input &, std::string & s ) const { s += c; } }; struct fobble : sor< state< state1, alpha >, digit > {}; struct fibble : until< eof, fobble > {}; template< typename Rule > struct action1 : nothing< Rule > {}; template<> struct action1< alpha > { static void apply( const input & in, state1 & s ) { assert( in.size() == 1 ); s.c = 0[ in.begin() ]; } }; void state_test() { std::string result; parse< fibble, action1 >( "dk41sk41xk3", __FILE__, result ); TEST_ASSERT( result == "dkskxk" ); } } // test1 void unit_test() { parse< disable< test1::bar >, test_action >( "baab", __FILE__ ); TEST_ASSERT( applied.size() == 1 ); TEST_ASSERT( applied[ 0 ].first == internal::demangle< disable< test1::bar > >() ); TEST_ASSERT( applied[ 0 ].second == "baab" ); applied.clear(); parse< at< action< test_action, test1::bar > > >( "baab", __FILE__ ); TEST_ASSERT( applied.empty() ); applied.clear(); parse< test1::bar, test_action >( "baab", __FILE__ ); test1::test_result(); applied.clear(); parse< action< test_action, test1::bar > >( "baab", __FILE__ ); test1::test_result(); applied.clear(); parse< disable< enable< action< test_action, test1::bar > > > >( "baab", __FILE__ ); test1::test_result(); test1::state_test(); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/analyze.cc000066400000000000000000000152501270130067200165430ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { template< typename ... Rules > struct any_seq : public seq< Rules ... > { using analyze_t = analysis::generic< analysis::rule_type::ANY, Rules ... >; }; void unit_test() { verify_analyze< eof >( __LINE__, __FILE__, false, false ); verify_analyze< eolf >( __LINE__, __FILE__, false, false ); verify_analyze< success >( __LINE__, __FILE__, false, false ); verify_analyze< failure >( __LINE__, __FILE__, true, false ); { struct tst : seq< eof, at< digit >, tst > {}; verify_analyze< tst >( __LINE__, __FILE__, false, true ); // This is a false positive. } { struct tst : sor< digit, seq< at< digit >, tst > > {}; verify_analyze< tst >( __LINE__, __FILE__, false, true ); // This is a false positive. } { struct tst : sor< digit, seq< opt< digit >, tst > > {}; verify_analyze< tst >( __LINE__, __FILE__, false, true ); } { struct tst : sor< digit, tst > {}; verify_analyze< tst >( __LINE__, __FILE__, false, true ); } { struct tst : at< any > {}; verify_analyze< tst >( __LINE__, __FILE__, false, false ); } { struct tst : at< tst > {}; verify_analyze< tst >( __LINE__, __FILE__, false, true ); } { struct tst : at< any, tst > {}; verify_analyze< tst >( __LINE__, __FILE__, false, false ); } { struct tst : not_at< any > {}; verify_analyze< tst >( __LINE__, __FILE__, false, false ); } { struct tst : opt< tst > {}; verify_analyze< tst >( __LINE__, __FILE__, false, true ); } { struct tst : opt< any, tst > {}; verify_analyze< tst >( __LINE__, __FILE__, false, false ); } { struct rec : sor< seq< rec, alpha >, alpha > {}; verify_analyze< rec >( __LINE__, __FILE__, true, true ); } { struct bar; struct foo : seq< digit, bar > {}; struct bar : plus< foo > {}; verify_analyze< seq< any, bar > >( __LINE__, __FILE__, true, false ); } { struct bar; struct foo : seq< bar, digit > {}; struct bar : plus< foo > {}; verify_analyze< seq< bar, any > >( __LINE__, __FILE__, true, true ); } { struct bar; struct foo : sor< digit, bar > {}; struct bar : plus< foo > {}; verify_analyze< bar >( __LINE__, __FILE__, false, true ); verify_analyze< foo >( __LINE__, __FILE__, false, true ); verify_analyze< sor< any, bar > >( __LINE__, __FILE__, false, true ); } { // Excerpt from the Lua 5.3 grammar: // prefixexp ::= var | functioncall | ‘(’ exp ‘)’ // functioncall ::= prefixexp args | prefixexp ‘:’ Name args // var ::= Name | prefixexp ‘[’ exp ‘]’ | prefixexp ‘.’ Name // Simplified version, equivalent regarding consumption of input: struct var; struct fun; struct exp : sor< var, fun, seq< any, exp, any > > {}; struct fun : seq< exp, any > {}; struct var : sor< any, seq< exp, any, exp >, seq< exp, any > > {}; verify_analyze< exp >( __LINE__, __FILE__, true, true ); verify_analyze< fun >( __LINE__, __FILE__, true, true ); verify_analyze< var >( __LINE__, __FILE__, true, true ); } { struct exp : sor< exp, seq< any, exp > > {}; verify_analyze< exp >( __LINE__, __FILE__, false, true ); } { struct tst : until< any > {}; verify_analyze< tst >( __LINE__, __FILE__, true, false ); } { struct tst : until< star< any > > {}; verify_analyze< tst >( __LINE__, __FILE__, false, false ); } { struct tst : until< any, star< any > > {}; verify_analyze< tst >( __LINE__, __FILE__, true, true ); } { struct tst : until< star< any >, star< any > > {}; verify_analyze< tst >( __LINE__, __FILE__, false, true ); } { struct tst : until< star< any >, star< any > > {}; verify_analyze< any_seq< tst > >( __LINE__, __FILE__, true, true ); } { struct tst : until< any, any > {}; verify_analyze< tst >( __LINE__, __FILE__, true, false ); } { struct tst : until< star< any >, any > {}; verify_analyze< tst >( __LINE__, __FILE__, false, false ); } { struct tst : plus< plus< any > > {}; verify_analyze< tst >( __LINE__, __FILE__, true, false ); } { struct tst : star< star< any > > {}; verify_analyze< tst >( __LINE__, __FILE__, false, true ); } { struct tst : plus< star< any > > {}; verify_analyze< tst >( __LINE__, __FILE__, false, true ); } { struct tst : plus< opt< any > > {}; verify_analyze< tst >( __LINE__, __FILE__, false, true ); } { struct tst : star< opt< any > > {}; verify_analyze< tst >( __LINE__, __FILE__, false, true ); } { struct tst : star< plus< opt< any > > > {}; verify_analyze< tst >( __LINE__, __FILE__, false, true ); } { struct tst : list< any, any > {}; verify_analyze< tst >( __LINE__, __FILE__, true, false ); } { struct tst : list< star< any >, any > {}; verify_analyze< tst >( __LINE__, __FILE__, false, false ); } { struct tst : list< any, opt< any > > {}; verify_analyze< tst >( __LINE__, __FILE__, true, false ); } { struct tst : list< star< any >, opt< any > > {}; verify_analyze< tst >( __LINE__, __FILE__, false, true ); } { struct tst : list_must< any, any > {}; verify_analyze< tst >( __LINE__, __FILE__, true, false ); } { struct tst : list_must< star< any >, any > {}; verify_analyze< tst >( __LINE__, __FILE__, false, false ); } { struct tst : list_must< any, opt< any > > {}; verify_analyze< tst >( __LINE__, __FILE__, true, false ); } { struct tst : list_must< star< any >, opt< any > > {}; verify_analyze< tst >( __LINE__, __FILE__, false, true ); } { struct tst : plus< pad_opt< alpha, digit > > {}; verify_analyze< tst >( __LINE__, __FILE__, false, true ); } { struct tst : rep< 42, opt< alpha > > {}; verify_analyze< tst >( __LINE__, __FILE__, false, false ); } { struct tst : rep_min< 42, opt< alpha > > {}; verify_analyze< tst >( __LINE__, __FILE__, false, true ); } } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/ascii_classes.cc000066400000000000000000000151031270130067200177020ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< alnum >( __LINE__, __FILE__, true, false ); verify_analyze< alpha >( __LINE__, __FILE__, true, false ); verify_analyze< any >( __LINE__, __FILE__, true, false ); verify_analyze< blank >( __LINE__, __FILE__, true, false ); verify_analyze< digit >( __LINE__, __FILE__, true, false ); verify_analyze< eol >( __LINE__, __FILE__, true, false ); verify_analyze< identifier_first >( __LINE__, __FILE__, true, false ); verify_analyze< identifier_other >( __LINE__, __FILE__, true, false ); verify_analyze< lower >( __LINE__, __FILE__, true, false ); verify_analyze< nul >( __LINE__, __FILE__, true, false ); verify_analyze< print >( __LINE__, __FILE__, true, false ); verify_analyze< seven >( __LINE__, __FILE__, true, false ); verify_analyze< space >( __LINE__, __FILE__, true, false ); verify_analyze< upper >( __LINE__, __FILE__, true, false ); verify_analyze< xdigit >( __LINE__, __FILE__, true, false ); verify_analyze< not_one< 'a' > >( __LINE__, __FILE__, true, false ); verify_analyze< not_one< 'a', 'z' > >( __LINE__, __FILE__, true, false ); verify_analyze< not_range< 'a', 'z' > >( __LINE__, __FILE__, true, false ); verify_analyze< one< 'a' > >( __LINE__, __FILE__, true, false ); verify_analyze< one< 'a', 'z' > >( __LINE__, __FILE__, true, false ); verify_analyze< range< 'a', 'z' > >( __LINE__, __FILE__, true, false ); verify_analyze< ranges< 'a', 'z' > >( __LINE__, __FILE__, true, false ); verify_analyze< ranges< 'a', 'z', '4' > >( __LINE__, __FILE__, true, false ); verify_rule< alnum >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< alpha >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< any >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< blank >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< digit >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< eol >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< identifier_first >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< identifier_other >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< lower >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< nul >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< print >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< seven >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< space >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< upper >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< xdigit >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< not_one< 'a' > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< not_one< 'a', 'z' > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< not_range< 'a' ,'z' > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< one< 'a' > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< one< 'a', 'z' > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< range< 'a', 'z' > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< ranges< 'a', 'z' > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< ranges< 'a', 'z', '4' > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); for ( int i = -100; i < 200; ++i ) { const bool is_blank = ( i == ' ' ) || ( i == '\t' ); const bool is_digit = ( '0' <= i ) && ( i <= '9' ); const bool is_lower = ( 'a' <= i ) && ( i <= 'z' ); const bool is_print = ( ( ' ' <= i ) && ( i <= 126 ) ); const bool is_seven = ( ( i >= 0 ) && ( i <= 127 ) ); const bool is_space = ( i == '\n' ) || ( i == '\r' ) || ( i == '\v' ) || ( i == '\f' ); const bool is_upper = ( 'A' <= i ) && ( i <= 'Z' ); const bool is_xalpha = ( ( 'a' <= i ) && ( i <= 'f' ) ) || ( ( 'A' <= i ) && ( i <= 'F' ) ); const bool is_newline = ( i == '\n' ); const bool is_ident_first = ( i == '_' ) || is_lower || is_upper; const bool is_ident_other = is_ident_first || is_digit; verify_char< alnum >( __LINE__, __FILE__, i, is_lower || is_upper || is_digit ); verify_char< alpha >( __LINE__, __FILE__, i, is_lower || is_upper ); verify_char< any >( __LINE__, __FILE__, i, true ); verify_char< blank >( __LINE__, __FILE__, i, is_blank ); verify_char< digit >( __LINE__, __FILE__, i, is_digit ); verify_char< eol >( __LINE__, __FILE__, i, is_newline ); verify_char< identifier_first >( __LINE__, __FILE__, i, is_ident_first ); verify_char< identifier_other >( __LINE__, __FILE__, i, is_ident_other ); verify_char< lower >( __LINE__, __FILE__, i, is_lower ); verify_char< nul >( __LINE__, __FILE__, i, i == 0 ); verify_char< print >( __LINE__, __FILE__, i, is_print ); verify_char< seven >( __LINE__, __FILE__, i, is_seven ); verify_char< space >( __LINE__, __FILE__, i, is_blank || is_space ); verify_char< upper >( __LINE__, __FILE__, i, is_upper ); verify_char< xdigit >( __LINE__, __FILE__, i, is_digit || is_xalpha ); const bool is_one = ( i == '#' ) || ( i == 'a' ) || ( i == ' ' ); const bool is_range = ( 20 <= i ) && ( i <= 120 ); const bool is_ranges = is_range || ( i == 3 ); verify_char< not_one< 'P' > >( __LINE__, __FILE__, i, i != 'P' ); verify_char< not_one< 'a', '#', ' ' > >( __LINE__, __FILE__, i, ! is_one ); verify_char< not_range< 20, 120 > >( __LINE__, __FILE__, i, ! is_range ); verify_char< one< 'T' > >( __LINE__, __FILE__, i, i == 'T' ); verify_char< one< 'a', '#', ' ' > >( __LINE__, __FILE__, i, is_one ); verify_char< range< 20, 120 > >( __LINE__, __FILE__, i, is_range ); verify_char< ranges< 20, 120 > >( __LINE__, __FILE__, i, is_range ); verify_char< ranges< 20, 120, 3 > >( __LINE__, __FILE__, i, is_ranges ); verify_char< eolf >( __LINE__, __FILE__, i, is_newline ); } } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/ascii_eol.cc000066400000000000000000000021571270130067200170310ustar00rootroot00000000000000// Copyright (c) 2016 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< eol >( __LINE__, __FILE__, true, false ); verify_rule< eol >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); for ( char i = 1; i < 127; ++i ) { verify_char< eol >( __LINE__, __FILE__, i, ( i == '\n' ) ? result_type::SUCCESS : result_type::LOCAL_FAILURE ); } verify_rule< eol >( __LINE__, __FILE__, "\r\n", result_type::SUCCESS, 0 ); verify_rule< eol >( __LINE__, __FILE__, "\n\r", result_type::SUCCESS, 1 ); verify_rule< eol >( __LINE__, __FILE__, "\na", result_type::SUCCESS, 1 ); verify_rule< eol >( __LINE__, __FILE__, "\ra", result_type::LOCAL_FAILURE, 2 ); verify_rule< eol >( __LINE__, __FILE__, "\r\na", result_type::SUCCESS, 1 ); verify_rule< eol >( __LINE__, __FILE__, "\r\n\r", result_type::SUCCESS, 1 ); verify_rule< eol >( __LINE__, __FILE__, "\r\n\n", result_type::SUCCESS, 1 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/ascii_eolf.cc000066400000000000000000000021711270130067200171730ustar00rootroot00000000000000// Copyright (c) 2014-2016 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< eolf >( __LINE__, __FILE__, false, false ); verify_rule< eolf >( __LINE__, __FILE__, "", result_type::SUCCESS, 0 ); for ( char i = 1; i < 127; ++i ) { verify_char< eolf >( __LINE__, __FILE__, i, ( i == '\n' ) ? result_type::SUCCESS : result_type::LOCAL_FAILURE ); } verify_rule< eolf >( __LINE__, __FILE__, "\r\n", result_type::SUCCESS, 0 ); verify_rule< eolf >( __LINE__, __FILE__, "\n\r", result_type::SUCCESS, 1 ); verify_rule< eolf >( __LINE__, __FILE__, "\na", result_type::SUCCESS, 1 ); verify_rule< eolf >( __LINE__, __FILE__, "\ra", result_type::LOCAL_FAILURE, 2 ); verify_rule< eolf >( __LINE__, __FILE__, "\r\na", result_type::SUCCESS, 1 ); verify_rule< eolf >( __LINE__, __FILE__, "\r\n\r", result_type::SUCCESS, 1 ); verify_rule< eolf >( __LINE__, __FILE__, "\r\n\n", result_type::SUCCESS, 1 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/ascii_identifier.cc000066400000000000000000000027111270130067200203700ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< identifier >( __LINE__, __FILE__, true, false ); verify_rule< identifier >( __LINE__, __FILE__, "_", result_type::SUCCESS, 0 ); verify_rule< identifier >( __LINE__, __FILE__, "_a", result_type::SUCCESS, 0 ); verify_rule< identifier >( __LINE__, __FILE__, "_1", result_type::SUCCESS, 0 ); verify_rule< identifier >( __LINE__, __FILE__, "_123", result_type::SUCCESS, 0 ); verify_rule< identifier >( __LINE__, __FILE__, "_1a", result_type::SUCCESS, 0 ); verify_rule< identifier >( __LINE__, __FILE__, "_a1", result_type::SUCCESS, 0 ); verify_rule< identifier >( __LINE__, __FILE__, "_fro_bble", result_type::SUCCESS, 0 ); verify_rule< identifier >( __LINE__, __FILE__, "f_o_o42", result_type::SUCCESS, 0 ); verify_rule< identifier >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< identifier >( __LINE__, __FILE__, "1", result_type::LOCAL_FAILURE, 1 ); verify_rule< identifier >( __LINE__, __FILE__, " ", result_type::LOCAL_FAILURE, 1 ); verify_rule< identifier >( __LINE__, __FILE__, " _", result_type::LOCAL_FAILURE, 2 ); verify_rule< identifier >( __LINE__, __FILE__, " a", result_type::LOCAL_FAILURE, 2 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/ascii_istring.cc000066400000000000000000000050521270130067200177260ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< istring<> >( __LINE__, __FILE__, false, false ); verify_analyze< istring< 1 > >( __LINE__, __FILE__, true, false ); verify_analyze< istring< 1, 2> >( __LINE__, __FILE__, true, false ); verify_analyze< istring< 1, 2, 3, 4 > >( __LINE__, __FILE__, true, false ); verify_analyze< istring< 1, 2, 3, 4, 5, 6, 7 > >( __LINE__, __FILE__, true, false ); verify_rule< istring<> >( __LINE__, __FILE__, "", result_type::SUCCESS, 0 ); verify_rule< istring< 'a', 'b' > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< istring< 'a', 'b' > >( __LINE__, __FILE__, "a", result_type::LOCAL_FAILURE, 1 ); verify_rule< istring< 'a', 'b' > >( __LINE__, __FILE__, "b", result_type::LOCAL_FAILURE, 1 ); verify_rule< istring< 'a', 'b' > >( __LINE__, __FILE__, "c", result_type::LOCAL_FAILURE, 1 ); verify_rule< istring< 'a', 'b' > >( __LINE__, __FILE__, "aa", result_type::LOCAL_FAILURE, 2 ); verify_rule< istring< 'a', 'b' > >( __LINE__, __FILE__, "aB", result_type::SUCCESS, 0 ); verify_rule< istring< 'a', 'b' > >( __LINE__, __FILE__, "AB", result_type::SUCCESS, 0 ); verify_rule< istring< 'a', 'b' > >( __LINE__, __FILE__, "Ab", result_type::SUCCESS, 0 ); verify_rule< istring< 'a', 'b' > >( __LINE__, __FILE__, "ac", result_type::LOCAL_FAILURE, 2 ); verify_rule< istring< 'a', 'b' > >( __LINE__, __FILE__, "ba", result_type::LOCAL_FAILURE, 2 ); verify_rule< istring< 'a', 'b' > >( __LINE__, __FILE__, "bb", result_type::LOCAL_FAILURE, 2 ); verify_rule< istring< 'a', 'b' > >( __LINE__, __FILE__, "aab", result_type::LOCAL_FAILURE, 3 ); verify_rule< istring< 'a', 'b' > >( __LINE__, __FILE__, "aab", result_type::LOCAL_FAILURE, 3 ); verify_rule< istring< 'a', 'b' > >( __LINE__, __FILE__, "ab", result_type::SUCCESS, 0 ); verify_rule< istring< 'a', 'b' > >( __LINE__, __FILE__, "aba", result_type::SUCCESS, 1 ); verify_rule< istring< 'a', 'b' > >( __LINE__, __FILE__, "Abb", result_type::SUCCESS, 1 ); verify_rule< istring< 'a', 'b' > >( __LINE__, __FILE__, "abc", result_type::SUCCESS, 1 ); verify_rule< istring< 'a', 'b' > >( __LINE__, __FILE__, "aBab", result_type::SUCCESS, 2 ); verify_rule< istring< 'a', '0' > >( __LINE__, __FILE__, "a0A0", result_type::SUCCESS, 2 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/ascii_shebang.cc000066400000000000000000000031671270130067200176630ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< shebang >( __LINE__, __FILE__, true, false ); verify_rule< shebang >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< shebang >( __LINE__, __FILE__, "#", result_type::LOCAL_FAILURE, 1 ); verify_rule< shebang >( __LINE__, __FILE__, "!", result_type::LOCAL_FAILURE, 1 ); verify_rule< shebang >( __LINE__, __FILE__, "!#", result_type::LOCAL_FAILURE, 2 ); verify_rule< shebang >( __LINE__, __FILE__, "# ", result_type::LOCAL_FAILURE, 3 ); verify_rule< shebang >( __LINE__, __FILE__, "! ", result_type::LOCAL_FAILURE, 3 ); verify_rule< shebang >( __LINE__, __FILE__, "## ", result_type::LOCAL_FAILURE, 3 ); verify_rule< shebang >( __LINE__, __FILE__, "!! ", result_type::LOCAL_FAILURE, 3 ); verify_rule< shebang >( __LINE__, __FILE__, "#!", result_type::SUCCESS, 0 ); verify_rule< shebang >( __LINE__, __FILE__, "#! ", result_type::SUCCESS, 0 ); verify_rule< shebang >( __LINE__, __FILE__, "#!/bin/bash", result_type::SUCCESS, 0 ); verify_rule< shebang >( __LINE__, __FILE__, "#!/bin/bash\n", result_type::SUCCESS, 0 ); verify_rule< shebang >( __LINE__, __FILE__, "#!/bin/bash\n#!/b", result_type::SUCCESS, 4 ); verify_rule< shebang >( __LINE__, __FILE__, "#!\n", result_type::SUCCESS, 0 ); verify_rule< shebang >( __LINE__, __FILE__, "#!\n ", result_type::SUCCESS, 1 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/ascii_string.cc000066400000000000000000000047011270130067200175550ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< string<> >( __LINE__, __FILE__, false, false); verify_analyze< string< 1 > >( __LINE__, __FILE__, true, false ); verify_analyze< string< 1, 2> >( __LINE__, __FILE__, true, false ); verify_analyze< string< 1, 2, 3, 4 > >( __LINE__, __FILE__, true, false ); verify_analyze< string< 1, 2, 3, 4, 5, 6, 7 > >( __LINE__, __FILE__, true, false ); verify_rule< string<> >( __LINE__, __FILE__, "", result_type::SUCCESS, 0 ); verify_rule< string< 'a', 'b' > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< string< 'a', 'b' > >( __LINE__, __FILE__, "a", result_type::LOCAL_FAILURE, 1 ); verify_rule< string< 'a', 'b' > >( __LINE__, __FILE__, "b", result_type::LOCAL_FAILURE, 1 ); verify_rule< string< 'a', 'b' > >( __LINE__, __FILE__, "c", result_type::LOCAL_FAILURE, 1 ); verify_rule< string< 'a', 'b' > >( __LINE__, __FILE__, "aa", result_type::LOCAL_FAILURE, 2 ); verify_rule< string< 'a', 'b' > >( __LINE__, __FILE__, "aB", result_type::LOCAL_FAILURE, 2 ); verify_rule< string< 'a', 'b' > >( __LINE__, __FILE__, "AB", result_type::LOCAL_FAILURE, 2 ); verify_rule< string< 'a', 'b' > >( __LINE__, __FILE__, "Ab", result_type::LOCAL_FAILURE, 2 ); verify_rule< string< 'a', 'b' > >( __LINE__, __FILE__, "ac", result_type::LOCAL_FAILURE, 2 ); verify_rule< string< 'a', 'b' > >( __LINE__, __FILE__, "ba", result_type::LOCAL_FAILURE, 2 ); verify_rule< string< 'a', 'b' > >( __LINE__, __FILE__, "bb", result_type::LOCAL_FAILURE, 2 ); verify_rule< string< 'a', 'b' > >( __LINE__, __FILE__, "aab", result_type::LOCAL_FAILURE, 3 ); verify_rule< string< 'a', 'b' > >( __LINE__, __FILE__, "aab", result_type::LOCAL_FAILURE, 3 ); verify_rule< string< 'a', 'b' > >( __LINE__, __FILE__, "ab", result_type::SUCCESS, 0 ); verify_rule< string< 'a', 'b' > >( __LINE__, __FILE__, "aba", result_type::SUCCESS, 1 ); verify_rule< string< 'a', 'b' > >( __LINE__, __FILE__, "abb", result_type::SUCCESS, 1 ); verify_rule< string< 'a', 'b' > >( __LINE__, __FILE__, "abc", result_type::SUCCESS, 1 ); verify_rule< string< 'a', 'b' > >( __LINE__, __FILE__, "abab", result_type::SUCCESS, 2 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/ascii_two.cc000066400000000000000000000015131270130067200170560ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< two< 'a' > >( __LINE__, __FILE__, true, false ); verify_rule< two< 'a' > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< two< 'a' > >( __LINE__, __FILE__, "a", result_type::LOCAL_FAILURE, 1 ); verify_rule< two< 'a' > >( __LINE__, __FILE__, "ab", result_type::LOCAL_FAILURE, 2 ); verify_rule< two< 'a' > >( __LINE__, __FILE__, "aa", result_type::SUCCESS, 0 ); verify_rule< two< 'a' > >( __LINE__, __FILE__, "aaa", result_type::SUCCESS, 1 ); verify_rule< two< 'a' > >( __LINE__, __FILE__, "aaaa", result_type::SUCCESS, 2 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/contrib_alphabet.cc000066400000000000000000000045431270130067200204030ustar00rootroot00000000000000// Copyright (c) 2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" #include namespace pegtl { void unit_test() { TEST_ASSERT( alphabet::a == 'a' ); TEST_ASSERT( alphabet::b == 'b' ); TEST_ASSERT( alphabet::c == 'c' ); TEST_ASSERT( alphabet::d == 'd' ); TEST_ASSERT( alphabet::e == 'e' ); TEST_ASSERT( alphabet::f == 'f' ); TEST_ASSERT( alphabet::g == 'g' ); TEST_ASSERT( alphabet::h == 'h' ); TEST_ASSERT( alphabet::i == 'i' ); TEST_ASSERT( alphabet::j == 'j' ); TEST_ASSERT( alphabet::k == 'k' ); TEST_ASSERT( alphabet::l == 'l' ); TEST_ASSERT( alphabet::m == 'm' ); TEST_ASSERT( alphabet::n == 'n' ); TEST_ASSERT( alphabet::o == 'o' ); TEST_ASSERT( alphabet::p == 'p' ); TEST_ASSERT( alphabet::q == 'q' ); TEST_ASSERT( alphabet::r == 'r' ); TEST_ASSERT( alphabet::s == 's' ); TEST_ASSERT( alphabet::t == 't' ); TEST_ASSERT( alphabet::u == 'u' ); TEST_ASSERT( alphabet::v == 'v' ); TEST_ASSERT( alphabet::w == 'w' ); TEST_ASSERT( alphabet::x == 'x' ); TEST_ASSERT( alphabet::y == 'y' ); TEST_ASSERT( alphabet::z == 'z' ); TEST_ASSERT( alphabet::A == 'A' ); TEST_ASSERT( alphabet::B == 'B' ); TEST_ASSERT( alphabet::C == 'C' ); TEST_ASSERT( alphabet::D == 'D' ); TEST_ASSERT( alphabet::E == 'E' ); TEST_ASSERT( alphabet::F == 'F' ); TEST_ASSERT( alphabet::G == 'G' ); TEST_ASSERT( alphabet::H == 'H' ); TEST_ASSERT( alphabet::I == 'I' ); TEST_ASSERT( alphabet::J == 'J' ); TEST_ASSERT( alphabet::K == 'K' ); TEST_ASSERT( alphabet::L == 'L' ); TEST_ASSERT( alphabet::M == 'M' ); TEST_ASSERT( alphabet::N == 'N' ); TEST_ASSERT( alphabet::O == 'O' ); TEST_ASSERT( alphabet::P == 'P' ); TEST_ASSERT( alphabet::Q == 'Q' ); TEST_ASSERT( alphabet::R == 'R' ); TEST_ASSERT( alphabet::S == 'S' ); TEST_ASSERT( alphabet::T == 'T' ); TEST_ASSERT( alphabet::U == 'U' ); TEST_ASSERT( alphabet::V == 'V' ); TEST_ASSERT( alphabet::W == 'W' ); TEST_ASSERT( alphabet::X == 'X' ); TEST_ASSERT( alphabet::Y == 'Y' ); TEST_ASSERT( alphabet::Z == 'Z' ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/contrib_json.cc000066400000000000000000000212441270130067200175710ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" #include #include namespace pegtl { template< typename Rule > void verify_file_fail( const std::size_t line, const char * file, const std::string & s ) { try { file_parser( s ).parse< Rule >(); TEST_FAILED( "expected exception" ); } catch ( ... ) { } } using GRAMMAR = must< json::text, eof >; void unit_test() { const auto p = analyze< GRAMMAR >(); assert( p == 0 ); verify_rule< GRAMMAR >( __LINE__, __FILE__, "[]", result_type::SUCCESS, 0 ); verify_rule< GRAMMAR >( __LINE__, __FILE__, "{}", result_type::SUCCESS, 0 ); verify_rule< GRAMMAR >( __LINE__, __FILE__, " [ ] ", result_type::SUCCESS, 0 ); verify_rule< GRAMMAR >( __LINE__, __FILE__, " { } ", result_type::SUCCESS, 0 ); verify_rule< GRAMMAR >( __LINE__, __FILE__, " [ ] ", result_type::SUCCESS, 0 ); verify_rule< GRAMMAR >( __LINE__, __FILE__, " { } ", result_type::SUCCESS, 0 ); verify_rule< GRAMMAR >( __LINE__, __FILE__, "[[{}],[],{}]", result_type::SUCCESS, 0 ); verify_rule< GRAMMAR >( __LINE__, __FILE__, "[ null, true, false, 0, 1, 2, 123, 1.23, 0.12, -1, -0, -1.23, \"\", \"abc\" ]", result_type::SUCCESS, 0 ); verify_rule< GRAMMAR >( __LINE__, __FILE__, "[\"\\b\"]", result_type::SUCCESS, 0 ); verify_rule< GRAMMAR >( __LINE__, __FILE__, "[\"\\f\"]", result_type::SUCCESS, 0 ); verify_rule< GRAMMAR >( __LINE__, __FILE__, "[\"\\n\"]", result_type::SUCCESS, 0 ); verify_rule< GRAMMAR >( __LINE__, __FILE__, "[\"\\r\"]", result_type::SUCCESS, 0 ); verify_rule< GRAMMAR >( __LINE__, __FILE__, "[\"\\t\"]", result_type::SUCCESS, 0 ); verify_rule< GRAMMAR >( __LINE__, __FILE__, "[\"\\/\"]", result_type::SUCCESS, 0 ); verify_rule< GRAMMAR >( __LINE__, __FILE__, "[\"\\\\\"]", result_type::SUCCESS, 0 ); verify_rule< GRAMMAR >( __LINE__, __FILE__, "[\"\\\"\"]", result_type::SUCCESS, 0 ); verify_rule< GRAMMAR >( __LINE__, __FILE__, "[\"\\u002C\"]", result_type::SUCCESS, 0 ); verify_rule< GRAMMAR >( __LINE__, __FILE__, "[\"\\u002c\"]", result_type::SUCCESS, 0 ); verify_rule< GRAMMAR >( __LINE__, __FILE__, "[\"ab\\u002Ccd\"]", result_type::SUCCESS, 0 ); verify_rule< GRAMMAR >( __LINE__, __FILE__, "[\"ab\\u002ccd\"]", result_type::SUCCESS, 0 ); verify_rule< GRAMMAR >( __LINE__, __FILE__, "[\"\\uD834\\uDD1E\"]", result_type::SUCCESS, 0 ); verify_rule< GRAMMAR >( __LINE__, __FILE__, "[\"\\uD834\"]", result_type::SUCCESS, 0 ); // unfortunately, this is valid for the grammar... verify_rule< GRAMMAR >( __LINE__, __FILE__, "[\"\\uDD1E\"]", result_type::SUCCESS, 0 ); // ...although both inputs are illegal in unicode. verify_rule< GRAMMAR >( __LINE__, __FILE__, "[\"\xC3\x84\"]", result_type::SUCCESS, 0 ); // German a-umlaut verify_rule< GRAMMAR >( __LINE__, __FILE__, "[\"\xF4\x8F\xBF\xBF\"]", result_type::SUCCESS, 0 ); // largest allowed codepoint U+10FFFF verify_rule< GRAMMAR >( __LINE__, __FILE__, "[\"\U0010FFFF\"]", result_type::SUCCESS, 0 ); // largest allowed codepoint U+10FFFF verify_fail< GRAMMAR >( __LINE__, __FILE__, "" ); verify_fail< GRAMMAR >( __LINE__, __FILE__, " " ); verify_fail< GRAMMAR >( __LINE__, __FILE__, " " ); verify_fail< GRAMMAR >( __LINE__, __FILE__, "[" ); verify_fail< GRAMMAR >( __LINE__, __FILE__, "]" ); verify_fail< GRAMMAR >( __LINE__, __FILE__, " [" ); verify_fail< GRAMMAR >( __LINE__, __FILE__, " ]" ); verify_fail< GRAMMAR >( __LINE__, __FILE__, "[ " ); verify_fail< GRAMMAR >( __LINE__, __FILE__, "] " ); verify_fail< GRAMMAR >( __LINE__, __FILE__, " [ " ); verify_fail< GRAMMAR >( __LINE__, __FILE__, " ] " ); verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\\a\"]" ); verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\\c\"]" ); verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\\d\"]" ); verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\\e\"]" ); verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\\v\"]" ); verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\\'\"]" ); verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\b\"]" ); verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\f\"]" ); verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\n\"]" ); verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\r\"]" ); verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\t\"]" ); verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\\\"]" ); verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\\\\\\\"]" ); verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\\u12\"]" ); verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\xFF\"]" ); verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\xF4\x90\x80\x80\"]" ); verify_fail< GRAMMAR >( __LINE__, __FILE__, "[\"\xF7\xBF\xBF\xBF\"]" ); TEST_ASSERT( file_parser( "unit_tests/data/pass1.json" ).parse< GRAMMAR >() ); TEST_ASSERT( file_parser( "unit_tests/data/pass2.json" ).parse< GRAMMAR >() ); TEST_ASSERT( file_parser( "unit_tests/data/pass3.json" ).parse< GRAMMAR >() ); // verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail1.json" ); // disabled as it is valid now verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail2.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail3.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail4.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail5.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail6.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail7.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail8.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail9.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail10.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail11.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail12.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail13.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail14.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail15.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail16.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail17.json" ); // verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail18.json" ); // disabled as deep nesting is allowed verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail19.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail20.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail21.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail22.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail23.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail24.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail25.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail26.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail27.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail28.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail29.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail30.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail31.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail32.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail33.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail34.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail35.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail36.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail37.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail38.json" ); verify_file_fail< GRAMMAR >( __LINE__, __FILE__, "unit_tests/data/fail39.json" ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/contrib_raw_string.cc000066400000000000000000000046341270130067200210030ustar00rootroot00000000000000// Copyright (c) 2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" #include namespace pegtl { std::string content; using rstring = raw_string< '[', '=', ']' >; template< typename Rule > struct rsaction : nothing< Rule > {}; template<> struct rsaction< rstring::content > { template< typename ... States > static void apply( const input & in, const States & ... ) { content.assign( in.begin(), in.end() ); } }; struct rgrammar : must< rstring, eof > {}; template< typename Rule, unsigned M, unsigned N > void verify_data( const std::size_t line, const char * file, const char ( & m )[ M ], const char ( & n )[ N ] ) { content.clear(); input i( line, 0, m, m + M - 1, file ); const auto r = parse_input< Rule, rsaction >( i ); if ( ( ! r ) || ( content != std::string( n, N - 1 ) ) ) { TEST_FAILED( "input data [ '" << m << "' ] expected success with [ '" << n << "' ] but got [ '" << content << "' ] result [ " << r << " ]" ); } } void unit_test() { verify_data< rgrammar >( __LINE__, __FILE__, "[[]]", "" ); verify_data< rgrammar >( __LINE__, __FILE__, "[[foo]]", "foo" ); verify_data< rgrammar >( __LINE__, __FILE__, "[===[foo]===]", "foo" ); verify_data< rgrammar >( __LINE__, __FILE__, "[===[\nfoo]===]", "foo" ); verify_data< rgrammar >( __LINE__, __FILE__, "[===[\0\0\0]===]", "\0\0\0" ); verify_fail< rgrammar >( __LINE__, __FILE__, "" ); verify_fail< rgrammar >( __LINE__, __FILE__, "[" ); verify_fail< rgrammar >( __LINE__, __FILE__, "[=" ); verify_fail< rgrammar >( __LINE__, __FILE__, "[=[" ); verify_fail< rgrammar >( __LINE__, __FILE__, "[=[]=" ); verify_fail< rgrammar >( __LINE__, __FILE__, "[=[]]" ); verify_fail< rgrammar >( __LINE__, __FILE__, "[]" ); verify_fail< rgrammar >( __LINE__, __FILE__, "[[]] " ); verify_fail< rgrammar >( __LINE__, __FILE__, " [[]]" ); verify_fail< rgrammar >( __LINE__, __FILE__, "[=[]-]" ); verify_fail< rgrammar >( __LINE__, __FILE__, "[-[]=]" ); verify_fail< rgrammar >( __LINE__, __FILE__, "[-[]-]" ); verify_fail< rgrammar >( __LINE__, __FILE__, "[===[]====]" ); verify_fail< rgrammar >( __LINE__, __FILE__, "[====[]===]" ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/contrib_unescape.cc000066400000000000000000000123251270130067200204230ustar00rootroot00000000000000// Copyright (c) 2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" #include namespace pegtl { struct escaped_c : one< '"', '\\', 't' > {}; struct escaped_u : seq< one< 'u' >, rep< 4, must< xdigit > > > {}; struct escaped_U : seq< one< 'U' >, rep< 8, must< xdigit > > > {}; struct escaped_j : list< seq< one< 'j' >, rep< 4, must< xdigit > > >, one< '\\' > > {}; struct escaped_x : seq< one< 'x' >, rep< 2, must< xdigit > > > {}; struct escaped : sor< escaped_c, escaped_u, escaped_U, escaped_j, escaped_x > {}; struct character : if_then_else< one< '\\' >, must< escaped >, utf8::any > {}; struct unstring : until< eof, character > {}; template< typename Rule > struct unaction : nothing< Rule > {}; template<> struct unaction< escaped_c > : unescape::unescape_c< escaped_c, '"', '\\', '\t' > {}; template<> struct unaction< escaped_u > : unescape::unescape_u {}; template<> struct unaction< escaped_U > : unescape::unescape_u {}; template<> struct unaction< escaped_j > : unescape::unescape_j {}; template<> struct unaction< escaped_x > : unescape::unescape_x {}; template<> struct unaction< utf8::any > : unescape::append_all {}; template< unsigned M, unsigned N > void verify_data( const char ( & m )[ M ], const char ( & n )[ N ] ) { unescape::state st; parse< unstring, unaction >( std::string( m, M - 1 ), __FUNCTION__, st ); assert( st.unescaped == std::string( n, N - 1 ) ); } void unit_test() { verify_data( "\\t", "\t" ); verify_data( "\\\\", "\\" ); verify_data( "abc", "abc" ); verify_data( "\\\"foo\\\"", "\"foo\"" ); verify_data( "\\x20", " " ); verify_data( "\\x30", "0" ); verify_data( "\\x2000", " 00" ); verify_data( "\\u0020", " " ); verify_data( "\\u0020\\u0020", " " ); verify_data( "\\u00e4", "\xc3\xa4" ); verify_data( "\\u00E4", "\xC3\xA4" ); verify_data( "\\u20ac", "\xe2\x82\xac" ); verify_data( "\\ud800\\u0020", "\xed\xa0\x80 " ); verify_data( "\\ud800\\udc00", "\xed\xa0\x80\xed\xb0\x80" ); verify_data( "\\j0020", " " ); verify_data( "\\j0020\\j0020", " " ); verify_data( "\\j20ac", "\xe2\x82\xac" ); verify_data( "\\jd800\\j0020", "\xed\xa0\x80 " ); verify_data( "\\jd800\\jdc00", "\xf0\x90\x80\x80" ); verify_data( "\\j0000\\u0000\x00", "\x00\x00\x00" ); unescape::state st; verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\\\\\", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\x", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\xx", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\xa", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\x1", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\x1h", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "a\\", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "a\\x", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "a\\xx", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "a\\xa", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "a\\x1", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "a\\x1h", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\a", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\_", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\z", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\1", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\a00", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\_1111", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\z22222222", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\13333333333333333", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\u", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\uu", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\uuuu", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\u123", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\u999", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\u444h", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\j", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\ju", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\juuu", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\j123", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\j999", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\j444h", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\U00110000", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\U80000000", st ); verify_fail< unstring, unaction >( __LINE__, __FILE__, "\\Uffffffff", st ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/contrib_uri.cc000066400000000000000000000033261270130067200174200ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include #include #include #include using GRAMMAR = pegtl::must< pegtl::uri::URI, pegtl::eof >; void test( const std::string& in ) { pegtl::parse< GRAMMAR >( in, "test" ); } void fail( const std::string& in ) { try { pegtl::parse< GRAMMAR >( in, "expect_exception" ); std::cerr << "FAILED: " << in << std::endl; assert( false ); } catch( ... ) { } } int main( int, char ** ) { // ensure the grammar does not contain any obvious problems pegtl::analyze< GRAMMAR >(); // some unit tests that should work test( "http://de.wikipedia.org/wiki/Uniform_Resource_Identifier" ); test( "ftp://ftp.is.co.za/rfc/rfc1808.txt" ); test( "file:///C:/Users/Benutzer/Desktop/Uniform%20Resource%20Identifier.html" ); test( "file:///etc/fstab" ); test( "geo:48.33,14.122;u=22.5" ); test( "ldap://[2001:db8::7]/c=GB?objectClass?one" ); test( "gopher://gopher.floodgap.com" ); test( "mailto:John.Doe@example.com" ); test( "sip:911@pbx.mycompany.com" ); test( "news:comp.infosystems.www.servers.unix" ); test( "data:text/plain;charset=iso-8859-7,%be%fa%be" ); test( "tel:+1-816-555-1212" ); test( "telnet://192.0.2.16:80/" ); test( "urn:oasis:names:specification:docbook:dtd:xml:4.1.2" ); test( "git://github.com/rails/rails.git" ); test( "crid://broadcaster.com/movies/BestActionMovieEver" ); test( "http://nobody:password@example.org:8080/cgi-bin/script.php?action=submit&pageid=86392001#section_2" ); // some unit tests that should fail fail( "" ); return 0; } PEGTL-1.3.1/unit_tests/data/000077500000000000000000000000001270130067200154775ustar00rootroot00000000000000PEGTL-1.3.1/unit_tests/data/README.txt000066400000000000000000000006631270130067200172020ustar00rootroot00000000000000pass1 thru pass3 fail1 thru fail33 ================= Test suite from http://json.org/JSON_checker/. If the JSON grammar and the PEGTL are working correctly, they must accept all of the `pass*.json` files and reject all of the `fail*.json` files. Two of the failure tests are disabled since they are no longer applicable to newer JSON standards. fail34 thru fail39 ================== Additional tests added by the PEGTL authors. PEGTL-1.3.1/unit_tests/data/fail1.json000066400000000000000000000000741270130067200173670ustar00rootroot00000000000000"A JSON payload should be an object or array, not a string."PEGTL-1.3.1/unit_tests/data/fail10.json000066400000000000000000000000721270130067200174450ustar00rootroot00000000000000{"Extra value after close": true} "misplaced quoted value"PEGTL-1.3.1/unit_tests/data/fail11.json000066400000000000000000000000351270130067200174450ustar00rootroot00000000000000{"Illegal expression": 1 + 2}PEGTL-1.3.1/unit_tests/data/fail12.json000066400000000000000000000000371270130067200174500ustar00rootroot00000000000000{"Illegal invocation": alert()}PEGTL-1.3.1/unit_tests/data/fail13.json000066400000000000000000000000531270130067200174470ustar00rootroot00000000000000{"Numbers cannot have leading zeroes": 013}PEGTL-1.3.1/unit_tests/data/fail14.json000066400000000000000000000000371270130067200174520ustar00rootroot00000000000000{"Numbers cannot be hex": 0x14}PEGTL-1.3.1/unit_tests/data/fail15.json000066400000000000000000000000421270130067200174470ustar00rootroot00000000000000["Illegal backslash escape: \x15"]PEGTL-1.3.1/unit_tests/data/fail16.json000066400000000000000000000000101270130067200174430ustar00rootroot00000000000000[\naked]PEGTL-1.3.1/unit_tests/data/fail17.json000066400000000000000000000000421270130067200174510ustar00rootroot00000000000000["Illegal backslash escape: \017"]PEGTL-1.3.1/unit_tests/data/fail18.json000066400000000000000000000000621270130067200174540ustar00rootroot00000000000000[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]PEGTL-1.3.1/unit_tests/data/fail19.json000066400000000000000000000000261270130067200174550ustar00rootroot00000000000000{"Missing colon" null}PEGTL-1.3.1/unit_tests/data/fail2.json000066400000000000000000000000211270130067200173600ustar00rootroot00000000000000["Unclosed array"PEGTL-1.3.1/unit_tests/data/fail20.json000066400000000000000000000000271270130067200174460ustar00rootroot00000000000000{"Double colon":: null}PEGTL-1.3.1/unit_tests/data/fail21.json000066400000000000000000000000401270130067200174420ustar00rootroot00000000000000{"Comma instead of colon", null}PEGTL-1.3.1/unit_tests/data/fail22.json000066400000000000000000000000411270130067200174440ustar00rootroot00000000000000["Colon instead of comma": false]PEGTL-1.3.1/unit_tests/data/fail23.json000066400000000000000000000000241270130067200174460ustar00rootroot00000000000000["Bad value", truth]PEGTL-1.3.1/unit_tests/data/fail24.json000066400000000000000000000000201270130067200174430ustar00rootroot00000000000000['single quote']PEGTL-1.3.1/unit_tests/data/fail25.json000066400000000000000000000000351270130067200174520ustar00rootroot00000000000000[" tab character in string "]PEGTL-1.3.1/unit_tests/data/fail26.json000066400000000000000000000000461270130067200174550ustar00rootroot00000000000000["tab\ character\ in\ string\ "]PEGTL-1.3.1/unit_tests/data/fail27.json000066400000000000000000000000161270130067200174530ustar00rootroot00000000000000["line break"]PEGTL-1.3.1/unit_tests/data/fail28.json000066400000000000000000000000171270130067200174550ustar00rootroot00000000000000["line\ break"]PEGTL-1.3.1/unit_tests/data/fail29.json000066400000000000000000000000041270130067200174520ustar00rootroot00000000000000[0e]PEGTL-1.3.1/unit_tests/data/fail3.json000066400000000000000000000000451270130067200173670ustar00rootroot00000000000000{unquoted_key: "keys must be quoted"}PEGTL-1.3.1/unit_tests/data/fail30.json000066400000000000000000000000051270130067200174430ustar00rootroot00000000000000[0e+]PEGTL-1.3.1/unit_tests/data/fail31.json000066400000000000000000000000071270130067200174460ustar00rootroot00000000000000[0e+-1]PEGTL-1.3.1/unit_tests/data/fail32.json000066400000000000000000000000501270130067200174450ustar00rootroot00000000000000{"Comma instead if closing brace": true,PEGTL-1.3.1/unit_tests/data/fail33.json000066400000000000000000000000141270130067200174460ustar00rootroot00000000000000["mismatch"}PEGTL-1.3.1/unit_tests/data/fail34.json000066400000000000000000000000021270130067200174440ustar00rootroot0000000000000000PEGTL-1.3.1/unit_tests/data/fail35.json000066400000000000000000000000241270130067200174510ustar00rootroot00000000000000["bracket mismatch"}PEGTL-1.3.1/unit_tests/data/fail36.json000066400000000000000000000000261270130067200174540ustar00rootroot00000000000000{"bracket":"mismatch"]PEGTL-1.3.1/unit_tests/data/fail37.json000066400000000000000000000000001270130067200174450ustar00rootroot00000000000000PEGTL-1.3.1/unit_tests/data/fail38.json000066400000000000000000000000011270130067200174470ustar00rootroot00000000000000 PEGTL-1.3.1/unit_tests/data/fail39.json000066400000000000000000000000321270130067200174540ustar00rootroot00000000000000"invalid utf-8 sequence Ã"PEGTL-1.3.1/unit_tests/data/fail4.json000066400000000000000000000000201270130067200173610ustar00rootroot00000000000000["extra comma",]PEGTL-1.3.1/unit_tests/data/fail5.json000066400000000000000000000000301270130067200173630ustar00rootroot00000000000000["double extra comma",,]PEGTL-1.3.1/unit_tests/data/fail6.json000066400000000000000000000000321270130067200173660ustar00rootroot00000000000000[ , "<-- missing value"]PEGTL-1.3.1/unit_tests/data/fail7.json000066400000000000000000000000321270130067200173670ustar00rootroot00000000000000["Comma after the close"],PEGTL-1.3.1/unit_tests/data/fail8.json000066400000000000000000000000201270130067200173650ustar00rootroot00000000000000["Extra close"]]PEGTL-1.3.1/unit_tests/data/fail9.json000066400000000000000000000000261270130067200173740ustar00rootroot00000000000000{"Extra comma": true,}PEGTL-1.3.1/unit_tests/data/pass1.json000066400000000000000000000026411270130067200174240ustar00rootroot00000000000000[ "JSON Test Pattern pass1", {"object with 1 member":["array with 1 element"]}, {}, [], -42, true, false, null, { "integer": 1234567890, "real": -9876.543210, "e": 0.123456789e-12, "E": 1.234567890E+34, "": 23456789012E66, "zero": 0, "one": 1, "space": " ", "quote": "\"", "backslash": "\\", "controls": "\b\f\n\r\t", "slash": "/ & \/", "alpha": "abcdefghijklmnopqrstuvwyz", "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ", "digit": "0123456789", "0123456789": "digit", "special": "`1~!@#$%^&*()_+-={':[,]}|;.?", "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A", "true": true, "false": false, "null": null, "array":[ ], "object":{ }, "address": "50 St. James Street", "url": "http://www.JSON.org/", "comment": "// /* */": " ", " s p a c e d " :[1,2 , 3 , 4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7], "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}", "quotes": "" \u0022 %22 0x22 034 "", "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?" : "A key can be any string" }, 0.5 ,98.6 , 99.44 , 1066, 1e1, 0.1e1, 1e-1, 1e00,2e+00,2e-00 ,"rosebud"]PEGTL-1.3.1/unit_tests/data/pass2.json000066400000000000000000000000641270130067200174220ustar00rootroot00000000000000[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]PEGTL-1.3.1/unit_tests/data/pass3.json000066400000000000000000000002241270130067200174210ustar00rootroot00000000000000{ "JSON Test Pattern pass3": { "The outermost value": "must be an object or array.", "In this test": "It is an object." } } PEGTL-1.3.1/unit_tests/file_data.txt000066400000000000000000000002321270130067200172340ustar00rootroot00000000000000dummy content dummy content dummy content dummy content dummy content dummy content dummy content dummy content dummy content dummy content dummy content PEGTL-1.3.1/unit_tests/file_file.cc000066400000000000000000000004471270130067200170200ustar00rootroot00000000000000// Copyright (c) 2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" #include "verify_file.hh" namespace pegtl { void unit_test() { verify_file< file_parser >(); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/file_mmap.cc000066400000000000000000000006511270130067200170300ustar00rootroot00000000000000// Copyright (c) 2014-2016 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include #if defined(_POSIX_MAPPED_FILES) #include "test.hh" #include "verify_file.hh" namespace pegtl { void unit_test() { verify_file< mmap_parser >(); } } // pegtl #include "main.hh" #else int main( int, char ** ) { return 0; } #endif PEGTL-1.3.1/unit_tests/file_read.cc000066400000000000000000000004541270130067200170120ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" #include "verify_file.hh" namespace pegtl { void unit_test() { verify_file< read_parser >(); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/internal_file_mapper.cc000066400000000000000000000011121270130067200212470ustar00rootroot00000000000000// Copyright (c) 2015-2016 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include #if defined(_POSIX_MAPPED_FILES) #include "test.hh" namespace pegtl { void unit_test() { try { internal::file_mapper( "pegtl" ); std::cerr << "pegtl: unit test failed for [ internal::file_mapper ] " << std::endl; ++failed; } catch ( const std::exception & ) { } } } // pegtl #include "main.hh" #else int main( int, char ** ) { return 0; } #endif PEGTL-1.3.1/unit_tests/internal_file_opener.cc000066400000000000000000000012671270130067200212660ustar00rootroot00000000000000// Copyright (c) 2015-2016 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include #if defined(_POSIX_MAPPED_FILES) #include "test.hh" namespace pegtl { void unit_test() { const internal::file_opener fo( "Makefile" ); ::close( fo.m_fd ); // Provoke exception, nobody would normally do this. try { fo.size(); std::cerr << "pegtl: unit test failed for [ internal::file_opener ] " << std::endl; ++failed; } catch ( const std::exception & ) { } } } // pegtl #include "main.hh" #else int main( int, char ** ) { return 0; } #endif PEGTL-1.3.1/unit_tests/main.hh000066400000000000000000000007421270130067200160360ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_UNIT_TESTS_MAIN_HH #define PEGTL_UNIT_TESTS_MAIN_HH #include int main( int, char ** argv ) { pegtl::unit_test(); if ( pegtl::failed ) { std::cerr << "pegtl: unit test " << argv[ 0 ] << " failed " << pegtl::failed << std::endl; } return ( pegtl::failed == 0 ) ? EXIT_SUCCESS : EXIT_FAILURE; } #endif PEGTL-1.3.1/unit_tests/pegtl_string_t.cc000066400000000000000000000025741270130067200201310ustar00rootroot00000000000000// Copyright (c) 2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include #include #include namespace test { // We only need to test that this compiles... struct foo : pegtl_string_t( "foo" ) {}; struct foobar : pegtl::sor< pegtl_string_t( "foo" ), pegtl_string_t( "bar" ) > {}; static_assert( std::is_same< pegtl_string_t( "Hello" ), pegtl::string< 'H', 'e', 'l', 'l', 'o' > >::value, "pegtl_string_t broken" ); static_assert( ! std::is_same< pegtl_istring_t( "Hello" ), pegtl::string< 'H', 'e', 'l', 'l', 'o' > >::value, "pegtl_istring_t broken" ); static_assert( std::is_same< pegtl_istring_t( "Hello" ), pegtl::istring< 'H', 'e', 'l', 'l', 'o' > >::value, "pegtl_istring_t broken" ); using namespace pegtl::alphabet; // The strings currently have a maximum length of 100 characters. static_assert( std::is_same< pegtl_string_t( "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy" ), pegtl::string< a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y > >::value, "pegtl_string_t broken" ); } // test int main() { return 0; } PEGTL-1.3.1/unit_tests/position.cc000066400000000000000000000047611270130067200167510ustar00rootroot00000000000000// Copyright (c) 2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { template< typename Rule > void test_matches_lf() { static const std::string s1 = "\n"; input i1( 1, 0, s1.data(), s1.data() + s1.size(), __FUNCTION__ ); TEST_ASSERT( parse_input< Rule >( i1 ) ); TEST_ASSERT( i1.line() == 2 ); TEST_ASSERT( i1.column() == 0 ); } template< typename Rule > void test_matches_other( const std::string & s2 ) { TEST_ASSERT( s2.size() == 1 ); input i2( 1, 0, s2.data(), s2.data() + s2.size(), __FUNCTION__ ); TEST_ASSERT( parse_input< Rule >( i2 ) ); TEST_ASSERT( i2.line() == 1 ); TEST_ASSERT( i2.column() == 1 ); } template< typename Rule > void test_mismatch( const std::string & s3 ) { TEST_ASSERT( s3.size() == 1 ); input i3( 1, 0, s3.data(), s3.data() + s3.size(), __FUNCTION__ ); TEST_ASSERT( ! parse_input< Rule >( i3 ) ); TEST_ASSERT( i3.line() == 1 ); TEST_ASSERT( i3.column() == 0 ); } void unit_test() { test_matches_lf< any >(); test_matches_other< any >( " " ); test_matches_lf< one< '\n' > >(); test_mismatch< one< '\n' > >( " " ); test_matches_lf< one< ' ', '\n' > >(); test_matches_other< one< ' ', '\n' > >( " " ); test_matches_lf< one< ' ', '\n', 'b' > >(); test_matches_other< one< ' ', '\n', 'b' > >( " " ); test_matches_lf< string< '\n' > >(); test_mismatch< string< '\n' > >( " " ); test_matches_other< string< ' ' > >( " " ); test_mismatch< string< ' ' > >( "\n" ); test_matches_lf< range< 8, 33 > >(); test_matches_other< range< 8, 33 > >( " " ); test_mismatch< range< 11, 30 > >( "\n" ); test_mismatch< range< 11, 30 > >( " " ); test_matches_lf< not_range< 20, 30 > >(); test_matches_other< not_range< 20, 30 > >( " " ); test_mismatch< not_range< 5, 35 > >( "\n" ); test_mismatch< not_range< 5, 35 > >( " " ); test_matches_lf< ranges< 'a', 'z', 8, 33, 'A', 'Z' > >(); test_matches_other< ranges< 'a', 'z', 8, 33, 'A', 'Z' > >( "N" ); test_mismatch< ranges< 'a', 'z', 8, 33, 'A', 'Z' > >( "9" ); test_matches_lf< ranges< 'a', 'z', 'A', 'Z', '\n' > >(); test_matches_other< ranges< 'a', 'z', 'A', 'Z', '\n' > >( "P" ); test_mismatch< ranges< 'a', 'z', 'A', 'Z', '\n' > >( "8" ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/result_type.hh000066400000000000000000000015101270130067200174630ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_UNIT_TESTS_RESULT_TYPE_HH #define PEGTL_UNIT_TESTS_RESULT_TYPE_HH #include namespace pegtl { enum class result_type { SUCCESS = 1, LOCAL_FAILURE = 0, GLOBAL_FAILURE = -1 }; // The following is inlined so it shows up as not executed on lcov: inline std::ostream & operator<< ( std::ostream & o, const result_type t ) { switch ( t ) { case result_type::SUCCESS: return o << "success"; case result_type::LOCAL_FAILURE: return o << "local failure"; case result_type::GLOBAL_FAILURE: return o << "global failure"; } return o << int( t ); } } // pegtl #endif PEGTL-1.3.1/unit_tests/rule_action.cc000066400000000000000000000006131270130067200174010ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" #include "verify_seqs.hh" namespace pegtl { template< typename ... Rules > using test_action_rule = action< nothing, Rules ... >; void unit_test() { verify_seqs< test_action_rule >(); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_at.cc000066400000000000000000000016101270130067200165260ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< at< eof > >( __LINE__, __FILE__, false, false ); verify_analyze< at< any > >( __LINE__, __FILE__, false, false ); verify_rule< at< eof > >( __LINE__, __FILE__, "", result_type::SUCCESS, 0 ); verify_rule< at< eof > >( __LINE__, __FILE__, "a", result_type::LOCAL_FAILURE, 1 ); verify_rule< at< any > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< at< any > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 1 ); verify_rule< at< any > >( __LINE__, __FILE__, "aa", result_type::SUCCESS, 2 ); verify_rule< at< any > >( __LINE__, __FILE__, "aaaa", result_type::SUCCESS, 4 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_bytes.cc000066400000000000000000000025321270130067200172540ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< bytes< 0 > >( __LINE__, __FILE__, false, false ); verify_rule< bytes< 0 > >( __LINE__, __FILE__, "", result_type::SUCCESS, 0 ); verify_rule< bytes< 0 > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 1 ); verify_analyze< bytes< 1 > >( __LINE__, __FILE__, true, false ); for ( char c = 0; c < 127; ++c ) { verify_char< bytes< 1 > >( __LINE__, __FILE__, c, result_type::SUCCESS ); } verify_rule< bytes< 1 > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< bytes< 1 > >( __LINE__, __FILE__, "aa", result_type::SUCCESS, 1 ); verify_analyze< bytes< 2 > >( __LINE__, __FILE__, true, false ); verify_analyze< bytes< 42 > >( __LINE__, __FILE__, true, false ); verify_rule< bytes< 3 > >( __LINE__, __FILE__, "abcd", result_type::SUCCESS, 1 ); verify_rule< bytes< 4 > >( __LINE__, __FILE__, "abcd", result_type::SUCCESS, 0 ); verify_rule< bytes< 5 > >( __LINE__, __FILE__, "abcd", result_type::LOCAL_FAILURE, 4 ); verify_rule< bytes< 4 > >( __LINE__, __FILE__, "abcdefghij", result_type::SUCCESS, 6 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_control.cc000066400000000000000000000006151270130067200176060ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" #include "verify_seqs.hh" namespace pegtl { template< typename ... Rules > using test_control_rule = control< normal, Rules ... >; void unit_test() { verify_seqs< test_control_rule >(); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_disable.cc000066400000000000000000000004501270130067200175260ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" #include "verify_seqs.hh" namespace pegtl { void unit_test() { verify_seqs< disable >(); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_enable.cc000066400000000000000000000004471270130067200173570ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" #include "verify_seqs.hh" namespace pegtl { void unit_test() { verify_seqs< enable >(); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_eof.cc000066400000000000000000000011441270130067200166750ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< eof >( __LINE__, __FILE__, false, false ); verify_rule< eof >( __LINE__, __FILE__, "", result_type::SUCCESS, 0 ); for ( char i = 1; i < 127; ++i ) { verify_char< eof >( __LINE__, __FILE__, i, result_type::LOCAL_FAILURE ); } verify_rule< eof >( __LINE__, __FILE__, "abcdefghijklmn", result_type::LOCAL_FAILURE, 14 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_failure.cc000066400000000000000000000011351270130067200175530ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< failure >( __LINE__, __FILE__, true, false ); // "Success implies consumption" is true because "success" never happens. verify_rule< failure >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); for ( char i = 1; i < 127; ++i ) { verify_char< failure >( __LINE__, __FILE__, i, result_type::LOCAL_FAILURE ); } } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_if_must.cc000066400000000000000000000062601270130067200175760ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< if_must< any, any > >( __LINE__, __FILE__, true, false ); verify_analyze< if_must< eof, any > >( __LINE__, __FILE__, true, false ); verify_analyze< if_must< opt< any >, any > >( __LINE__, __FILE__, true, false ); verify_analyze< if_must< any, opt< any > > >( __LINE__, __FILE__, true, false ); verify_analyze< if_must< any, eof > >( __LINE__, __FILE__, true, false ); verify_analyze< if_must< opt< any >, opt< any > > >( __LINE__, __FILE__, false, false ); verify_analyze< if_must< eof, eof > >( __LINE__, __FILE__, false, false ); verify_rule< if_must< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< if_must< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "a", result_type::GLOBAL_FAILURE, 0 ); verify_rule< if_must< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "b", result_type::LOCAL_FAILURE, 1 ); verify_rule< if_must< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ba", result_type::LOCAL_FAILURE, 2 ); verify_rule< if_must< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ab", result_type::SUCCESS, 0 ); verify_rule< if_must< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "aba", result_type::SUCCESS, 1 ); verify_rule< if_must< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "abb", result_type::SUCCESS, 1 ); verify_rule< if_must< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "abab", result_type::SUCCESS, 2 ); verify_rule< if_must< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ac", result_type::GLOBAL_FAILURE, 1 ); verify_rule< if_must< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "acb", result_type::GLOBAL_FAILURE, 2 ); verify_rule< if_must< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< if_must< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "b", result_type::LOCAL_FAILURE, 1 ); verify_rule< if_must< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "bc", result_type::LOCAL_FAILURE, 2 ); verify_rule< if_must< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "a", result_type::GLOBAL_FAILURE, 1 ); verify_rule< if_must< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "ab", result_type::GLOBAL_FAILURE, 2 ); verify_rule< if_must< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "ac", result_type::GLOBAL_FAILURE, 2 ); verify_rule< if_must< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "abb", result_type::GLOBAL_FAILURE, 3 ); verify_rule< if_must< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "acc", result_type::GLOBAL_FAILURE, 3 ); verify_rule< if_must< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "acb", result_type::GLOBAL_FAILURE, 3 ); verify_rule< if_must< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "abc", result_type::SUCCESS, 0 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_if_must_else.cc000066400000000000000000000005121270130067200206000ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" #include "verify_ifmt.hh" namespace pegtl { void unit_test() { verify_ifmt< if_must_else >( result_type::GLOBAL_FAILURE ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_if_then_else.cc000066400000000000000000000004551270130067200205540ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" #include "verify_ifmt.hh" namespace pegtl { void unit_test() { verify_ifmt< if_then_else >(); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_list.cc000066400000000000000000000100641270130067200171000ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< list< eof, eof > >( __LINE__, __FILE__, false, true ); verify_analyze< list< eof, any > >( __LINE__, __FILE__, false, false ); verify_analyze< list< any, eof > >( __LINE__, __FILE__, true, false ); verify_analyze< list< any, any > >( __LINE__, __FILE__, true, false ); verify_analyze< list< eof, eof, eof > >( __LINE__, __FILE__, false, true ); verify_analyze< list< eof, eof, any > >( __LINE__, __FILE__, false, true ); verify_analyze< list< eof, any, eof > >( __LINE__, __FILE__, false, true ); verify_analyze< list< eof, any, any > >( __LINE__, __FILE__, false, false ); verify_analyze< list< any, eof, eof > >( __LINE__, __FILE__, true, true ); verify_analyze< list< any, eof, any > >( __LINE__, __FILE__, true, false ); verify_analyze< list< any, any, eof > >( __LINE__, __FILE__, true, true ); verify_analyze< list< any, any, any > >( __LINE__, __FILE__, true, false ); verify_rule< list< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< list< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "b", result_type::LOCAL_FAILURE, 1 ); verify_rule< list< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, ",", result_type::LOCAL_FAILURE, 1 ); verify_rule< list< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, ",a", result_type::LOCAL_FAILURE, 2 ); verify_rule< list< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a,", result_type::SUCCESS, 1 ); verify_rule< list< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 0 ); verify_rule< list< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a,a", result_type::SUCCESS, 0 ); verify_rule< list< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a,b", result_type::SUCCESS, 2 ); verify_rule< list< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a,a,a", result_type::SUCCESS, 0 ); verify_rule< list< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a,a,a,a", result_type::SUCCESS, 0 ); verify_rule< list< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a,a,a,b", result_type::SUCCESS, 2 ); verify_rule< list< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a,a,a,,", result_type::SUCCESS, 2 ); verify_rule< list< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a ", result_type::SUCCESS, 1 ); verify_rule< list< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, " a", result_type::LOCAL_FAILURE, 2 ); verify_rule< list< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a ,a", result_type::SUCCESS, 3 ); verify_rule< list< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a, a", result_type::SUCCESS, 3 ); verify_rule< list< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< list< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, " ", result_type::LOCAL_FAILURE, 1 ); verify_rule< list< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, ",", result_type::LOCAL_FAILURE, 1 ); verify_rule< list< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, "a ", result_type::SUCCESS, 1 ); verify_rule< list< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, " a", result_type::LOCAL_FAILURE, 2 ); verify_rule< list< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, "a ,a", result_type::SUCCESS, 0 ); verify_rule< list< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, "a, a", result_type::SUCCESS, 0 ); verify_rule< list< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, "a, a,", result_type::SUCCESS, 1 ); verify_rule< list< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, "a, a ,", result_type::SUCCESS, 2 ); verify_rule< list< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, " a , a ", result_type::LOCAL_FAILURE, 7 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_list_must.cc000066400000000000000000000100531270130067200201460ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< list_must< eof, eof > >( __LINE__, __FILE__, false, true ); verify_analyze< list_must< eof, any > >( __LINE__, __FILE__, false, false ); verify_analyze< list_must< any, eof > >( __LINE__, __FILE__, true, false ); verify_analyze< list_must< any, any > >( __LINE__, __FILE__, true, false ); verify_analyze< list_must< eof, eof, eof > >( __LINE__, __FILE__, false, true ); verify_analyze< list_must< eof, eof, any > >( __LINE__, __FILE__, false, true ); verify_analyze< list_must< eof, any, eof > >( __LINE__, __FILE__, false, true ); verify_analyze< list_must< eof, any, any > >( __LINE__, __FILE__, false, false ); verify_analyze< list_must< any, eof, eof > >( __LINE__, __FILE__, true, true ); verify_analyze< list_must< any, eof, any > >( __LINE__, __FILE__, true, false ); verify_analyze< list_must< any, any, eof > >( __LINE__, __FILE__, true, true ); verify_analyze< list_must< any, any, any > >( __LINE__, __FILE__, true, false ); verify_rule< list_must< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< list_must< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "b", result_type::LOCAL_FAILURE, 1 ); verify_rule< list_must< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, ",", result_type::LOCAL_FAILURE, 1 ); verify_rule< list_must< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, ",a", result_type::LOCAL_FAILURE, 2 ); verify_rule< list_must< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a,", result_type::GLOBAL_FAILURE, 2 ); verify_rule< list_must< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 0 ); verify_rule< list_must< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a,a", result_type::SUCCESS, 0 ); verify_rule< list_must< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a,b", result_type::GLOBAL_FAILURE, 3 ); verify_rule< list_must< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a,a,a", result_type::SUCCESS, 0 ); verify_rule< list_must< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a,a,a,a", result_type::SUCCESS, 0 ); verify_rule< list_must< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a ", result_type::SUCCESS, 1 ); verify_rule< list_must< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, " a", result_type::LOCAL_FAILURE, 2 ); verify_rule< list_must< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a ,a", result_type::SUCCESS, 3 ); verify_rule< list_must< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a, a", result_type::GLOBAL_FAILURE, 0 ); verify_rule< list_must< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< list_must< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, " ", result_type::LOCAL_FAILURE, 1 ); verify_rule< list_must< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, ",", result_type::LOCAL_FAILURE, 1 ); verify_rule< list_must< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, "a ", result_type::SUCCESS, 1 ); verify_rule< list_must< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, " a", result_type::LOCAL_FAILURE, 2 ); verify_rule< list_must< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, "a ,a", result_type::SUCCESS, 0 ); verify_rule< list_must< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, "a, a", result_type::SUCCESS, 0 ); verify_rule< list_must< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, "a, a,", result_type::GLOBAL_FAILURE, 5 ); verify_rule< list_must< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, "a, a ,", result_type::GLOBAL_FAILURE, 6 ); verify_rule< list_must< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, " a , a ", result_type::LOCAL_FAILURE, 7 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_list_tail.cc000066400000000000000000000103621270130067200201120ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< list_tail< eof, eof > >( __LINE__, __FILE__, false, true ); verify_analyze< list_tail< eof, any > >( __LINE__, __FILE__, false, false ); verify_analyze< list_tail< any, eof > >( __LINE__, __FILE__, true, false ); verify_analyze< list_tail< any, any > >( __LINE__, __FILE__, true, false ); verify_analyze< list_tail< eof, eof, eof > >( __LINE__, __FILE__, false, true ); verify_analyze< list_tail< eof, eof, any > >( __LINE__, __FILE__, false, true ); verify_analyze< list_tail< eof, any, eof > >( __LINE__, __FILE__, false, true ); verify_analyze< list_tail< eof, any, any > >( __LINE__, __FILE__, false, false ); verify_analyze< list_tail< any, eof, eof > >( __LINE__, __FILE__, true, true ); verify_analyze< list_tail< any, eof, any > >( __LINE__, __FILE__, true, false ); verify_analyze< list_tail< any, any, eof > >( __LINE__, __FILE__, true, true ); verify_analyze< list_tail< any, any, any > >( __LINE__, __FILE__, true, false ); verify_rule< list_tail< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< list_tail< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "b", result_type::LOCAL_FAILURE, 1 ); verify_rule< list_tail< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, ",", result_type::LOCAL_FAILURE, 1 ); verify_rule< list_tail< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, ",a", result_type::LOCAL_FAILURE, 2 ); verify_rule< list_tail< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a,", result_type::SUCCESS, 0 ); verify_rule< list_tail< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 0 ); verify_rule< list_tail< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a,a", result_type::SUCCESS, 0 ); verify_rule< list_tail< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a,b", result_type::SUCCESS, 1 ); verify_rule< list_tail< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a,a,a", result_type::SUCCESS, 0 ); verify_rule< list_tail< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a,a,a,a", result_type::SUCCESS, 0 ); verify_rule< list_tail< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a,a,a,b", result_type::SUCCESS, 1 ); verify_rule< list_tail< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a,a,a,,", result_type::SUCCESS, 1 ); verify_rule< list_tail< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a ", result_type::SUCCESS, 1 ); verify_rule< list_tail< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, " a", result_type::LOCAL_FAILURE, 2 ); verify_rule< list_tail< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a ,a", result_type::SUCCESS, 3 ); verify_rule< list_tail< one< 'a' >, one< ',' > > >( __LINE__, __FILE__, "a, a", result_type::SUCCESS, 2 ); verify_rule< list_must< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< list_must< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, " ", result_type::LOCAL_FAILURE, 1 ); verify_rule< list_must< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, ",", result_type::LOCAL_FAILURE, 1 ); verify_rule< list_tail< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, "a ", result_type::SUCCESS, 1 ); verify_rule< list_tail< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, " a", result_type::LOCAL_FAILURE, 2 ); verify_rule< list_tail< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, "a ,a", result_type::SUCCESS, 0 ); verify_rule< list_tail< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, "a, a", result_type::SUCCESS, 0 ); verify_rule< list_tail< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, "a, a,", result_type::SUCCESS, 0 ); verify_rule< list_tail< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, "a, a ,", result_type::SUCCESS, 0 ); verify_rule< list_tail< one< 'a' >, one< ',' >, blank > >( __LINE__, __FILE__, " a , a ", result_type::LOCAL_FAILURE, 7 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_must.cc000066400000000000000000000005021270130067200171110ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" #include "verify_seqs.hh" namespace pegtl { void unit_test() { verify_seqs< must >( result_type::GLOBAL_FAILURE ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_not_at.cc000066400000000000000000000016641270130067200174170ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< not_at< eof > >( __LINE__, __FILE__, false, false ); verify_analyze< not_at< any > >( __LINE__, __FILE__, false, false ); verify_rule< not_at< eof > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< not_at< eof > >( __LINE__, __FILE__, " ", result_type::SUCCESS, 1 ); verify_rule< not_at< any > >( __LINE__, __FILE__, "", result_type::SUCCESS, 0 ); verify_rule< not_at< any > >( __LINE__, __FILE__, "a", result_type::LOCAL_FAILURE, 1 ); verify_rule< not_at< any > >( __LINE__, __FILE__, "aa", result_type::LOCAL_FAILURE, 2 ); verify_rule< not_at< any > >( __LINE__, __FILE__, "aaaa", result_type::LOCAL_FAILURE, 4 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_opt.cc000066400000000000000000000030711270130067200167270ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< opt< any > >( __LINE__, __FILE__, false, false ); verify_analyze< opt< eof > >( __LINE__, __FILE__, false, false ); verify_rule< opt< one< 'a' > > >( __LINE__, __FILE__, "", result_type::SUCCESS, 0 ); verify_rule< opt< one< 'a' > > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 0 ); verify_rule< opt< one< 'a' > > >( __LINE__, __FILE__, "aa", result_type::SUCCESS, 1 ); verify_rule< opt< one< 'a' > > >( __LINE__, __FILE__, "ab", result_type::SUCCESS, 1 ); verify_rule< opt< one< 'a' > > >( __LINE__, __FILE__, "ba", result_type::SUCCESS, 2 ); verify_rule< opt< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "", result_type::SUCCESS, 0 ); verify_rule< opt< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 1 ); verify_rule< opt< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ab", result_type::SUCCESS, 0 ); verify_rule< opt< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "aba", result_type::SUCCESS, 1 ); verify_rule< opt< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "abab", result_type::SUCCESS, 2 ); verify_rule< opt< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "bab", result_type::SUCCESS, 3 ); verify_rule< opt< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "cb", result_type::SUCCESS, 2 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_pad.cc000066400000000000000000000063671270130067200167040ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< pad< eof, eof, eof > >( __LINE__, __FILE__, false, true ); verify_analyze< pad< eof, eof, any > >( __LINE__, __FILE__, false, true ); verify_analyze< pad< eof, any, eof > >( __LINE__, __FILE__, false, true ); verify_analyze< pad< eof, any, any > >( __LINE__, __FILE__, false, false ); verify_analyze< pad< any, eof, eof > >( __LINE__, __FILE__, true, true ); verify_analyze< pad< any, eof, any > >( __LINE__, __FILE__, true, true ); verify_analyze< pad< any, any, eof > >( __LINE__, __FILE__, true, true ); verify_analyze< pad< any, any, any > >( __LINE__, __FILE__, true, false ); verify_rule< pad< one< 'a' >, space > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< pad< one< 'a' >, space > >( __LINE__, __FILE__, " ", result_type::LOCAL_FAILURE, 1 ); verify_rule< pad< one< 'a' >, space > >( __LINE__, __FILE__, " ", result_type::LOCAL_FAILURE, 2 ); verify_rule< pad< one< 'a' >, space > >( __LINE__, __FILE__, "b", result_type::LOCAL_FAILURE, 1 ); verify_rule< pad< one< 'a' >, space > >( __LINE__, __FILE__, "ba", result_type::LOCAL_FAILURE, 2 ); verify_rule< pad< one< 'a' >, space > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 0 ); verify_rule< pad< one< 'a' >, space > >( __LINE__, __FILE__, " a", result_type::SUCCESS, 0 ); verify_rule< pad< one< 'a' >, space > >( __LINE__, __FILE__, "a ", result_type::SUCCESS, 0 ); verify_rule< pad< one< 'a' >, space > >( __LINE__, __FILE__, " a", result_type::SUCCESS, 0 ); verify_rule< pad< one< 'a' >, space > >( __LINE__, __FILE__, "a ", result_type::SUCCESS, 0 ); verify_rule< pad< one< 'a' >, space > >( __LINE__, __FILE__, " a ", result_type::SUCCESS, 0 ); verify_rule< pad< one< 'a' >, space > >( __LINE__, __FILE__, " a ", result_type::SUCCESS, 0 ); verify_rule< pad< one< 'a' >, space > >( __LINE__, __FILE__, "aa", result_type::SUCCESS, 1 ); verify_rule< pad< one< 'a' >, space > >( __LINE__, __FILE__, "a a", result_type::SUCCESS, 1 ); verify_rule< pad< one< 'a' >, space > >( __LINE__, __FILE__, " a a ", result_type::SUCCESS, 2 ); verify_rule< pad< one< 'a' >, digit, blank > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 0 ); verify_rule< pad< one< 'a' >, digit, blank > >( __LINE__, __FILE__, "1a", result_type::SUCCESS, 0 ); verify_rule< pad< one< 'a' >, digit, blank > >( __LINE__, __FILE__, "123a", result_type::SUCCESS, 0 ); verify_rule< pad< one< 'a' >, digit, blank > >( __LINE__, __FILE__, "a ", result_type::SUCCESS, 0 ); verify_rule< pad< one< 'a' >, digit, blank > >( __LINE__, __FILE__, "a ", result_type::SUCCESS, 0 ); verify_rule< pad< one< 'a' >, digit, blank > >( __LINE__, __FILE__, "123a ", result_type::SUCCESS, 0 ); verify_rule< pad< one< 'a' >, digit, blank > >( __LINE__, __FILE__, " a", result_type::LOCAL_FAILURE, 2 ); verify_rule< pad< one< 'a' >, digit, blank > >( __LINE__, __FILE__, "a1", result_type::SUCCESS, 1 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_pad_opt.cc000066400000000000000000000043141270130067200175540ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< pad_opt< eof, eof > >( __LINE__, __FILE__, false, true ); verify_analyze< pad_opt< eof, any > >( __LINE__, __FILE__, false, false ); verify_analyze< pad_opt< any, eof > >( __LINE__, __FILE__, false, true ); verify_analyze< pad_opt< any, any > >( __LINE__, __FILE__, false, false ); verify_rule< pad_opt< one< 'a' >, space > >( __LINE__, __FILE__, "", result_type::SUCCESS, 0 ); verify_rule< pad_opt< one< 'a' >, space > >( __LINE__, __FILE__, " ", result_type::SUCCESS, 0 ); verify_rule< pad_opt< one< 'a' >, space > >( __LINE__, __FILE__, " ", result_type::SUCCESS, 0 ); verify_rule< pad_opt< one< 'a' >, space > >( __LINE__, __FILE__, "b", result_type::SUCCESS, 1 ); verify_rule< pad_opt< one< 'a' >, space > >( __LINE__, __FILE__, "ba", result_type::SUCCESS, 2 ); verify_rule< pad_opt< one< 'a' >, space > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 0 ); verify_rule< pad_opt< one< 'a' >, space > >( __LINE__, __FILE__, " a", result_type::SUCCESS, 0 ); verify_rule< pad_opt< one< 'a' >, space > >( __LINE__, __FILE__, "a ", result_type::SUCCESS, 0 ); verify_rule< pad_opt< one< 'a' >, space > >( __LINE__, __FILE__, " a", result_type::SUCCESS, 0 ); verify_rule< pad_opt< one< 'a' >, space > >( __LINE__, __FILE__, " b", result_type::SUCCESS, 1 ); verify_rule< pad_opt< one< 'a' >, space > >( __LINE__, __FILE__, "a ", result_type::SUCCESS, 0 ); verify_rule< pad_opt< one< 'a' >, space > >( __LINE__, __FILE__, " a ", result_type::SUCCESS, 0 ); verify_rule< pad_opt< one< 'a' >, space > >( __LINE__, __FILE__, " a ", result_type::SUCCESS, 0 ); verify_rule< pad_opt< one< 'a' >, space > >( __LINE__, __FILE__, "aa", result_type::SUCCESS, 1 ); verify_rule< pad_opt< one< 'a' >, space > >( __LINE__, __FILE__, "a a", result_type::SUCCESS, 1 ); verify_rule< pad_opt< one< 'a' >, space > >( __LINE__, __FILE__, " a a ", result_type::SUCCESS, 2 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_plus.cc000066400000000000000000000051201270130067200171050ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< plus< eof > >( __LINE__, __FILE__, false, true ); verify_analyze< plus< any > >( __LINE__, __FILE__, true, false ); verify_analyze< plus< eof, eof, eof > >( __LINE__, __FILE__, false, true ); verify_analyze< plus< any, eof, any > >( __LINE__, __FILE__, true, false ); verify_rule< plus< one< 'a' > > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< plus< one< 'a' > > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 0 ); verify_rule< plus< one< 'a' > > >( __LINE__, __FILE__, "aa", result_type::SUCCESS, 0 ); verify_rule< plus< one< 'a' > > >( __LINE__, __FILE__, "aaa", result_type::SUCCESS, 0 ); verify_rule< plus< one< 'a' > > >( __LINE__, __FILE__, "b", result_type::LOCAL_FAILURE, 1 ); verify_rule< plus< one< 'a' > > >( __LINE__, __FILE__, "ab", result_type::SUCCESS, 1 ); verify_rule< plus< one< 'a' > > >( __LINE__, __FILE__, "aab", result_type::SUCCESS, 1 ); verify_rule< plus< one< 'a' > > >( __LINE__, __FILE__, "aaab", result_type::SUCCESS, 1 ); verify_rule< plus< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< plus< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "a", result_type::LOCAL_FAILURE, 1 ); verify_rule< plus< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "b", result_type::LOCAL_FAILURE, 1 ); verify_rule< plus< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ab", result_type::SUCCESS, 0 ); verify_rule< plus< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ac", result_type::LOCAL_FAILURE, 2 ); verify_rule< plus< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "aa", result_type::LOCAL_FAILURE, 2 ); verify_rule< plus< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "aba", result_type::SUCCESS, 1 ); verify_rule< plus< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "abb", result_type::SUCCESS, 1 ); verify_rule< plus< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "abc", result_type::SUCCESS, 1 ); verify_rule< plus< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "abab", result_type::SUCCESS, 0 ); verify_rule< plus< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ababa", result_type::SUCCESS, 1 ); verify_rule< plus< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ababb", result_type::SUCCESS, 1 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_rep.cc000066400000000000000000000057551270130067200167260ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< rep< 0, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< rep< 0, any > >( __LINE__, __FILE__, false, false ); verify_analyze< rep< 1, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< rep< 1, any > >( __LINE__, __FILE__, true, false ); verify_analyze< rep< 7, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< rep< 9, any > >( __LINE__, __FILE__, true, false ); verify_analyze< rep< 0, eof, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< rep< 0, any, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< rep< 0, any, any > >( __LINE__, __FILE__, false, false ); verify_analyze< rep< 0, eof, any > >( __LINE__, __FILE__, false, false ); verify_analyze< rep< 1, eof, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< rep< 1, any, eof > >( __LINE__, __FILE__, true, false ); verify_analyze< rep< 1, any, any > >( __LINE__, __FILE__, true, false ); verify_analyze< rep< 1, eof, any > >( __LINE__, __FILE__, true, false ); verify_rule< rep< 3, one< 'a' > > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< rep< 3, one< 'a' > > >( __LINE__, __FILE__, "a", result_type::LOCAL_FAILURE, 1 ); verify_rule< rep< 3, one< 'a' > > >( __LINE__, __FILE__, "aa", result_type::LOCAL_FAILURE, 2 ); verify_rule< rep< 3, one< 'a' > > >( __LINE__, __FILE__, "b", result_type::LOCAL_FAILURE, 1 ); verify_rule< rep< 3, one< 'a' > > >( __LINE__, __FILE__, "bb", result_type::LOCAL_FAILURE, 2 ); verify_rule< rep< 3, one< 'a' > > >( __LINE__, __FILE__, "bbb", result_type::LOCAL_FAILURE, 3 ); verify_rule< rep< 3, one< 'a' > > >( __LINE__, __FILE__, "aaa", result_type::SUCCESS, 0 ); verify_rule< rep< 3, one< 'a' > > >( __LINE__, __FILE__, "aaaa", result_type::SUCCESS, 1 ); verify_rule< rep< 3, one< 'a' > > >( __LINE__, __FILE__, "aaab", result_type::SUCCESS, 1 ); verify_rule< rep< 3, one< 'a' > > >( __LINE__, __FILE__, "baaab", result_type::LOCAL_FAILURE, 5 ); verify_rule< rep< 2, two< 'a' > > >( __LINE__, __FILE__, "a", result_type::LOCAL_FAILURE, 1 ); verify_rule< rep< 2, two< 'a' > > >( __LINE__, __FILE__, "aa", result_type::LOCAL_FAILURE, 2 ); verify_rule< rep< 2, two< 'a' > > >( __LINE__, __FILE__, "aaa", result_type::LOCAL_FAILURE, 3 ); verify_rule< rep< 2, two< 'a' > > >( __LINE__, __FILE__, "aaaa", result_type::SUCCESS, 0 ); verify_rule< rep< 2, two< 'a' > > >( __LINE__, __FILE__, "aaaaa", result_type::SUCCESS, 1 ); verify_rule< rep< 2, two< 'a' > > >( __LINE__, __FILE__, "aaaaaa", result_type::SUCCESS, 2 ); verify_rule< rep< 2, two< 'a' > > >( __LINE__, __FILE__, "aaaaaaa", result_type::SUCCESS, 3 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_rep_max.cc000066400000000000000000000074001270130067200175600ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< rep_max< 1, any > >( __LINE__, __FILE__, false, false ); verify_analyze< rep_max< 2, any > >( __LINE__, __FILE__, false, false ); verify_analyze< rep_max< 1, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< rep_max< 2, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< rep_max< 1, any, any > >( __LINE__, __FILE__, false, false ); verify_analyze< rep_max< 2, any, any > >( __LINE__, __FILE__, false, false ); verify_rule< rep_max< 3, one< 'a' > > >( __LINE__, __FILE__, "", result_type::SUCCESS, 0 ); verify_rule< rep_max< 3, one< 'a' > > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 0 ); verify_rule< rep_max< 3, one< 'a' > > >( __LINE__, __FILE__, "aa", result_type::SUCCESS, 0 ); verify_rule< rep_max< 3, one< 'a' > > >( __LINE__, __FILE__, "b", result_type::SUCCESS, 1 ); verify_rule< rep_max< 3, one< 'a' > > >( __LINE__, __FILE__, "bb", result_type::SUCCESS, 2 ); verify_rule< rep_max< 3, one< 'a' > > >( __LINE__, __FILE__, "bbb", result_type::SUCCESS, 3 ); verify_rule< rep_max< 3, one< 'a' > > >( __LINE__, __FILE__, "aaa", result_type::SUCCESS, 0 ); verify_rule< rep_max< 3, one< 'a' > > >( __LINE__, __FILE__, "aaaa", result_type::LOCAL_FAILURE, 4 ); verify_rule< rep_max< 3, one< 'a' > > >( __LINE__, __FILE__, "aaab", result_type::SUCCESS, 1 ); verify_rule< rep_max< 3, one< 'a' > > >( __LINE__, __FILE__, "baaab", result_type::SUCCESS, 5 ); verify_rule< rep_max< 2, one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "", result_type::SUCCESS, 0 ); verify_rule< rep_max< 2, one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 1 ); verify_rule< rep_max< 2, one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "aa", result_type::SUCCESS, 2 ); verify_rule< rep_max< 2, one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ba", result_type::SUCCESS, 2 ); verify_rule< rep_max< 2, one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ab", result_type::SUCCESS, 0 ); verify_rule< rep_max< 2, one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "aba", result_type::SUCCESS, 1 ); verify_rule< rep_max< 2, one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "abb", result_type::SUCCESS, 1 ); verify_rule< rep_max< 2, one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "aab", result_type::SUCCESS, 3 ); verify_rule< rep_max< 2, one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "abab", result_type::SUCCESS, 0 ); verify_rule< rep_max< 2, one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ababb", result_type::SUCCESS, 1 ); verify_rule< rep_max< 2, one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ababa", result_type::SUCCESS, 1 ); verify_rule< rep_max< 2, one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ababab", result_type::LOCAL_FAILURE, 6 ); verify_rule< rep_max< 2, two< 'a' > > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 1 ); verify_rule< rep_max< 2, two< 'a' > > >( __LINE__, __FILE__, "aa", result_type::SUCCESS, 0 ); verify_rule< rep_max< 2, two< 'a' > > >( __LINE__, __FILE__, "aaa", result_type::SUCCESS, 1 ); verify_rule< rep_max< 2, two< 'a' > > >( __LINE__, __FILE__, "aaaa", result_type::SUCCESS, 0 ); verify_rule< rep_max< 2, two< 'a' > > >( __LINE__, __FILE__, "aaaaa", result_type::SUCCESS, 1 ); verify_rule< rep_max< 2, two< 'a' > > >( __LINE__, __FILE__, "aaaaaa", result_type::LOCAL_FAILURE, 6 ); verify_rule< rep_max< 2, two< 'a' > > >( __LINE__, __FILE__, "aaaaaaa", result_type::LOCAL_FAILURE, 7 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_rep_min.cc000066400000000000000000000044541270130067200175640ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< rep_min< 0, eof > >( __LINE__, __FILE__, false, true ); verify_analyze< rep_min< 1, eof > >( __LINE__, __FILE__, false, true ); verify_analyze< rep_min< 0, any > >( __LINE__, __FILE__, false, false ); verify_analyze< rep_min< 1, any > >( __LINE__, __FILE__, true, false ); verify_rule< rep_min< 3, one< 'a' > > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< rep_min< 3, one< 'a' > > >( __LINE__, __FILE__, "a", result_type::LOCAL_FAILURE, 1 ); verify_rule< rep_min< 3, one< 'a' > > >( __LINE__, __FILE__, "aa", result_type::LOCAL_FAILURE, 2 ); verify_rule< rep_min< 3, one< 'a' > > >( __LINE__, __FILE__, "b", result_type::LOCAL_FAILURE, 1 ); verify_rule< rep_min< 3, one< 'a' > > >( __LINE__, __FILE__, "bb", result_type::LOCAL_FAILURE, 2 ); verify_rule< rep_min< 3, one< 'a' > > >( __LINE__, __FILE__, "bbb", result_type::LOCAL_FAILURE, 3 ); verify_rule< rep_min< 3, one< 'a' > > >( __LINE__, __FILE__, "aaa", result_type::SUCCESS, 0 ); verify_rule< rep_min< 3, one< 'a' > > >( __LINE__, __FILE__, "aaaa", result_type::SUCCESS, 0 ); verify_rule< rep_min< 3, one< 'a' > > >( __LINE__, __FILE__, "aaab", result_type::SUCCESS, 1 ); verify_rule< rep_min< 3, one< 'a' > > >( __LINE__, __FILE__, "baaab", result_type::LOCAL_FAILURE, 5 ); verify_rule< rep_min< 2, two< 'a' > > >( __LINE__, __FILE__, "a", result_type::LOCAL_FAILURE, 1 ); verify_rule< rep_min< 2, two< 'a' > > >( __LINE__, __FILE__, "aa", result_type::LOCAL_FAILURE, 2 ); verify_rule< rep_min< 2, two< 'a' > > >( __LINE__, __FILE__, "aaa", result_type::LOCAL_FAILURE, 3 ); verify_rule< rep_min< 2, two< 'a' > > >( __LINE__, __FILE__, "aaaa", result_type::SUCCESS, 0 ); verify_rule< rep_min< 2, two< 'a' > > >( __LINE__, __FILE__, "aaaaa", result_type::SUCCESS, 1 ); verify_rule< rep_min< 2, two< 'a' > > >( __LINE__, __FILE__, "aaaaaa", result_type::SUCCESS, 0 ); verify_rule< rep_min< 2, two< 'a' > > >( __LINE__, __FILE__, "aaaaaaa", result_type::SUCCESS, 1 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_rep_min_max.cc000066400000000000000000000056751270130067200204370ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< rep_min_max< 0, 1, any > >( __LINE__, __FILE__, false, false ); verify_analyze< rep_min_max< 0, 2, any > >( __LINE__, __FILE__, false, false ); verify_analyze< rep_min_max< 1, 2, any > >( __LINE__, __FILE__, true, false ); verify_analyze< rep_min_max< 0, 1, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< rep_min_max< 0, 2, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< rep_min_max< 1, 2, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< rep_min_max< 0, 1, any, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< rep_min_max< 0, 2, any, any > >( __LINE__, __FILE__, false, false ); verify_analyze< rep_min_max< 1, 2, eof, any > >( __LINE__, __FILE__, true, false ); verify_analyze< rep_min_max< 0, 1, eof, any > >( __LINE__, __FILE__, false, false ); verify_analyze< rep_min_max< 0, 2, eof, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< rep_min_max< 1, 2, eof, eof > >( __LINE__, __FILE__, false, false ); verify_rule< rep_min_max< 2, 4, one< 'a' > > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< rep_min_max< 2, 4, one< 'a' > > >( __LINE__, __FILE__, "a", result_type::LOCAL_FAILURE, 1 ); verify_rule< rep_min_max< 2, 4, one< 'a' > > >( __LINE__, __FILE__, "aa", result_type::SUCCESS, 0 ); verify_rule< rep_min_max< 2, 4, one< 'a' > > >( __LINE__, __FILE__, "aaa", result_type::SUCCESS, 0 ); verify_rule< rep_min_max< 2, 4, one< 'a' > > >( __LINE__, __FILE__, "aaaa", result_type::SUCCESS, 0 ); verify_rule< rep_min_max< 2, 4, one< 'a' > > >( __LINE__, __FILE__, "aaaaa", result_type::LOCAL_FAILURE, 5 ); verify_rule< rep_min_max< 2, 4, one< 'a' > > >( __LINE__, __FILE__, "b", result_type::LOCAL_FAILURE, 1 ); verify_rule< rep_min_max< 2, 4, one< 'a' > > >( __LINE__, __FILE__, "bb", result_type::LOCAL_FAILURE, 2 ); verify_rule< rep_min_max< 2, 4, one< 'a' > > >( __LINE__, __FILE__, "bbb", result_type::LOCAL_FAILURE, 3 ); verify_rule< rep_min_max< 2, 4, one< 'a' > > >( __LINE__, __FILE__, "bbbb", result_type::LOCAL_FAILURE, 4 ); verify_rule< rep_min_max< 2, 4, one< 'a' > > >( __LINE__, __FILE__, "bbbbb", result_type::LOCAL_FAILURE, 5 ); verify_rule< rep_min_max< 2, 4, one< 'a' > > >( __LINE__, __FILE__, "ba", result_type::LOCAL_FAILURE, 2 ); verify_rule< rep_min_max< 2, 4, one< 'a' > > >( __LINE__, __FILE__, "baa", result_type::LOCAL_FAILURE, 3 ); verify_rule< rep_min_max< 2, 4, one< 'a' > > >( __LINE__, __FILE__, "baaa", result_type::LOCAL_FAILURE, 4 ); verify_rule< rep_min_max< 2, 4, one< 'a' > > >( __LINE__, __FILE__, "baaaa", result_type::LOCAL_FAILURE, 5 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_rep_opt.cc000066400000000000000000000051041270130067200175740ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< rep_opt< 1, any > >( __LINE__, __FILE__, false, false ); verify_analyze< rep_opt< 6, any > >( __LINE__, __FILE__, false, false ); verify_analyze< rep_opt< 1, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< rep_opt< 6, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< rep_opt< 1, any, any > >( __LINE__, __FILE__, false, false ); verify_analyze< rep_opt< 1, eof, any > >( __LINE__, __FILE__, false, false ); verify_analyze< rep_opt< 1, any, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< rep_opt< 1, eof, eof > >( __LINE__, __FILE__, false, false ); verify_rule< rep_opt< 3, one< 'a' > > >( __LINE__, __FILE__, "", result_type::SUCCESS, 0 ); verify_rule< rep_opt< 3, one< 'a' > > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 0 ); verify_rule< rep_opt< 3, one< 'a' > > >( __LINE__, __FILE__, "aa", result_type::SUCCESS, 0 ); verify_rule< rep_opt< 3, one< 'a' > > >( __LINE__, __FILE__, "b", result_type::SUCCESS, 1 ); verify_rule< rep_opt< 3, one< 'a' > > >( __LINE__, __FILE__, "bb", result_type::SUCCESS, 2 ); verify_rule< rep_opt< 3, one< 'a' > > >( __LINE__, __FILE__, "bbb", result_type::SUCCESS, 3 ); verify_rule< rep_opt< 3, one< 'a' > > >( __LINE__, __FILE__, "aaa", result_type::SUCCESS, 0 ); verify_rule< rep_opt< 3, one< 'a' > > >( __LINE__, __FILE__, "aaaa", result_type::SUCCESS, 1 ); verify_rule< rep_opt< 3, one< 'a' > > >( __LINE__, __FILE__, "aaab", result_type::SUCCESS, 1 ); verify_rule< rep_opt< 3, one< 'a' > > >( __LINE__, __FILE__, "baaab", result_type::SUCCESS, 5 ); verify_rule< rep_opt< 2, two< 'a' > > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 1 ); verify_rule< rep_opt< 2, two< 'a' > > >( __LINE__, __FILE__, "aa", result_type::SUCCESS, 0 ); verify_rule< rep_opt< 2, two< 'a' > > >( __LINE__, __FILE__, "aaa", result_type::SUCCESS, 1 ); verify_rule< rep_opt< 2, two< 'a' > > >( __LINE__, __FILE__, "aaaa", result_type::SUCCESS, 0 ); verify_rule< rep_opt< 2, two< 'a' > > >( __LINE__, __FILE__, "aaaaa", result_type::SUCCESS, 1 ); verify_rule< rep_opt< 2, two< 'a' > > >( __LINE__, __FILE__, "aaaaaa", result_type::SUCCESS, 2 ); verify_rule< rep_opt< 2, two< 'a' > > >( __LINE__, __FILE__, "aaaaaaa", result_type::SUCCESS, 3 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_seq.cc000066400000000000000000000004441270130067200167160ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" #include "verify_seqs.hh" namespace pegtl { void unit_test() { verify_seqs< seq >(); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_sor.cc000066400000000000000000000044461270130067200167370ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< sor< any, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< sor< eof, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< sor< eof, any > >( __LINE__, __FILE__, false, false ); verify_analyze< sor< any, any > >( __LINE__, __FILE__, true, false ); verify_analyze< sor< any, any, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< sor< any, eof, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< sor< any, eof, any > >( __LINE__, __FILE__, false, false ); verify_analyze< sor< any, any, any > >( __LINE__, __FILE__, true, false ); verify_analyze< sor< eof, any, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< sor< eof, eof, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< sor< eof, eof, any > >( __LINE__, __FILE__, false, false ); verify_analyze< sor< eof, any, any > >( __LINE__, __FILE__, false, false ); verify_rule< sor<> >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< sor<> >( __LINE__, __FILE__, "a", result_type::LOCAL_FAILURE, 1 ); verify_rule< sor< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< sor< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 0 ); verify_rule< sor< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "b", result_type::SUCCESS, 0 ); verify_rule< sor< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "c", result_type::LOCAL_FAILURE, 1 ); verify_rule< sor< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "aa", result_type::SUCCESS, 1 ); verify_rule< sor< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ab", result_type::SUCCESS, 1 ); verify_rule< sor< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ba", result_type::SUCCESS, 1 ); verify_rule< sor< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "bb", result_type::SUCCESS, 1 ); verify_rule< sor< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "cb", result_type::LOCAL_FAILURE, 2 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_star.cc000066400000000000000000000036741270130067200171070ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< star< eof > >( __LINE__, __FILE__, false, true ); verify_analyze< star< any > >( __LINE__, __FILE__, false, false ); verify_analyze< star< eof, eof, eof > >( __LINE__, __FILE__, false, true ); verify_analyze< star< any, eof, any > >( __LINE__, __FILE__, false, false ); verify_rule< star< one< 'a' > > >( __LINE__, __FILE__, "", result_type::SUCCESS, 0 ); verify_rule< star< one< 'a' > > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 0 ); verify_rule< star< one< 'a' > > >( __LINE__, __FILE__, "aa", result_type::SUCCESS, 0 ); verify_rule< star< one< 'a' > > >( __LINE__, __FILE__, "aaa", result_type::SUCCESS, 0 ); verify_rule< star< one< 'a' > > >( __LINE__, __FILE__, "ba", result_type::SUCCESS, 2 ); verify_rule< star< one< 'a' > > >( __LINE__, __FILE__, "b", result_type::SUCCESS, 1 ); verify_rule< star< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "", result_type::SUCCESS, 0 ); verify_rule< star< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 1 ); verify_rule< star< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ab", result_type::SUCCESS, 0 ); verify_rule< star< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "aba", result_type::SUCCESS, 1 ); verify_rule< star< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "abb", result_type::SUCCESS, 1 ); verify_rule< star< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "abab", result_type::SUCCESS, 0 ); verify_rule< star< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ababc", result_type::SUCCESS, 1 ); verify_rule< star< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ababab", result_type::SUCCESS, 0 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_star_must.cc000066400000000000000000000040441270130067200201470ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< star_must< eof > >( __LINE__, __FILE__, false, true ); verify_analyze< star_must< any > >( __LINE__, __FILE__, false, false ); verify_analyze< star_must< eof, eof, eof > >( __LINE__, __FILE__, false, true ); verify_analyze< star_must< any, eof, any > >( __LINE__, __FILE__, false, false ); verify_rule< star_must< one< 'a' > > >( __LINE__, __FILE__, "", result_type::SUCCESS, 0 ); verify_rule< star_must< one< 'a' > > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 0 ); verify_rule< star_must< one< 'a' > > >( __LINE__, __FILE__, "aa", result_type::SUCCESS, 0 ); verify_rule< star_must< one< 'a' > > >( __LINE__, __FILE__, "aaa", result_type::SUCCESS, 0 ); verify_rule< star_must< one< 'a' > > >( __LINE__, __FILE__, "ba", result_type::SUCCESS, 2 ); verify_rule< star_must< one< 'a' > > >( __LINE__, __FILE__, "b", result_type::SUCCESS, 1 ); verify_rule< star_must< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "", result_type::SUCCESS, 0 ); verify_rule< star_must< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "a", result_type::GLOBAL_FAILURE, 1 ); verify_rule< star_must< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ab", result_type::SUCCESS, 0 ); verify_rule< star_must< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "aba", result_type::GLOBAL_FAILURE, 3 ); verify_rule< star_must< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "abb", result_type::SUCCESS, 1 ); verify_rule< star_must< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "abab", result_type::SUCCESS, 0 ); verify_rule< star_must< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ababc", result_type::SUCCESS, 1 ); verify_rule< star_must< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ababab", result_type::SUCCESS, 0 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_state.cc000066400000000000000000000022231270130067200172430ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" #include "verify_seqs.hh" namespace pegtl { struct test_state_state { template< typename Input > test_state_state( const Input & ) { } template< typename Input > void success( const Input & ) const { } }; struct test_state_with_template_parameters_state { template< typename Input > test_state_with_template_parameters_state( const Input & ) { } template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input > void success( const Input & ) const { } }; template< typename ... Rules > using test_state_rule = state< test_state_state, Rules ... >; template< typename ... Rules > using test_state_with_template_parameters_rule = state< test_state_with_template_parameters_state, Rules ... >; void unit_test() { verify_seqs< test_state_rule >(); verify_seqs< test_state_with_template_parameters_rule >(); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_success.cc000066400000000000000000000010701270130067200175720ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< success >( __LINE__, __FILE__, false, false ); verify_rule< success >( __LINE__, __FILE__, "", result_type::SUCCESS, 0 ); for ( char i = 1; i < 127; ++i ) { char t[] = { i, 0 }; verify_rule< success >( __LINE__, __FILE__, std::string( t ), result_type::SUCCESS, 1 ); } } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_try_catch.cc000066400000000000000000000006651270130067200201130ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" #include "verify_seqs.hh" namespace pegtl { template< typename ... Rules > using test_try_catch_rule = try_catch< must< Rules ... > >; void unit_test() { verify_seqs< try_catch >(); verify_seqs< test_try_catch_rule >(); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/rule_until.cc000066400000000000000000000134051270130067200172620ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_analyze< until< eof > >( __LINE__, __FILE__, false, false ); verify_analyze< until< any > >( __LINE__, __FILE__, true, false ); verify_analyze< until< eof, any > >( __LINE__, __FILE__, false, false ); verify_analyze< until< any, any > >( __LINE__, __FILE__, true, false ); verify_rule< until< eof > >( __LINE__, __FILE__, "", result_type::SUCCESS, 0 ); verify_rule< until< any > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< until< one< 'a' > > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 0 ); verify_rule< until< one< 'a' > > >( __LINE__, __FILE__, "ba", result_type::SUCCESS, 0 ); verify_rule< until< one< 'a' > > >( __LINE__, __FILE__, "bba", result_type::SUCCESS, 0 ); verify_rule< until< one< 'a' > > >( __LINE__, __FILE__, "bbbbbbbbbbbbbbba", result_type::SUCCESS, 0 ); verify_rule< until< one< 'a' > > >( __LINE__, __FILE__, "ab", result_type::SUCCESS, 1 ); verify_rule< until< one< 'a' > > >( __LINE__, __FILE__, "bab", result_type::SUCCESS, 1 ); verify_rule< until< one< 'a' > > >( __LINE__, __FILE__, "bbab", result_type::SUCCESS, 1 ); verify_rule< until< one< 'a' > > >( __LINE__, __FILE__, "bbbbbbbbbbbbbbbab", result_type::SUCCESS, 1 ); verify_rule< until< eof, any > >( __LINE__, __FILE__, "", result_type::SUCCESS, 0 ); verify_rule< until< any, any > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< until< one< 'a' >, any > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 0 ); verify_rule< until< one< 'a' >, any > >( __LINE__, __FILE__, "ba", result_type::SUCCESS, 0 ); verify_rule< until< one< 'a' >, any > >( __LINE__, __FILE__, "bba", result_type::SUCCESS, 0 ); verify_rule< until< one< 'a' >, any > >( __LINE__, __FILE__, "bbbbbbbbbbbbbbba", result_type::SUCCESS, 0 ); verify_rule< until< one< 'a' >, any > >( __LINE__, __FILE__, "ab", result_type::SUCCESS, 1 ); verify_rule< until< one< 'a' >, any > >( __LINE__, __FILE__, "bab", result_type::SUCCESS, 1 ); verify_rule< until< one< 'a' >, any > >( __LINE__, __FILE__, "bbab", result_type::SUCCESS, 1 ); verify_rule< until< one< 'a' >, any > >( __LINE__, __FILE__, "bbbbbbbbbbbbbbbab", result_type::SUCCESS, 1 ); verify_rule< until< eof, one< 'a' > > >( __LINE__, __FILE__, "", result_type::SUCCESS, 0 ); verify_rule< until< eof, one< 'a' > > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 0 ); verify_rule< until< eof, one< 'a' > > >( __LINE__, __FILE__, "aa", result_type::SUCCESS, 0 ); verify_rule< until< eof, one< 'a' > > >( __LINE__, __FILE__, "aaaaab", result_type::LOCAL_FAILURE, 6 ); verify_rule< until< eof, one< 'a' > > >( __LINE__, __FILE__, "baaaaa", result_type::LOCAL_FAILURE, 6 ); verify_rule< until< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< until< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 0 ); verify_rule< until< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "aa", result_type::SUCCESS, 1 ); verify_rule< until< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ab", result_type::SUCCESS, 1 ); verify_rule< until< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "b", result_type::LOCAL_FAILURE, 1 ); verify_rule< until< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "bb", result_type::LOCAL_FAILURE, 2 ); verify_rule< until< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ba", result_type::SUCCESS, 0 ); verify_rule< until< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "bba", result_type::SUCCESS, 0 ); verify_rule< until< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "bbbbbbbbbbbbbba", result_type::SUCCESS, 0 ); verify_rule< until< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "baa", result_type::SUCCESS, 1 ); verify_rule< until< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "bbaa", result_type::SUCCESS, 1 ); verify_rule< until< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "bbbbbbbbbbbbbbaa", result_type::SUCCESS, 1 ); verify_rule< until< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "bab", result_type::SUCCESS, 1 ); verify_rule< until< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "bbab", result_type::SUCCESS, 1 ); verify_rule< until< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "bbbbbbbbbbbbbbab", result_type::SUCCESS, 1 ); verify_rule< until< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< until< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "a", result_type::SUCCESS, 0 ); verify_rule< until< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "bca", result_type::SUCCESS, 0 ); verify_rule< until< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "bcbca", result_type::SUCCESS, 0 ); verify_rule< until< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "bcbcbcbcbca", result_type::SUCCESS, 0 ); verify_rule< until< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "babca", result_type::LOCAL_FAILURE, 5 ); verify_rule< until< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "bcbcb", result_type::LOCAL_FAILURE, 5 ); verify_rule< until< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "cbcbc", result_type::LOCAL_FAILURE, 5 ); verify_rule< until< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "bcbcbc", result_type::LOCAL_FAILURE, 6 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/test.hh000066400000000000000000000011651270130067200160710ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_UNIT_TESTS_TEST_HH #define PEGTL_UNIT_TESTS_TEST_HH #include #include #include #include namespace pegtl { std::size_t failed = 0; std::vector< std::pair< std::string, std::string > > applied; } // pegtl #include "test_action.hh" #include "test_assert.hh" #include "test_control.hh" #include "test_failed.hh" #include "verify_rule.hh" #include "verify_char.hh" #include "verify_fail.hh" #include "verify_analyze.hh" #endif PEGTL-1.3.1/unit_tests/test_action.hh000066400000000000000000000010611270130067200174210ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_UNIT_TESTS_TEST_ACTION_HH #define PEGTL_UNIT_TESTS_TEST_ACTION_HH #include #include namespace pegtl { template< typename Rule > struct test_action { template< typename Input > static void apply( const Input & in ) { applied.push_back( std::make_pair( internal::demangle< Rule >(), in.string() ) ); } }; } // pegtl #endif PEGTL-1.3.1/unit_tests/test_assert.hh000066400000000000000000000016111270130067200174460ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_UNIT_TESTS_TEST_ASSERT_HH #define PEGTL_UNIT_TESTS_TEST_ASSERT_HH #include #define TEST_ASSERT( eXPReSSioN ) \ do { \ if ( ! ( eXPReSSioN ) ) { \ std::cerr << "pegtl: unit test assert [ " \ << ( # eXPReSSioN ) \ << " ] failed in line [ " \ << __LINE__ \ << " ] file [ " \ << __FILE__ << " ]" \ << std::endl; \ ++failed; \ } } while ( 0 ) #endif PEGTL-1.3.1/unit_tests/test_control.hh000066400000000000000000000010641270130067200176270ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_UNIT_TESTS_TEST_CONTROL_HH #define PEGTL_UNIT_TESTS_TEST_CONTROL_HH #include #include namespace pegtl { template< typename Rule > struct test_control { template< typename Input > static void apply( const Input & in ) { applied.push_back( std::make_pair( internal::demangle< Rule >(), in.string() ) ); } }; } // pegtl #endif PEGTL-1.3.1/unit_tests/test_failed.hh000066400000000000000000000017001270130067200173700ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_UNIT_TESTS_TEST_FAILED_HH #define PEGTL_UNIT_TESTS_TEST_FAILED_HH #include #define TEST_FAILED( MeSSaGe ) \ do { \ std::cerr << "pegtl: unit test failed for [ " \ << internal::demangle< Rule >() \ << " ] " \ << MeSSaGe \ << " in line [ " \ << line \ << " ] file [ " \ << file << " ]" \ << std::endl; \ ++failed; \ } while ( 0 ) #endif PEGTL-1.3.1/unit_tests/trace.cc000066400000000000000000000006331270130067200161750ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" #include namespace pegtl { using GRAMMAR = pegtl::sor< pegtl::failure, pegtl::one< 'a' > >; void unit_test() { failed = ! pegtl::trace< GRAMMAR >( "ab", "trace test please ignore" ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/utf16_general.cc000066400000000000000000000061531270130067200175440ustar00rootroot00000000000000// Copyright (c) 2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { namespace { std::string u16s( const char16_t u ) { return std::string( reinterpret_cast< const char * >( & u ), sizeof( u ) ); } } // void unit_test() { verify_rule< utf16::any >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< utf16::any >( __LINE__, __FILE__, "\x01", result_type::LOCAL_FAILURE, 1 ); verify_rule< utf16::any >( __LINE__, __FILE__, "\xff", result_type::LOCAL_FAILURE, 1 ); verify_rule< utf16::any >( __LINE__, __FILE__, u16s( 0 ), result_type::SUCCESS, 0 ); verify_rule< utf16::any >( __LINE__, __FILE__, u16s( 1 ), result_type::SUCCESS, 0 ); verify_rule< utf16::any >( __LINE__, __FILE__, " ", result_type::SUCCESS, 0 ); verify_rule< utf16::any >( __LINE__, __FILE__, u16s( 0x00ff ), result_type::SUCCESS, 0 ); verify_rule< utf16::any >( __LINE__, __FILE__, u16s( 0x0100 ), result_type::SUCCESS, 0 ); verify_rule< utf16::any >( __LINE__, __FILE__, u16s( 0x0fff ), result_type::SUCCESS, 0 ); verify_rule< utf16::any >( __LINE__, __FILE__, u16s( 0x1000 ), result_type::SUCCESS, 0 ); verify_rule< utf16::any >( __LINE__, __FILE__, u16s( 0xd800 ), result_type::SUCCESS, 0 ); verify_rule< utf16::any >( __LINE__, __FILE__, u16s( 0xd900 ), result_type::SUCCESS, 0 ); verify_rule< utf16::any >( __LINE__, __FILE__, u16s( 0xde00 ), result_type::SUCCESS, 0 ); verify_rule< utf16::any >( __LINE__, __FILE__, u16s( 0xfffe ) + " ", result_type::SUCCESS, 1 ); verify_rule< utf16::any >( __LINE__, __FILE__, u16s( 0xffff ) + " ", result_type::SUCCESS, 2 ); verify_rule< utf16::any >( __LINE__, __FILE__, u16s( 0xd7ff ) + u16s( 0xdfff ), result_type::SUCCESS, 2 ); verify_rule< utf16::any >( __LINE__, __FILE__, u16s( 0xdc00 ) + u16s( 0xdfff ), result_type::SUCCESS, 2 ); verify_rule< utf16::any >( __LINE__, __FILE__, u16s( 0xd800 ) + u16s( 0x0020 ), result_type::SUCCESS, 2 ); verify_rule< utf16::any >( __LINE__, __FILE__, u16s( 0xd800 ) + u16s( 0xff20 ), result_type::SUCCESS, 2 ); verify_rule< utf16::any >( __LINE__, __FILE__, u16s( 0xd800 ) + u16s( 0xdf00 ), result_type::SUCCESS, 0 ); verify_rule< utf16::any >( __LINE__, __FILE__, u16s( 0xd800 ) + u16s( 0xdfff ), result_type::SUCCESS, 0 ); verify_rule< utf16::any >( __LINE__, __FILE__, u16s( 0xd800 ) + u16s( 0xdfff ), result_type::SUCCESS, 0 ); verify_rule< utf16::any >( __LINE__, __FILE__, u16s( 0xdbff ) + u16s( 0xdc00 ), result_type::SUCCESS, 0 ); verify_rule< utf16::any >( __LINE__, __FILE__, u16s( 0xdbff ) + u16s( 0xdfff ), result_type::SUCCESS, 0 ); verify_rule< utf16::one< 0x20 > >( __LINE__, __FILE__, u16s( 0x20 ), result_type::SUCCESS, 0 ); verify_rule< utf16::one< 0x20ac > >( __LINE__, __FILE__, u16s( 0x20ac ), result_type::SUCCESS, 0 ); verify_rule< utf16::one< 0x10437 > >( __LINE__, __FILE__, u16s( 0xd801 ) + u16s( 0xdc37 ), result_type::SUCCESS, 0 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/utf32_general.cc000066400000000000000000000045601270130067200175420ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { namespace { std::string u32s( const char32_t u ) { return std::string( reinterpret_cast< const char * >( & u ), sizeof( u ) ); } } // void unit_test() { verify_rule< utf32::any >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); verify_rule< utf32::any >( __LINE__, __FILE__, "\xff", result_type::LOCAL_FAILURE, 1 ); verify_rule< utf32::any >( __LINE__, __FILE__, "\xff\xff", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf32::any >( __LINE__, __FILE__, "\xff\xff\xff", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf32::any >( __LINE__, __FILE__, u32s( 0 ), result_type::SUCCESS, 0 ); verify_rule< utf32::any >( __LINE__, __FILE__, u32s( 1 ), result_type::SUCCESS, 0 ); verify_rule< utf32::any >( __LINE__, __FILE__, u32s( 0x00ff ) + " ", result_type::SUCCESS, 1 ); verify_rule< utf32::any >( __LINE__, __FILE__, u32s( 0x0100 ) + " ", result_type::SUCCESS, 2 ); verify_rule< utf32::any >( __LINE__, __FILE__, u32s( 0x0fff ) + " ", result_type::SUCCESS, 3 ); verify_rule< utf32::any >( __LINE__, __FILE__, u32s( 0x1000 ) + " ", result_type::SUCCESS, 4 ); verify_rule< utf32::any >( __LINE__, __FILE__, u32s( 0xfffe ), result_type::SUCCESS, 0 ); verify_rule< utf32::any >( __LINE__, __FILE__, u32s( 0xffff ), result_type::SUCCESS, 0 ); verify_rule< utf32::any >( __LINE__, __FILE__, u32s( 0x100000 ), result_type::SUCCESS, 0 ); verify_rule< utf32::any >( __LINE__, __FILE__, u32s( 0x10fffe ), result_type::SUCCESS, 0 ); verify_rule< utf32::any >( __LINE__, __FILE__, u32s( 0x10ffff ), result_type::SUCCESS, 0 ); verify_rule< utf32::any >( __LINE__, __FILE__, u32s( 0x110000 ), result_type::LOCAL_FAILURE, 4 ); verify_rule< utf32::any >( __LINE__, __FILE__, u32s( 0x110000 ) + u32s( 0 ), result_type::LOCAL_FAILURE, 8 ); verify_rule< utf32::one< 0x20 > >( __LINE__, __FILE__, u32s( 0x20 ), result_type::SUCCESS, 0 ); verify_rule< utf32::one< 0x20ac > >( __LINE__, __FILE__, u32s( 0x20ac ), result_type::SUCCESS, 0 ); verify_rule< utf32::one< 0x10fedc > >( __LINE__, __FILE__, u32s( 0x10fedc ), result_type::SUCCESS, 0 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/utf8_general.cc000066400000000000000000000516211270130067200174650ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #include "test.hh" namespace pegtl { void unit_test() { verify_rule< utf8::any >( __LINE__, __FILE__, "", result_type::LOCAL_FAILURE, 0 ); for ( int i = -100; i < 200; ++i ) { verify_char< utf8::any >( __LINE__, __FILE__, i, ( i & 0x80 ) == 0 ); } verify_rule< utf8::any >( __LINE__, __FILE__, "\x30", result_type::SUCCESS, 0 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xc2\xa2", result_type::SUCCESS, 0 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xe2\x82\xac", result_type::SUCCESS, 0 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf0\x90\x8d\x88", result_type::SUCCESS, 0 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x30\x20", result_type::SUCCESS, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xc2\xa2\x20", result_type::SUCCESS, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xe2\x82\xac\x20", result_type::SUCCESS, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf0\x90\x8d\x88\x20", result_type::SUCCESS, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xc0", result_type::LOCAL_FAILURE, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xcf", result_type::LOCAL_FAILURE, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xc0\x01", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xc0\x3c", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xc0\x7f", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xcf\x01", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xcf\x3c", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xcf\x7f", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xc0\x01\x81", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xc0\x3c\x81", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xc0\x7f\x81", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xcf\x01\x81", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xcf\x3c\x81", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xcf\x7f\x81", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xc3\x81", result_type::SUCCESS, 0 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xc3\x81\x81", result_type::SUCCESS, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xc3\x81\x81\x81", result_type::SUCCESS, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xc3\x81\x81\x81\x81", result_type::SUCCESS, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xcf\x80", result_type::SUCCESS, 0 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xcf\x80\x80", result_type::SUCCESS, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xcf\x80\x80\x80", result_type::SUCCESS, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xcf\x80\x80\x80\x80", result_type::SUCCESS, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xcf\xbf", result_type::SUCCESS, 0 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xcf\xbf\xbf", result_type::SUCCESS, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xcf\xbf\xbf\xbf", result_type::SUCCESS, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xcf\xbf\xbf\xbf\xbf", result_type::SUCCESS, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xcf\xff", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xcf\xff\xff", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xcf\xff\xff\xff", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xcf\xff\xff\xff\xff", result_type::LOCAL_FAILURE, 5 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xe0", result_type::LOCAL_FAILURE, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xe7", result_type::LOCAL_FAILURE, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xef", result_type::LOCAL_FAILURE, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xe0\x0f", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xe7\x0f", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xef\x0f", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xe0\x80", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xe7\x80", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xef\x80", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xe0\xff", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xe7\xff", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xef\xff", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xe0\x80\x80", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xe0\x80\x80\x80", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xe0\xff\xff", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xef\xff\xff\xff", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xef\xff\xff", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xef\xff\xff\xff", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xe7\x80\x80", result_type::SUCCESS, 0 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xe7\x80\x80\x80", result_type::SUCCESS, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xe7\x80\x80\x80\x80", result_type::SUCCESS, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xef\xbf\xbf", result_type::SUCCESS, 0 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xef\xbf\xbf\xbf", result_type::SUCCESS, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xef\xbf\xbf\xbf\xbf", result_type::SUCCESS, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xef\x80\xff", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xef\x80\xff\xff", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xef\x80\xff\xff\xff", result_type::LOCAL_FAILURE, 5 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xef\xff\xff", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xef\xff\xff\xff", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xef\xff\xff\xff\xff", result_type::LOCAL_FAILURE, 5 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf0", result_type::LOCAL_FAILURE, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf7", result_type::LOCAL_FAILURE, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf0\x80", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf7\x80", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf0\x80\x80", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf7\x80\x80", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf0\x80\x80\xff", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf7\x80\x80\xff", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf0\xc0\x80\x80", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf7\xc0\x80\x80", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf0\x80\xf0\x80", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf7\x80\xf0\x80", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf0\x80\x80\x80", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf5\x80\x80\x80", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf6\x80\x80\x80", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf7\x80\x80\x80", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf4\x9f\xbf\xbf", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf1\x80\x80\x80", result_type::SUCCESS, 0 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf2\x80\x80\x80", result_type::SUCCESS, 0 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf3\x80\x80\x80", result_type::SUCCESS, 0 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf4\x80\x80\x80", result_type::SUCCESS, 0 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf0\xa0\x80\x80", result_type::SUCCESS, 0 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf0\x90\x80\x80", result_type::SUCCESS, 0 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf4\x8f\xbf\xbf", result_type::SUCCESS, 0 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf1\x80\x80\x80\x80", result_type::SUCCESS, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf2\x80\x80\x80\x80", result_type::SUCCESS, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf3\x80\x80\x80\x80", result_type::SUCCESS, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf4\x80\x80\x80\x80", result_type::SUCCESS, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf0\xa0\x80\x80\x80", result_type::SUCCESS, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf0\x90\x80\x80\x80", result_type::SUCCESS, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xff", result_type::LOCAL_FAILURE, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xff ", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xff ", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xff ", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xff ", result_type::LOCAL_FAILURE, 5 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xff ", result_type::LOCAL_FAILURE, 6 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xff ", result_type::LOCAL_FAILURE, 7 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xff ", result_type::LOCAL_FAILURE, 8 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xff\x80", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xff\x80\x80", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xff\x80\x80\x80", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xff\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 5 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xff\x80\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 6 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xff\x80\x80\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 7 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xff\x80\x80\x80\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 8 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfe", result_type::LOCAL_FAILURE, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfe ", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfe ", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfe ", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfe ", result_type::LOCAL_FAILURE, 5 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfe ", result_type::LOCAL_FAILURE, 6 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfe ", result_type::LOCAL_FAILURE, 7 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfe ", result_type::LOCAL_FAILURE, 8 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfe\x80", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfe\x80\x80", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfe\x80\x80\x80", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfe\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 5 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfe\x80\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 6 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfe\x80\x80\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 7 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfe\x80\x80\x80\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 8 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfc", result_type::LOCAL_FAILURE, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfc ", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfc ", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfc ", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfc ", result_type::LOCAL_FAILURE, 5 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfc ", result_type::LOCAL_FAILURE, 6 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfc ", result_type::LOCAL_FAILURE, 7 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfc ", result_type::LOCAL_FAILURE, 8 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfc\x80", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfc\x80\x80", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfc\x80\x80\x80", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfc\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 5 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfc\x80\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 6 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfc\x80\x80\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 7 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xfc\x80\x80\x80\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 8 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf8", result_type::LOCAL_FAILURE, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf8 ", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf8 ", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf8 ", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf8 ", result_type::LOCAL_FAILURE, 5 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf8 ", result_type::LOCAL_FAILURE, 6 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf8 ", result_type::LOCAL_FAILURE, 7 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf8 ", result_type::LOCAL_FAILURE, 8 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf8\x80", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf8\x80\x80", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf8\x80\x80\x80", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf8\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 5 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf8\x80\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 6 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf8\x80\x80\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 7 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\xf8\x80\x80\x80\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 8 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x80", result_type::LOCAL_FAILURE, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x80 ", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x80 ", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x80 ", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x80 ", result_type::LOCAL_FAILURE, 5 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x80 ", result_type::LOCAL_FAILURE, 6 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x80 ", result_type::LOCAL_FAILURE, 7 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x80 ", result_type::LOCAL_FAILURE, 8 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x80\x80", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x80\x80\x80", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x80\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 5 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x80\x80\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 6 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x80\x80\x80\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 7 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x80\x80\x80\x80\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 8 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x81", result_type::LOCAL_FAILURE, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x81 ", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x81 ", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x81 ", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x81 ", result_type::LOCAL_FAILURE, 5 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x81 ", result_type::LOCAL_FAILURE, 6 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x81 ", result_type::LOCAL_FAILURE, 7 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x81 ", result_type::LOCAL_FAILURE, 8 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x81\x80", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x81\x80\x80", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x81\x80\x80\x80", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x81\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 5 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x81\x80\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 6 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x81\x80\x80\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 7 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x81\x80\x80\x80\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 8 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x8f", result_type::LOCAL_FAILURE, 1 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x8f ", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x8f ", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x8f ", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x8f ", result_type::LOCAL_FAILURE, 5 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x8f ", result_type::LOCAL_FAILURE, 6 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x8f ", result_type::LOCAL_FAILURE, 7 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x8f ", result_type::LOCAL_FAILURE, 8 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x8f\x80", result_type::LOCAL_FAILURE, 2 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x8f\x80\x80", result_type::LOCAL_FAILURE, 3 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x8f\x80\x80\x80", result_type::LOCAL_FAILURE, 4 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x8f\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 5 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x8f\x80\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 6 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x8f\x80\x80\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 7 ); verify_rule< utf8::any >( __LINE__, __FILE__, "\x8f\x80\x80\x80\x80\x80\x80\x80", result_type::LOCAL_FAILURE, 8 ); verify_rule< utf8::one< 0x20 > >( __LINE__, __FILE__, "\x20", result_type::SUCCESS, 0 ); verify_rule< utf8::one< 0xa2 > >( __LINE__, __FILE__, "\xc2\xa2", result_type::SUCCESS, 0 ); verify_rule< utf8::one< 0x20ac > >( __LINE__, __FILE__, "\xe2\x82\xac", result_type::SUCCESS, 0 ); verify_rule< utf8::one< 0x10348 > >( __LINE__, __FILE__, "\xf0\x90\x8d\x88", result_type::SUCCESS, 0 ); } } // pegtl #include "main.hh" PEGTL-1.3.1/unit_tests/verify_analyze.hh000066400000000000000000000017431270130067200201430ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_UNIT_TESTS_VERIFY_ANALYZE_HH #define PEGTL_UNIT_TESTS_VERIFY_ANALYZE_HH #include #include "test_failed.hh" namespace pegtl { template< typename Rule > void verify_analyze( const unsigned line, const char * file, const bool expect_consume, const bool expect_problems ) { analysis::analyze_cycles< Rule > a( true ); const bool has_problems = ( a.problems() != 0 ); const bool does_consume = a.template consumes< Rule >(); if ( has_problems != expect_problems ) { TEST_FAILED( "analyze -- problems received/expected [ " << has_problems << " / " << expect_problems << " ]" ); } if ( does_consume != expect_consume ) { TEST_FAILED( "analyze -- consumes received/expected [ " << does_consume << " / " << expect_consume << " ]" ); } } } // pegtl #endif PEGTL-1.3.1/unit_tests/verify_char.hh000066400000000000000000000015521270130067200174130ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_UNIT_TESTS_VERIFY_CHAR_HH #define PEGTL_UNIT_TESTS_VERIFY_CHAR_HH #include #include #include "result_type.hh" #include "verify_rule.hh" namespace pegtl { template< typename Rule > void verify_char( const std::size_t line, const char * file, const char data, const result_type result ) { verify_rule< Rule >( line, file, std::string( std::size_t( 1 ), data ), result, ( result == result_type::SUCCESS ) ? 0 : 1 ); } template< typename Rule > void verify_char( const std::size_t line, const char * file, const char data, const bool result ) { verify_char< Rule >( line, file, data, result ? result_type::SUCCESS : result_type::LOCAL_FAILURE ); } } // pegtl #endif PEGTL-1.3.1/unit_tests/verify_fail.hh000066400000000000000000000013071270130067200174070ustar00rootroot00000000000000// Copyright (c) 2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_UNIT_TESTS_VERIFY_FAIL_HH #define PEGTL_UNIT_TESTS_VERIFY_FAIL_HH #include #include #include #include "test_failed.hh" namespace pegtl { template< typename Rule, template< typename > class Action = nothing, typename ... States > void verify_fail( const std::size_t line, const char * file, const std::string & s, States && ... st ) { try { parse< Rule, Action >( s, "expect_exception", st ... ); TEST_FAILED( "expected exception" ); } catch ( ... ) { } } } // pegtl #endif PEGTL-1.3.1/unit_tests/verify_file.hh000066400000000000000000000050141270130067200174120ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_UNIT_TESTS_VERIFY_FILE_HH #define PEGTL_UNIT_TESTS_VERIFY_FILE_HH #include namespace pegtl { struct file_content : seq< pegtl_string_t( "dummy content" ), eol > {}; struct file_grammar : seq< rep_min_max< 11, 11, file_content >, eof > {}; template< typename Rule > struct file_action : nothing< Rule > {}; template<> struct file_action< eof > { static void apply( const input &, bool & flag ) { flag = true; } }; template< typename Rule > struct file_control : normal< Rule > {}; template<> struct file_control< eof > : normal< eof > { static void success( const input &, bool & flag ) { flag = true; } }; template< typename T > void verify_file() { { const std::string f{ "unit_tests/no_such_file.txt" }; try { T p{ f }; TEST_ASSERT( !"no error on opening non-existing file" ); } catch( const input_error& e ) { } } { const std::string f{ "unit_tests/file_data.txt" }; T p{ f }; TEST_ASSERT( p.source() == f ); TEST_ASSERT( p.template parse< file_grammar >() ); TEST_ASSERT( p.source() == f ); } { const std::string f{ "unit_tests/file_data.txt" }; T p{ f }; bool flag = true; TEST_ASSERT( p.source() == f ); TEST_ASSERT( p.template parse< file_grammar >( flag ) ); TEST_ASSERT( flag == true ); } { const std::string f{ "unit_tests/file_data.txt" }; T p{ f }; bool flag = false; TEST_ASSERT( p.source() == f ); TEST_ASSERT( p.template parse< file_grammar >( flag ) ); TEST_ASSERT( flag == false ); } { const std::string f{ "unit_tests/file_data.txt" }; T p{ f }; bool flag = false; TEST_ASSERT( p.source() == f ); const bool result = p.template parse< file_grammar, file_action >( flag ); TEST_ASSERT( result ); TEST_ASSERT( flag == true ); } { const std::string f{ "unit_tests/file_data.txt" }; T p{ f }; bool flag = false; TEST_ASSERT( p.source() == f ); const bool result = p.template parse< file_grammar, nothing, file_control >( flag ); TEST_ASSERT( result ); TEST_ASSERT( flag == true ); } } } // pegtl #endif PEGTL-1.3.1/unit_tests/verify_help.hh000066400000000000000000000013651270130067200174300ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_UNIT_TESTS_VERIFY_HELP_HH #define PEGTL_UNIT_TESTS_VERIFY_HELP_HH #include #include "result_type.hh" namespace pegtl { template< typename Rule, typename Input > result_type verify_help( Input & i ) { try { if ( normal< Rule >::template match< apply_mode::ACTION, nothing, normal >( i ) ) { return result_type::SUCCESS; } return result_type::LOCAL_FAILURE; } catch ( const std::exception & ) { return result_type::GLOBAL_FAILURE; } catch ( ... ) { assert( false ); } } } // pegtl #endif PEGTL-1.3.1/unit_tests/verify_ifmt.hh000066400000000000000000000031741270130067200174370ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_UNIT_TESTS_VERIFY_IFMT_HH #define PEGTL_UNIT_TESTS_VERIFY_IFMT_HH #include #include "verify_rule.hh" #include "verify_analyze.hh" namespace pegtl { template< template< typename, typename, typename > class S > void verify_ifmt( const result_type failure = result_type::LOCAL_FAILURE ) { verify_analyze< S< eof, eof, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< S< eof, eof, any > >( __LINE__, __FILE__, false, false ); verify_analyze< S< eof, any, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< S< eof, any, any > >( __LINE__, __FILE__, true, false ); verify_analyze< S< any, eof, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< S< any, eof, any > >( __LINE__, __FILE__, true, false ); verify_analyze< S< any, any, eof > >( __LINE__, __FILE__, false, false ); verify_analyze< S< any, any, any > >( __LINE__, __FILE__, true, false ); verify_rule< S< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "", failure, 0 ); verify_rule< S< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "b", failure, 1 ); verify_rule< S< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "c", result_type::SUCCESS, 0 ); verify_rule< S< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "ab", result_type::SUCCESS, 0 ); verify_rule< S< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "ac", failure, 2 ); } } // pegtl #endif PEGTL-1.3.1/unit_tests/verify_impl.hh000066400000000000000000000017571270130067200174460ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_UNIT_TESTS_VERIFY_IMPL_HH #define PEGTL_UNIT_TESTS_VERIFY_IMPL_HH #include #include #include "test_failed.hh" #include "verify_help.hh" namespace pegtl { template< typename Rule > void verify_impl( const std::size_t line, const char * file, const std::string & data, const result_type expected, const std::size_t remain ) { pegtl::input i( line, 0, data.data(), data.data() + data.size(), file ); const result_type received = verify_help< Rule >( i ); if ( ( received == expected ) && ( ( received == result_type::GLOBAL_FAILURE ) || ( i.size() == remain ) ) ) { return; } TEST_FAILED( "input data [ '" << data << "' ] result received/expected [ " << received << " / " << expected << " ] remain received/expected [ " << i.size() << " / " << remain << " ]" ); } } // pegtl #endif PEGTL-1.3.1/unit_tests/verify_rule.hh000066400000000000000000000011201270130067200174340ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_UNIT_TESTS_VERIFY_RULE_HH #define PEGTL_UNIT_TESTS_VERIFY_RULE_HH #include #include #include "result_type.hh" #include "verify_impl.hh" namespace pegtl { template< typename Rule > void verify_rule( const std::size_t line, const char * file, const std::string & data, const result_type result, const std::size_t remain ) { verify_impl< Rule >( line, file, data, result, remain ); } } // pegtl #endif PEGTL-1.3.1/unit_tests/verify_seqs.hh000066400000000000000000000061471270130067200174560ustar00rootroot00000000000000// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey // Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/ #ifndef PEGTL_UNIT_TESTS_VERIFY_SEQS_HH #define PEGTL_UNIT_TESTS_VERIFY_SEQS_HH #include #include "verify_rule.hh" #include "verify_analyze.hh" namespace pegtl { template< template< typename ... > class S > void verify_seqs( const result_type failure = result_type::LOCAL_FAILURE ) { verify_analyze< S< any > >( __LINE__, __FILE__, true, false ); verify_analyze< S< eof > >( __LINE__, __FILE__, false, false ); verify_analyze< S< any, eof > >( __LINE__, __FILE__, true, false ); verify_analyze< S< opt< any >, eof > >( __LINE__, __FILE__, false, false ); verify_rule< S<> >( __LINE__, __FILE__, "", result_type::SUCCESS, 0 ); verify_rule< S<> >( __LINE__, __FILE__, "a", result_type::SUCCESS, 1 ); verify_rule< S< eof > >( __LINE__, __FILE__, "", result_type::SUCCESS, 0 ); verify_rule< S< eof > >( __LINE__, __FILE__, "a", failure, 1 ); verify_rule< S< one< 'c' > > >( __LINE__, __FILE__, "", failure, 0 ); verify_rule< S< one< 'c' >, eof > >( __LINE__, __FILE__, "", failure, 0 ); verify_rule< S< one< 'c' > > >( __LINE__, __FILE__, "c", result_type::SUCCESS, 0 ); verify_rule< S< one< 'c' > > >( __LINE__, __FILE__, "a", failure, 1 ); verify_rule< S< one< 'c' > > >( __LINE__, __FILE__, "b", failure, 1 ); verify_rule< S< one< 'c' > > >( __LINE__, __FILE__, "cc", result_type::SUCCESS, 1 ); verify_rule< S< one< 'c' > > >( __LINE__, __FILE__, "bc", failure, 2 ); verify_rule< S< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "", failure, 0 ); verify_rule< S< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "a", failure, 1 ); verify_rule< S< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "b", failure, 1 ); verify_rule< S< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "c", failure, 1 ); verify_rule< S< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "ab", result_type::SUCCESS, 0 ); verify_rule< S< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "aba", result_type::SUCCESS, 1 ); verify_rule< S< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "abb", result_type::SUCCESS, 1 ); verify_rule< S< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "abc", result_type::SUCCESS, 1 ); verify_rule< S< one< 'a' >, one< 'b' > > >( __LINE__, __FILE__, "abab", result_type::SUCCESS, 2 ); verify_rule< S< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "", failure, 0 ); verify_rule< S< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "a", failure, 1 ); verify_rule< S< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "ab", failure, 2 ); verify_rule< S< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "abc", result_type::SUCCESS, 0 ); verify_rule< S< one< 'a' >, one< 'b' >, one< 'c' >, eof > >( __LINE__, __FILE__, "abc", result_type::SUCCESS, 0 ); verify_rule< S< one< 'a' >, one< 'b' >, one< 'c' > > >( __LINE__, __FILE__, "abcd", result_type::SUCCESS, 1 ); } } // pegtl #endif