From 2dc481058998344b7f97721d47987be3ac053768 Mon Sep 17 00:00:00 2001 From: Li Jin Date: Wed, 5 Jul 2017 14:30:02 +0800 Subject: Learn PEGTL a little. --- MoonParser.xcodeproj/project.pbxproj | 568 ++++++++ .../project.xcworkspace/contents.xcworkspacedata | 7 + MoonParser/main.cpp | 1399 ++++++++++++++++++++ MoonParser/pegtl.hpp | 31 + MoonParser/pegtl/analysis/analyze_cycles.hpp | 134 ++ MoonParser/pegtl/analysis/counted.hpp | 29 + MoonParser/pegtl/analysis/generic.hpp | 39 + MoonParser/pegtl/analysis/grammar_info.hpp | 40 + MoonParser/pegtl/analysis/insert_guard.hpp | 66 + MoonParser/pegtl/analysis/insert_rules.hpp | 45 + MoonParser/pegtl/analysis/rule_info.hpp | 37 + MoonParser/pegtl/analysis/rule_type.hpp | 29 + MoonParser/pegtl/analyze.hpp | 25 + MoonParser/pegtl/apply_mode.hpp | 23 + MoonParser/pegtl/argv_input.hpp | 52 + MoonParser/pegtl/ascii.hpp | 67 + MoonParser/pegtl/buffer_input.hpp | 179 +++ MoonParser/pegtl/config.hpp | 15 + MoonParser/pegtl/contrib/abnf.hpp | 43 + MoonParser/pegtl/contrib/alphabet.hpp | 75 ++ MoonParser/pegtl/contrib/changes.hpp | 86 ++ MoonParser/pegtl/contrib/counter.hpp | 58 + MoonParser/pegtl/contrib/http.hpp | 152 +++ MoonParser/pegtl/contrib/json.hpp | 98 ++ MoonParser/pegtl/contrib/raw_string.hpp | 252 ++++ MoonParser/pegtl/contrib/rep_one_min_max.hpp | 72 + MoonParser/pegtl/contrib/to_string.hpp | 42 + MoonParser/pegtl/contrib/tracer.hpp | 111 ++ MoonParser/pegtl/contrib/unescape.hpp | 203 +++ MoonParser/pegtl/contrib/uri.hpp | 116 ++ MoonParser/pegtl/cstream_input.hpp | 34 + MoonParser/pegtl/eol.hpp | 54 + MoonParser/pegtl/file_input.hpp | 37 + MoonParser/pegtl/input_error.hpp | 41 + MoonParser/pegtl/internal/action.hpp | 52 + MoonParser/pegtl/internal/action_input.hpp | 108 ++ MoonParser/pegtl/internal/alnum.hpp | 26 + MoonParser/pegtl/internal/alpha.hpp | 26 + MoonParser/pegtl/internal/any.hpp | 68 + MoonParser/pegtl/internal/apply.hpp | 79 ++ MoonParser/pegtl/internal/apply0.hpp | 77 ++ MoonParser/pegtl/internal/at.hpp | 62 + MoonParser/pegtl/internal/bof.hpp | 41 + MoonParser/pegtl/internal/bol.hpp | 41 + MoonParser/pegtl/internal/bump_help.hpp | 64 + MoonParser/pegtl/internal/bump_impl.hpp | 53 + MoonParser/pegtl/internal/bytes.hpp | 46 + MoonParser/pegtl/internal/control.hpp | 52 + MoonParser/pegtl/internal/cr_crlf_eol.hpp | 39 + MoonParser/pegtl/internal/cr_eol.hpp | 39 + MoonParser/pegtl/internal/crlf_eol.hpp | 39 + MoonParser/pegtl/internal/cstream_reader.hpp | 48 + MoonParser/pegtl/internal/cstring_reader.hpp | 49 + MoonParser/pegtl/internal/demangle.hpp | 44 + MoonParser/pegtl/internal/demangle_cxxabi.hpp | 41 + MoonParser/pegtl/internal/demangle_nop.hpp | 28 + MoonParser/pegtl/internal/demangle_sanitise.hpp | 48 + MoonParser/pegtl/internal/disable.hpp | 52 + MoonParser/pegtl/internal/discard.hpp | 42 + MoonParser/pegtl/internal/dusel_mode.hpp | 25 + MoonParser/pegtl/internal/duseltronik.hpp | 114 ++ MoonParser/pegtl/internal/enable.hpp | 52 + MoonParser/pegtl/internal/eof.hpp | 41 + MoonParser/pegtl/internal/eol.hpp | 42 + MoonParser/pegtl/internal/eolf.hpp | 43 + MoonParser/pegtl/internal/file_mapper.hpp | 91 ++ MoonParser/pegtl/internal/file_opener.hpp | 70 + MoonParser/pegtl/internal/file_reader.hpp | 96 ++ MoonParser/pegtl/internal/has_apply0.hpp | 38 + MoonParser/pegtl/internal/identifier.hpp | 30 + MoonParser/pegtl/internal/if_apply.hpp | 90 ++ MoonParser/pegtl/internal/if_must.hpp | 27 + MoonParser/pegtl/internal/if_must_else.hpp | 27 + MoonParser/pegtl/internal/if_then_else.hpp | 59 + MoonParser/pegtl/internal/input_pair.hpp | 35 + MoonParser/pegtl/internal/integer_sequence.hpp | 85 ++ MoonParser/pegtl/internal/istream_reader.hpp | 47 + MoonParser/pegtl/internal/istring.hpp | 107 ++ MoonParser/pegtl/internal/iterator.hpp | 53 + MoonParser/pegtl/internal/lf_crlf_eol.hpp | 44 + MoonParser/pegtl/internal/lf_eol.hpp | 39 + MoonParser/pegtl/internal/list.hpp | 27 + MoonParser/pegtl/internal/list_must.hpp | 28 + MoonParser/pegtl/internal/list_tail.hpp | 28 + MoonParser/pegtl/internal/list_tail_pad.hpp | 30 + MoonParser/pegtl/internal/marker.hpp | 93 ++ MoonParser/pegtl/internal/minus.hpp | 69 + MoonParser/pegtl/internal/must.hpp | 79 ++ MoonParser/pegtl/internal/not_at.hpp | 62 + MoonParser/pegtl/internal/one.hpp | 81 ++ MoonParser/pegtl/internal/opt.hpp | 67 + MoonParser/pegtl/internal/pad.hpp | 27 + MoonParser/pegtl/internal/pad_opt.hpp | 28 + MoonParser/pegtl/internal/peek_char.hpp | 35 + MoonParser/pegtl/internal/peek_utf16.hpp | 54 + MoonParser/pegtl/internal/peek_utf32.hpp | 46 + MoonParser/pegtl/internal/peek_utf8.hpp | 88 ++ MoonParser/pegtl/internal/pegtl_string.hpp | 98 ++ MoonParser/pegtl/internal/plus.hpp | 61 + MoonParser/pegtl/internal/raise.hpp | 57 + MoonParser/pegtl/internal/range.hpp | 60 + MoonParser/pegtl/internal/ranges.hpp | 102 ++ MoonParser/pegtl/internal/rep.hpp | 75 ++ MoonParser/pegtl/internal/rep_min.hpp | 28 + MoonParser/pegtl/internal/rep_min_max.hpp | 88 ++ MoonParser/pegtl/internal/rep_opt.hpp | 54 + MoonParser/pegtl/internal/require.hpp | 52 + MoonParser/pegtl/internal/result_on_found.hpp | 27 + MoonParser/pegtl/internal/rule_conjunction.hpp | 63 + MoonParser/pegtl/internal/rules.hpp | 61 + MoonParser/pegtl/internal/seq.hpp | 80 ++ MoonParser/pegtl/internal/skip_control.hpp | 35 + MoonParser/pegtl/internal/sor.hpp | 74 ++ MoonParser/pegtl/internal/star.hpp | 56 + MoonParser/pegtl/internal/star_must.hpp | 27 + MoonParser/pegtl/internal/state.hpp | 83 ++ MoonParser/pegtl/internal/string.hpp | 68 + MoonParser/pegtl/internal/trivial.hpp | 42 + MoonParser/pegtl/internal/try_catch_type.hpp | 72 + MoonParser/pegtl/internal/until.hpp | 91 ++ MoonParser/pegtl/istream_input.hpp | 34 + MoonParser/pegtl/memory_input.hpp | 285 ++++ MoonParser/pegtl/mmap_input.hpp | 55 + MoonParser/pegtl/normal.hpp | 81 ++ MoonParser/pegtl/nothing.hpp | 27 + MoonParser/pegtl/parse.hpp | 53 + MoonParser/pegtl/parse_error.hpp | 45 + MoonParser/pegtl/position.hpp | 54 + MoonParser/pegtl/read_input.hpp | 52 + MoonParser/pegtl/rewind_mode.hpp | 24 + MoonParser/pegtl/rules.hpp | 69 + MoonParser/pegtl/string_input.hpp | 51 + MoonParser/pegtl/tracking_mode.hpp | 23 + MoonParser/pegtl/utf16.hpp | 35 + MoonParser/pegtl/utf32.hpp | 35 + MoonParser/pegtl/utf8.hpp | 35 + MoonParser/pegtl/version.hpp | 13 + MoonParser/slice.cpp | 119 ++ MoonParser/slice.h | 157 +++ 139 files changed, 10321 insertions(+) create mode 100644 MoonParser.xcodeproj/project.pbxproj create mode 100644 MoonParser.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 MoonParser/main.cpp create mode 100644 MoonParser/pegtl.hpp create mode 100644 MoonParser/pegtl/analysis/analyze_cycles.hpp create mode 100644 MoonParser/pegtl/analysis/counted.hpp create mode 100644 MoonParser/pegtl/analysis/generic.hpp create mode 100644 MoonParser/pegtl/analysis/grammar_info.hpp create mode 100644 MoonParser/pegtl/analysis/insert_guard.hpp create mode 100644 MoonParser/pegtl/analysis/insert_rules.hpp create mode 100644 MoonParser/pegtl/analysis/rule_info.hpp create mode 100644 MoonParser/pegtl/analysis/rule_type.hpp create mode 100644 MoonParser/pegtl/analyze.hpp create mode 100644 MoonParser/pegtl/apply_mode.hpp create mode 100644 MoonParser/pegtl/argv_input.hpp create mode 100644 MoonParser/pegtl/ascii.hpp create mode 100644 MoonParser/pegtl/buffer_input.hpp create mode 100644 MoonParser/pegtl/config.hpp create mode 100644 MoonParser/pegtl/contrib/abnf.hpp create mode 100644 MoonParser/pegtl/contrib/alphabet.hpp create mode 100644 MoonParser/pegtl/contrib/changes.hpp create mode 100644 MoonParser/pegtl/contrib/counter.hpp create mode 100644 MoonParser/pegtl/contrib/http.hpp create mode 100644 MoonParser/pegtl/contrib/json.hpp create mode 100644 MoonParser/pegtl/contrib/raw_string.hpp create mode 100644 MoonParser/pegtl/contrib/rep_one_min_max.hpp create mode 100644 MoonParser/pegtl/contrib/to_string.hpp create mode 100644 MoonParser/pegtl/contrib/tracer.hpp create mode 100644 MoonParser/pegtl/contrib/unescape.hpp create mode 100644 MoonParser/pegtl/contrib/uri.hpp create mode 100644 MoonParser/pegtl/cstream_input.hpp create mode 100644 MoonParser/pegtl/eol.hpp create mode 100644 MoonParser/pegtl/file_input.hpp create mode 100644 MoonParser/pegtl/input_error.hpp create mode 100644 MoonParser/pegtl/internal/action.hpp create mode 100644 MoonParser/pegtl/internal/action_input.hpp create mode 100644 MoonParser/pegtl/internal/alnum.hpp create mode 100644 MoonParser/pegtl/internal/alpha.hpp create mode 100644 MoonParser/pegtl/internal/any.hpp create mode 100644 MoonParser/pegtl/internal/apply.hpp create mode 100644 MoonParser/pegtl/internal/apply0.hpp create mode 100644 MoonParser/pegtl/internal/at.hpp create mode 100644 MoonParser/pegtl/internal/bof.hpp create mode 100644 MoonParser/pegtl/internal/bol.hpp create mode 100644 MoonParser/pegtl/internal/bump_help.hpp create mode 100644 MoonParser/pegtl/internal/bump_impl.hpp create mode 100644 MoonParser/pegtl/internal/bytes.hpp create mode 100644 MoonParser/pegtl/internal/control.hpp create mode 100644 MoonParser/pegtl/internal/cr_crlf_eol.hpp create mode 100644 MoonParser/pegtl/internal/cr_eol.hpp create mode 100644 MoonParser/pegtl/internal/crlf_eol.hpp create mode 100644 MoonParser/pegtl/internal/cstream_reader.hpp create mode 100644 MoonParser/pegtl/internal/cstring_reader.hpp create mode 100644 MoonParser/pegtl/internal/demangle.hpp create mode 100644 MoonParser/pegtl/internal/demangle_cxxabi.hpp create mode 100644 MoonParser/pegtl/internal/demangle_nop.hpp create mode 100644 MoonParser/pegtl/internal/demangle_sanitise.hpp create mode 100644 MoonParser/pegtl/internal/disable.hpp create mode 100644 MoonParser/pegtl/internal/discard.hpp create mode 100644 MoonParser/pegtl/internal/dusel_mode.hpp create mode 100644 MoonParser/pegtl/internal/duseltronik.hpp create mode 100644 MoonParser/pegtl/internal/enable.hpp create mode 100644 MoonParser/pegtl/internal/eof.hpp create mode 100644 MoonParser/pegtl/internal/eol.hpp create mode 100644 MoonParser/pegtl/internal/eolf.hpp create mode 100644 MoonParser/pegtl/internal/file_mapper.hpp create mode 100644 MoonParser/pegtl/internal/file_opener.hpp create mode 100644 MoonParser/pegtl/internal/file_reader.hpp create mode 100644 MoonParser/pegtl/internal/has_apply0.hpp create mode 100644 MoonParser/pegtl/internal/identifier.hpp create mode 100644 MoonParser/pegtl/internal/if_apply.hpp create mode 100644 MoonParser/pegtl/internal/if_must.hpp create mode 100644 MoonParser/pegtl/internal/if_must_else.hpp create mode 100644 MoonParser/pegtl/internal/if_then_else.hpp create mode 100644 MoonParser/pegtl/internal/input_pair.hpp create mode 100644 MoonParser/pegtl/internal/integer_sequence.hpp create mode 100644 MoonParser/pegtl/internal/istream_reader.hpp create mode 100644 MoonParser/pegtl/internal/istring.hpp create mode 100644 MoonParser/pegtl/internal/iterator.hpp create mode 100644 MoonParser/pegtl/internal/lf_crlf_eol.hpp create mode 100644 MoonParser/pegtl/internal/lf_eol.hpp create mode 100644 MoonParser/pegtl/internal/list.hpp create mode 100644 MoonParser/pegtl/internal/list_must.hpp create mode 100644 MoonParser/pegtl/internal/list_tail.hpp create mode 100644 MoonParser/pegtl/internal/list_tail_pad.hpp create mode 100644 MoonParser/pegtl/internal/marker.hpp create mode 100644 MoonParser/pegtl/internal/minus.hpp create mode 100644 MoonParser/pegtl/internal/must.hpp create mode 100644 MoonParser/pegtl/internal/not_at.hpp create mode 100644 MoonParser/pegtl/internal/one.hpp create mode 100644 MoonParser/pegtl/internal/opt.hpp create mode 100644 MoonParser/pegtl/internal/pad.hpp create mode 100644 MoonParser/pegtl/internal/pad_opt.hpp create mode 100644 MoonParser/pegtl/internal/peek_char.hpp create mode 100644 MoonParser/pegtl/internal/peek_utf16.hpp create mode 100644 MoonParser/pegtl/internal/peek_utf32.hpp create mode 100644 MoonParser/pegtl/internal/peek_utf8.hpp create mode 100644 MoonParser/pegtl/internal/pegtl_string.hpp create mode 100644 MoonParser/pegtl/internal/plus.hpp create mode 100644 MoonParser/pegtl/internal/raise.hpp create mode 100644 MoonParser/pegtl/internal/range.hpp create mode 100644 MoonParser/pegtl/internal/ranges.hpp create mode 100644 MoonParser/pegtl/internal/rep.hpp create mode 100644 MoonParser/pegtl/internal/rep_min.hpp create mode 100644 MoonParser/pegtl/internal/rep_min_max.hpp create mode 100644 MoonParser/pegtl/internal/rep_opt.hpp create mode 100644 MoonParser/pegtl/internal/require.hpp create mode 100644 MoonParser/pegtl/internal/result_on_found.hpp create mode 100644 MoonParser/pegtl/internal/rule_conjunction.hpp create mode 100644 MoonParser/pegtl/internal/rules.hpp create mode 100644 MoonParser/pegtl/internal/seq.hpp create mode 100644 MoonParser/pegtl/internal/skip_control.hpp create mode 100644 MoonParser/pegtl/internal/sor.hpp create mode 100644 MoonParser/pegtl/internal/star.hpp create mode 100644 MoonParser/pegtl/internal/star_must.hpp create mode 100644 MoonParser/pegtl/internal/state.hpp create mode 100644 MoonParser/pegtl/internal/string.hpp create mode 100644 MoonParser/pegtl/internal/trivial.hpp create mode 100644 MoonParser/pegtl/internal/try_catch_type.hpp create mode 100644 MoonParser/pegtl/internal/until.hpp create mode 100644 MoonParser/pegtl/istream_input.hpp create mode 100644 MoonParser/pegtl/memory_input.hpp create mode 100644 MoonParser/pegtl/mmap_input.hpp create mode 100644 MoonParser/pegtl/normal.hpp create mode 100644 MoonParser/pegtl/nothing.hpp create mode 100644 MoonParser/pegtl/parse.hpp create mode 100644 MoonParser/pegtl/parse_error.hpp create mode 100644 MoonParser/pegtl/position.hpp create mode 100644 MoonParser/pegtl/read_input.hpp create mode 100644 MoonParser/pegtl/rewind_mode.hpp create mode 100644 MoonParser/pegtl/rules.hpp create mode 100644 MoonParser/pegtl/string_input.hpp create mode 100644 MoonParser/pegtl/tracking_mode.hpp create mode 100644 MoonParser/pegtl/utf16.hpp create mode 100644 MoonParser/pegtl/utf32.hpp create mode 100644 MoonParser/pegtl/utf8.hpp create mode 100644 MoonParser/pegtl/version.hpp create mode 100644 MoonParser/slice.cpp create mode 100644 MoonParser/slice.h diff --git a/MoonParser.xcodeproj/project.pbxproj b/MoonParser.xcodeproj/project.pbxproj new file mode 100644 index 0000000..2585cd1 --- /dev/null +++ b/MoonParser.xcodeproj/project.pbxproj @@ -0,0 +1,568 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 3C06322F1F0CBE210089D0AB /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C0631A21F0CBE210089D0AB /* main.cpp */; }; + 3C0632301F0CBE210089D0AB /* slice.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C06322D1F0CBE210089D0AB /* slice.cpp */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 3C0F0F6A1EF3781E000EADDB /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 3C0631A21F0CBE210089D0AB /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; + 3C0631A51F0CBE210089D0AB /* analyze_cycles.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = analyze_cycles.hpp; sourceTree = ""; }; + 3C0631A61F0CBE210089D0AB /* counted.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = counted.hpp; sourceTree = ""; }; + 3C0631A71F0CBE210089D0AB /* generic.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = generic.hpp; sourceTree = ""; }; + 3C0631A81F0CBE210089D0AB /* grammar_info.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = grammar_info.hpp; sourceTree = ""; }; + 3C0631A91F0CBE210089D0AB /* insert_guard.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = insert_guard.hpp; sourceTree = ""; }; + 3C0631AA1F0CBE210089D0AB /* insert_rules.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = insert_rules.hpp; sourceTree = ""; }; + 3C0631AB1F0CBE210089D0AB /* rule_info.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = rule_info.hpp; sourceTree = ""; }; + 3C0631AC1F0CBE210089D0AB /* rule_type.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = rule_type.hpp; sourceTree = ""; }; + 3C0631AD1F0CBE210089D0AB /* analyze.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = analyze.hpp; sourceTree = ""; }; + 3C0631AE1F0CBE210089D0AB /* apply_mode.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = apply_mode.hpp; sourceTree = ""; }; + 3C0631AF1F0CBE210089D0AB /* argv_input.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = argv_input.hpp; sourceTree = ""; }; + 3C0631B01F0CBE210089D0AB /* ascii.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ascii.hpp; sourceTree = ""; }; + 3C0631B11F0CBE210089D0AB /* buffer_input.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = buffer_input.hpp; sourceTree = ""; }; + 3C0631B21F0CBE210089D0AB /* config.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = config.hpp; sourceTree = ""; }; + 3C0631B41F0CBE210089D0AB /* abnf.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = abnf.hpp; sourceTree = ""; }; + 3C0631B51F0CBE210089D0AB /* alphabet.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = alphabet.hpp; sourceTree = ""; }; + 3C0631B61F0CBE210089D0AB /* changes.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = changes.hpp; sourceTree = ""; }; + 3C0631B71F0CBE210089D0AB /* counter.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = counter.hpp; sourceTree = ""; }; + 3C0631B81F0CBE210089D0AB /* http.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = http.hpp; sourceTree = ""; }; + 3C0631B91F0CBE210089D0AB /* json.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = json.hpp; sourceTree = ""; }; + 3C0631BA1F0CBE210089D0AB /* raw_string.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = raw_string.hpp; sourceTree = ""; }; + 3C0631BB1F0CBE210089D0AB /* rep_one_min_max.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = rep_one_min_max.hpp; sourceTree = ""; }; + 3C0631BC1F0CBE210089D0AB /* to_string.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = to_string.hpp; sourceTree = ""; }; + 3C0631BD1F0CBE210089D0AB /* tracer.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = tracer.hpp; sourceTree = ""; }; + 3C0631BE1F0CBE210089D0AB /* unescape.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = unescape.hpp; sourceTree = ""; }; + 3C0631BF1F0CBE210089D0AB /* uri.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = uri.hpp; sourceTree = ""; }; + 3C0631C01F0CBE210089D0AB /* cstream_input.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = cstream_input.hpp; sourceTree = ""; }; + 3C0631C11F0CBE210089D0AB /* eol.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = eol.hpp; sourceTree = ""; }; + 3C0631C21F0CBE210089D0AB /* file_input.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = file_input.hpp; sourceTree = ""; }; + 3C0631C31F0CBE210089D0AB /* input_error.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = input_error.hpp; sourceTree = ""; }; + 3C0631C51F0CBE210089D0AB /* action.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = action.hpp; sourceTree = ""; }; + 3C0631C61F0CBE210089D0AB /* action_input.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = action_input.hpp; sourceTree = ""; }; + 3C0631C71F0CBE210089D0AB /* alnum.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = alnum.hpp; sourceTree = ""; }; + 3C0631C81F0CBE210089D0AB /* alpha.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = alpha.hpp; sourceTree = ""; }; + 3C0631C91F0CBE210089D0AB /* any.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = any.hpp; sourceTree = ""; }; + 3C0631CA1F0CBE210089D0AB /* apply.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = apply.hpp; sourceTree = ""; }; + 3C0631CB1F0CBE210089D0AB /* apply0.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = apply0.hpp; sourceTree = ""; }; + 3C0631CC1F0CBE210089D0AB /* at.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = at.hpp; sourceTree = ""; }; + 3C0631CD1F0CBE210089D0AB /* bof.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = bof.hpp; sourceTree = ""; }; + 3C0631CE1F0CBE210089D0AB /* bol.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = bol.hpp; sourceTree = ""; }; + 3C0631CF1F0CBE210089D0AB /* bump_help.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = bump_help.hpp; sourceTree = ""; }; + 3C0631D01F0CBE210089D0AB /* bump_impl.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = bump_impl.hpp; sourceTree = ""; }; + 3C0631D11F0CBE210089D0AB /* bytes.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = bytes.hpp; sourceTree = ""; }; + 3C0631D21F0CBE210089D0AB /* control.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = control.hpp; sourceTree = ""; }; + 3C0631D31F0CBE210089D0AB /* cr_crlf_eol.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = cr_crlf_eol.hpp; sourceTree = ""; }; + 3C0631D41F0CBE210089D0AB /* cr_eol.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = cr_eol.hpp; sourceTree = ""; }; + 3C0631D51F0CBE210089D0AB /* crlf_eol.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = crlf_eol.hpp; sourceTree = ""; }; + 3C0631D61F0CBE210089D0AB /* cstream_reader.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = cstream_reader.hpp; sourceTree = ""; }; + 3C0631D71F0CBE210089D0AB /* cstring_reader.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = cstring_reader.hpp; sourceTree = ""; }; + 3C0631D81F0CBE210089D0AB /* demangle.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = demangle.hpp; sourceTree = ""; }; + 3C0631D91F0CBE210089D0AB /* demangle_cxxabi.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = demangle_cxxabi.hpp; sourceTree = ""; }; + 3C0631DA1F0CBE210089D0AB /* demangle_nop.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = demangle_nop.hpp; sourceTree = ""; }; + 3C0631DB1F0CBE210089D0AB /* demangle_sanitise.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = demangle_sanitise.hpp; sourceTree = ""; }; + 3C0631DC1F0CBE210089D0AB /* disable.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = disable.hpp; sourceTree = ""; }; + 3C0631DD1F0CBE210089D0AB /* discard.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = discard.hpp; sourceTree = ""; }; + 3C0631DE1F0CBE210089D0AB /* dusel_mode.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = dusel_mode.hpp; sourceTree = ""; }; + 3C0631DF1F0CBE210089D0AB /* duseltronik.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = duseltronik.hpp; sourceTree = ""; }; + 3C0631E01F0CBE210089D0AB /* enable.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = enable.hpp; sourceTree = ""; }; + 3C0631E11F0CBE210089D0AB /* eof.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = eof.hpp; sourceTree = ""; }; + 3C0631E21F0CBE210089D0AB /* eol.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = eol.hpp; sourceTree = ""; }; + 3C0631E31F0CBE210089D0AB /* eolf.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = eolf.hpp; sourceTree = ""; }; + 3C0631E41F0CBE210089D0AB /* file_mapper.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = file_mapper.hpp; sourceTree = ""; }; + 3C0631E51F0CBE210089D0AB /* file_opener.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = file_opener.hpp; sourceTree = ""; }; + 3C0631E61F0CBE210089D0AB /* file_reader.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = file_reader.hpp; sourceTree = ""; }; + 3C0631E71F0CBE210089D0AB /* has_apply0.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = has_apply0.hpp; sourceTree = ""; }; + 3C0631E81F0CBE210089D0AB /* identifier.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = identifier.hpp; sourceTree = ""; }; + 3C0631E91F0CBE210089D0AB /* if_apply.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = if_apply.hpp; sourceTree = ""; }; + 3C0631EA1F0CBE210089D0AB /* if_must.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = if_must.hpp; sourceTree = ""; }; + 3C0631EB1F0CBE210089D0AB /* if_must_else.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = if_must_else.hpp; sourceTree = ""; }; + 3C0631EC1F0CBE210089D0AB /* if_then_else.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = if_then_else.hpp; sourceTree = ""; }; + 3C0631ED1F0CBE210089D0AB /* input_pair.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = input_pair.hpp; sourceTree = ""; }; + 3C0631EE1F0CBE210089D0AB /* integer_sequence.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = integer_sequence.hpp; sourceTree = ""; }; + 3C0631EF1F0CBE210089D0AB /* istream_reader.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = istream_reader.hpp; sourceTree = ""; }; + 3C0631F01F0CBE210089D0AB /* istring.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = istring.hpp; sourceTree = ""; }; + 3C0631F11F0CBE210089D0AB /* iterator.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = iterator.hpp; sourceTree = ""; }; + 3C0631F21F0CBE210089D0AB /* lf_crlf_eol.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lf_crlf_eol.hpp; sourceTree = ""; }; + 3C0631F31F0CBE210089D0AB /* lf_eol.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = lf_eol.hpp; sourceTree = ""; }; + 3C0631F41F0CBE210089D0AB /* list.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = list.hpp; sourceTree = ""; }; + 3C0631F51F0CBE210089D0AB /* list_must.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = list_must.hpp; sourceTree = ""; }; + 3C0631F61F0CBE210089D0AB /* list_tail.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = list_tail.hpp; sourceTree = ""; }; + 3C0631F71F0CBE210089D0AB /* list_tail_pad.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = list_tail_pad.hpp; sourceTree = ""; }; + 3C0631F81F0CBE210089D0AB /* marker.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = marker.hpp; sourceTree = ""; }; + 3C0631F91F0CBE210089D0AB /* minus.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = minus.hpp; sourceTree = ""; }; + 3C0631FA1F0CBE210089D0AB /* must.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = must.hpp; sourceTree = ""; }; + 3C0631FB1F0CBE210089D0AB /* not_at.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = not_at.hpp; sourceTree = ""; }; + 3C0631FC1F0CBE210089D0AB /* one.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = one.hpp; sourceTree = ""; }; + 3C0631FD1F0CBE210089D0AB /* opt.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = opt.hpp; sourceTree = ""; }; + 3C0631FE1F0CBE210089D0AB /* pad.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = pad.hpp; sourceTree = ""; }; + 3C0631FF1F0CBE210089D0AB /* pad_opt.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = pad_opt.hpp; sourceTree = ""; }; + 3C0632001F0CBE210089D0AB /* peek_char.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = peek_char.hpp; sourceTree = ""; }; + 3C0632011F0CBE210089D0AB /* peek_utf16.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = peek_utf16.hpp; sourceTree = ""; }; + 3C0632021F0CBE210089D0AB /* peek_utf32.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = peek_utf32.hpp; sourceTree = ""; }; + 3C0632031F0CBE210089D0AB /* peek_utf8.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = peek_utf8.hpp; sourceTree = ""; }; + 3C0632041F0CBE210089D0AB /* pegtl_string.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = pegtl_string.hpp; sourceTree = ""; }; + 3C0632051F0CBE210089D0AB /* plus.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = plus.hpp; sourceTree = ""; }; + 3C0632061F0CBE210089D0AB /* raise.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = raise.hpp; sourceTree = ""; }; + 3C0632071F0CBE210089D0AB /* range.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = range.hpp; sourceTree = ""; }; + 3C0632081F0CBE210089D0AB /* ranges.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ranges.hpp; sourceTree = ""; }; + 3C0632091F0CBE210089D0AB /* rep.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = rep.hpp; sourceTree = ""; }; + 3C06320A1F0CBE210089D0AB /* rep_min.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = rep_min.hpp; sourceTree = ""; }; + 3C06320B1F0CBE210089D0AB /* rep_min_max.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = rep_min_max.hpp; sourceTree = ""; }; + 3C06320C1F0CBE210089D0AB /* rep_opt.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = rep_opt.hpp; sourceTree = ""; }; + 3C06320D1F0CBE210089D0AB /* require.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = require.hpp; sourceTree = ""; }; + 3C06320E1F0CBE210089D0AB /* result_on_found.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = result_on_found.hpp; sourceTree = ""; }; + 3C06320F1F0CBE210089D0AB /* rule_conjunction.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = rule_conjunction.hpp; sourceTree = ""; }; + 3C0632101F0CBE210089D0AB /* rules.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = rules.hpp; sourceTree = ""; }; + 3C0632111F0CBE210089D0AB /* seq.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = seq.hpp; sourceTree = ""; }; + 3C0632121F0CBE210089D0AB /* skip_control.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = skip_control.hpp; sourceTree = ""; }; + 3C0632131F0CBE210089D0AB /* sor.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = sor.hpp; sourceTree = ""; }; + 3C0632141F0CBE210089D0AB /* star.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = star.hpp; sourceTree = ""; }; + 3C0632151F0CBE210089D0AB /* star_must.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = star_must.hpp; sourceTree = ""; }; + 3C0632161F0CBE210089D0AB /* state.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = state.hpp; sourceTree = ""; }; + 3C0632171F0CBE210089D0AB /* string.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = string.hpp; sourceTree = ""; }; + 3C0632181F0CBE210089D0AB /* trivial.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = trivial.hpp; sourceTree = ""; }; + 3C0632191F0CBE210089D0AB /* try_catch_type.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = try_catch_type.hpp; sourceTree = ""; }; + 3C06321A1F0CBE210089D0AB /* until.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = until.hpp; sourceTree = ""; }; + 3C06321B1F0CBE210089D0AB /* istream_input.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = istream_input.hpp; sourceTree = ""; }; + 3C06321C1F0CBE210089D0AB /* memory_input.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = memory_input.hpp; sourceTree = ""; }; + 3C06321D1F0CBE210089D0AB /* mmap_input.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = mmap_input.hpp; sourceTree = ""; }; + 3C06321E1F0CBE210089D0AB /* normal.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = normal.hpp; sourceTree = ""; }; + 3C06321F1F0CBE210089D0AB /* nothing.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = nothing.hpp; sourceTree = ""; }; + 3C0632201F0CBE210089D0AB /* parse.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = parse.hpp; sourceTree = ""; }; + 3C0632211F0CBE210089D0AB /* parse_error.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = parse_error.hpp; sourceTree = ""; }; + 3C0632221F0CBE210089D0AB /* position.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = position.hpp; sourceTree = ""; }; + 3C0632231F0CBE210089D0AB /* read_input.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = read_input.hpp; sourceTree = ""; }; + 3C0632241F0CBE210089D0AB /* rewind_mode.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = rewind_mode.hpp; sourceTree = ""; }; + 3C0632251F0CBE210089D0AB /* rules.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = rules.hpp; sourceTree = ""; }; + 3C0632261F0CBE210089D0AB /* string_input.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = string_input.hpp; sourceTree = ""; }; + 3C0632271F0CBE210089D0AB /* tracking_mode.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = tracking_mode.hpp; sourceTree = ""; }; + 3C0632281F0CBE210089D0AB /* utf16.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = utf16.hpp; sourceTree = ""; }; + 3C0632291F0CBE210089D0AB /* utf32.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = utf32.hpp; sourceTree = ""; }; + 3C06322A1F0CBE210089D0AB /* utf8.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = utf8.hpp; sourceTree = ""; }; + 3C06322B1F0CBE210089D0AB /* version.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = version.hpp; sourceTree = ""; }; + 3C06322C1F0CBE210089D0AB /* pegtl.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = pegtl.hpp; sourceTree = ""; }; + 3C06322D1F0CBE210089D0AB /* slice.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = slice.cpp; sourceTree = ""; }; + 3C06322E1F0CBE210089D0AB /* slice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = slice.h; sourceTree = ""; }; + 3C0F0F6C1EF3781E000EADDB /* MoonParser */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = MoonParser; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 3C0F0F691EF3781E000EADDB /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 3C0631A11F0CBE210089D0AB /* MoonParser */ = { + isa = PBXGroup; + children = ( + 3C0631A21F0CBE210089D0AB /* main.cpp */, + 3C0631A31F0CBE210089D0AB /* pegtl */, + 3C06322C1F0CBE210089D0AB /* pegtl.hpp */, + 3C06322D1F0CBE210089D0AB /* slice.cpp */, + 3C06322E1F0CBE210089D0AB /* slice.h */, + ); + path = MoonParser; + sourceTree = ""; + }; + 3C0631A31F0CBE210089D0AB /* pegtl */ = { + isa = PBXGroup; + children = ( + 3C0631A41F0CBE210089D0AB /* analysis */, + 3C0631AD1F0CBE210089D0AB /* analyze.hpp */, + 3C0631AE1F0CBE210089D0AB /* apply_mode.hpp */, + 3C0631AF1F0CBE210089D0AB /* argv_input.hpp */, + 3C0631B01F0CBE210089D0AB /* ascii.hpp */, + 3C0631B11F0CBE210089D0AB /* buffer_input.hpp */, + 3C0631B21F0CBE210089D0AB /* config.hpp */, + 3C0631B31F0CBE210089D0AB /* contrib */, + 3C0631C01F0CBE210089D0AB /* cstream_input.hpp */, + 3C0631C11F0CBE210089D0AB /* eol.hpp */, + 3C0631C21F0CBE210089D0AB /* file_input.hpp */, + 3C0631C31F0CBE210089D0AB /* input_error.hpp */, + 3C0631C41F0CBE210089D0AB /* internal */, + 3C06321B1F0CBE210089D0AB /* istream_input.hpp */, + 3C06321C1F0CBE210089D0AB /* memory_input.hpp */, + 3C06321D1F0CBE210089D0AB /* mmap_input.hpp */, + 3C06321E1F0CBE210089D0AB /* normal.hpp */, + 3C06321F1F0CBE210089D0AB /* nothing.hpp */, + 3C0632201F0CBE210089D0AB /* parse.hpp */, + 3C0632211F0CBE210089D0AB /* parse_error.hpp */, + 3C0632221F0CBE210089D0AB /* position.hpp */, + 3C0632231F0CBE210089D0AB /* read_input.hpp */, + 3C0632241F0CBE210089D0AB /* rewind_mode.hpp */, + 3C0632251F0CBE210089D0AB /* rules.hpp */, + 3C0632261F0CBE210089D0AB /* string_input.hpp */, + 3C0632271F0CBE210089D0AB /* tracking_mode.hpp */, + 3C0632281F0CBE210089D0AB /* utf16.hpp */, + 3C0632291F0CBE210089D0AB /* utf32.hpp */, + 3C06322A1F0CBE210089D0AB /* utf8.hpp */, + 3C06322B1F0CBE210089D0AB /* version.hpp */, + ); + path = pegtl; + sourceTree = ""; + }; + 3C0631A41F0CBE210089D0AB /* analysis */ = { + isa = PBXGroup; + children = ( + 3C0631A51F0CBE210089D0AB /* analyze_cycles.hpp */, + 3C0631A61F0CBE210089D0AB /* counted.hpp */, + 3C0631A71F0CBE210089D0AB /* generic.hpp */, + 3C0631A81F0CBE210089D0AB /* grammar_info.hpp */, + 3C0631A91F0CBE210089D0AB /* insert_guard.hpp */, + 3C0631AA1F0CBE210089D0AB /* insert_rules.hpp */, + 3C0631AB1F0CBE210089D0AB /* rule_info.hpp */, + 3C0631AC1F0CBE210089D0AB /* rule_type.hpp */, + ); + path = analysis; + sourceTree = ""; + }; + 3C0631B31F0CBE210089D0AB /* contrib */ = { + isa = PBXGroup; + children = ( + 3C0631B41F0CBE210089D0AB /* abnf.hpp */, + 3C0631B51F0CBE210089D0AB /* alphabet.hpp */, + 3C0631B61F0CBE210089D0AB /* changes.hpp */, + 3C0631B71F0CBE210089D0AB /* counter.hpp */, + 3C0631B81F0CBE210089D0AB /* http.hpp */, + 3C0631B91F0CBE210089D0AB /* json.hpp */, + 3C0631BA1F0CBE210089D0AB /* raw_string.hpp */, + 3C0631BB1F0CBE210089D0AB /* rep_one_min_max.hpp */, + 3C0631BC1F0CBE210089D0AB /* to_string.hpp */, + 3C0631BD1F0CBE210089D0AB /* tracer.hpp */, + 3C0631BE1F0CBE210089D0AB /* unescape.hpp */, + 3C0631BF1F0CBE210089D0AB /* uri.hpp */, + ); + path = contrib; + sourceTree = ""; + }; + 3C0631C41F0CBE210089D0AB /* internal */ = { + isa = PBXGroup; + children = ( + 3C0631C51F0CBE210089D0AB /* action.hpp */, + 3C0631C61F0CBE210089D0AB /* action_input.hpp */, + 3C0631C71F0CBE210089D0AB /* alnum.hpp */, + 3C0631C81F0CBE210089D0AB /* alpha.hpp */, + 3C0631C91F0CBE210089D0AB /* any.hpp */, + 3C0631CA1F0CBE210089D0AB /* apply.hpp */, + 3C0631CB1F0CBE210089D0AB /* apply0.hpp */, + 3C0631CC1F0CBE210089D0AB /* at.hpp */, + 3C0631CD1F0CBE210089D0AB /* bof.hpp */, + 3C0631CE1F0CBE210089D0AB /* bol.hpp */, + 3C0631CF1F0CBE210089D0AB /* bump_help.hpp */, + 3C0631D01F0CBE210089D0AB /* bump_impl.hpp */, + 3C0631D11F0CBE210089D0AB /* bytes.hpp */, + 3C0631D21F0CBE210089D0AB /* control.hpp */, + 3C0631D31F0CBE210089D0AB /* cr_crlf_eol.hpp */, + 3C0631D41F0CBE210089D0AB /* cr_eol.hpp */, + 3C0631D51F0CBE210089D0AB /* crlf_eol.hpp */, + 3C0631D61F0CBE210089D0AB /* cstream_reader.hpp */, + 3C0631D71F0CBE210089D0AB /* cstring_reader.hpp */, + 3C0631D81F0CBE210089D0AB /* demangle.hpp */, + 3C0631D91F0CBE210089D0AB /* demangle_cxxabi.hpp */, + 3C0631DA1F0CBE210089D0AB /* demangle_nop.hpp */, + 3C0631DB1F0CBE210089D0AB /* demangle_sanitise.hpp */, + 3C0631DC1F0CBE210089D0AB /* disable.hpp */, + 3C0631DD1F0CBE210089D0AB /* discard.hpp */, + 3C0631DE1F0CBE210089D0AB /* dusel_mode.hpp */, + 3C0631DF1F0CBE210089D0AB /* duseltronik.hpp */, + 3C0631E01F0CBE210089D0AB /* enable.hpp */, + 3C0631E11F0CBE210089D0AB /* eof.hpp */, + 3C0631E21F0CBE210089D0AB /* eol.hpp */, + 3C0631E31F0CBE210089D0AB /* eolf.hpp */, + 3C0631E41F0CBE210089D0AB /* file_mapper.hpp */, + 3C0631E51F0CBE210089D0AB /* file_opener.hpp */, + 3C0631E61F0CBE210089D0AB /* file_reader.hpp */, + 3C0631E71F0CBE210089D0AB /* has_apply0.hpp */, + 3C0631E81F0CBE210089D0AB /* identifier.hpp */, + 3C0631E91F0CBE210089D0AB /* if_apply.hpp */, + 3C0631EA1F0CBE210089D0AB /* if_must.hpp */, + 3C0631EB1F0CBE210089D0AB /* if_must_else.hpp */, + 3C0631EC1F0CBE210089D0AB /* if_then_else.hpp */, + 3C0631ED1F0CBE210089D0AB /* input_pair.hpp */, + 3C0631EE1F0CBE210089D0AB /* integer_sequence.hpp */, + 3C0631EF1F0CBE210089D0AB /* istream_reader.hpp */, + 3C0631F01F0CBE210089D0AB /* istring.hpp */, + 3C0631F11F0CBE210089D0AB /* iterator.hpp */, + 3C0631F21F0CBE210089D0AB /* lf_crlf_eol.hpp */, + 3C0631F31F0CBE210089D0AB /* lf_eol.hpp */, + 3C0631F41F0CBE210089D0AB /* list.hpp */, + 3C0631F51F0CBE210089D0AB /* list_must.hpp */, + 3C0631F61F0CBE210089D0AB /* list_tail.hpp */, + 3C0631F71F0CBE210089D0AB /* list_tail_pad.hpp */, + 3C0631F81F0CBE210089D0AB /* marker.hpp */, + 3C0631F91F0CBE210089D0AB /* minus.hpp */, + 3C0631FA1F0CBE210089D0AB /* must.hpp */, + 3C0631FB1F0CBE210089D0AB /* not_at.hpp */, + 3C0631FC1F0CBE210089D0AB /* one.hpp */, + 3C0631FD1F0CBE210089D0AB /* opt.hpp */, + 3C0631FE1F0CBE210089D0AB /* pad.hpp */, + 3C0631FF1F0CBE210089D0AB /* pad_opt.hpp */, + 3C0632001F0CBE210089D0AB /* peek_char.hpp */, + 3C0632011F0CBE210089D0AB /* peek_utf16.hpp */, + 3C0632021F0CBE210089D0AB /* peek_utf32.hpp */, + 3C0632031F0CBE210089D0AB /* peek_utf8.hpp */, + 3C0632041F0CBE210089D0AB /* pegtl_string.hpp */, + 3C0632051F0CBE210089D0AB /* plus.hpp */, + 3C0632061F0CBE210089D0AB /* raise.hpp */, + 3C0632071F0CBE210089D0AB /* range.hpp */, + 3C0632081F0CBE210089D0AB /* ranges.hpp */, + 3C0632091F0CBE210089D0AB /* rep.hpp */, + 3C06320A1F0CBE210089D0AB /* rep_min.hpp */, + 3C06320B1F0CBE210089D0AB /* rep_min_max.hpp */, + 3C06320C1F0CBE210089D0AB /* rep_opt.hpp */, + 3C06320D1F0CBE210089D0AB /* require.hpp */, + 3C06320E1F0CBE210089D0AB /* result_on_found.hpp */, + 3C06320F1F0CBE210089D0AB /* rule_conjunction.hpp */, + 3C0632101F0CBE210089D0AB /* rules.hpp */, + 3C0632111F0CBE210089D0AB /* seq.hpp */, + 3C0632121F0CBE210089D0AB /* skip_control.hpp */, + 3C0632131F0CBE210089D0AB /* sor.hpp */, + 3C0632141F0CBE210089D0AB /* star.hpp */, + 3C0632151F0CBE210089D0AB /* star_must.hpp */, + 3C0632161F0CBE210089D0AB /* state.hpp */, + 3C0632171F0CBE210089D0AB /* string.hpp */, + 3C0632181F0CBE210089D0AB /* trivial.hpp */, + 3C0632191F0CBE210089D0AB /* try_catch_type.hpp */, + 3C06321A1F0CBE210089D0AB /* until.hpp */, + ); + path = internal; + sourceTree = ""; + }; + 3C0F0F631EF3781E000EADDB = { + isa = PBXGroup; + children = ( + 3C0631A11F0CBE210089D0AB /* MoonParser */, + 3C0F0F6D1EF3781E000EADDB /* Products */, + ); + sourceTree = ""; + }; + 3C0F0F6D1EF3781E000EADDB /* Products */ = { + isa = PBXGroup; + children = ( + 3C0F0F6C1EF3781E000EADDB /* MoonParser */, + ); + name = Products; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 3C0F0F6B1EF3781E000EADDB /* MoonParser */ = { + isa = PBXNativeTarget; + buildConfigurationList = 3C0F0F731EF3781E000EADDB /* Build configuration list for PBXNativeTarget "MoonParser" */; + buildPhases = ( + 3C0F0F681EF3781E000EADDB /* Sources */, + 3C0F0F691EF3781E000EADDB /* Frameworks */, + 3C0F0F6A1EF3781E000EADDB /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = MoonParser; + productName = PegtlStudy; + productReference = 3C0F0F6C1EF3781E000EADDB /* MoonParser */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 3C0F0F641EF3781E000EADDB /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0820; + ORGANIZATIONNAME = "Li Jin"; + TargetAttributes = { + 3C0F0F6B1EF3781E000EADDB = { + CreatedOnToolsVersion = 8.2.1; + ProvisioningStyle = Automatic; + }; + }; + }; + buildConfigurationList = 3C0F0F671EF3781E000EADDB /* Build configuration list for PBXProject "MoonParser" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 3C0F0F631EF3781E000EADDB; + productRefGroup = 3C0F0F6D1EF3781E000EADDB /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 3C0F0F6B1EF3781E000EADDB /* MoonParser */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 3C0F0F681EF3781E000EADDB /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 3C0632301F0CBE210089D0AB /* slice.cpp in Sources */, + 3C06322F1F0CBE210089D0AB /* main.cpp in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 3C0F0F711EF3781E000EADDB /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.12; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + }; + name = Debug; + }; + 3C0F0F721EF3781E000EADDB /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.12; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + }; + name = Release; + }; + 3C0F0F741EF3781E000EADDB /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + OTHER_CPLUSPLUSFLAGS = ( + "$(OTHER_CFLAGS)", + "-ftemplate-depth=512", + ); + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 3C0F0F751EF3781E000EADDB /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + OTHER_CPLUSPLUSFLAGS = ( + "$(OTHER_CFLAGS)", + "-ftemplate-depth=512", + ); + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 3C0F0F671EF3781E000EADDB /* Build configuration list for PBXProject "MoonParser" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 3C0F0F711EF3781E000EADDB /* Debug */, + 3C0F0F721EF3781E000EADDB /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 3C0F0F731EF3781E000EADDB /* Build configuration list for PBXNativeTarget "MoonParser" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 3C0F0F741EF3781E000EADDB /* Debug */, + 3C0F0F751EF3781E000EADDB /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 3C0F0F641EF3781E000EADDB /* Project object */; +} diff --git a/MoonParser.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/MoonParser.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..1effa34 --- /dev/null +++ b/MoonParser.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/MoonParser/main.cpp b/MoonParser/main.cpp new file mode 100644 index 0000000..332b1b4 --- /dev/null +++ b/MoonParser/main.cpp @@ -0,0 +1,1399 @@ +// +// main.cpp +// PegtlStudy +// +// Created by Li Jin on 2017/6/16. +// Copyright © 2017年 Li Jin. All rights reserved. +// + +#include +#include +#include +#include +#include +#include "pegtl.hpp" +#include "pegtl/analyze.hpp" +#include "slice.h" +using namespace silly; + +using namespace tao::pegtl; + +namespace helloworld // with operator precedence climbing +{ + struct Stack + { + Stack() + { + pushStack(); + } + void pushValue(int value) + { + _values.back().push(value); + } + void pushOp(char op) + { + _ops.back().push(op); + } + void pushStack() + { + _values.emplace_back(); + _ops.emplace_back(); + } + int getPriority(char op) + { + switch (op) + { + case '+': return 1; + case '-': return 1; + case '*': return 2; + case '/': return 2; + } + return 0; + } + /* + def compute_expr(tokenizer, min_prec): + atom_lhs = tokenizer.get_next_token() + + while True: + cur = tokenizer.cur_token + if (cur is None or OPINFO_MAP[cur.value].prec < min_prec): + break + + op = cur.value + prec, assoc = OPINFO_MAP[op] + next_min_prec = prec + 1 if assoc == 'LEFT' else prec + + atom_rhs = compute_expr(tokenizer, next_min_prec) + + atom_lhs = compute_op(op, atom_lhs, atom_rhs) + + return atom_lhs + */ + int parseNext(int minPrecedence) + { + int lhs = _values.back().front(); + _values.back().pop(); + + while (true) + { + if (_ops.back().empty()) + { + break; + } + char op = _ops.back().front(); + if (getPriority(op) < minPrecedence) + { + break; + } + _ops.back().pop(); + int nextMinPrecedence = getPriority(op) + 1; + int rhs = parseNext(nextMinPrecedence); + switch (op) + { + case '+': + std::cout << lhs << " + " << rhs << " = " << lhs+rhs << '\n'; + lhs = lhs + rhs; + break; + case '-': + std::cout << lhs << " - " << rhs << " = " << lhs-rhs << '\n'; + lhs = lhs - rhs; + break; + case '*': + std::cout << lhs << " * " << rhs << " = " << lhs*rhs << '\n'; + lhs = lhs * rhs; + break; + case '/': + std::cout << lhs << " / " << rhs << " = " << lhs/rhs << '\n'; + lhs = lhs / rhs; + break; + } + } + return lhs; + } + void popStack() + { + int value = parseNext(0); + _values.pop_back(); + if (_values.empty()) + { + _values.emplace_back(); + } + _ops.pop_back(); + if (_ops.empty()) + { + _ops.emplace_back(); + } + pushValue(value); + } + int getValue() const + { + return _values.back().back(); + } + private: + std::vector> _ops; + std::vector> _values; + }; + + struct number : seq>, plus> { }; + + struct expr; + + struct bracket : if_must, expr, one<')'>> { }; + + struct atomic : sor { }; + + struct op : one<'+', '-', '*', '/'> { }; + + struct expr : list { }; + + template + struct action : nothing { }; + + template<> + struct action + { + template + static void apply(const Input& in, Stack& stack) + { + stack.pushValue(std::stoi(in.string())); + } + }; + + template<> + struct action + { + template + static void apply(const Input& in, Stack& stack) + { + stack.pushOp(*in.begin()); + } + }; + + template<> + struct action> + { + static void apply0(Stack& stack) + { + stack.pushStack(); + } + }; + + template<> + struct action + { + template + static void apply(const Input& in, Stack& stack) + { + stack.popStack(); + } + }; + +} // namespace hello + +namespace moon +{ + struct State + { + State() + { + indents.push(0); + stringOpen = -1; + } + size_t stringOpen; + std::stack indents; + std::stack doStack; + std::unordered_set keywords = + { + "and", "while", "else", "using", "continue", + "local", "not", "then", "return", "from", + "extends", "for", "do", "or", "export", + "class", "in", "unless", "when", "elseif", + "switch", "break", "if", "with", "import" + }; + }; + + struct White : star> {}; + struct plain_space : star> {}; + struct Break : seq>, one<'\n'>> {}; + struct Stop : sor {}; + struct Comment : seq, star>, Stop> {}; + struct Indent : star> {}; + struct Space : seq> {}; + struct SomeSpace : seq, opt> {}; + struct SpaceBreak : seq {}; + typedef SpaceBreak EmptyLine; + struct AlphaNum : ranges<'a', 'z', 'A', 'Z', '0', '9', '_', '_'> {}; + struct _Name : seq, star> {}; + struct SpaceName : seq {}; + struct _Num : sor< + seq< + string<'0' ,'x'>, + plus>, + opt>, one<'l', 'L'>, one<'l', 'L'> + >> + >, + seq< + plus>, + seq< + opt>, one<'l', 'L'>, one<'l', 'L'> + > + >, + seq< + sor< + seq< + plus>, + opt, plus> + >> + >, + seq< + one<'.'>, + plus> + > + >, + opt, opt>, plus> + >> + > + > {}; + struct Num : seq {}; + + struct Cut : failure {}; + + template struct sym : seq> {}; + template struct symx : string {}; + + template + struct ensure : sor, seq> {}; + + template struct key : seq, not_at> {}; + template struct op : seq, not_at> {}; + + struct Name + { + using analyze_t = analysis::generic; + + template class Action, + template class Control, + typename Input> + static bool match(Input& in, const State& st) + { + const char* current = in.current(); + if (SpaceName::match(in, st)) + { + auto name = slice::Slice(current, in.current() - current + 1); + name.trimSpace(); + auto it = st.keywords.find(name); + if (it == st.keywords.end()) + { + return true; + } + } + return false; + } + }; + + struct self : one<'@'> {}; + struct self_name : seq, _Name> {}; + struct self_class : string<'@', '@'> {}; + struct self_class_name : seq, _Name> {}; + + struct SelfName : seq> {}; + struct KeyName : sor {}; + struct VarArg : seq> {}; + + struct CheckIndent + { + using analyze_t = analysis::generic; + + template class Action, + template class Control, + typename Input> + static bool match(Input& in, const State& st) + { + const char* current = in.current(); + if (Indent::match(in, st)) + { + int indent = 0; + for (const char* ch = current; ch < in.current(); ch++) + { + switch (*ch) + { + case ' ': indent++; break; + case '\t': indent += 4; break; + } + } + return st.indents.top() == indent; + } + return false; + } + }; + + struct Advance + { + using analyze_t = analysis::generic; + + template class Action, + template class Control, + typename Input> + static bool match(Input& in, State& st) + { + const char* current = in.current(); + if (Indent::match(in)) + { + int indent = 0; + for (const char* ch = current; ch < in.current(); ch++) + { + switch (*ch) + { + case ' ': indent++; break; + case '\t': indent += 4; break; + } + } + int top = st.indents.top(); + if (top != -1 && indent > top) + { + st.indents.push(indent); + } + return true; + } + return false; + } + }; + + struct PushIndent + { + using analyze_t = analysis::generic; + + template class Action, + template class Control, + typename Input> + static bool match(Input& in, State& st) + { + const char* current = in.current(); + if (Indent::match(in)) + { + int indent = 0; + for (const char* ch = current; ch < in.current(); ch++) + { + switch (*ch) + { + case ' ': indent++; break; + case '\t': indent += 4; break; + } + } + st.indents.push(indent); + return true; + } + return false; + } + }; + + struct PreventIndent + { + using analyze_t = analysis::generic; + + template class Action, + template class Control, + typename Input> + static bool match(Input& in, State& st) + { + st.indents.push(-1); + return true; + } + }; + + struct PopIndent + { + using analyze_t = analysis::generic; + + template class Action, + template class Control, + typename Input> + static bool match(Input& in, State& st) + { + if (st.indents.size() > 1) st.indents.pop(); + return true; + } + }; + + struct Block; + + struct InBlock : seq {}; + + struct NameList; + + struct Local : seq, sor, op<'^'>>>, NameList> {}; + + struct colon_import_name : seq, Name> {}; + struct ImportName : sor {}; + struct ImportNameList : seq< + star, + ImportName, + star< + sor, seq, star>>, + ImportName + > + > {}; + + struct Exp; + + struct Import : seq, ImportNameList, star, key<'f', 'r', 'o', 'm'>, Exp> {}; + + struct BreakLoop : sor, key<'c', 'o', 'n', 't', 'i', 'n', 'u', 'e'>> {}; + + struct ExpListLow; + + struct ExpList; + struct Assign; + + struct Return : seq, sor> {}; + struct WithExp : seq> {}; + + struct DisableDo; + struct PopDo; + struct Body; + + struct With : seq, DisableDo, ensure, opt>, Body> {}; + + struct SwitchCase : seq, ExpList, opt>, Body> {}; + struct SwitchElse : seq, Body> {}; + struct SwitchBlock : seq< + star, + Advance, + seq< + SwitchCase, + star, SwitchCase>, + opt, SwitchElse> + >, + PopIndent + > {}; + struct Switch : seq, DisableDo, ensure, opt>, opt, Break, SwitchBlock> {}; + + struct IfCond : seq> {}; + + struct IfElse : seq< + opt, CheckIndent>, + string<'e', 'l', 's', 'e'>, Body + > {}; + struct IfElseIf : seq< + opt, CheckIndent>, + key<'e', 'l', 's', 'e', 'i', 'f'>, IfCond, + opt>, Body + > {}; + + struct If : seq, IfCond, opt>, Body, star, opt> {}; + struct Unless : seq, IfCond, opt>, Body, star, opt> {}; + + struct While : seq, DisableDo, ensure, opt>, Body> {}; + struct For : seq, DisableDo, + ensure< + seq< + Name, sym<'='>, + seq, Exp, opt, Exp>> + >, + PopDo + >, + opt>, Body> {}; + + struct AssignableNameList; + + struct ForEach : seq< + key<'f', 'o', 'r'>, + AssignableNameList, + key<'i', 'n'>, + DisableDo, + ensure< + sor< + seq, Exp>, ExpList + >, + PopDo + > + > {}; + + struct Do + { + using analyze_t = analysis::generic; + + template class Action, + template class Control, + typename Input> + static bool match(Input& in, State& st) + { + if (seq, Body>::match(in, st)) + { + if (st.doStack.empty() || st.doStack.top()) + { + return true; + } + } + return false; + } + }; + + struct DisableDo + { + using analyze_t = analysis::generic; + + template class Action, + template class Control, + typename Input> + static bool match(Input& in, State& st) + { + st.doStack.push(false); + return true; + } + }; + + struct PopDo + { + using analyze_t = analysis::generic; + + template class Action, + template class Control, + typename Input> + static bool match(Input& in, State& st) + { + st.doStack.pop(); + return true; + } + }; + + struct CompInner; + + struct Comprehension : seq, Exp, CompInner, sym<']'>> {}; + struct TblComprehension : seq, seq, Exp>>, CompInner, sym<'}'>> {}; + + struct CompForEach; + struct CompFor; + struct CompClause; + + struct CompInner : seq, star> {}; + struct CompForEach : seq< + key<'f', 'o', 'r'>, + AssignableNameList, + key<'i', 'n'>, + sor< + seq, Exp>, Exp + > + > {}; + struct CompFor : seq, Name, sym<'='>, seq, Exp, opt, Exp>>> {}; + struct CompClause : sor, Exp>> {}; + + struct TableBlock; + + struct Assign : seq, sor> {}; + + struct Update : seq', '>', '='>, + sym<'<', '<', '='> + >, Exp> {}; + + struct CharOperators : seq', '<', '|', '&'>> {}; + struct WordOperators : sor< + op<'o', 'r'>, + op<'a', 'n', 'd'>, + op<'<', '='>, + op<'>', '='>, + op<'~', '='>, + op<'!', '='>, + op<'=', '='>, + op<'.', '.'>, + op<'<', '<'>, + op<'>', '>'>, + op<'/', '/'>> {}; + struct BinaryOperator : seq, star> {}; + + struct Chain; + + struct Assignable : sor {}; + + struct Value; + + struct Exp : seq> {}; + + struct Callable; + struct InvokeArgs; + + struct ChainValue : seq, opt> {}; + + struct KeyValueList; + struct String; + struct SimpleValue; + + struct Value : sor {}; + struct SliceValue : Exp {}; + + struct LuaString; + + struct single_string_inner : sor, string<'\\', '\\'>, not_one<'\''>> {}; + struct SingleString : seq, star, sym<'\''>> {}; + struct interp : seq, Exp, sym<'}'>> {}; + struct double_string_plain : sor, string<'\\', '\\'>, not_one<'\"'>> {}; + struct double_string_inner : plus, double_string_plain>> {}; + struct DoubleString : seq, star>, sym<'\"'>> {}; + struct String : sor, seq, LuaString> {}; + + struct lua_string_open : seq, star>, one<'['>> {}; + struct lua_string_close : seq, star>, one<']'>> {}; + + struct LuaStringOpen + { + using analyze_t = analysis::generic; + + template class Action, + template class Control, + typename Input> + static bool match(Input& in, State& st) + { + const char* current = in.current(); + if (lua_string_open::match(in, st)) + { + st.stringOpen = in.current() - current + 1; + return true; + } + return false; + } + }; + + struct LuaStringClose + { + using analyze_t = analysis::generic; + + template class Action, + template class Control, + typename Input> + static bool match(Input& in, State& st) + { + const char* current = in.current(); + if (lua_string_close::match(in, st)) + { + return st.stringOpen == in.current() - current + 1; + } + return false; + } + }; + + struct LuaStringContent : star, any> {}; + + struct LuaString + { + using analyze_t = analysis::generic; + + template class Action, + template class Control, + typename Input> + static bool match(Input& in, State& st) + { + bool result = seq, LuaStringContent, LuaStringClose>::match(in, st); + st.stringOpen = -1; + return result; + } + }; + + struct Parens : seq, star, Exp, star, sym<')'>> {}; + struct Callable : sor {}; + + struct FnArgsExpList : seq>, White, Exp>> {}; + struct FnArgs : sor< + seq, star, opt, star, sym<')'>>, + seq, not_at>> + > {}; + + struct ChainItems; + struct DotChainItem; + struct ColonChain; + + struct Chain : sor< + seq>, ChainItems>, + seq>, + ColonChain + > + > + > {}; + + struct ChainItem; + + struct ChainItems : sor< + seq, opt>, + ColonChain + > {}; + + struct Invoke; + struct Slice; + + struct ChainItem : sor< + Invoke, + DotChainItem, + Slice, + seq, Exp, sym<']'>> + > {}; + + struct DotChainItem : seq, _Name> {}; + struct ColonChainItem : seq, _Name> {}; + struct ColonChain : seq< + ColonChainItem, + opt> + > {}; + + struct SliceOne : success {}; + struct SliceTwo : success {}; + struct Slice : seq< + symx<'['>, sor, sym<','>, sor, opt, SliceValue>, sym<']'>> {}; + + struct Invoke : sor< + FnArgs, + SingleString, + DoubleString, + seq>, LuaString> + > {}; + + struct KeyValue; + struct TableValueList; + struct TableLitLine; + + struct TableValue : sor {}; + struct TableLit : seq< + sym<'{'>, + seq< + opt, opt>, + opt< + SpaceBreak, TableLitLine, + star>, SpaceBreak, TableLitLine>, + opt> + > + >, + White, sym<'}'> + > {}; + + struct TableValueList : seq, TableValue>> {}; + struct TableLitLine : sor< + seq, seq>>, + Space + > {}; + + struct KeyValueLine; + + struct TableBlockInner : seq, KeyValueLine>> {}; + struct TableBlock : seq, Advance, ensure> {}; + + struct Statement; + + struct ClassLine : seq< + CheckIndent, + seq< + sor, + opt> + > + > {}; + + struct ClassBlock : seq, Advance, ClassLine, star, ClassLine>, PopIndent> {}; + + struct class_no_derive : success {}; + struct class_no_extend : success {}; + struct class_no_body : success {}; + struct ClassDecl : seq< + string<'c', 'l', 'a', 's', 's'>, + not_at>, + sor, + opt, PreventIndent, ensure, class_no_extend>>, + sor + > {}; + + struct Export : seq< + string<'e', 'x', 'p', 'o', 'r', 't'>, + sor< + ClassDecl, + op<'*'>, + op<'^'>, + seq, not_at, Name>, + seq< + sor< + KeyName, + seq, Exp, sym<']'>>, + seq, + seq + >, + symx<':'>, + sor< + Exp, TableBlock, seq, Exp> + > + > + > {}; + + struct KeyValueList : seq, KeyValue>> {}; + struct KeyValueLine : seq>> {}; + + struct FnArgDef : seq, opt, Exp>> {}; + + struct FnArgDefList : sor< + seq< + FnArgDef, + star, Break>, White, FnArgDef>, + star, Break>, White, VarArg> + >, + VarArg + > {}; + + struct outer_value_shadow : seq, sor>>> {}; + struct outer_value_no_shadowing : success {}; + struct without_args_def : success {}; + + struct FnArgsDef : sor< + seq, White, opt, + sor< + outer_value_shadow, + outer_value_no_shadowing + >, + White, sym<')'> + >, + without_args_def + > {}; + + struct FunLit : seq'>, sym<'=', '>'>>, sor> {}; + + struct NameList : seq, Name>> {}; + struct NameOrDestructure : sor {}; + struct AssignableNameList : seq, NameOrDestructure>> {}; + + struct ExpList : seq, Exp>> {}; + struct ExpListLow : seq, sym<';'>, Exp>>> {}; + + struct ArgLine : seq {}; + struct ArgBlock : seq, SpaceBreak, ArgLine>, PopIndent> {}; + + struct InvokeArgs : seq< + at>, + sor< + seq< + ExpList, + opt, + sor< + TableBlock, seq> + > + >, + TableBlock + >> + >, + TableBlock + > + > {}; + + struct SimpleValue : sor< + key<'n', 'i', 'l'>, + key<'t', 'r', 'u', 'e'>, + key<'f', 'a', 'l', 's', 'e'>, + If, Unless, Switch, With, ClassDecl, ForEach, For, While, Do, + seq, not_at, Exp>, + seq, Exp>, + seq, Exp>, + seq, Exp>, + TblComprehension, + TableLit, + Comprehension, + FunLit, + Num + > {}; + + struct Assignment : seq< + ExpList, + sor + > {}; + + struct Sentence : sor< + Import, While, With, For, ForEach, + Switch, Return, Local, Export, BreakLoop, + Assignment, ExpList + > {}; + + struct Statement : seq< + Sentence, + Space, + opt< + sor< + seq< + key<'i', 'f'>, Exp, + opt< + key<'e', 'l', 's', 'e'>, Exp + >, + Space + >, + seq, Exp>, + CompInner + >, + Space + > + > {}; + + struct Body : sor< + seq, Break, star, InBlock>, + Statement + > {}; + + struct Line : sor< + seq, + seq> + > {}; + + struct Block : seq, Line>> {}; + + struct BlockWithEnd : seq {}; + + template + struct action : nothing {}; + + template<> + struct action + { + template + static void apply(const Input& in, State&) + { + std::cout << "Assignment: " << in.string() << '\n'; + } + }; + + template<> + struct action + { + template + static void apply(const Input& in, State&) + { + std::cout << "Return: " << in.string() << "\n\n"; + } + }; +} + +int main() +{ + analyze(); + moon::State state; + string_input<> inName(R"xoxo( +debug_grammar = false +lpeg = require "lpeg" + +lpeg.setmaxstack 10000 -- whoa + +err_msg = "Failed to parse:%s\n [%d] >> %s" + +import Stack from require "moonscript.data" +import trim, pos_to_line, get_line from require "moonscript.util" +import unpack from require "moonscript.util" +import wrap_env from require "moonscript.parse.env" + +{ + :R, :S, :V, :P, :C, :Ct, :Cmt, :Cg, :Cb, :Cc +} = lpeg + +{ + :White, :Break, :Stop, :Comment, :Space, :SomeSpace, :SpaceBreak, :EmptyLine, + :AlphaNum, :Num, :Shebang, :L + Name: _Name +} = require "moonscript.parse.literals" + +SpaceName = Space * _Name +Num = Space * (Num / (v) -> {"number", v}) + +{ + :Indent, :Cut, :ensure, :extract_line, :mark, :pos, :flatten_or_mark, + :is_assignable, :check_assignable, :format_assign, :format_single_assign, + :sym, :symx, :simple_string, :wrap_func_arg, :join_chain, + :wrap_decorator, :check_lua_string, :self_assign, :got + +} = require "moonscript.parse.util" + + +build_grammar = wrap_env debug_grammar, (root) -> + _indent = Stack 0 + _do_stack = Stack 0 + + state = { + -- last pos we saw, used to report error location + last_pos: 0 + } + + check_indent = (str, pos, indent) -> + state.last_pos = pos + _indent\top! == indent + + advance_indent = (str, pos, indent) -> + top = _indent\top! + if top != -1 and indent > top + _indent\push indent + true + + push_indent = (str, pos, indent) -> + _indent\push indent + true + + pop_indent = -> + assert _indent\pop!, "unexpected outdent" + true + + check_do = (str, pos, do_node) -> + top = _do_stack\top! + if top == nil or top + return true, do_node + false + + disable_do = -> + _do_stack\push false + true + + pop_do = -> + assert _do_stack\pop! != nil, "unexpected do pop" + true + + DisableDo = Cmt "", disable_do + PopDo = Cmt "", pop_do + + keywords = {} + key = (chars) -> + keywords[chars] = true + Space * chars * -AlphaNum + + op = (chars) -> + patt = Space * C chars + -- it's a word, treat like keyword + if chars\match "^%w*$" + keywords[chars] = true + patt *= -AlphaNum + + patt + + Name = Cmt(SpaceName, (str, pos, name) -> + return false if keywords[name] + true + ) / trim + + SelfName = Space * "@" * ( + "@" * (_Name / mark"self_class" + Cc"self.__class") + + _Name / mark"self" + + Cc"self" -- @ by itself + ) + + KeyName = SelfName + Space * _Name / mark"key_literal" + VarArg = Space * P"..." / trim + + g = P { + root or File + File: Shebang^-1 * (Block + Ct"") + Block: Ct(Line * (Break^1 * Line)^0) + CheckIndent: Cmt(Indent, check_indent), -- validates line is in correct indent + Line: (CheckIndent * Statement + Space * L(Stop)) + + Statement: pos( + Import + While + With + For + ForEach + Switch + Return + + Local + Export + BreakLoop + + Ct(ExpList) * (Update + Assign)^-1 / format_assign + ) * Space * (( + -- statement decorators + key"if" * Exp * (key"else" * Exp)^-1 * Space / mark"if" + + key"unless" * Exp / mark"unless" + + CompInner / mark"comprehension" + ) * Space)^-1 / wrap_decorator + + Body: Space^-1 * Break * EmptyLine^0 * InBlock + Ct(Statement) -- either a statement, or an indented block + + Advance: L Cmt(Indent, advance_indent) -- Advances the indent, gives back whitespace for CheckIndent + PushIndent: Cmt(Indent, push_indent) + PreventIndent: Cmt(Cc(-1), push_indent) + PopIndent: Cmt("", pop_indent) + InBlock: Advance * Block * PopIndent + + Local: key"local" * ((op"*" + op"^") / mark"declare_glob" + Ct(NameList) / mark"declare_with_shadows") + + Import: key"import" * Ct(ImportNameList) * SpaceBreak^0 * key"from" * Exp / mark"import" + ImportName: (sym"\\" * Ct(Cc"colon" * Name) + Name) + ImportNameList: SpaceBreak^0 * ImportName * ((SpaceBreak^1 + sym"," * SpaceBreak^0) * ImportName)^0 + + BreakLoop: Ct(key"break"/trim) + Ct(key"continue"/trim) + + Return: key"return" * (ExpListLow/mark"explist" + C"") / mark"return" + + WithExp: Ct(ExpList) * Assign^-1 / format_assign + With: key"with" * DisableDo * ensure(WithExp, PopDo) * key"do"^-1 * Body / mark"with" + + Switch: key"switch" * DisableDo * ensure(Exp, PopDo) * key"do"^-1 * Space^-1 * Break * SwitchBlock / mark"switch" + + SwitchBlock: EmptyLine^0 * Advance * Ct(SwitchCase * (Break^1 * SwitchCase)^0 * (Break^1 * SwitchElse)^-1) * PopIndent + SwitchCase: key"when" * Ct(ExpList) * key"then"^-1 * Body / mark"case" + SwitchElse: key"else" * Body / mark"else" + + IfCond: Exp * Assign^-1 / format_single_assign + + IfElse: (Break * EmptyLine^0 * CheckIndent)^-1 * key"else" * Body / mark"else" + IfElseIf: (Break * EmptyLine^0 * CheckIndent)^-1 * key"elseif" * pos(IfCond) * key"then"^-1 * Body / mark"elseif" + + If: key"if" * IfCond * key"then"^-1 * Body * IfElseIf^0 * IfElse^-1 / mark"if" + Unless: key"unless" * IfCond * key"then"^-1 * Body * IfElseIf^0 * IfElse^-1 / mark"unless" + + While: key"while" * DisableDo * ensure(Exp, PopDo) * key"do"^-1 * Body / mark"while" + + For: key"for" * DisableDo * ensure(Name * sym"=" * Ct(Exp * sym"," * Exp * (sym"," * Exp)^-1), PopDo) * + key"do"^-1 * Body / mark"for" + + ForEach: key"for" * Ct(AssignableNameList) * key"in" * DisableDo * ensure(Ct(sym"*" * Exp / mark"unpack" + ExpList), PopDo) * key"do"^-1 * Body / mark"foreach" + + Do: key"do" * Body / mark"do" + + Comprehension: sym"[" * Exp * CompInner * sym"]" / mark"comprehension" + + TblComprehension: sym"{" * Ct(Exp * (sym"," * Exp)^-1) * CompInner * sym"}" / mark"tblcomprehension" + + CompInner: Ct((CompForEach + CompFor) * CompClause^0) + CompForEach: key"for" * Ct(AssignableNameList) * key"in" * (sym"*" * Exp / mark"unpack" + Exp) / mark"foreach" + CompFor: key "for" * Name * sym"=" * Ct(Exp * sym"," * Exp * (sym"," * Exp)^-1) / mark"for" + CompClause: CompFor + CompForEach + key"when" * Exp / mark"when" + + Assign: sym"=" * (Ct(With + If + Switch) + Ct(TableBlock + ExpListLow)) / mark"assign" + Update: ((sym"..=" + sym"+=" + sym"-=" + sym"*=" + sym"/=" + sym"%=" + sym"or=" + sym"and=" + sym"&=" + sym"|=" + sym">>=" + sym"<<=") / trim) * Exp / mark"update" + + CharOperators: Space * C(S"+-*/%^><|&") + WordOperators: op"or" + op"and" + op"<=" + op">=" + op"~=" + op"!=" + op"==" + op".." + op"<<" + op">>" + op"//" + BinaryOperator: (WordOperators + CharOperators) * SpaceBreak^0 + + Assignable: Cmt(Chain, check_assignable) + Name + SelfName + Exp: Ct(Value * (BinaryOperator * Value)^0) / flatten_or_mark"exp" + + SimpleValue: + If + Unless + + Switch + + With + + ClassDecl + + ForEach + For + While + + Cmt(Do, check_do) + + sym"-" * -SomeSpace * Exp / mark"minus" + + sym"#" * Exp / mark"length" + + sym"~" * Exp / mark"bitnot" + + key"not" * Exp / mark"not" + + TblComprehension + + TableLit + + Comprehension + + FunLit + + Num + + -- a function call or an object access + ChainValue: (Chain + Callable) * Ct(InvokeArgs^-1) / join_chain + + Value: pos( + SimpleValue + + Ct(KeyValueList) / mark"table" + + ChainValue + + String) + + SliceValue: Exp + + String: Space * DoubleString + Space * SingleString + LuaString + SingleString: simple_string("'") + DoubleString: simple_string('"', true) + + LuaString: Cg(LuaStringOpen, "string_open") * Cb"string_open" * Break^-1 * + C((1 - Cmt(C(LuaStringClose) * Cb"string_open", check_lua_string))^0) * + LuaStringClose / mark"string" + + LuaStringOpen: sym"[" * P"="^0 * "[" / trim + LuaStringClose: "]" * P"="^0 * "]" + + Callable: pos(Name / mark"ref") + SelfName + VarArg + Parens / mark"parens" + Parens: sym"(" * SpaceBreak^0 * Exp * SpaceBreak^0 * sym")" + + FnArgs: symx"(" * SpaceBreak^0 * Ct(FnArgsExpList^-1) * SpaceBreak^0 * sym")" + sym"!" * -P"=" * Ct"" + FnArgsExpList: Exp * ((Break + sym",") * White * Exp)^0 + + Chain: (Callable + String + -S".\\") * ChainItems / mark"chain" + + Space * (DotChainItem * ChainItems^-1 + ColonChain) / mark"chain" + + ChainItems: ChainItem^1 * ColonChain^-1 + ColonChain + + ChainItem: + Invoke + + DotChainItem + + Slice + + symx"[" * Exp/mark"index" * sym"]" + + DotChainItem: symx"." * _Name/mark"dot" + ColonChainItem: symx"\\" * _Name / mark"colon" + ColonChain: ColonChainItem * (Invoke * ChainItems^-1)^-1 + + Slice: symx"[" * (SliceValue + Cc(1)) * sym"," * (SliceValue + Cc"") * + (sym"," * SliceValue)^-1 *sym"]" / mark"slice" + + Invoke: FnArgs / mark"call" + + SingleString / wrap_func_arg + + DoubleString / wrap_func_arg + + L(P"[") * LuaString / wrap_func_arg + + TableValue: KeyValue + Ct(Exp) + + TableLit: sym"{" * Ct( + TableValueList^-1 * sym","^-1 * + (SpaceBreak * TableLitLine * (sym","^-1 * SpaceBreak * TableLitLine)^0 * sym","^-1)^-1 + ) * White * sym"}" / mark"table" + + TableValueList: TableValue * (sym"," * TableValue)^0 + TableLitLine: PushIndent * ((TableValueList * PopIndent) + (PopIndent * Cut)) + Space + + -- the unbounded table + TableBlockInner: Ct(KeyValueLine * (SpaceBreak^1 * KeyValueLine)^0) + TableBlock: SpaceBreak^1 * Advance * ensure(TableBlockInner, PopIndent) / mark"table" + + ClassDecl: key"class" * -P":" * (Assignable + Cc(nil)) * (key"extends" * PreventIndent * ensure(Exp, PopIndent) + C"")^-1 * (ClassBlock + Ct("")) / mark"class" + + ClassBlock: SpaceBreak^1 * Advance * + Ct(ClassLine * (SpaceBreak^1 * ClassLine)^0) * PopIndent + ClassLine: CheckIndent * (( + KeyValueList / mark"props" + + Statement / mark"stm" + + Exp / mark"stm" + ) * sym","^-1) + + Export: key"export" * ( + Cc"class" * ClassDecl + + op"*" + op"^" + + Ct(NameList) * (sym"=" * Ct(ExpListLow))^-1) / mark"export" + + KeyValue: (sym":" * -SomeSpace * Name * lpeg.Cp!) / self_assign + + Ct( + (KeyName + sym"[" * Exp * sym"]" +Space * DoubleString + Space * SingleString) * + symx":" * + (Exp + TableBlock + SpaceBreak^1 * Exp) + ) + + KeyValueList: KeyValue * (sym"," * KeyValue)^0 + KeyValueLine: CheckIndent * KeyValueList * sym","^-1 + + FnArgsDef: sym"(" * White * Ct(FnArgDefList^-1) * + (key"using" * Ct(NameList + Space * "nil") + Ct"") * + White * sym")" + Ct"" * Ct"" + + FnArgDefList: FnArgDef * ((sym"," + Break) * White * FnArgDef)^0 * ((sym"," + Break) * White * Ct(VarArg))^0 + Ct(VarArg) + FnArgDef: Ct((Name + SelfName) * (sym"=" * Exp)^-1) + + FunLit: FnArgsDef * + (sym"->" * Cc"slim" + sym"=>" * Cc"fat") * + (Body + Ct"") / mark"fndef" + + NameList: Name * (sym"," * Name)^0 + NameOrDestructure: Name + TableLit + AssignableNameList: NameOrDestructure * (sym"," * NameOrDestructure)^0 + + ExpList: Exp * (sym"," * Exp)^0 + ExpListLow: Exp * ((sym"," + sym";") * Exp)^0 + + -- open args + InvokeArgs: -P"-" * (ExpList * (sym"," * (TableBlock + SpaceBreak * Advance * ArgBlock * TableBlock^-1) + TableBlock)^-1 + TableBlock) + ArgBlock: ArgLine * (sym"," * SpaceBreak * ArgLine)^0 * PopIndent + ArgLine: CheckIndent * ExpList + } + + g, state + +file_parser = -> + g, state = build_grammar! + file_grammar = White * g * White * -1 + + { + match: (str) => + local tree + _, err = xpcall (-> + tree = file_grammar\match str + ), (err) -> + debug.traceback err, 2 + + -- regular error, let it bubble up + if type(err) == "string" + return nil, err + + unless tree + local msg + err_pos = state.last_pos + + if err + node, msg = unpack err + msg = " " .. msg if msg + err_pos = node[-1] + + line_no = pos_to_line str, err_pos + line_str = get_line(str, line_no) or "" + return nil, err_msg\format msg or "", line_no, trim line_str + + tree + } + +{ + :extract_line + :build_grammar + + -- parse a string as a file + -- returns tree, or nil and error message + string: (str) -> file_parser!\match str +} +)xoxo", "abc"); + try + { + if (parse, moon::action>(inName, state)) + { + std::cout << "matched.\n"; + } + else + { + std::cout << "not matched.\n"; + } + } + catch (parse_error e) + { + std::cout << e.what() << '\n'; + } +/* + analyze(); + const char* text = "1 + 2 + 3 * 4 / 2"; + string_input<> in(text, "abc"); + try + { + hello::Stack stack; + if (parse(in, stack)) + { + std::cout << text << " = " << stack.getValue() << '\n'; + } + return 0; + } + catch (parse_error e) + { + std::cout << e.what() << '\n'; + return 1; + } +*/ + return 0; +} diff --git a/MoonParser/pegtl.hpp b/MoonParser/pegtl.hpp new file mode 100644 index 0000000..e96cd79 --- /dev/null +++ b/MoonParser/pegtl.hpp @@ -0,0 +1,31 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_PEGTL_HPP +#define TAOCPP_PEGTL_INCLUDE_PEGTL_HPP + +#include "pegtl/config.hpp" +#include "pegtl/version.hpp" + +#include "pegtl/ascii.hpp" +#include "pegtl/parse.hpp" +#include "pegtl/rules.hpp" +#include "pegtl/utf16.hpp" +#include "pegtl/utf32.hpp" +#include "pegtl/utf8.hpp" + +#include "pegtl/argv_input.hpp" +#include "pegtl/buffer_input.hpp" +#include "pegtl/cstream_input.hpp" +#include "pegtl/file_input.hpp" +#include "pegtl/istream_input.hpp" +#include "pegtl/memory_input.hpp" +#include "pegtl/read_input.hpp" +#include "pegtl/string_input.hpp" + +// The following are not included by +// default because they include . + +// #include "pegtl/analyze.hpp" + +#endif diff --git a/MoonParser/pegtl/analysis/analyze_cycles.hpp b/MoonParser/pegtl/analysis/analyze_cycles.hpp new file mode 100644 index 0000000..f063ee1 --- /dev/null +++ b/MoonParser/pegtl/analysis/analyze_cycles.hpp @@ -0,0 +1,134 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_ANALYSIS_ANALYZE_CYCLES_HPP +#define TAOCPP_PEGTL_INCLUDE_ANALYSIS_ANALYZE_CYCLES_HPP + +#include + +#include +#include + +#include +#include + +#include "../config.hpp" + +#include "grammar_info.hpp" +#include "insert_guard.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace analysis + { + class analyze_cycles_impl + { + protected: + explicit analyze_cycles_impl( const bool verbose ) noexcept + : 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 noexcept + { + 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 = 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 = 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 = 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 = a && work( find( r ), accum ); + } + return m_cache[ start->first ] = a; + } + } + throw std::runtime_error( "code should be unreachable" ); // 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 noexcept + { + const auto i = m_results.find( internal::demangle< Rule >() ); + assert( i != m_results.end() ); + return i->second; + } + }; + + } // namespace analysis + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/analysis/counted.hpp b/MoonParser/pegtl/analysis/counted.hpp new file mode 100644 index 0000000..84a12ae --- /dev/null +++ b/MoonParser/pegtl/analysis/counted.hpp @@ -0,0 +1,29 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_ANALYSIS_COUNTED_HPP +#define TAOCPP_PEGTL_INCLUDE_ANALYSIS_COUNTED_HPP + +#include "../config.hpp" + +#include "generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace analysis + { + template< rule_type Type, unsigned Count, typename... Rules > + struct counted + : generic< ( Count != 0 ) ? Type : rule_type::OPT, Rules... > + { + }; + + } // namespace analysis + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/analysis/generic.hpp b/MoonParser/pegtl/analysis/generic.hpp new file mode 100644 index 0000000..27e0ffe --- /dev/null +++ b/MoonParser/pegtl/analysis/generic.hpp @@ -0,0 +1,39 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_ANALYSIS_GENERIC_HPP +#define TAOCPP_PEGTL_INCLUDE_ANALYSIS_GENERIC_HPP + +#include "../config.hpp" + +#include "grammar_info.hpp" +#include "insert_rules.hpp" +#include "rule_type.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + 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; + } + }; + + } // namespace analysis + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/analysis/grammar_info.hpp b/MoonParser/pegtl/analysis/grammar_info.hpp new file mode 100644 index 0000000..15c96ab --- /dev/null +++ b/MoonParser/pegtl/analysis/grammar_info.hpp @@ -0,0 +1,40 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_ANALYSIS_GRAMMAR_INFO_HPP +#define TAOCPP_PEGTL_INCLUDE_ANALYSIS_GRAMMAR_INFO_HPP + +#include +#include +#include + +#include "../config.hpp" +#include "../internal/demangle.hpp" + +#include "rule_info.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + 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 ) ) ); + } + }; + + } // namespace analysis + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/analysis/insert_guard.hpp b/MoonParser/pegtl/analysis/insert_guard.hpp new file mode 100644 index 0000000..9a4cc35 --- /dev/null +++ b/MoonParser/pegtl/analysis/insert_guard.hpp @@ -0,0 +1,66 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_ANALYSIS_INSERT_GUARD_HPP +#define TAOCPP_PEGTL_INCLUDE_ANALYSIS_INSERT_GUARD_HPP + +#include + +#include "../config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace analysis + { + template< typename C > + class insert_guard + { + public: + insert_guard( insert_guard&& other ) noexcept + : m_i( other.m_i ), + m_c( other.m_c ) + { + other.m_c = nullptr; + } + + insert_guard( C& container, const typename C::value_type& value ) + : m_i( container.insert( value ) ), + m_c( &container ) + { + } + + ~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 noexcept + { + return m_i.second; + } + + private: + const std::pair< typename C::iterator, bool > m_i; + C* m_c; + }; + + template< typename C > + insert_guard< C > make_insert_guard( C& container, const typename C::value_type& value ) + { + return insert_guard< C >( container, value ); + } + + } // namespace analysis + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/analysis/insert_rules.hpp b/MoonParser/pegtl/analysis/insert_rules.hpp new file mode 100644 index 0000000..ff55f66 --- /dev/null +++ b/MoonParser/pegtl/analysis/insert_rules.hpp @@ -0,0 +1,45 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_ANALYSIS_INSERT_RULES_HPP +#define TAOCPP_PEGTL_INCLUDE_ANALYSIS_INSERT_RULES_HPP + +#include "../config.hpp" + +#include "grammar_info.hpp" +#include "rule_info.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + 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 ); + } + }; + + } // namespace analysis + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/analysis/rule_info.hpp b/MoonParser/pegtl/analysis/rule_info.hpp new file mode 100644 index 0000000..22910ec --- /dev/null +++ b/MoonParser/pegtl/analysis/rule_info.hpp @@ -0,0 +1,37 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_ANALYSIS_RULE_INFO_HPP +#define TAOCPP_PEGTL_INCLUDE_ANALYSIS_RULE_INFO_HPP + +#include +#include + +#include "../config.hpp" + +#include "rule_type.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace analysis + { + struct rule_info + { + explicit rule_info( const rule_type in_type ) + : type( in_type ) + { + } + + rule_type type; + std::vector< std::string > rules; + }; + + } // namespace analysis + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/analysis/rule_type.hpp b/MoonParser/pegtl/analysis/rule_type.hpp new file mode 100644 index 0000000..fc5d4c8 --- /dev/null +++ b/MoonParser/pegtl/analysis/rule_type.hpp @@ -0,0 +1,29 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_ANALYSIS_RULE_TYPE_HPP +#define TAOCPP_PEGTL_INCLUDE_ANALYSIS_RULE_TYPE_HPP + +#include "../config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + 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. + }; + + } // namespace analysis + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/analyze.hpp b/MoonParser/pegtl/analyze.hpp new file mode 100644 index 0000000..5468a14 --- /dev/null +++ b/MoonParser/pegtl/analyze.hpp @@ -0,0 +1,25 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_ANALYZE_HPP +#define TAOCPP_PEGTL_INCLUDE_ANALYZE_HPP + +#include "config.hpp" + +#include "analysis/analyze_cycles.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + template< typename Rule > + std::size_t analyze( const bool verbose = true ) + { + return analysis::analyze_cycles< Rule >( verbose ).problems(); + } + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/apply_mode.hpp b/MoonParser/pegtl/apply_mode.hpp new file mode 100644 index 0000000..93a701b --- /dev/null +++ b/MoonParser/pegtl/apply_mode.hpp @@ -0,0 +1,23 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_APPLY_MODE_HPP +#define TAOCPP_PEGTL_INCLUDE_APPLY_MODE_HPP + +#include "config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + enum class apply_mode : bool + { + ACTION = true, + NOTHING = false + }; + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/argv_input.hpp b/MoonParser/pegtl/argv_input.hpp new file mode 100644 index 0000000..3846975 --- /dev/null +++ b/MoonParser/pegtl/argv_input.hpp @@ -0,0 +1,52 @@ +// Copyright (c) 2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_ARGV_INPUT_HPP +#define TAOCPP_PEGTL_INCLUDE_ARGV_INPUT_HPP + +#include +#include +#include +#include + +#include "config.hpp" +#include "eol.hpp" +#include "memory_input.hpp" +#include "tracking_mode.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + inline std::string make_argv_source( const std::size_t argn ) + { + std::ostringstream os; + os << "argv[" << argn << ']'; + return os.str(); + } + + } // namespace internal + + template< tracking_mode P = tracking_mode::IMMEDIATE, typename Eol = eol::lf_crlf > + struct argv_input + : public memory_input< P, Eol > + { + template< typename T > + argv_input( char** argv, const std::size_t argn, T&& in_source ) + : memory_input< P, Eol >( static_cast< const char* >( argv[ argn ] ), std::forward< T >( in_source ) ) + { + } + + argv_input( char** argv, const std::size_t argn ) + : argv_input( argv, argn, internal::make_argv_source( argn ) ) + { + } + }; + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/ascii.hpp b/MoonParser/pegtl/ascii.hpp new file mode 100644 index 0000000..9158061 --- /dev/null +++ b/MoonParser/pegtl/ascii.hpp @@ -0,0 +1,67 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_ASCII_HPP +#define TAOCPP_PEGTL_INCLUDE_ASCII_HPP + +#include "config.hpp" +#include "eol.hpp" + +#include "internal/result_on_found.hpp" +#include "internal/rules.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + inline namespace ascii + { + // clang-format off + struct alnum : internal::alnum {}; + struct alpha : internal::alpha {}; + 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 eolf : internal::eolf {}; + struct identifier_first : internal::identifier_first {}; + struct identifier_other : internal::identifier_other {}; + struct identifier : internal::identifier {}; + template< char... Cs > struct istring : internal::istring< Cs... > {}; + template< char... Cs > struct keyword : internal::seq< internal::string< Cs... >, internal::not_at< internal::identifier_other > > {}; + 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' > {}; + // clang-format on + + template<> + struct keyword<> + { + template< typename Input > + static bool match( Input& ) noexcept + { + static_assert( sizeof( Input ) == 0, "empty keywords not allowed" ); + return false; + } + }; + + } // namespace ascii + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#include "internal/pegtl_string.hpp" + +#endif diff --git a/MoonParser/pegtl/buffer_input.hpp b/MoonParser/pegtl/buffer_input.hpp new file mode 100644 index 0000000..b65e365 --- /dev/null +++ b/MoonParser/pegtl/buffer_input.hpp @@ -0,0 +1,179 @@ +// Copyright (c) 2016-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_BUFFER_INPUT_HPP +#define TAOCPP_PEGTL_INCLUDE_BUFFER_INPUT_HPP + +#include +#include +#include +#include + +#include "config.hpp" +#include "eol.hpp" +#include "memory_input.hpp" +#include "position.hpp" +#include "tracking_mode.hpp" + +#include "internal/action_input.hpp" +#include "internal/bump_impl.hpp" +#include "internal/iterator.hpp" +#include "internal/marker.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + template< typename Reader, typename Eol = eol::lf_crlf, typename Source = std::string > + class buffer_input + { + public: + static constexpr tracking_mode tracking_mode_v = tracking_mode::IMMEDIATE; + using reader_t = Reader; + + using eol_t = Eol; + using source_t = Source; + + using iterator_t = internal::iterator; + + using action_t = internal::action_input< buffer_input >; + + template< typename T, typename... As > + buffer_input( T&& in_source, const std::size_t maximum, As&&... as ) + : m_reader( std::forward< As >( as )... ), + m_maximum( maximum ), + m_buffer( new char[ maximum ] ), + m_current( m_buffer.get() ), + m_end( m_buffer.get() ), + m_source( std::forward< T >( in_source ) ) + { + } + + buffer_input( const buffer_input& ) = delete; + void operator=( const buffer_input& ) = delete; + + bool empty() + { + require( 1 ); + return m_current.data == m_end; + } + + std::size_t size( const std::size_t amount ) + { + require( amount ); + return std::size_t( m_end - m_current.data ); + } + + const char* current() const noexcept + { + return m_current.data; + } + + const char* end( const std::size_t amount ) + { + require( amount ); + return m_end; + } + + std::size_t byte() const noexcept + { + return m_current.byte; + } + + std::size_t line() const noexcept + { + return m_current.line; + } + + std::size_t byte_in_line() const noexcept + { + return m_current.byte_in_line; + } + + const Source& source() const noexcept + { + return m_source; + } + + char peek_char( const std::size_t offset = 0 ) const noexcept + { + return m_current.data[ offset ]; + } + + unsigned char peek_byte( const std::size_t offset = 0 ) const noexcept + { + return static_cast< unsigned char >( peek_char( offset ) ); + } + + void bump( const std::size_t in_count = 1 ) noexcept + { + internal::bump( m_current, in_count, Eol::ch ); + } + + void bump_in_this_line( const std::size_t in_count = 1 ) noexcept + { + internal::bump_in_this_line( m_current, in_count ); + } + + void bump_to_next_line( const std::size_t in_count = 1 ) noexcept + { + internal::bump_to_next_line( m_current, in_count ); + } + + void discard() noexcept + { + const auto s = m_end - m_current.data; + std::memmove( m_buffer.get(), m_current.data, s ); + m_current.data = m_buffer.get(); + m_end = m_buffer.get() + s; + } + + void require( const std::size_t amount ) + { + if( m_current.data + amount > m_end ) { + if( m_current.data + amount <= m_buffer.get() + m_maximum ) { + if( const auto r = m_reader( const_cast< char* >( m_end ), amount - std::size_t( m_end - m_current.data ) ) ) { + m_end += r; + } + else { + m_maximum = 0; + } + } + } + } + + template< rewind_mode M > + internal::marker< iterator_t, M > mark() noexcept + { + return internal::marker< iterator_t, M >( m_current ); + } + + TAOCPP_PEGTL_NAMESPACE::position position( const iterator_t& it ) const + { + return TAOCPP_PEGTL_NAMESPACE::position( it, m_source ); + } + + TAOCPP_PEGTL_NAMESPACE::position position() const + { + return position( m_current ); + } + + const iterator_t& iterator() const noexcept + { + return m_current; + } + + private: + Reader m_reader; + std::size_t m_maximum; + std::unique_ptr< char[] > m_buffer; + iterator_t m_current; + const char* m_end; + const Source m_source; + }; + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/config.hpp b/MoonParser/pegtl/config.hpp new file mode 100644 index 0000000..e93f74a --- /dev/null +++ b/MoonParser/pegtl/config.hpp @@ -0,0 +1,15 @@ +// Copyright (c) 2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_CONFIG_HPP +#define TAOCPP_PEGTL_INCLUDE_CONFIG_HPP + +#ifndef TAOCPP_PEGTL_NAMESPACE +#define TAOCPP_PEGTL_NAMESPACE pegtl +#endif + +// Enable some improvements to the readability of +// demangled type names under some circumstances. +// #define TAOCPP_PEGTL_PRETTY_DEMANGLE + +#endif diff --git a/MoonParser/pegtl/contrib/abnf.hpp b/MoonParser/pegtl/contrib/abnf.hpp new file mode 100644 index 0000000..15319f5 --- /dev/null +++ b/MoonParser/pegtl/contrib/abnf.hpp @@ -0,0 +1,43 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_CONTRIB_ABNF_HPP +#define TAOCPP_PEGTL_INCLUDE_CONTRIB_ABNF_HPP + +#include "../config.hpp" +#include "../internal/rules.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace abnf + { + // Core ABNF rules according to RFC 5234, Appendix B + + // clang-format off + 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' > {}; + // clang-format on + + } // namespace abnf + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/contrib/alphabet.hpp b/MoonParser/pegtl/contrib/alphabet.hpp new file mode 100644 index 0000000..c0dce42 --- /dev/null +++ b/MoonParser/pegtl/contrib/alphabet.hpp @@ -0,0 +1,75 @@ +// Copyright (c) 2015-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_CONTRIB_ALPHABET_HPP +#define TAOCPP_PEGTL_INCLUDE_CONTRIB_ALPHABET_HPP + +#include "../config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + 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'; + + } // namespace alphabet + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/contrib/changes.hpp b/MoonParser/pegtl/contrib/changes.hpp new file mode 100644 index 0000000..7b9f8dc --- /dev/null +++ b/MoonParser/pegtl/contrib/changes.hpp @@ -0,0 +1,86 @@ +// Copyright (c) 2015-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_CONTRIB_CHANGES_HPP +#define TAOCPP_PEGTL_INCLUDE_CONTRIB_CHANGES_HPP + +#include + +#include "../config.hpp" +#include "../normal.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + struct dummy_disabled_state + { + template< typename... Ts > + void success( Ts&&... ) const noexcept + { + } + }; + + template< apply_mode A, typename State > + using state_disable_helper = typename std::conditional< A == apply_mode::ACTION, State, dummy_disabled_state >::type; + + } // namespace internal + + template< typename Rule, typename State, template< typename... > class Base = normal > + struct change_state + : public Base< Rule > + { + template< apply_mode A, + rewind_mode M, + 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, M, Action, Control >( in, s ) ) { + s.success( st... ); + return true; + } + return false; + } + }; + + template< typename Rule, template< typename... > class Action, template< typename... > class Base = normal > + struct change_action + : public Base< Rule > + { + template< apply_mode A, + rewind_mode M, + template< typename... > class, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + return Base< Rule >::template match< A, M, 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 = normal > + struct change_state_and_action + : public change_state< Rule, State, change_both_helper< Action, Base >::template change_action > + { + }; + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/contrib/counter.hpp b/MoonParser/pegtl/contrib/counter.hpp new file mode 100644 index 0000000..52beb3b --- /dev/null +++ b/MoonParser/pegtl/contrib/counter.hpp @@ -0,0 +1,58 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_CONTRIB_COUNTER_HPP +#define TAOCPP_PEGTL_INCLUDE_CONTRIB_COUNTER_HPP + +#include +#include + +#include "../config.hpp" +#include "../normal.hpp" + +#include "../internal/demangle.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + struct counter_data + { + unsigned start = 0; + unsigned success = 0; + unsigned failure = 0; + }; + + struct counter_state + { + std::map< std::string, counter_data > counts; + }; + + template< typename Rule > + struct counter + : normal< Rule > + { + template< typename Input > + static void start( const Input&, counter_state& ts ) + { + ++ts.counts[ internal::demangle< Rule >() ].start; + } + + template< typename Input > + static void success( const Input&, counter_state& ts ) + { + ++ts.counts[ internal::demangle< Rule >() ].success; + } + + template< typename Input > + static void failure( const Input&, counter_state& ts ) + { + ++ts.counts[ internal::demangle< Rule >() ].failure; + } + }; + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/contrib/http.hpp b/MoonParser/pegtl/contrib/http.hpp new file mode 100644 index 0000000..1446449 --- /dev/null +++ b/MoonParser/pegtl/contrib/http.hpp @@ -0,0 +1,152 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_CONTRIB_HTTP_HPP +#define TAOCPP_PEGTL_INCLUDE_CONTRIB_HTTP_HPP + +#include "../ascii.hpp" +#include "../config.hpp" +#include "../rules.hpp" +#include "../utf8.hpp" +#include "abnf.hpp" +#include "uri.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + 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 rules for attached 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 + + // cppcheck-suppress constStatement + using obs_text = not_range< 0x00, 0x7F >; + using obs_fold = seq< CRLF, plus< WSP > >; + + // clang-format off + 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< TAOCPP_PEGTL_STRING( "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< status_line, request_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< TAOCPP_PEGTL_ISTRING( "chunked" ), + TAOCPP_PEGTL_ISTRING( "compress" ), + TAOCPP_PEGTL_ISTRING( "deflate" ), + TAOCPP_PEGTL_ISTRING( "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< TAOCPP_PEGTL_ISTRING( "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< TAOCPP_PEGTL_ISTRING( "http://" ), uri::authority, uri::path_abempty, uri::opt_query, uri::opt_fragment > {}; + struct https_URI : if_must< TAOCPP_PEGTL_ISTRING( "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 > {}; + // clang-format on + + } // namespace http + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/contrib/json.hpp b/MoonParser/pegtl/contrib/json.hpp new file mode 100644 index 0000000..688f607 --- /dev/null +++ b/MoonParser/pegtl/contrib/json.hpp @@ -0,0 +1,98 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_CONTRIB_JSON_HPP +#define TAOCPP_PEGTL_INCLUDE_CONTRIB_JSON_HPP + +#include "../ascii.hpp" +#include "../config.hpp" +#include "../rules.hpp" +#include "../utf8.hpp" + +#include "abnf.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace json + { + // JSON grammar according to RFC 7159 (for UTF-8 encoded JSON only). + + // clang-format off + 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_ : TAOCPP_PEGTL_STRING( "false" ) {}; + struct null : TAOCPP_PEGTL_STRING( "null" ) {}; + struct true_ : TAOCPP_PEGTL_STRING( "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 > {}; + // clang-format on + + } // namespace json + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/contrib/raw_string.hpp b/MoonParser/pegtl/contrib/raw_string.hpp new file mode 100644 index 0000000..592ce5b --- /dev/null +++ b/MoonParser/pegtl/contrib/raw_string.hpp @@ -0,0 +1,252 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_CONTRIB_RAW_STRING_HPP +#define TAOCPP_PEGTL_INCLUDE_CONTRIB_RAW_STRING_HPP + +#include "../apply_mode.hpp" +#include "../config.hpp" +#include "../nothing.hpp" +#include "../rewind_mode.hpp" + +#include "../internal/iterator.hpp" +#include "../internal/must.hpp" +#include "../internal/skip_control.hpp" +#include "../internal/state.hpp" +#include "../internal/until.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< char Open, char Marker, char Close, typename... Contents > + struct raw_string_tag + { + }; + + template< bool use_action, bool use_apply0, typename Tag > + struct raw_string_state_apply; + + template< typename Tag > + struct raw_string_state_apply< false, false, Tag > + { + template< template< typename... > class, + template< typename... > class, + typename State, + typename Input, + typename... States > + static void success( const State&, const Input&, States&&... ) + { + } + }; + + template< typename Tag > + struct raw_string_state_apply< true, false, Tag > + { + template< template< typename... > class Action, + template< typename... > class Control, + typename State, + typename Input, + typename... States > + static void success( const State& s, const Input& in, States&&... st ) + { + Control< Tag >::template apply< Action >( s.iter, in, st... ); + } + }; + + template< typename Tag > + struct raw_string_state_apply< true, true, Tag > + { + template< template< typename... > class Action, + template< typename... > class Control, + typename State, + typename Input, + typename... States > + static void success( const State&, const Input& in, States&&... st ) + { + Control< Tag >::template apply0< Action >( in, st... ); + } + }; + + template< typename Tag, typename Iterator > + struct raw_string_state + { + template< typename Input, typename... States > + raw_string_state( const Input&, States&&... ) + { + } + + template< apply_mode A, + rewind_mode, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + void success( Input& in, States&&... st ) const + { + constexpr bool use_action = ( A == apply_mode::ACTION ) && ( !is_nothing< Action, Tag >::value ); + constexpr bool use_apply0 = use_action && has_apply0< Action< Tag >, type_list< States... > >::value; + raw_string_state_apply< use_action, use_apply0, Tag >::template success< Action, Control >( *this, in, st... ); + in.bump_in_this_line( marker_size ); + } + + raw_string_state( const raw_string_state& ) = delete; + void operator=( const raw_string_state& ) = delete; + + Iterator iter; + std::size_t marker_size = 0; + }; + + template< char Open, char Marker > + struct raw_string_open + { + using analyze_t = analysis::generic< analysis::rule_type::ANY >; + + template< apply_mode A, + rewind_mode, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename State > + static bool match( Input& in, State& ls ) + { + if( in.empty() || ( in.peek_char( 0 ) != Open ) ) { + return false; + } + for( std::size_t i = 1; i < in.size( i + 1 ); ++i ) { + switch( const auto c = in.peek_char( i ) ) { + case Open: + ls.marker_size = i + 1; + in.bump( ls.marker_size ); + eol::match( in ); + ls.iter = in.iterator(); + return true; + case Marker: + break; + default: + return false; + } + } + return false; + } + }; + + template< char Open, char Marker > + struct skip_control< raw_string_open< Open, Marker > > : std::true_type + { + }; + + template< char Marker, char Close > + struct at_raw_string_close + { + using analyze_t = analysis::generic< analysis::rule_type::ANY >; + + template< apply_mode A, + rewind_mode, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename State > + static bool match( Input& in, const State& ls ) + { + if( in.size( ls.marker_size ) < ls.marker_size ) { + return false; + } + if( in.peek_char( 0 ) != Close ) { + return false; + } + if( in.peek_char( ls.marker_size - 1 ) != Close ) { + return false; + } + for( std::size_t i = 0; i < ls.marker_size - 2; ++i ) { + if( in.peek_char( i + 1 ) != Marker ) { + return false; + } + } + return true; + } + }; + + template< char Marker, char Close > + struct skip_control< at_raw_string_close< Marker, Close > > : std::true_type + { + }; + + template< class Tag, typename... Rules > + struct raw_string_switch_state + { + using analyze_t = analysis::generic< analysis::rule_type::SEQ, Rules... >; + + template< apply_mode A, + rewind_mode M, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + using Iterator = typename Input::iterator_t; + raw_string_state< Tag, Iterator > s( const_cast< const Input& >( in ), st... ); + + if( duseltronik< seq< Rules... >, A, M, Action, Control >::match( in, s ) ) { + s.template success< A, M, Action, Control >( in, st... ); + return true; + } + return false; + } + }; + + template< typename Tag, typename... Rules > + struct skip_control< raw_string_switch_state< Tag, Rules... > > : std::true_type + { + }; + + } // namespace 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 Marker, char Close, typename... Contents > + struct raw_string + : internal::raw_string_switch_state< internal::raw_string_tag< Open, Marker, Close >, + internal::raw_string_open< Open, Marker >, + internal::must< internal::until< internal::at_raw_string_close< Marker, Close >, Contents... > > > + { + // This is used to bind an action to the content. + using content = internal::raw_string_tag< Open, Marker, Close, Contents... >; + + // This is used for error-reporting when a raw string is not closed properly. + using close = internal::until< internal::at_raw_string_close< Marker, Close > >; + }; + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/contrib/rep_one_min_max.hpp b/MoonParser/pegtl/contrib/rep_one_min_max.hpp new file mode 100644 index 0000000..28fdbcd --- /dev/null +++ b/MoonParser/pegtl/contrib/rep_one_min_max.hpp @@ -0,0 +1,72 @@ +// Copyright (c) 2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_CONTRIB_REP_ONE_MIN_MAX_HPP +#define TAOCPP_PEGTL_INCLUDE_CONTRIB_REP_ONE_MIN_MAX_HPP + +#include + +#include "../config.hpp" + +#include "../analysis/counted.hpp" + +#include "../internal/bump_help.hpp" +#include "../internal/skip_control.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< unsigned Min, unsigned Max, char C > + struct rep_one_min_max + { + using analyze_t = analysis::counted< analysis::rule_type::ANY, Min >; + + static_assert( Min <= Max, "invalid rep_one_min_max rule (maximum number of repetitions smaller than minimum)" ); + + template< typename Input > + static bool match( Input& in ) + { + const auto size = in.size( Max + 1 ); + if( size < Min ) { + return false; + } + std::size_t i = 0; + while( ( i < size ) && ( in.peek_char( i ) == C ) ) { + ++i; + } + if( ( Min <= i ) && ( i <= Max ) ) { + bump_help< result_on_found::SUCCESS, Input, char, C >( in, i ); + return true; + } + return false; + } + }; + + template< unsigned Min, unsigned Max, char C > + struct skip_control< rep_one_min_max< Min, Max, C > > : std::true_type + { + }; + + } // namespace internal + + inline namespace ascii + { + template< unsigned Min, unsigned Max, char C > + struct rep_one_min_max : internal::rep_one_min_max< Min, Max, C > + { + }; + + struct ellipsis : internal::rep_one_min_max< 3, 3, '.' > + { + }; + + } // namespace ascii + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/contrib/to_string.hpp b/MoonParser/pegtl/contrib/to_string.hpp new file mode 100644 index 0000000..4c19931 --- /dev/null +++ b/MoonParser/pegtl/contrib/to_string.hpp @@ -0,0 +1,42 @@ +// Copyright (c) 2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_CONTRIB_TO_STRING_HPP +#define TAOCPP_PEGTL_INCLUDE_CONTRIB_TO_STRING_HPP + +#include + +#include "../config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename > + struct to_string; + + template< template< char... > class X, char... Cs > + struct to_string< X< Cs... > > + { + static std::string get() + { + const char s[] = { Cs..., 0 }; + return std::string( s, sizeof...( Cs ) ); + } + }; + + } // namespace internal + + template< typename T > + std::string to_string() + { + return internal::to_string< T >::get(); + } + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/contrib/tracer.hpp b/MoonParser/pegtl/contrib/tracer.hpp new file mode 100644 index 0000000..5649078 --- /dev/null +++ b/MoonParser/pegtl/contrib/tracer.hpp @@ -0,0 +1,111 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_CONTRIB_TRACER_HPP +#define TAOCPP_PEGTL_INCLUDE_CONTRIB_TRACER_HPP + +#include +#include +#include +#include +#include + +#include "../config.hpp" +#include "../normal.hpp" + +#include "../internal/demangle.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + struct trace_state + { + unsigned rule = 0; + unsigned line = 0; + std::vector< unsigned > stack; + }; + + template< typename Rule > + struct tracer + : normal< Rule > + { + template< typename Input, typename... States > + static void start( const Input& in, States&&... ) + { + std::cerr << in.position() << " start " << internal::demangle< Rule >() << std::endl; + } + + template< typename Input > + static void start( const Input& in, trace_state& ts ) + { + std::cerr << std::setw( 6 ) << ++ts.line << " " << std::setw( 6 ) << ++ts.rule << " " << in.position() << " start " << internal::demangle< Rule >() << std::endl; + ts.stack.push_back( ts.rule ); + } + + template< typename Input, typename... States > + static void success( const Input& in, States&&... ) + { + std::cerr << in.position() << " success " << internal::demangle< Rule >() << std::endl; + } + + template< typename Input > + static void success( const Input& in, trace_state& ts ) + { + assert( !ts.stack.empty() ); + std::cerr << std::setw( 6 ) << ++ts.line << " " << std::setw( 6 ) << ts.stack.back() << " " << in.position() << " success " << internal::demangle< Rule >() << std::endl; + ts.stack.pop_back(); + } + + template< typename Input, typename... States > + static void failure( const Input& in, States&&... ) + { + std::cerr << in.position() << " failure " << internal::demangle< Rule >() << std::endl; + } + + template< typename Input > + static void failure( const Input& in, trace_state& ts ) + { + assert( !ts.stack.empty() ); + std::cerr << std::setw( 6 ) << ++ts.line << " " << std::setw( 6 ) << ts.stack.back() << " " << in.position() << " failure " << internal::demangle< Rule >() << std::endl; + ts.stack.pop_back(); + } + + template< template< typename... > class Action, typename Input, typename... States > + static void apply0( const Input&, States&&... st ) + { + std::cerr << "apply0 " << internal::demangle< Action< Rule > >() << std::endl; + Action< Rule >::apply0( st... ); + } + + template< template< typename... > class Action, typename Input > + static void apply0( const Input&, trace_state& ts ) + { + std::cerr << std::setw( 6 ) << ++ts.line << " " << internal::demangle< Action< Rule > >() << "::apply0()" << std::endl; + Action< Rule >::apply0( ts ); + } + + template< template< typename... > class Action, typename Iterator, typename Input, typename... States > + static void apply( const Iterator& begin, const Input& in, States&&... st ) + { + std::cerr << "apply " << internal::demangle< Action< Rule > >() << std::endl; + using action_t = typename Input::action_t; + const action_t action_input( begin, in ); + Action< Rule >::apply( action_input, st... ); + } + + template< template< typename... > class Action, typename Iterator, typename Input > + static void apply( const Iterator& begin, const Input& in, trace_state& ts ) + { + std::cerr << std::setw( 6 ) << ++ts.line << " " << internal::demangle< Action< Rule > >() << "::apply()" << std::endl; + using action_t = typename Input::action_t; + const action_t action_input( begin, in ); + Action< Rule >::apply( action_input, ts ); + } + }; + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/contrib/unescape.hpp b/MoonParser/pegtl/contrib/unescape.hpp new file mode 100644 index 0000000..2a7c53f --- /dev/null +++ b/MoonParser/pegtl/contrib/unescape.hpp @@ -0,0 +1,203 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_CONTRIB_UNESCAPE_HPP +#define TAOCPP_PEGTL_INCLUDE_CONTRIB_UNESCAPE_HPP + +#include +#include + +#include "../ascii.hpp" +#include "../config.hpp" +#include "../parse_error.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + 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; + } + if( utf32 <= 0x7ff ) { + char tmp[] = { char( ( ( utf32 & 0x7c0 ) >> 6 ) | 0xc0 ), + char( ( ( utf32 & 0x03f ) ) | 0x80 ) }; + string.append( tmp, sizeof( tmp ) ); + return true; + } + 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; + } + 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 tao::TAOCPP_PEGTL_NAMESPACE::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 ); + } + throw std::runtime_error( "invalid character in unhex" ); // 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 action MUST be called for a character matching T which MUST be tao::TAOCPP_PEGTL_NAMESPACE::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 ); + } + } + throw std::runtime_error( "invalid character in unescape" ); // LCOV_EXCL_LINE + } + }; + + // See src/example/pegtl/unescape.cpp for why the following two actions + // skip the first input character. They also MUST be called + // with non-empty matched inputs! + + 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() ); + } + }; + + // The unescape_j action is similar to unescape_u, however unlike + // unescape_u it + // (a) assumes exactly 4 hexdigits per escape sequence, + // (b) accepts multiple consecutive escaped 16-bit values. + // When applied to more than one escape sequence, unescape_j + // translates UTF-16 surrogate pairs in the input into a single + // UTF-8 sequence in st.unescaped, 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", starting with the first "u". + 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 ); + } + } + }; + + } // namespace unescape + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/contrib/uri.hpp b/MoonParser/pegtl/contrib/uri.hpp new file mode 100644 index 0000000..1401a7d --- /dev/null +++ b/MoonParser/pegtl/contrib/uri.hpp @@ -0,0 +1,116 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_CONTRIB_URI_HPP +#define TAOCPP_PEGTL_INCLUDE_CONTRIB_URI_HPP + +#include "../ascii.hpp" +#include "../config.hpp" +#include "../rules.hpp" +#include "../utf8.hpp" + +#include "abnf.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + 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 rules for attached actions, please contact the developers. + + // Note that this grammar has multiple top-level rules. + + using namespace abnf; + + using dot = one< '.' >; + using colon = one< ':' >; + + // clang-format off + 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 > {}; + // clang-format on + + } // namespace uri + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/cstream_input.hpp b/MoonParser/pegtl/cstream_input.hpp new file mode 100644 index 0000000..ad520e3 --- /dev/null +++ b/MoonParser/pegtl/cstream_input.hpp @@ -0,0 +1,34 @@ +// Copyright (c) 2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_CSTREAM_INPUT_HPP +#define TAOCPP_PEGTL_INCLUDE_CSTREAM_INPUT_HPP + +#include + +#include "buffer_input.hpp" +#include "config.hpp" +#include "eol.hpp" + +#include "internal/cstream_reader.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + template< typename Eol = eol::lf_crlf > + struct cstream_input + : buffer_input< internal::cstream_reader, Eol > + { + template< typename T > + cstream_input( std::FILE* in_stream, const std::size_t in_maximum, T&& in_source ) + : buffer_input< internal::cstream_reader, Eol >( std::forward< T >( in_source ), in_maximum, in_stream ) + { + } + }; + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/eol.hpp b/MoonParser/pegtl/eol.hpp new file mode 100644 index 0000000..ca3e604 --- /dev/null +++ b/MoonParser/pegtl/eol.hpp @@ -0,0 +1,54 @@ +// Copyright (c) 2016-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_EOL_HPP +#define TAOCPP_PEGTL_INCLUDE_EOL_HPP + +#include +#include + +#include "config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + using eol_pair = std::pair< bool, std::size_t >; + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#include "internal/cr_crlf_eol.hpp" +#include "internal/cr_eol.hpp" +#include "internal/crlf_eol.hpp" +#include "internal/lf_crlf_eol.hpp" +#include "internal/lf_eol.hpp" + +#include "internal/eol.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + inline namespace ascii + { + // this is both a rule and a pseudo-namespace for eol::cr, ... + struct eol : internal::eol + { + // clang-format off + struct cr : internal::cr_eol {}; + struct cr_crlf : internal::cr_crlf_eol {}; + struct crlf : internal::crlf_eol {}; + struct lf : internal::lf_eol {}; + struct lf_crlf : internal::lf_crlf_eol {}; + // clang-format on + }; + + } // namespace ascii + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/file_input.hpp b/MoonParser/pegtl/file_input.hpp new file mode 100644 index 0000000..625d491 --- /dev/null +++ b/MoonParser/pegtl/file_input.hpp @@ -0,0 +1,37 @@ +// Copyright (c) 2015-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_FILE_INPUT_HPP +#define TAOCPP_PEGTL_INCLUDE_FILE_INPUT_HPP + +#include "config.hpp" +#include "eol.hpp" +#include "tracking_mode.hpp" + +#if defined( __unix__ ) || ( defined( __APPLE__ ) && defined( __MACH__ ) ) +#include // Required for _POSIX_MAPPED_FILES +#endif + +#if defined( _POSIX_MAPPED_FILES ) +#include "mmap_input.hpp" +#else +#include "read_input.hpp" +#endif + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { +#if defined( _POSIX_MAPPED_FILES ) + template< tracking_mode P = tracking_mode::IMMEDIATE, typename Eol = eol::lf_crlf > + using file_input = mmap_input< P, Eol >; +#else + template< tracking_mode P = tracking_mode::IMMEDIATE, typename Eol = eol::lf_crlf > + using file_input = read_input< P, Eol >; +#endif + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/input_error.hpp b/MoonParser/pegtl/input_error.hpp new file mode 100644 index 0000000..605ce4d --- /dev/null +++ b/MoonParser/pegtl/input_error.hpp @@ -0,0 +1,41 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INPUT_ERROR_HPP +#define TAOCPP_PEGTL_INCLUDE_INPUT_ERROR_HPP + +#include +#include +#include + +#include "config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + struct input_error + : std::runtime_error + { + input_error( const std::string& message, const int in_errorno ) + : std::runtime_error( message ), + errorno( in_errorno ) + { + } + + int errorno; + }; + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#define TAOCPP_PEGTL_THROW_INPUT_ERROR( MESSAGE ) \ + do { \ + const int errorno = errno; \ + std::ostringstream oss; \ + oss << "pegtl: " << MESSAGE << " errno " << errorno; \ + throw tao::TAOCPP_PEGTL_NAMESPACE::input_error( oss.str(), errorno ); \ + } while( false ) + +#endif diff --git a/MoonParser/pegtl/internal/action.hpp b/MoonParser/pegtl/internal/action.hpp new file mode 100644 index 0000000..933bffe --- /dev/null +++ b/MoonParser/pegtl/internal/action.hpp @@ -0,0 +1,52 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_ACTION_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_ACTION_HPP + +#include "../config.hpp" + +#include "duseltronik.hpp" +#include "seq.hpp" +#include "skip_control.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + 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, + rewind_mode M, + template< typename... > class, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + return duseltronik< seq< Rules... >, A, M, Action, Control >::match( in, st... ); + } + }; + + template< template< typename... > class Action, typename... Rules > + struct skip_control< action< Action, Rules... > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/action_input.hpp b/MoonParser/pegtl/internal/action_input.hpp new file mode 100644 index 0000000..db48950 --- /dev/null +++ b/MoonParser/pegtl/internal/action_input.hpp @@ -0,0 +1,108 @@ +// Copyright (c) 2016-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_ACTION_INPUT_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_ACTION_INPUT_HPP + +#include +#include + +#include "iterator.hpp" + +#include "../config.hpp" +#include "../position.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + inline const char* begin_c_ptr( const char* p ) noexcept + { + return p; + } + + inline const char* begin_c_ptr( const iterator& it ) noexcept + { + return it.data; + } + + template< typename Input > + class action_input + { + public: + using input_t = Input; + using iterator_t = typename Input::iterator_t; + + action_input( const iterator_t& in_begin, const Input& in_input ) noexcept + : m_begin( in_begin ), + m_input( in_input ) + { + } + + action_input( const action_input& ) = delete; + action_input& operator=( const action_input& ) = delete; + + const iterator_t& iterator() const noexcept + { + return m_begin; + } + + const Input& input() const noexcept + { + return m_input; + } + + const char* begin() const noexcept + { + return begin_c_ptr( iterator() ); + } + + const char* end() const noexcept + { + return input().current(); + } + + bool empty() const noexcept + { + return begin() == end(); + } + + std::size_t size() const noexcept + { + return std::size_t( end() - begin() ); + } + + std::string string() const + { + return std::string( begin(), end() ); + } + + char peek_char( const std::size_t offset = 0 ) const noexcept + { + return begin()[ offset ]; + } + + unsigned char peek_byte( const std::size_t offset = 0 ) const noexcept + { + return static_cast< unsigned char >( peek_char( offset ) ); + } + + TAOCPP_PEGTL_NAMESPACE::position position() const noexcept + { + return input().position( iterator() ); // NOTE: Not efficient with LAZY inputs. + } + + protected: + const iterator_t m_begin; + const Input& m_input; + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/alnum.hpp b/MoonParser/pegtl/internal/alnum.hpp new file mode 100644 index 0000000..cdad330 --- /dev/null +++ b/MoonParser/pegtl/internal/alnum.hpp @@ -0,0 +1,26 @@ +// Copyright (c) 2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_ALNUM_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_ALNUM_HPP + +#include "../config.hpp" + +#include "peek_char.hpp" +#include "ranges.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + using alnum = ranges< peek_char, 'a', 'z', 'A', 'Z', '0', '9' >; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/alpha.hpp b/MoonParser/pegtl/internal/alpha.hpp new file mode 100644 index 0000000..d696ca2 --- /dev/null +++ b/MoonParser/pegtl/internal/alpha.hpp @@ -0,0 +1,26 @@ +// Copyright (c) 2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_ALPHA_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_ALPHA_HPP + +#include "../config.hpp" + +#include "peek_char.hpp" +#include "ranges.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + using alpha = ranges< peek_char, 'a', 'z', 'A', 'Z' >; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/any.hpp b/MoonParser/pegtl/internal/any.hpp new file mode 100644 index 0000000..aebe239 --- /dev/null +++ b/MoonParser/pegtl/internal/any.hpp @@ -0,0 +1,68 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_ANY_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_ANY_HPP + +#include "../config.hpp" + +#include "peek_char.hpp" +#include "skip_control.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename Peek > + struct any; + + 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; + } + }; + + template< typename Peek > + struct skip_control< any< Peek > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/apply.hpp b/MoonParser/pegtl/internal/apply.hpp new file mode 100644 index 0000000..4e70255 --- /dev/null +++ b/MoonParser/pegtl/internal/apply.hpp @@ -0,0 +1,79 @@ +// Copyright (c) 2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_APPLY_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_APPLY_HPP + +#include "../config.hpp" + +#include "skip_control.hpp" +#include "trivial.hpp" + +#include "../analysis/counted.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< apply_mode A, typename... Actions > + struct apply_impl; + + template< typename... Actions > + struct apply_impl< apply_mode::ACTION, Actions... > + { + template< typename Input, typename... States > + static bool match( Input& in, States&&... st ) + { + using action_t = typename Input::action_t; + const action_t i2( in.iterator(), in ); // No data -- range is from begin to begin. +#ifdef __cpp_fold_expressions + ( Actions::apply( i2, st... ), ... ); +#else + using swallow = bool[]; + (void)swallow{ ( Actions::apply( i2, st... ), true )..., true }; +#endif + return true; + } + }; + + template< typename... Actions > + struct apply_impl< apply_mode::NOTHING, Actions... > + { + template< typename Input, typename... States > + static bool match( Input&, States&&... ) + { + return true; + } + }; + + template< typename... Actions > + struct apply + { + using analyze_t = analysis::counted< analysis::rule_type::ANY, 0 >; + + template< apply_mode A, + rewind_mode M, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + return apply_impl< A, Actions... >::match( in, st... ); + } + }; + + template< typename... Actions > + struct skip_control< apply< Actions... > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/apply0.hpp b/MoonParser/pegtl/internal/apply0.hpp new file mode 100644 index 0000000..c8aa7aa --- /dev/null +++ b/MoonParser/pegtl/internal/apply0.hpp @@ -0,0 +1,77 @@ +// Copyright (c) 2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_APPLY0_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_APPLY0_HPP + +#include "../config.hpp" + +#include "skip_control.hpp" +#include "trivial.hpp" + +#include "../analysis/counted.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< apply_mode A, typename... Actions > + struct apply0_impl; + + template< typename... Actions > + struct apply0_impl< apply_mode::ACTION, Actions... > + { + template< typename... States > + static bool match( States&&... st ) + { +#ifdef __cpp_fold_expressions + ( Actions::apply0( st... ), ... ); +#else + using swallow = bool[]; + (void)swallow{ ( Actions::apply0( st... ), true )..., true }; +#endif + return true; + } + }; + + template< typename... Actions > + struct apply0_impl< apply_mode::NOTHING, Actions... > + { + template< typename... States > + static bool match( States&&... ) + { + return true; + } + }; + + template< typename... Actions > + struct apply0 + { + using analyze_t = analysis::counted< analysis::rule_type::ANY, 0 >; + + template< apply_mode A, + rewind_mode M, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input&, States&&... st ) + { + return apply0_impl< A, Actions... >::match( st... ); + } + }; + + template< typename... Actions > + struct skip_control< apply0< Actions... > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/at.hpp b/MoonParser/pegtl/internal/at.hpp new file mode 100644 index 0000000..d5bb455 --- /dev/null +++ b/MoonParser/pegtl/internal/at.hpp @@ -0,0 +1,62 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_AT_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_AT_HPP + +#include "../config.hpp" + +#include "rule_conjunction.hpp" +#include "skip_control.hpp" +#include "trivial.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename... Rules > + struct at; + + template<> + struct at<> + : trivial< true > + { + }; + + template< typename... Rules > + struct at + { + using analyze_t = analysis::generic< analysis::rule_type::OPT, Rules... >; + + template< apply_mode, + rewind_mode, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + const auto m = in.template mark< rewind_mode::REQUIRED >(); + return rule_conjunction< Rules... >::template match< apply_mode::NOTHING, rewind_mode::ACTIVE, Action, Control >( in, st... ); + } + }; + + template< typename... Rules > + struct skip_control< at< Rules... > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/bof.hpp b/MoonParser/pegtl/internal/bof.hpp new file mode 100644 index 0000000..8a1dde7 --- /dev/null +++ b/MoonParser/pegtl/internal/bof.hpp @@ -0,0 +1,41 @@ +// Copyright (c) 2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_BOF_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_BOF_HPP + +#include "../config.hpp" + +#include "skip_control.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + struct bof + { + using analyze_t = analysis::generic< analysis::rule_type::OPT >; + + template< typename Input > + static bool match( Input& in ) noexcept + { + return in.byte() == 0; + } + }; + + template<> + struct skip_control< bof > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/bol.hpp b/MoonParser/pegtl/internal/bol.hpp new file mode 100644 index 0000000..bf3e33f --- /dev/null +++ b/MoonParser/pegtl/internal/bol.hpp @@ -0,0 +1,41 @@ +// Copyright (c) 2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_BOL_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_BOL_HPP + +#include "../config.hpp" + +#include "skip_control.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + struct bol + { + using analyze_t = analysis::generic< analysis::rule_type::OPT >; + + template< typename Input > + static bool match( Input& in ) noexcept + { + return in.byte_in_line() == 0; + } + }; + + template<> + struct skip_control< bol > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/bump_help.hpp b/MoonParser/pegtl/internal/bump_help.hpp new file mode 100644 index 0000000..577870e --- /dev/null +++ b/MoonParser/pegtl/internal/bump_help.hpp @@ -0,0 +1,64 @@ +// Copyright (c) 2015-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_BUMP_UTIL_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_BUMP_UTIL_HPP + +#include +#include + +#include "../config.hpp" + +#include "result_on_found.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< bool > + struct bump_impl; + + template<> + struct bump_impl< true > + { + template< typename Input > + static void bump( Input& in, const std::size_t count ) noexcept + { + in.bump( count ); + } + }; + + template<> + struct bump_impl< false > + { + template< typename Input > + static void bump( Input& in, const std::size_t count ) noexcept + { + in.bump_in_this_line( count ); + } + }; + + template< bool... > + struct bool_list + { + }; + + template< bool... Bs > + using bool_and = std::is_same< bool_list< Bs..., true >, bool_list< true, Bs... > >; + + template< result_on_found R, typename Input, typename Char, Char... Cs > + void bump_help( Input& in, const std::size_t count ) noexcept + { + using eol_t = typename Input::eol_t; + bump_impl< bool_and< ( Cs != eol_t::ch )... >::value != bool( R ) >::bump( in, count ); + } + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/bump_impl.hpp b/MoonParser/pegtl/internal/bump_impl.hpp new file mode 100644 index 0000000..6ab9005 --- /dev/null +++ b/MoonParser/pegtl/internal/bump_impl.hpp @@ -0,0 +1,53 @@ +// Copyright (c) 2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_BUMP_IMPL_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_BUMP_IMPL_HPP + +#include "../config.hpp" + +#include "iterator.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + inline void bump( iterator& iter, const std::size_t count, const int ch ) noexcept + { + for( std::size_t i = 0; i < count; ++i ) { + if( iter.data[ i ] == ch ) { + ++iter.line; + iter.byte_in_line = 0; + } + else { + ++iter.byte_in_line; + } + } + iter.byte += count; + iter.data += count; + } + + inline void bump_in_this_line( iterator& iter, const std::size_t count ) noexcept + { + iter.data += count; + iter.byte += count; + iter.byte_in_line += count; + } + + inline void bump_to_next_line( iterator& iter, const std::size_t count ) noexcept + { + ++iter.line; + iter.byte += count; + iter.byte_in_line = 0; + iter.data += count; + } + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/bytes.hpp b/MoonParser/pegtl/internal/bytes.hpp new file mode 100644 index 0000000..c180a68 --- /dev/null +++ b/MoonParser/pegtl/internal/bytes.hpp @@ -0,0 +1,46 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_BYTES_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_BYTES_HPP + +#include "../config.hpp" + +#include "skip_control.hpp" + +#include "../analysis/counted.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + 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 ) >= Num ) { + in.bump( Num ); + return true; + } + return false; + } + }; + + template< unsigned Num > + struct skip_control< bytes< Num > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/control.hpp b/MoonParser/pegtl/internal/control.hpp new file mode 100644 index 0000000..16fab5c --- /dev/null +++ b/MoonParser/pegtl/internal/control.hpp @@ -0,0 +1,52 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_CONTROL_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_CONTROL_HPP + +#include "../config.hpp" + +#include "duseltronik.hpp" +#include "seq.hpp" +#include "skip_control.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + 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, + rewind_mode M, + template< typename... > class Action, + template< typename... > class, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + return duseltronik< seq< Rules... >, A, M, Action, Control >::match( in, st... ); + } + }; + + template< template< typename... > class Control, typename... Rules > + struct skip_control< control< Control, Rules... > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/cr_crlf_eol.hpp b/MoonParser/pegtl/internal/cr_crlf_eol.hpp new file mode 100644 index 0000000..ebfc75d --- /dev/null +++ b/MoonParser/pegtl/internal/cr_crlf_eol.hpp @@ -0,0 +1,39 @@ +// Copyright (c) 2016-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_CR_CRLF_EOL_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_CR_CRLF_EOL_HPP + +#include "../config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + struct cr_crlf_eol + { + static constexpr int ch = '\r'; + + template< typename Input > + static eol_pair match( Input& in ) + { + eol_pair p = { false, in.size( 2 ) }; + if( p.second ) { + if( in.peek_char() == '\r' ) { + in.bump_to_next_line( 1 + ( ( p.second > 1 ) && ( in.peek_char( 1 ) == '\n' ) ) ); + p.first = true; + } + } + return p; + } + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/cr_eol.hpp b/MoonParser/pegtl/internal/cr_eol.hpp new file mode 100644 index 0000000..79388eb --- /dev/null +++ b/MoonParser/pegtl/internal/cr_eol.hpp @@ -0,0 +1,39 @@ +// Copyright (c) 2016-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_CR_EOL_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_CR_EOL_HPP + +#include "../config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + struct cr_eol + { + static constexpr int ch = '\r'; + + template< typename Input > + static eol_pair match( Input& in ) + { + eol_pair p = { false, in.size( 1 ) }; + if( p.second ) { + if( in.peek_char() == '\r' ) { + in.bump_to_next_line(); + p.first = true; + } + } + return p; + } + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/crlf_eol.hpp b/MoonParser/pegtl/internal/crlf_eol.hpp new file mode 100644 index 0000000..621b6b3 --- /dev/null +++ b/MoonParser/pegtl/internal/crlf_eol.hpp @@ -0,0 +1,39 @@ +// Copyright (c) 2016-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_CRLF_EOL_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_CRLF_EOL_HPP + +#include "../config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + struct crlf_eol + { + static constexpr int ch = '\n'; + + template< typename Input > + static eol_pair match( Input& in ) + { + eol_pair p = { false, in.size( 2 ) }; + if( p.second > 1 ) { + if( ( in.peek_char() == '\r' ) && ( in.peek_char( 1 ) == '\n' ) ) { + in.bump_to_next_line( 2 ); + p.first = true; + } + } + return p; + } + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/cstream_reader.hpp b/MoonParser/pegtl/internal/cstream_reader.hpp new file mode 100644 index 0000000..c1670bf --- /dev/null +++ b/MoonParser/pegtl/internal/cstream_reader.hpp @@ -0,0 +1,48 @@ +// Copyright (c) 2016-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_CSTREAM_READER_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_CSTREAM_READER_HPP + +#include +#include + +#include "../config.hpp" +#include "../input_error.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + struct cstream_reader + { + explicit cstream_reader( std::FILE* s ) noexcept + : m_cstream( s ) + { + } + + std::size_t operator()( char* buffer, const std::size_t length ) + { + if( const auto r = std::fread( buffer, 1, length, m_cstream ) ) { + return r; + } + if( std::feof( m_cstream ) != 0 ) { + return 0; + } + // Please contact us if you know how to provoke the following exception. + // The example on cppreference.com doesn't work, at least not on macOS. + TAOCPP_PEGTL_THROW_INPUT_ERROR( "error in fread() from cstream" ); // LCOV_EXCL_LINE + } + + std::FILE* m_cstream; + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/cstring_reader.hpp b/MoonParser/pegtl/internal/cstring_reader.hpp new file mode 100644 index 0000000..ff8c11e --- /dev/null +++ b/MoonParser/pegtl/internal/cstring_reader.hpp @@ -0,0 +1,49 @@ +// Copyright (c) 2016-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_CSTRING_READER_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_CSTRING_READER_HPP + +#include +#include + +#include "../config.hpp" +#include "../input_error.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + struct cstring_reader + { + explicit cstring_reader( const char* zero_terminated ) noexcept + : m_cstring( zero_terminated ) + { + assert( m_cstring ); + } + + std::size_t operator()( char* buffer, const std::size_t length ) noexcept + { + std::size_t i = 0; + char c; + + while( ( i < length ) && ( ( c = m_cstring[ i ] ) != 0 ) ) { + *buffer++ = c; + ++i; + } + m_cstring += i; + return i; + } + + const char* m_cstring; + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/demangle.hpp b/MoonParser/pegtl/internal/demangle.hpp new file mode 100644 index 0000000..64efe6f --- /dev/null +++ b/MoonParser/pegtl/internal/demangle.hpp @@ -0,0 +1,44 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_DEMANGLE_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_DEMANGLE_HPP + +#include +#include + +#include "../config.hpp" + +#if defined( __GLIBCXX__ ) +#include "demangle_cxxabi.hpp" +#elif defined( __has_include ) +// clang-format off +#if __has_include( ) +// clang-format on +#include "demangle_cxxabi.hpp" +#else +#include "demangle_nop.hpp" +#endif +#else +#include "demangle_nop.hpp" +#endif + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename T > + std::string demangle() + { + return demangle( typeid( T ).name() ); + } + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/demangle_cxxabi.hpp b/MoonParser/pegtl/internal/demangle_cxxabi.hpp new file mode 100644 index 0000000..aba72f9 --- /dev/null +++ b/MoonParser/pegtl/internal/demangle_cxxabi.hpp @@ -0,0 +1,41 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_DEMANGLE_CXXABI_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_DEMANGLE_CXXABI_HPP + +#include +#include +#include +#include + +#include "../config.hpp" + +#include "demangle_sanitise.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + 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 ); + if( !demangled ) { + return symbol; + } + std::string result( demangled.get() ); +#ifdef TAOCPP_PEGTL_PRETTY_DEMANGLE + demangle_sanitise_chars( result ); +#endif + return result; + } + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/demangle_nop.hpp b/MoonParser/pegtl/internal/demangle_nop.hpp new file mode 100644 index 0000000..70bf3ec --- /dev/null +++ b/MoonParser/pegtl/internal/demangle_nop.hpp @@ -0,0 +1,28 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_DEMANGLE_NOP_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_DEMANGLE_NOP_HPP + +#include + +#include "../config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + inline std::string demangle( const char* symbol ) + { + return symbol; + } + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/demangle_sanitise.hpp b/MoonParser/pegtl/internal/demangle_sanitise.hpp new file mode 100644 index 0000000..f869ea6 --- /dev/null +++ b/MoonParser/pegtl/internal/demangle_sanitise.hpp @@ -0,0 +1,48 @@ +// Copyright (c) 2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_DEMANGLE_SANITISE_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_DEMANGLE_SANITISE_HPP + +#include + +#include "../config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + inline void demangle_sanitise_chars( std::string& s ) + { + std::string::size_type p; + while( ( p = s.find( "(char)" ) ) != std::string::npos ) { + int c = 0; + std::string::size_type q; + for( q = p + 6; ( q < s.size() ) && ( s[ q ] >= '0' ) && ( s[ q ] <= '9' ); ++q ) { + c *= 10; + c += s[ q ] - '0'; + } + if( c == '\'' ) { + s.replace( p, q - p, "'\\''" ); + } + else if( c == '\\' ) { + s.replace( p, q - p, "'\\\\'" ); + } + else if( ( c < 32 ) || ( c > 126 ) ) { + s.replace( p, 6, std::string() ); + } + else { + s.replace( p, q - p, std::string( 1, '\'' ) + char( c ) + '\'' ); + } + } + } + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/disable.hpp b/MoonParser/pegtl/internal/disable.hpp new file mode 100644 index 0000000..19ccb1e --- /dev/null +++ b/MoonParser/pegtl/internal/disable.hpp @@ -0,0 +1,52 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_DISABLE_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_DISABLE_HPP + +#include "../config.hpp" + +#include "duseltronik.hpp" +#include "seq.hpp" +#include "skip_control.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename... Rules > + struct disable + { + using analyze_t = analysis::generic< analysis::rule_type::SEQ, Rules... >; + + template< apply_mode, + rewind_mode M, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + return duseltronik< seq< Rules... >, apply_mode::NOTHING, M, Action, Control >::match( in, st... ); + } + }; + + template< typename... Rules > + struct skip_control< disable< Rules... > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/discard.hpp b/MoonParser/pegtl/internal/discard.hpp new file mode 100644 index 0000000..9aac60f --- /dev/null +++ b/MoonParser/pegtl/internal/discard.hpp @@ -0,0 +1,42 @@ +// Copyright (c) 2016-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_DISCARD_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_DISCARD_HPP + +#include "../config.hpp" + +#include "skip_control.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + struct discard + { + using analyze_t = analysis::generic< analysis::rule_type::OPT >; + + template< typename Input > + static bool match( Input& in ) + { + in.discard(); + return true; + } + }; + + template<> + struct skip_control< discard > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/dusel_mode.hpp b/MoonParser/pegtl/internal/dusel_mode.hpp new file mode 100644 index 0000000..df757aa --- /dev/null +++ b/MoonParser/pegtl/internal/dusel_mode.hpp @@ -0,0 +1,25 @@ +// Copyright (c) 2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_DUSEL_MODE_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_DUSEL_MODE_HPP + +#include "../config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + enum class dusel_mode : char + { + NOTHING = 0, + CONTROL = 1, + CONTROL_AND_APPLY = 2, + CONTROL_AND_APPLY0 = 3 + }; + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/duseltronik.hpp b/MoonParser/pegtl/internal/duseltronik.hpp new file mode 100644 index 0000000..23a6e1f --- /dev/null +++ b/MoonParser/pegtl/internal/duseltronik.hpp @@ -0,0 +1,114 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_DUSELTRONIK_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_DUSELTRONIK_HPP + +#include "../apply_mode.hpp" +#include "../config.hpp" +#include "../rewind_mode.hpp" + +#include "dusel_mode.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > class Action, + template< typename... > class Control, + dusel_mode = dusel_mode::NOTHING > + struct duseltronik; + + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > class Action, + template< typename... > class Control > + struct duseltronik< Rule, A, M, Action, Control, dusel_mode::NOTHING > + { + template< typename Input, typename... States > + static auto match( Input& in, States&&... st ) -> decltype( Rule::template match< A, M, Action, Control >( in, st... ), true ) + { + return Rule::template match< A, M, 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 ); + } + }; + + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > class Action, + template< typename... > class Control > + struct duseltronik< Rule, A, M, Action, Control, dusel_mode::CONTROL > + { + template< typename Input, typename... States > + static bool match( Input& in, States&&... st ) + { + Control< Rule >::start( const_cast< const Input& >( in ), st... ); + + if( duseltronik< Rule, A, M, Action, Control, dusel_mode::NOTHING >::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, + rewind_mode M, + template< typename... > class Action, + template< typename... > class Control > + struct duseltronik< Rule, A, M, Action, Control, dusel_mode::CONTROL_AND_APPLY > + { + template< typename Input, typename... States > + static bool match( Input& in, States&&... st ) + { + auto m = in.template mark< rewind_mode::REQUIRED >(); + + if( duseltronik< Rule, A, rewind_mode::ACTIVE, Action, Control, dusel_mode::CONTROL >::match( in, st... ) ) { + Control< Rule >::template apply< Action >( m.iterator(), const_cast< const Input& >( in ), st... ); + return m( true ); + } + return false; + } + }; + + template< typename Rule, + apply_mode A, + rewind_mode M, + template< typename... > class Action, + template< typename... > class Control > + struct duseltronik< Rule, A, M, Action, Control, dusel_mode::CONTROL_AND_APPLY0 > + { + template< typename Input, typename... States > + static bool match( Input& in, States&&... st ) + { + if( duseltronik< Rule, A, M, Action, Control, dusel_mode::CONTROL >::match( in, st... ) ) { + Control< Rule >::template apply0< Action >( const_cast< const Input& >( in ), st... ); + return true; + } + return false; + } + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/enable.hpp b/MoonParser/pegtl/internal/enable.hpp new file mode 100644 index 0000000..c01268c --- /dev/null +++ b/MoonParser/pegtl/internal/enable.hpp @@ -0,0 +1,52 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_ENABLE_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_ENABLE_HPP + +#include "../config.hpp" + +#include "duseltronik.hpp" +#include "seq.hpp" +#include "skip_control.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename... Rules > + struct enable + { + using analyze_t = analysis::generic< analysis::rule_type::SEQ, Rules... >; + + template< apply_mode, + rewind_mode M, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + return duseltronik< seq< Rules... >, apply_mode::ACTION, M, Action, Control >::match( in, st... ); + } + }; + + template< typename... Rules > + struct skip_control< enable< Rules... > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/eof.hpp b/MoonParser/pegtl/internal/eof.hpp new file mode 100644 index 0000000..a702fa6 --- /dev/null +++ b/MoonParser/pegtl/internal/eof.hpp @@ -0,0 +1,41 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_EOF_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_EOF_HPP + +#include "../config.hpp" + +#include "skip_control.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + 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 + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/eol.hpp b/MoonParser/pegtl/internal/eol.hpp new file mode 100644 index 0000000..bfd43c2 --- /dev/null +++ b/MoonParser/pegtl/internal/eol.hpp @@ -0,0 +1,42 @@ +// Copyright (c) 2016-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_EOL_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_EOL_HPP + +#include "../config.hpp" + +#include "skip_control.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + struct eol + { + using analyze_t = analysis::generic< analysis::rule_type::ANY >; + + template< typename Input > + static bool match( Input& in ) + { + using eol_t = typename Input::eol_t; + return eol_t::match( in ).first; + } + }; + + template<> + struct skip_control< eol > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/eolf.hpp b/MoonParser/pegtl/internal/eolf.hpp new file mode 100644 index 0000000..168311c --- /dev/null +++ b/MoonParser/pegtl/internal/eolf.hpp @@ -0,0 +1,43 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_EOLF_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_EOLF_HPP + +#include "../config.hpp" + +#include "skip_control.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + struct eolf + { + using analyze_t = analysis::generic< analysis::rule_type::OPT >; + + template< typename Input > + static bool match( Input& in ) + { + using eol_t = typename Input::eol_t; + const auto p = eol_t::match( in ); + return p.first || ( !p.second ); + } + }; + + template<> + struct skip_control< eolf > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/file_mapper.hpp b/MoonParser/pegtl/internal/file_mapper.hpp new file mode 100644 index 0000000..800b9df --- /dev/null +++ b/MoonParser/pegtl/internal/file_mapper.hpp @@ -0,0 +1,91 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_FILE_MAPPER_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_FILE_MAPPER_HPP + +#include +#include + +#include "../config.hpp" + +#include "file_opener.hpp" + +#include "../input_error.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + class file_mapper + { + public: + explicit file_mapper( const char* filename ) + : file_mapper( file_opener( filename ) ) + { + } + + explicit file_mapper( const file_opener& reader ) + : m_size( reader.size() ), + m_data( static_cast< const char* >(::mmap( nullptr, m_size, PROT_READ, MAP_PRIVATE, reader.m_fd, 0 ) ) ) + { + if( m_size && ( intptr_t( m_data ) == -1 ) ) { + TAOCPP_PEGTL_THROW_INPUT_ERROR( "unable to mmap() file " << reader.m_source << " descriptor " << reader.m_fd ); + } + } + + ~file_mapper() noexcept + { + ::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 noexcept + { + return m_size == 0; + } + + std::size_t size() const noexcept + { + return m_size; + } + + using iterator = const char*; + using const_iterator = const char*; + + iterator data() const noexcept + { + return m_data; + } + + iterator begin() const noexcept + { + return m_data; + } + + iterator end() const noexcept + { + 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; + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/file_opener.hpp b/MoonParser/pegtl/internal/file_opener.hpp new file mode 100644 index 0000000..0b1ad6d --- /dev/null +++ b/MoonParser/pegtl/internal/file_opener.hpp @@ -0,0 +1,70 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_FILE_OPENER_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_FILE_OPENER_HPP + +#include +#include +#include +#include + +#include + +#include "../config.hpp" +#include "../input_error.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + struct file_opener + { + explicit file_opener( const char* filename ) + : m_source( filename ), + m_fd( open() ) + { + } + + ~file_opener() noexcept + { + ::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 ) { + TAOCPP_PEGTL_THROW_INPUT_ERROR( "unable to fstat() file " << m_source << " descriptor " << m_fd ); + } + return std::size_t( st.st_size ); + } + + const char* const m_source; + const int m_fd; + + private: + int open() const + { + errno = 0; + const int fd = ::open( m_source, O_RDONLY ); + if( fd >= 0 ) { + return fd; + } + TAOCPP_PEGTL_THROW_INPUT_ERROR( "unable to open() file " << m_source << " for reading" ); + } + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/file_reader.hpp b/MoonParser/pegtl/internal/file_reader.hpp new file mode 100644 index 0000000..9bcdf97 --- /dev/null +++ b/MoonParser/pegtl/internal/file_reader.hpp @@ -0,0 +1,96 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_FILE_READER_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_FILE_READER_HPP + +#include +#include +#include +#include + +#include "../config.hpp" +#include "../input_error.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + struct file_close + { + void operator()( FILE* f ) const + { + std::fclose( f ); + } + }; + + class file_reader + { + public: + explicit file_reader( const char* filename ) + : m_source( filename ), + m_file( open() ) + { + } + + 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 ) != 0 ) { + TAOCPP_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 ) { + TAOCPP_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 ) != 0 ) { + TAOCPP_PEGTL_THROW_INPUT_ERROR( "unable to fseek() to beginning of file " << m_source ); // LCOV_EXCL_LINE + } + return std::size_t( s ); + } + + std::string read() const + { + std::string nrv; + nrv.resize( size() ); + errno = 0; + if( ( nrv.size() != 0 ) && ( std::fread( &nrv[ 0 ], nrv.size(), 1, m_file.get() ) != 1 ) ) { + TAOCPP_PEGTL_THROW_INPUT_ERROR( "unable to fread() file " << m_source << " size " << nrv.size() ); // LCOV_EXCL_LINE + } + return nrv; + } + + private: + const char* const m_source; + const std::unique_ptr< std::FILE, file_close > m_file; + + std::FILE* open() const + { + errno = 0; +#if defined( _MSC_VER ) + std::FILE* file; + if(::fopen_s( &file, m_source, "rb" ) == 0 ) +#else + if( auto* file = std::fopen( m_source, "rb" ) ) +#endif + { + return file; + } + TAOCPP_PEGTL_THROW_INPUT_ERROR( "unable to fopen() file " << m_source << " for reading" ); + } + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/has_apply0.hpp b/MoonParser/pegtl/internal/has_apply0.hpp new file mode 100644 index 0000000..01ef7f9 --- /dev/null +++ b/MoonParser/pegtl/internal/has_apply0.hpp @@ -0,0 +1,38 @@ +// Copyright (c) 2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_HAS_APPLY0_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_HAS_APPLY0_HPP + +#include + +#include "../config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename... S > + struct type_list + { + }; + + template< typename A, typename L, typename = void > + struct has_apply0 : std::false_type + { + }; + + template< typename A, typename... S > + struct has_apply0< A, type_list< S... >, decltype( A::apply0( std::declval< S >()... ), void() ) > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/identifier.hpp b/MoonParser/pegtl/internal/identifier.hpp new file mode 100644 index 0000000..1ee4571 --- /dev/null +++ b/MoonParser/pegtl/internal/identifier.hpp @@ -0,0 +1,30 @@ +// Copyright (c) 2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_IDENTIFIER_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_IDENTIFIER_HPP + +#include "../config.hpp" + +#include "peek_char.hpp" +#include "ranges.hpp" +#include "seq.hpp" +#include "star.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + using identifier_first = ranges< peek_char, 'a', 'z', 'A', 'Z', '_' >; + using identifier_other = ranges< peek_char, 'a', 'z', 'A', 'Z', '0', '9', '_' >; + using identifier = seq< identifier_first, star< identifier_other > >; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/if_apply.hpp b/MoonParser/pegtl/internal/if_apply.hpp new file mode 100644 index 0000000..1e6bb99 --- /dev/null +++ b/MoonParser/pegtl/internal/if_apply.hpp @@ -0,0 +1,90 @@ +// Copyright (c) 2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_IF_APPLY_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_IF_APPLY_HPP + +#include "../config.hpp" + +#include "skip_control.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< apply_mode A, typename Rule, typename... Actions > + struct if_apply_impl; + + template< typename Rule, typename... Actions > + struct if_apply_impl< apply_mode::ACTION, Rule, Actions... > + { + template< rewind_mode, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + using action_t = typename Input::action_t; + + auto m = in.template mark< rewind_mode::REQUIRED >(); + + if( Control< Rule >::template match< apply_mode::ACTION, rewind_mode::ACTIVE, Action, Control >( in, st... ) ) { + const action_t i2( m.iterator(), in ); +#ifdef __cpp_fold_expressions + ( Actions::apply( i2, st... ), ... ); +#else + using swallow = bool[]; + (void)swallow{ ( Actions::apply( i2, st... ), true )..., true }; +#endif + return m( true ); + } + return false; + } + }; + + template< typename Rule, typename... Actions > + struct if_apply_impl< apply_mode::NOTHING, Rule, Actions... > + { + template< rewind_mode M, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + return Control< Rule >::template match< apply_mode::NOTHING, M, Action, Control >( in, st... ); + } + }; + + template< typename Rule, typename... Actions > + struct if_apply + { + using analyze_t = typename Rule::analyze_t; + + template< apply_mode A, + rewind_mode M, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + return if_apply_impl< A, Rule, Actions... >::template match< M, Action, Control >( in, st... ); + } + }; + + template< typename Rule, typename... Actions > + struct skip_control< if_apply< Rule, Actions... > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/if_must.hpp b/MoonParser/pegtl/internal/if_must.hpp new file mode 100644 index 0000000..2a56d7e --- /dev/null +++ b/MoonParser/pegtl/internal/if_must.hpp @@ -0,0 +1,27 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_IF_MUST_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_IF_MUST_HPP + +#include "../config.hpp" + +#include "must.hpp" +#include "seq.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename Cond, typename... Thens > + using if_must = seq< Cond, must< Thens... > >; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/if_must_else.hpp b/MoonParser/pegtl/internal/if_must_else.hpp new file mode 100644 index 0000000..2ccb205 --- /dev/null +++ b/MoonParser/pegtl/internal/if_must_else.hpp @@ -0,0 +1,27 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_IF_MUST_ELSE_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_IF_MUST_ELSE_HPP + +#include "../config.hpp" + +#include "if_then_else.hpp" +#include "must.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename Cond, typename Then, typename Else > + using if_must_else = if_then_else< Cond, must< Then >, must< Else > >; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/if_then_else.hpp b/MoonParser/pegtl/internal/if_then_else.hpp new file mode 100644 index 0000000..e55831f --- /dev/null +++ b/MoonParser/pegtl/internal/if_then_else.hpp @@ -0,0 +1,59 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_IF_THEN_ELSE_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_IF_THEN_ELSE_HPP + +#include "../config.hpp" + +#include "not_at.hpp" +#include "seq.hpp" +#include "skip_control.hpp" +#include "sor.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + 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, + rewind_mode M, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + auto m = in.template mark< M >(); + using m_t = decltype( m ); + + if( Control< Cond >::template match< A, rewind_mode::REQUIRED, Action, Control >( in, st... ) ) { + return m( Control< Then >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) ); + } + return m( Control< Else >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) ); + } + }; + + template< typename Cond, typename Then, typename Else > + struct skip_control< if_then_else< Cond, Then, Else > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/input_pair.hpp b/MoonParser/pegtl/internal/input_pair.hpp new file mode 100644 index 0000000..de4e6ba --- /dev/null +++ b/MoonParser/pegtl/internal/input_pair.hpp @@ -0,0 +1,35 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_INPUT_PAIR_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_INPUT_PAIR_HPP + +#include "../config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename Data > + struct input_pair + { + Data data; + unsigned char size; + + using data_t = Data; + + explicit operator bool() const noexcept + { + return size > 0; + } + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/integer_sequence.hpp b/MoonParser/pegtl/internal/integer_sequence.hpp new file mode 100644 index 0000000..cdcf20d --- /dev/null +++ b/MoonParser/pegtl/internal/integer_sequence.hpp @@ -0,0 +1,85 @@ +// Copyright (c) 2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_INTEGER_SEQUENCE_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_INTEGER_SEQUENCE_HPP + +#include +#include +#include + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename T, T... Ns > + struct integer_sequence + { + using value_type = T; + + static constexpr std::size_t size() noexcept + { + return sizeof...( Ns ); + } + }; + + template< std::size_t... Ns > + using index_sequence = integer_sequence< std::size_t, Ns... >; + + template< typename, std::size_t, bool > + struct double_up; + + template< typename T, T... Ns, std::size_t N > + struct double_up< integer_sequence< T, Ns... >, N, false > + { + using type = integer_sequence< T, Ns..., ( N + Ns )... >; + }; + + template< typename T, T... Ns, std::size_t N > + struct double_up< integer_sequence< T, Ns... >, N, true > + { + using type = integer_sequence< T, Ns..., ( N + Ns )..., 2 * N >; + }; + + template< typename T, T N, typename = void > + struct generate_sequence; + + template< typename T, T N > + using generate_sequence_t = typename generate_sequence< T, N >::type; + + template< typename T, T N, typename > + struct generate_sequence + : double_up< generate_sequence_t< T, N / 2 >, N / 2, N % 2 == 1 > + { + }; + + template< typename T, T N > + struct generate_sequence< T, N, typename std::enable_if< ( N == 0 ) >::type > + { + using type = integer_sequence< T >; + }; + + template< typename T, T N > + struct generate_sequence< T, N, typename std::enable_if< ( N == 1 ) >::type > + { + using type = integer_sequence< T, 0 >; + }; + + template< typename T, T N > + using make_integer_sequence = generate_sequence_t< T, N >; + + template< std::size_t N > + using make_index_sequence = make_integer_sequence< std::size_t, N >; + + template< typename... Ts > + using index_sequence_for = make_index_sequence< sizeof...( Ts ) >; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/istream_reader.hpp b/MoonParser/pegtl/internal/istream_reader.hpp new file mode 100644 index 0000000..8509080 --- /dev/null +++ b/MoonParser/pegtl/internal/istream_reader.hpp @@ -0,0 +1,47 @@ +// Copyright (c) 2016-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_ISTREAM_READER_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_ISTREAM_READER_HPP + +#include + +#include "../config.hpp" +#include "../input_error.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + struct istream_reader + { + explicit istream_reader( std::istream& s ) noexcept + : m_istream( s ) + { + } + + std::size_t operator()( char* buffer, const std::size_t length ) + { + m_istream.read( buffer, std::streamsize( length ) ); + + if( const auto r = m_istream.gcount() ) { + return std::size_t( r ); + } + if( m_istream.eof() ) { + return 0; + } + TAOCPP_PEGTL_THROW_INPUT_ERROR( "error in istream.read()" ); + } + + std::istream& m_istream; + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/istring.hpp b/MoonParser/pegtl/internal/istring.hpp new file mode 100644 index 0000000..3ed2835 --- /dev/null +++ b/MoonParser/pegtl/internal/istring.hpp @@ -0,0 +1,107 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_ISTRING_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_ISTRING_HPP + +#include + +#include "../config.hpp" + +#include "bump_help.hpp" +#include "result_on_found.hpp" +#include "skip_control.hpp" +#include "trivial.hpp" + +#include "../analysis/counted.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + 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 ) noexcept + { + return ( C | 0x20 ) == ( c | 0x20 ); + } + }; + + template< char C > + struct ichar_equal< C, false > + { + static bool match( const char c ) noexcept + { + return c == C; + } + }; + + template< char... Cs > + struct istring_equal; + + template<> + struct istring_equal<> + { + static bool match( const char* ) noexcept + { + return true; + } + }; + + template< char C, char... Cs > + struct istring_equal< C, Cs... > + { + static bool match( const char* r ) noexcept + { + return ichar_equal< C >::match( *r ) && istring_equal< Cs... >::match( r + 1 ); + } + }; + + template< char... Cs > + struct istring; + + 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 ) ) >= sizeof...( Cs ) ) { + if( istring_equal< Cs... >::match( in.current() ) ) { + bump_help< result_on_found::SUCCESS, Input, char, Cs... >( in, sizeof...( Cs ) ); + return true; + } + } + return false; + } + }; + + template< char... Cs > + struct skip_control< istring< Cs... > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/iterator.hpp b/MoonParser/pegtl/internal/iterator.hpp new file mode 100644 index 0000000..4179738 --- /dev/null +++ b/MoonParser/pegtl/internal/iterator.hpp @@ -0,0 +1,53 @@ +// Copyright (c) 2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_ITERATOR_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_ITERATOR_HPP + +#include + +#include "../config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + struct iterator + { + iterator() noexcept = default; + + explicit iterator( const char* in_data ) noexcept + : data( in_data ), + byte( 0 ), + line( 1 ), + byte_in_line( 0 ) + { + } + + iterator( const char* in_data, const std::size_t in_byte, const std::size_t in_line, const std::size_t in_byte_in_line ) noexcept + : data( in_data ), + byte( in_byte ), + line( in_line ), + byte_in_line( in_byte_in_line ) + { + } + + iterator( const iterator& ) = default; + iterator& operator=( const iterator& ) = default; + + const char* data; + + std::size_t byte; + std::size_t line; + std::size_t byte_in_line; + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/lf_crlf_eol.hpp b/MoonParser/pegtl/internal/lf_crlf_eol.hpp new file mode 100644 index 0000000..90b5b03 --- /dev/null +++ b/MoonParser/pegtl/internal/lf_crlf_eol.hpp @@ -0,0 +1,44 @@ +// Copyright (c) 2016-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_LF_CRLF_EOL_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_LF_CRLF_EOL_HPP + +#include "../config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + struct lf_crlf_eol + { + static constexpr int ch = '\n'; + + template< typename Input > + static eol_pair match( Input& in ) + { + eol_pair p = { false, in.size( 2 ) }; + if( p.second ) { + const auto a = in.peek_char(); + if( a == '\n' ) { + in.bump_to_next_line(); + p.first = true; + } + else if( ( a == '\r' ) && ( p.second > 1 ) && ( in.peek_char( 1 ) == '\n' ) ) { + in.bump_to_next_line( 2 ); + p.first = true; + } + } + return p; + } + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/lf_eol.hpp b/MoonParser/pegtl/internal/lf_eol.hpp new file mode 100644 index 0000000..438b8f0 --- /dev/null +++ b/MoonParser/pegtl/internal/lf_eol.hpp @@ -0,0 +1,39 @@ +// Copyright (c) 2016-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_LF_EOL_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_LF_EOL_HPP + +#include "../config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + struct lf_eol + { + static constexpr int ch = '\n'; + + template< typename Input > + static eol_pair match( Input& in ) + { + eol_pair p = { false, in.size( 1 ) }; + if( p.second ) { + if( in.peek_char() == '\n' ) { + in.bump_to_next_line(); + p.first = true; + } + } + return p; + } + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/list.hpp b/MoonParser/pegtl/internal/list.hpp new file mode 100644 index 0000000..1a812fb --- /dev/null +++ b/MoonParser/pegtl/internal/list.hpp @@ -0,0 +1,27 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_LIST_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_LIST_HPP + +#include "../config.hpp" + +#include "seq.hpp" +#include "star.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename Rule, typename Sep > + using list = seq< Rule, star< Sep, Rule > >; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/list_must.hpp b/MoonParser/pegtl/internal/list_must.hpp new file mode 100644 index 0000000..9b60311 --- /dev/null +++ b/MoonParser/pegtl/internal/list_must.hpp @@ -0,0 +1,28 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_LIST_MUST_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_LIST_MUST_HPP + +#include "../config.hpp" + +#include "must.hpp" +#include "seq.hpp" +#include "star.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename Rule, typename Sep > + using list_must = seq< Rule, star< Sep, must< Rule > > >; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/list_tail.hpp b/MoonParser/pegtl/internal/list_tail.hpp new file mode 100644 index 0000000..dd7b920 --- /dev/null +++ b/MoonParser/pegtl/internal/list_tail.hpp @@ -0,0 +1,28 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_LIST_TAIL_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_LIST_TAIL_HPP + +#include "../config.hpp" + +#include "list.hpp" +#include "opt.hpp" +#include "seq.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename Rule, typename Sep > + using list_tail = seq< list< Rule, Sep >, opt< Sep > >; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/list_tail_pad.hpp b/MoonParser/pegtl/internal/list_tail_pad.hpp new file mode 100644 index 0000000..0f3ebf6 --- /dev/null +++ b/MoonParser/pegtl/internal/list_tail_pad.hpp @@ -0,0 +1,30 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_LIST_TAIL_PAD_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_LIST_TAIL_PAD_HPP + +#include "../config.hpp" + +#include "list.hpp" +#include "opt.hpp" +#include "pad.hpp" +#include "seq.hpp" +#include "star.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename Rule, typename Sep, typename Pad > + using list_tail_pad = seq< list< Rule, pad< Sep, Pad > >, opt< star< Pad >, Sep > >; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/marker.hpp b/MoonParser/pegtl/internal/marker.hpp new file mode 100644 index 0000000..76cba0e --- /dev/null +++ b/MoonParser/pegtl/internal/marker.hpp @@ -0,0 +1,93 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_MARKER_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_MARKER_HPP + +#include "../config.hpp" +#include "../rewind_mode.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename Iterator, rewind_mode M > + class marker + { + public: + static constexpr rewind_mode next_rewind_mode = M; + + explicit marker( const Iterator& ) noexcept + { + } + + marker( marker&& ) noexcept + { + } + + marker( const marker& ) = delete; + void operator=( const marker& ) = delete; + + bool operator()( const bool result ) const noexcept + { + return result; + } + }; + + template< typename Iterator > + class marker< Iterator, rewind_mode::REQUIRED > + { + public: + static constexpr rewind_mode next_rewind_mode = rewind_mode::ACTIVE; + + explicit marker( Iterator& i ) noexcept + : m_saved( i ), + m_input( &i ) + { + } + + marker( marker&& i ) noexcept + : m_saved( i.m_saved ), + m_input( i.m_input ) + { + i.m_input = nullptr; + } + + ~marker() noexcept + { + if( m_input != nullptr ) { + ( *m_input ) = m_saved; + } + } + + marker( const marker& ) = delete; + void operator=( const marker& ) = delete; + + bool operator()( const bool result ) noexcept + { + if( result ) { + m_input = nullptr; + return true; + } + return false; + } + + const Iterator& iterator() const noexcept + { + return m_saved; + } + + private: + const Iterator m_saved; + Iterator* m_input; + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/minus.hpp b/MoonParser/pegtl/internal/minus.hpp new file mode 100644 index 0000000..88242e5 --- /dev/null +++ b/MoonParser/pegtl/internal/minus.hpp @@ -0,0 +1,69 @@ +// Copyright (c) 2016-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_MINUS_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_MINUS_HPP + +#include "../config.hpp" + +#include "skip_control.hpp" + +#include "../apply_mode.hpp" +#include "../memory_input.hpp" +#include "../rewind_mode.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + inline const char* source_pointer( const char* source ) noexcept + { + return source; + } + + inline const char* source_pointer( const std::string& source ) noexcept + { + return source.c_str(); + } + + template< typename R, typename S > + struct minus + { + using analyze_t = typename R::analyze_t; // NOTE: S is currently ignored for analyze(). + + template< apply_mode A, + rewind_mode, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + auto m = in.template mark< rewind_mode::REQUIRED >(); + + if( !Control< R >::template match< A, rewind_mode::ACTIVE, Action, Control >( in, st... ) ) { + return false; + } + memory_input< tracking_mode::LAZY, typename Input::eol_t, const char* > i2( m.iterator(), in.current(), source_pointer( in.source() ) ); + + if( !Control< S >::template match< apply_mode::NOTHING, rewind_mode::ACTIVE, Action, Control >( i2, st... ) ) { + return m( true ); + } + return m( !i2.empty() ); + } + }; + + template< typename R, typename S > + struct skip_control< minus< R, S > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/must.hpp b/MoonParser/pegtl/internal/must.hpp new file mode 100644 index 0000000..4ac9920 --- /dev/null +++ b/MoonParser/pegtl/internal/must.hpp @@ -0,0 +1,79 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_MUST_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_MUST_HPP + +#include "../config.hpp" + +#include "raise.hpp" +#include "rule_conjunction.hpp" +#include "skip_control.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + // The general case applies must<> to each of the + // rules in the 'Rules' parameter pack individually. + + template< typename... Rules > + struct must + { + using analyze_t = analysis::generic< analysis::rule_type::SEQ, Rules... >; + + template< apply_mode A, + rewind_mode M, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + return rule_conjunction< must< Rules >... >::template match< A, M, Action, Control >( in, st... ); + } + }; + + // 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, + rewind_mode, + 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, rewind_mode::DONTCARE, Action, Control >( in, st... ) ) { + raise< Rule >::template match< A, rewind_mode::DONTCARE, Action, Control >( in, st... ); + } + return true; + } + }; + + template< typename... Rules > + struct skip_control< must< Rules... > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/not_at.hpp b/MoonParser/pegtl/internal/not_at.hpp new file mode 100644 index 0000000..ed80c56 --- /dev/null +++ b/MoonParser/pegtl/internal/not_at.hpp @@ -0,0 +1,62 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_NOT_AT_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_NOT_AT_HPP + +#include "../config.hpp" + +#include "rule_conjunction.hpp" +#include "skip_control.hpp" +#include "trivial.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename... Rules > + struct not_at; + + 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, + rewind_mode, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + const auto m = in.template mark< rewind_mode::REQUIRED >(); + return !rule_conjunction< Rules... >::template match< apply_mode::NOTHING, rewind_mode::ACTIVE, Action, Control >( in, st... ); + } + }; + + template< typename... Rules > + struct skip_control< not_at< Rules... > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/one.hpp b/MoonParser/pegtl/internal/one.hpp new file mode 100644 index 0000000..a3941eb --- /dev/null +++ b/MoonParser/pegtl/internal/one.hpp @@ -0,0 +1,81 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_ONE_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_ONE_HPP + +#include +#include + +#include "../config.hpp" + +#include "bump_help.hpp" +#include "result_on_found.hpp" +#include "skip_control.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename Char > + bool contains( const Char c, const std::initializer_list< Char >& l ) noexcept + { + 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_help< 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_help< 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 + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/opt.hpp b/MoonParser/pegtl/internal/opt.hpp new file mode 100644 index 0000000..a897443 --- /dev/null +++ b/MoonParser/pegtl/internal/opt.hpp @@ -0,0 +1,67 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_OPT_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_OPT_HPP + +#include + +#include "../config.hpp" + +#include "duseltronik.hpp" +#include "seq.hpp" +#include "skip_control.hpp" +#include "trivial.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename... Rules > + struct opt; + + template<> + struct opt<> + : trivial< true > + { + }; + + template< typename... Rules > + struct opt + { + using analyze_t = analysis::generic< analysis::rule_type::OPT, Rules... >; + + template< apply_mode A, + rewind_mode, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + if( !in.empty() ) { + duseltronik< seq< Rules... >, A, rewind_mode::REQUIRED, Action, Control >::match( in, st... ); + } + return true; + } + }; + + template< typename... Rules > + struct skip_control< opt< Rules... > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/pad.hpp b/MoonParser/pegtl/internal/pad.hpp new file mode 100644 index 0000000..fcb6e4f --- /dev/null +++ b/MoonParser/pegtl/internal/pad.hpp @@ -0,0 +1,27 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_PAD_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_PAD_HPP + +#include "../config.hpp" + +#include "seq.hpp" +#include "star.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename Rule, typename Pad1, typename Pad2 = Pad1 > + using pad = seq< star< Pad1 >, Rule, star< Pad2 > >; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/pad_opt.hpp b/MoonParser/pegtl/internal/pad_opt.hpp new file mode 100644 index 0000000..4b7d400 --- /dev/null +++ b/MoonParser/pegtl/internal/pad_opt.hpp @@ -0,0 +1,28 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_PAD_OPT_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_PAD_OPT_HPP + +#include "../config.hpp" + +#include "opt.hpp" +#include "seq.hpp" +#include "star.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename Rule, typename Pad > + using pad_opt = seq< star< Pad >, opt< Rule, star< Pad > > >; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/peek_char.hpp b/MoonParser/pegtl/internal/peek_char.hpp new file mode 100644 index 0000000..064e6da --- /dev/null +++ b/MoonParser/pegtl/internal/peek_char.hpp @@ -0,0 +1,35 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_PEEK_CHAR_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_PEEK_CHAR_HPP + +#include + +#include "input_pair.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + 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 }; + } + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/peek_utf16.hpp b/MoonParser/pegtl/internal/peek_utf16.hpp new file mode 100644 index 0000000..a643b1f --- /dev/null +++ b/MoonParser/pegtl/internal/peek_utf16.hpp @@ -0,0 +1,54 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_PEEK_UTF16_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_PEEK_UTF16_HPP + +#include + +#include "../config.hpp" + +#include "input_pair.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + 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( 4 ); + if( s >= 2 ) { + const char32_t t = *reinterpret_cast< const short_t* >( in.current() ); + if( ( t < 0xd800 ) || ( t > 0xdbff ) || ( s < 4 ) ) { + return { t, 2 }; + } + const char32_t u = *reinterpret_cast< const short_t* >( in.current() + 2 ); + if( ( u < 0xdc00 ) || ( u > 0xdfff ) ) { + return { t, 2 }; + } + return { ( ( ( t & 0x03ff ) << 10 ) | ( u & 0x03ff ) ) + 0x10000, 4 }; + } + return { 0, 0 }; + } + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/peek_utf32.hpp b/MoonParser/pegtl/internal/peek_utf32.hpp new file mode 100644 index 0000000..f082064 --- /dev/null +++ b/MoonParser/pegtl/internal/peek_utf32.hpp @@ -0,0 +1,46 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_PEEK_UTF32_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_PEEK_UTF32_HPP + +#include + +#include "../config.hpp" + +#include "input_pair.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + 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( 4 ); + if( s >= 4 ) { + const char32_t t = *reinterpret_cast< const char32_t* >( in.current() ); + if( ( 0 <= t ) && ( t <= 0x10ffff ) ) { + return { t, 4 }; + } + } + return { 0, 0 }; + } + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/peek_utf8.hpp b/MoonParser/pegtl/internal/peek_utf8.hpp new file mode 100644 index 0000000..9ea0a0e --- /dev/null +++ b/MoonParser/pegtl/internal/peek_utf8.hpp @@ -0,0 +1,88 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_PEEK_UTF8_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_PEEK_UTF8_HPP + +#include "../config.hpp" + +#include "input_pair.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + 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 }; + } + if( ( c0 & 0xE0 ) == 0xC0 ) { + if( in.size( 2 ) >= 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 ) >= 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 ) >= 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 }; + } + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/pegtl_string.hpp b/MoonParser/pegtl/internal/pegtl_string.hpp new file mode 100644 index 0000000..7c27fd8 --- /dev/null +++ b/MoonParser/pegtl/internal/pegtl_string.hpp @@ -0,0 +1,98 @@ +// Copyright (c) 2015-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_TAOCPP_PEGTL_STRING_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_TAOCPP_PEGTL_STRING_HPP + +#include +#include + +#include "../ascii.hpp" +#include "../config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + // 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< typename, typename, typename, typename, typename, typename, typename, typename > + struct string_join; + + template< template< char... > class S, char... C0s, char... C1s, char... C2s, char... C3s, char... C4s, char... C5s, char... C6s, char... C7s > + struct string_join< S< C0s... >, S< C1s... >, S< C2s... >, S< C3s... >, S< C4s... >, S< C5s... >, S< C6s... >, S< C7s... > > + { + using type = S< C0s..., C1s..., C2s..., C3s..., C4s..., C5s..., C6s..., C7s... >; + }; + + template< template< char... > class S, char, bool > + struct string_at + { + using type = S<>; + }; + + template< template< char... > class S, char C > + struct string_at< S, C, true > + { + using type = S< C >; + }; + + template< typename T, std::size_t S > + struct string_max_length + { + static_assert( S <= 512, "String longer than 512 (excluding terminating \\0)!" ); + using type = T; + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#define TAOCPP_PEGTL_INTERNAL_EMPTY() +#define TAOCPP_PEGTL_INTERNAL_DEFER( X ) X TAOCPP_PEGTL_INTERNAL_EMPTY() +#define TAOCPP_PEGTL_INTERNAL_EXPAND( ... ) __VA_ARGS__ + +#define TAOCPP_PEGTL_INTERNAL_STRING_AT( S, x, n ) \ + tao::TAOCPP_PEGTL_NAMESPACE::internal::string_at< S, ( 0##n < sizeof( x ) ) ? x[ 0##n ] : 0, ( 0##n < sizeof( x ) - 1 ) >::type + +#define TAOCPP_PEGTL_INTERNAL_JOIN_8( M, S, x, n ) \ + tao::TAOCPP_PEGTL_NAMESPACE::internal::string_join< TAOCPP_PEGTL_INTERNAL_DEFER( M )( S, x, n##0 ), \ + TAOCPP_PEGTL_INTERNAL_DEFER( M )( S, x, n##1 ), \ + TAOCPP_PEGTL_INTERNAL_DEFER( M )( S, x, n##2 ), \ + TAOCPP_PEGTL_INTERNAL_DEFER( M )( S, x, n##3 ), \ + TAOCPP_PEGTL_INTERNAL_DEFER( M )( S, x, n##4 ), \ + TAOCPP_PEGTL_INTERNAL_DEFER( M )( S, x, n##5 ), \ + TAOCPP_PEGTL_INTERNAL_DEFER( M )( S, x, n##6 ), \ + TAOCPP_PEGTL_INTERNAL_DEFER( M )( S, x, n##7 ) >::type + +#define TAOCPP_PEGTL_INTERNAL_STRING_8( S, x, n ) \ + TAOCPP_PEGTL_INTERNAL_JOIN_8( TAOCPP_PEGTL_INTERNAL_STRING_AT, S, x, n ) + +#define TAOCPP_PEGTL_INTERNAL_STRING_64( S, x, n ) \ + TAOCPP_PEGTL_INTERNAL_JOIN_8( TAOCPP_PEGTL_INTERNAL_STRING_8, S, x, n ) + +#define TAOCPP_PEGTL_INTERNAL_STRING_512( S, x, n ) \ + TAOCPP_PEGTL_INTERNAL_JOIN_8( TAOCPP_PEGTL_INTERNAL_STRING_64, S, x, n ) + +#define TAOCPP_PEGTL_INTERNAL_STRING( S, x ) \ + TAOCPP_PEGTL_INTERNAL_EXPAND( \ + TAOCPP_PEGTL_INTERNAL_EXPAND( \ + TAOCPP_PEGTL_INTERNAL_EXPAND( \ + tao::TAOCPP_PEGTL_NAMESPACE::internal::string_max_length< TAOCPP_PEGTL_INTERNAL_STRING_512( S, x, ), sizeof( x ) - 1 >::type ) ) ) + +#define TAOCPP_PEGTL_STRING( x ) \ + TAOCPP_PEGTL_INTERNAL_STRING( tao::TAOCPP_PEGTL_NAMESPACE::ascii::string, x ) + +#define TAOCPP_PEGTL_ISTRING( x ) \ + TAOCPP_PEGTL_INTERNAL_STRING( tao::TAOCPP_PEGTL_NAMESPACE::ascii::istring, x ) + +#define TAOCPP_PEGTL_KEYWORD( x ) \ + TAOCPP_PEGTL_INTERNAL_STRING( tao::TAOCPP_PEGTL_NAMESPACE::ascii::keyword, x ) + +#endif diff --git a/MoonParser/pegtl/internal/plus.hpp b/MoonParser/pegtl/internal/plus.hpp new file mode 100644 index 0000000..5adc1f8 --- /dev/null +++ b/MoonParser/pegtl/internal/plus.hpp @@ -0,0 +1,61 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_PLUS_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_PLUS_HPP + +#include + +#include "../config.hpp" + +#include "duseltronik.hpp" +#include "opt.hpp" +#include "seq.hpp" +#include "skip_control.hpp" +#include "star.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + // While plus<> could easily be implemented with + // seq< Rule, Rules ..., star< Rule, Rules ... > > we + // provide an explicit implementation to optimise 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, + rewind_mode M, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + return duseltronik< seq< Rule, Rules... >, A, M, Action, Control >::match( in, st... ) && duseltronik< star< Rule, Rules... >, A, M, Action, Control >::match( in, st... ); + } + }; + + template< typename Rule, typename... Rules > + struct skip_control< plus< Rule, Rules... > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/raise.hpp b/MoonParser/pegtl/internal/raise.hpp new file mode 100644 index 0000000..d183ce0 --- /dev/null +++ b/MoonParser/pegtl/internal/raise.hpp @@ -0,0 +1,57 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_RAISE_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_RAISE_HPP + +#include +#include + +#include "../config.hpp" + +#include "skip_control.hpp" + +#include "../analysis/generic.hpp" +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename T > + struct raise + { + using analyze_t = analysis::generic< analysis::rule_type::ANY >; + + template< apply_mode, + rewind_mode, + 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... ); +#if defined( _MSC_VER ) + __assume( false ); // LCOV_EXCL_LINE +#else + std::abort(); // LCOV_EXCL_LINE +#endif + } + }; + + template< typename T > + struct skip_control< raise< T > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/range.hpp b/MoonParser/pegtl/internal/range.hpp new file mode 100644 index 0000000..227595f --- /dev/null +++ b/MoonParser/pegtl/internal/range.hpp @@ -0,0 +1,60 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_RANGE_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_RANGE_HPP + +#include "../config.hpp" + +#include "bump_help.hpp" +#include "result_on_found.hpp" +#include "skip_control.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + 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 >; + + template< int Eol > + struct can_match_eol + { + static constexpr bool value = ( ( ( Lo <= Eol ) && ( Eol <= Hi ) ) == bool( R ) ); + }; + + template< typename Input > + static bool match( Input& in ) + { + using eol_t = typename Input::eol_t; + + if( !in.empty() ) { + if( const auto t = Peek::peek( in ) ) { + if( ( ( Lo <= t.data ) && ( t.data <= Hi ) ) == bool( R ) ) { + bump_impl< can_match_eol< eol_t::ch >::value >::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 + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/ranges.hpp b/MoonParser/pegtl/internal/ranges.hpp new file mode 100644 index 0000000..e3ee65c --- /dev/null +++ b/MoonParser/pegtl/internal/ranges.hpp @@ -0,0 +1,102 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_RANGES_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_RANGES_HPP + +#include "../config.hpp" + +#include "bump_help.hpp" +#include "range.hpp" +#include "skip_control.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< int Eol, typename Char, Char... Cs > + struct ranges_impl; + + template< int Eol, typename Char > + struct ranges_impl< Eol, Char > + { + static constexpr bool can_match_eol = false; + + static bool match( const Char ) noexcept + { + return false; + } + }; + + template< int Eol, typename Char, Char Eq > + struct ranges_impl< Eol, Char, Eq > + { + static constexpr bool can_match_eol = ( Eq == Eol ); + + static bool match( const Char c ) noexcept + { + return c == Eq; + } + }; + + template< int Eol, typename Char, Char Lo, Char Hi, Char... Cs > + struct ranges_impl< Eol, Char, Lo, Hi, Cs... > + { + static constexpr bool can_match_eol = ( ( ( Lo <= Eol ) && ( Eol <= Hi ) ) || ranges_impl< Eol, Char, Cs... >::can_match_eol ); + + static bool match( const Char c ) noexcept + { + return ( ( Lo <= c ) && ( c <= Hi ) ) || ranges_impl< Eol, Char, Cs... >::match( c ); + } + }; + + template< typename Peek, typename Peek::data_t... Cs > + struct ranges + { + using analyze_t = analysis::generic< analysis::rule_type::ANY >; + + template< int Eol > + struct can_match_eol + { + static constexpr bool value = ranges_impl< Eol, typename Peek::data_t, Cs... >::can_match_eol; + }; + + template< typename Input > + static bool match( Input& in ) + { + using eol_t = typename Input::eol_t; + + if( !in.empty() ) { + if( const auto t = Peek::peek( in ) ) { + if( ranges_impl< eol_t::ch, typename Peek::data_t, Cs... >::match( t.data ) ) { + bump_impl< can_match_eol< eol_t::ch >::value >::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 + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/rep.hpp b/MoonParser/pegtl/internal/rep.hpp new file mode 100644 index 0000000..df66ee2 --- /dev/null +++ b/MoonParser/pegtl/internal/rep.hpp @@ -0,0 +1,75 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_REP_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_REP_HPP + +#include "../config.hpp" + +#include "rule_conjunction.hpp" +#include "skip_control.hpp" +#include "trivial.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" + +#include "../analysis/counted.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< unsigned Num, typename... Rules > + struct rep; + + 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, + rewind_mode M, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + auto m = in.template mark< M >(); + using m_t = decltype( m ); + + for( unsigned i = 0; i != Num; ++i ) { + if( !rule_conjunction< Rules... >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) ) { + return false; + } + } + return m( true ); + } + }; + + template< unsigned Num, typename... Rules > + struct skip_control< rep< Num, Rules... > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/rep_min.hpp b/MoonParser/pegtl/internal/rep_min.hpp new file mode 100644 index 0000000..f5e61da --- /dev/null +++ b/MoonParser/pegtl/internal/rep_min.hpp @@ -0,0 +1,28 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_REP_MIN_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_REP_MIN_HPP + +#include "../config.hpp" + +#include "rep.hpp" +#include "seq.hpp" +#include "star.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< unsigned Min, typename Rule, typename... Rules > + using rep_min = seq< rep< Min, Rule, Rules... >, star< Rule, Rules... > >; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/rep_min_max.hpp b/MoonParser/pegtl/internal/rep_min_max.hpp new file mode 100644 index 0000000..7463398 --- /dev/null +++ b/MoonParser/pegtl/internal/rep_min_max.hpp @@ -0,0 +1,88 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_REP_MIN_MAX_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_REP_MIN_MAX_HPP + +#include + +#include "../config.hpp" + +#include "duseltronik.hpp" +#include "not_at.hpp" +#include "rule_conjunction.hpp" +#include "seq.hpp" +#include "skip_control.hpp" +#include "trivial.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" + +#include "../analysis/counted.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< unsigned Min, unsigned Max, typename... Rules > + struct rep_min_max; + + template< unsigned Min, unsigned Max > + struct rep_min_max< Min, Max > + : trivial< false > + { + static_assert( Min <= Max, "invalid 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, "invalid rep_min_max rule (maximum number of repetitions smaller than minimum)" ); + + template< apply_mode A, + rewind_mode M, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + auto m = in.template mark< M >(); + using m_t = decltype( m ); + + for( unsigned i = 0; i != Min; ++i ) { + if( !rule_conjunction< Rules... >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) ) { + return false; + } + } + for( unsigned i = Min; i != Max; ++i ) { + if( !duseltronik< seq< Rules... >, A, rewind_mode::REQUIRED, Action, Control >::match( in, st... ) ) { + return m( true ); + } + } + return m( duseltronik< not_at< Rules... >, A, m_t::next_rewind_mode, Action, Control >::match( in, st... ) ); // NOTE that not_at<> will always rewind. + } + }; + + template< unsigned Min, unsigned Max, typename... Rules > + struct skip_control< rep_min_max< Min, Max, Rules... > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/rep_opt.hpp b/MoonParser/pegtl/internal/rep_opt.hpp new file mode 100644 index 0000000..55bcd47 --- /dev/null +++ b/MoonParser/pegtl/internal/rep_opt.hpp @@ -0,0 +1,54 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_REP_OPT_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_REP_OPT_HPP + +#include "../config.hpp" + +#include "duseltronik.hpp" +#include "seq.hpp" +#include "skip_control.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< unsigned Max, typename... Rules > + struct rep_opt + { + using analyze_t = analysis::generic< analysis::rule_type::OPT, Rules... >; + + template< apply_mode A, + rewind_mode, + 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 ) && duseltronik< seq< Rules... >, A, rewind_mode::REQUIRED, Action, Control >::match( in, st... ); ++i ) { + } + return true; + } + }; + + template< unsigned Max, typename... Rules > + struct skip_control< rep_opt< Max, Rules... > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/require.hpp b/MoonParser/pegtl/internal/require.hpp new file mode 100644 index 0000000..0506356 --- /dev/null +++ b/MoonParser/pegtl/internal/require.hpp @@ -0,0 +1,52 @@ +// Copyright (c) 2016-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_REQUIRE_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_REQUIRE_HPP + +#include "../config.hpp" + +#include "skip_control.hpp" +#include "trivial.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< unsigned Amount > + struct require; + + template<> + struct require< 0 > + : trivial< true > + { + }; + + template< unsigned Amount > + struct require + { + using analyze_t = analysis::generic< analysis::rule_type::OPT >; + + template< typename Input > + static bool match( Input& in ) + { + return in.size( Amount ) >= Amount; + } + }; + + template< unsigned Amount > + struct skip_control< require< Amount > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/result_on_found.hpp b/MoonParser/pegtl/internal/result_on_found.hpp new file mode 100644 index 0000000..e41f35c --- /dev/null +++ b/MoonParser/pegtl/internal/result_on_found.hpp @@ -0,0 +1,27 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_RESULT_ON_FOUND_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_RESULT_ON_FOUND_HPP + +#include "../config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + enum class result_on_found : bool + { + SUCCESS = true, + FAILURE = false + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/rule_conjunction.hpp b/MoonParser/pegtl/internal/rule_conjunction.hpp new file mode 100644 index 0000000..2eb41e2 --- /dev/null +++ b/MoonParser/pegtl/internal/rule_conjunction.hpp @@ -0,0 +1,63 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_RULE_CONJUNCTION_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_RULE_CONJUNCTION_HPP + +#include "../apply_mode.hpp" +#include "../config.hpp" +#include "../rewind_mode.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename... Rules > + struct rule_conjunction; + + template<> + struct rule_conjunction<> + { + template< apply_mode A, + rewind_mode M, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input&, States&&... ) + { + return true; + } + }; + + template< typename... Rules > + struct rule_conjunction + { + template< apply_mode A, + rewind_mode M, + 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, M, Action, Control >( in, st... ) && ... ); +#else + bool result = true; + using swallow = bool[]; + (void)swallow{ result = result && Control< Rules >::template match< A, M, Action, Control >( in, st... )... }; + return result; +#endif + } + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/rules.hpp b/MoonParser/pegtl/internal/rules.hpp new file mode 100644 index 0000000..91725ae --- /dev/null +++ b/MoonParser/pegtl/internal/rules.hpp @@ -0,0 +1,61 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_RULES_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_RULES_HPP + +#include "action.hpp" +#include "alnum.hpp" +#include "alpha.hpp" +#include "any.hpp" +#include "apply.hpp" +#include "apply0.hpp" +#include "at.hpp" +#include "bof.hpp" +#include "bol.hpp" +#include "bytes.hpp" +#include "control.hpp" +#include "disable.hpp" +#include "discard.hpp" +#include "enable.hpp" +#include "eof.hpp" +#include "eol.hpp" +#include "eolf.hpp" +#include "identifier.hpp" +#include "if_apply.hpp" +#include "if_must.hpp" +#include "if_must_else.hpp" +#include "if_then_else.hpp" +#include "istring.hpp" +#include "list.hpp" +#include "list_must.hpp" +#include "list_tail.hpp" +#include "list_tail_pad.hpp" +#include "minus.hpp" +#include "must.hpp" +#include "not_at.hpp" +#include "one.hpp" +#include "opt.hpp" +#include "pad.hpp" +#include "pad_opt.hpp" +#include "plus.hpp" +#include "raise.hpp" +#include "range.hpp" +#include "ranges.hpp" +#include "rep.hpp" +#include "rep_min.hpp" +#include "rep_min_max.hpp" +#include "rep_opt.hpp" +#include "require.hpp" +#include "seq.hpp" +#include "skip_control.hpp" +#include "sor.hpp" +#include "star.hpp" +#include "star_must.hpp" +#include "state.hpp" +#include "string.hpp" +#include "trivial.hpp" +#include "try_catch_type.hpp" +#include "until.hpp" + +#endif diff --git a/MoonParser/pegtl/internal/seq.hpp b/MoonParser/pegtl/internal/seq.hpp new file mode 100644 index 0000000..f99cc7c --- /dev/null +++ b/MoonParser/pegtl/internal/seq.hpp @@ -0,0 +1,80 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_SEQ_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_SEQ_HPP + +#include "../config.hpp" + +#include "rule_conjunction.hpp" +#include "skip_control.hpp" +#include "trivial.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename... Rules > + struct seq; + + template<> + struct seq<> + : trivial< true > + { + }; + + template< typename Rule > + struct seq< Rule > + { + using analyze_t = typename Rule::analyze_t; + + template< apply_mode A, + rewind_mode M, + 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, M, Action, Control >( in, st... ); + } + }; + + template< typename... Rules > + struct seq + { + using analyze_t = analysis::generic< analysis::rule_type::SEQ, Rules... >; + + template< apply_mode A, + rewind_mode M, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + auto m = in.template mark< M >(); + using m_t = decltype( m ); + return m( rule_conjunction< Rules... >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) ); + } + }; + + template< typename... Rules > + struct skip_control< seq< Rules... > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/skip_control.hpp b/MoonParser/pegtl/internal/skip_control.hpp new file mode 100644 index 0000000..e40ace5 --- /dev/null +++ b/MoonParser/pegtl/internal/skip_control.hpp @@ -0,0 +1,35 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_SKIP_CONTROL_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_SKIP_CONTROL_HPP + +#include + +#include "../config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + 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. + + template< typename Rule > + struct skip_control : std::false_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/sor.hpp b/MoonParser/pegtl/internal/sor.hpp new file mode 100644 index 0000000..6d85a5c --- /dev/null +++ b/MoonParser/pegtl/internal/sor.hpp @@ -0,0 +1,74 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_SOR_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_SOR_HPP + +#include "../config.hpp" + +#include "skip_control.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" + +#include "../analysis/generic.hpp" + +#include "integer_sequence.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename... Rules > + struct sor; + + template<> + struct sor<> + : trivial< false > + { + }; + + template< typename... Rules > + struct sor + : sor< index_sequence_for< Rules... >, Rules... > + { + }; + + template< std::size_t... Indices, typename... Rules > + struct sor< index_sequence< Indices... >, Rules... > + { + using analyze_t = analysis::generic< analysis::rule_type::SOR, Rules... >; + + template< apply_mode A, + rewind_mode M, + 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, ( Indices == ( sizeof...( Rules ) - 1 ) ) ? M : rewind_mode::REQUIRED, Action, Control > ( in, st... ) || ... ); +#else + bool result = false; + using swallow = bool[]; + (void)swallow{ result = result || Control< Rules >::template match < A, ( Indices == ( sizeof...( Rules ) - 1 ) ) ? M : rewind_mode::REQUIRED, Action, Control > ( in, st... )... }; + return result; +#endif + } + }; + + template< typename... Rules > + struct skip_control< sor< Rules... > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/star.hpp b/MoonParser/pegtl/internal/star.hpp new file mode 100644 index 0000000..854f25f --- /dev/null +++ b/MoonParser/pegtl/internal/star.hpp @@ -0,0 +1,56 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_STAR_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_STAR_HPP + +#include + +#include "../config.hpp" + +#include "duseltronik.hpp" +#include "seq.hpp" +#include "skip_control.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + 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, + rewind_mode, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + while( duseltronik< seq< Rule, Rules... >, A, rewind_mode::REQUIRED, Action, Control >::match( in, st... ) ) { + } + return true; + } + }; + + template< typename Rule, typename... Rules > + struct skip_control< star< Rule, Rules... > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/star_must.hpp b/MoonParser/pegtl/internal/star_must.hpp new file mode 100644 index 0000000..baaef4f --- /dev/null +++ b/MoonParser/pegtl/internal/star_must.hpp @@ -0,0 +1,27 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_STAR_MUST_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_STAR_MUST_HPP + +#include "../config.hpp" + +#include "if_must.hpp" +#include "star.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename Cond, typename... Rules > + using star_must = star< if_must< Cond, Rules... > >; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/state.hpp b/MoonParser/pegtl/internal/state.hpp new file mode 100644 index 0000000..7fbe921 --- /dev/null +++ b/MoonParser/pegtl/internal/state.hpp @@ -0,0 +1,83 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_STATE_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_STATE_HPP + +#include "../config.hpp" + +#include "duseltronik.hpp" +#include "seq.hpp" +#include "skip_control.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename State, typename... Rules > + struct state + { + using analyze_t = analysis::generic< analysis::rule_type::SEQ, Rules... >; + + template< apply_mode A, + rewind_mode M, + 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, M, Action, Control >( in, st... ), void() ) + { + s.template success< A, M, Action, Control >( in, st... ); + } + + // NOTE: The additional "int = 0" is a work-around for missing expression SFINAE in VS2015. + + template< apply_mode, + rewind_mode, + 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, + rewind_mode M, + 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( duseltronik< seq< Rules... >, A, M, Action, Control >::match( in, s ) ) { + success< A, M, Action, Control >( s, in, st... ); + return true; + } + return false; + } + }; + + template< typename State, typename... Rules > + struct skip_control< state< State, Rules... > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/string.hpp b/MoonParser/pegtl/internal/string.hpp new file mode 100644 index 0000000..75245e3 --- /dev/null +++ b/MoonParser/pegtl/internal/string.hpp @@ -0,0 +1,68 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_STRING_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_STRING_HPP + +#include +#include + +#include "../config.hpp" + +#include "bump_help.hpp" +#include "result_on_found.hpp" +#include "skip_control.hpp" +#include "trivial.hpp" + +#include "../analysis/counted.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + inline bool unsafe_equals( const char* s, const std::initializer_list< char >& l ) noexcept + { + return std::memcmp( s, &*l.begin(), l.size() ) == 0; + } + + template< char... Cs > + struct string; + + 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 ) ) >= sizeof...( Cs ) ) { + if( unsafe_equals( in.current(), { Cs... } ) ) { + bump_help< result_on_found::SUCCESS, Input, char, Cs... >( in, sizeof...( Cs ) ); + return true; + } + } + return false; + } + }; + + template< char... Cs > + struct skip_control< string< Cs... > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/trivial.hpp b/MoonParser/pegtl/internal/trivial.hpp new file mode 100644 index 0000000..3416175 --- /dev/null +++ b/MoonParser/pegtl/internal/trivial.hpp @@ -0,0 +1,42 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_TRIVIAL_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_TRIVIAL_HPP + +#include "../config.hpp" + +#include "skip_control.hpp" + +#include "../analysis/counted.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + 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& ) noexcept + { + return Result; + } + }; + + template< bool Result > + struct skip_control< trivial< Result > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/try_catch_type.hpp b/MoonParser/pegtl/internal/try_catch_type.hpp new file mode 100644 index 0000000..83fddb4 --- /dev/null +++ b/MoonParser/pegtl/internal/try_catch_type.hpp @@ -0,0 +1,72 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_TRY_CATCH_TYPE_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_TRY_CATCH_TYPE_HPP + +#include + +#include "../config.hpp" + +#include "duseltronik.hpp" +#include "seq.hpp" +#include "skip_control.hpp" +#include "trivial.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename Exception, typename... Rules > + struct try_catch_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, + rewind_mode M, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + auto m = in.template mark< M >(); + using m_t = decltype( m ); + + try { + return m( duseltronik< seq< Rules... >, A, m_t::next_rewind_mode, Action, Control >::match( in, st... ) ); + } + catch( const Exception& ) { + return false; + } + } + }; + + template< typename Exception, typename... Rules > + struct skip_control< try_catch_type< Exception, Rules... > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/internal/until.hpp b/MoonParser/pegtl/internal/until.hpp new file mode 100644 index 0000000..6a564a4 --- /dev/null +++ b/MoonParser/pegtl/internal/until.hpp @@ -0,0 +1,91 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_INTERNAL_UNTIL_HPP +#define TAOCPP_PEGTL_INCLUDE_INTERNAL_UNTIL_HPP + +#include "../config.hpp" + +#include "bytes.hpp" +#include "eof.hpp" +#include "not_at.hpp" +#include "rule_conjunction.hpp" +#include "skip_control.hpp" +#include "star.hpp" + +#include "../apply_mode.hpp" +#include "../rewind_mode.hpp" + +#include "../analysis/generic.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< typename Cond, typename... Rules > + struct until; + + 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, + rewind_mode M, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + auto m = in.template mark< M >(); + + while( !Control< Cond >::template match< A, rewind_mode::REQUIRED, Action, Control >( in, st... ) ) { + if( in.empty() ) { + return false; + } + in.bump(); + } + return m( 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, + rewind_mode M, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + auto m = in.template mark< M >(); + using m_t = decltype( m ); + + while( !Control< Cond >::template match< A, rewind_mode::REQUIRED, Action, Control >( in, st... ) ) { + if( in.empty() || ( !rule_conjunction< Rules... >::template match< A, m_t::next_rewind_mode, Action, Control >( in, st... ) ) ) { + return false; + } + } + return m( true ); + } + }; + + template< typename Cond, typename... Rules > + struct skip_control< until< Cond, Rules... > > : std::true_type + { + }; + + } // namespace internal + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/istream_input.hpp b/MoonParser/pegtl/istream_input.hpp new file mode 100644 index 0000000..b0232f9 --- /dev/null +++ b/MoonParser/pegtl/istream_input.hpp @@ -0,0 +1,34 @@ +// Copyright (c) 2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_ISTREAM_INPUT_HPP +#define TAOCPP_PEGTL_INCLUDE_ISTREAM_INPUT_HPP + +#include + +#include "buffer_input.hpp" +#include "config.hpp" +#include "eol.hpp" + +#include "internal/istream_reader.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + template< typename Eol = eol::lf_crlf > + struct istream_input + : buffer_input< internal::istream_reader, Eol > + { + template< typename T > + istream_input( std::istream& in_stream, const std::size_t in_maximum, T&& in_source ) + : buffer_input< internal::istream_reader, Eol >( std::forward< T >( in_source ), in_maximum, in_stream ) + { + } + }; + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/memory_input.hpp b/MoonParser/pegtl/memory_input.hpp new file mode 100644 index 0000000..2d7fa42 --- /dev/null +++ b/MoonParser/pegtl/memory_input.hpp @@ -0,0 +1,285 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_MEMORY_INPUT_HPP +#define TAOCPP_PEGTL_INCLUDE_MEMORY_INPUT_HPP + +#include +#include +#include +#include +#include + +#include "config.hpp" +#include "eol.hpp" +#include "position.hpp" +#include "tracking_mode.hpp" + +#include "internal/action_input.hpp" +#include "internal/bump_impl.hpp" +#include "internal/iterator.hpp" +#include "internal/marker.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + template< tracking_mode, typename Eol, typename Source > + class memory_input_base; + + template< typename Eol, typename Source > + class memory_input_base< tracking_mode::IMMEDIATE, Eol, Source > + { + public: + using iterator_t = internal::iterator; + + template< typename T > + memory_input_base( const iterator_t& in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value ) + : m_current( in_begin ), + m_end( in_end ), + m_source( std::forward< T >( in_source ) ) + { + } + + template< typename T > + memory_input_base( const char* in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value ) + : m_current( in_begin ), + m_end( in_end ), + m_source( std::forward< T >( in_source ) ) + { + } + + memory_input_base( const memory_input_base& ) = delete; + memory_input_base operator=( const memory_input_base& ) = delete; + + const char* current() const noexcept + { + return m_current.data; + } + + const char* end( const std::size_t = 0 ) const noexcept + { + return m_end; + } + + std::size_t byte() const noexcept + { + return m_current.byte; + } + + std::size_t line() const noexcept + { + return m_current.line; + } + + std::size_t byte_in_line() const noexcept + { + return m_current.byte_in_line; + } + + void bump( const std::size_t in_count = 1 ) noexcept + { + internal::bump( m_current, in_count, Eol::ch ); + } + + void bump_in_this_line( const std::size_t in_count = 1 ) noexcept + { + internal::bump_in_this_line( m_current, in_count ); + } + + void bump_to_next_line( const std::size_t in_count = 1 ) noexcept + { + internal::bump_to_next_line( m_current, in_count ); + } + + TAOCPP_PEGTL_NAMESPACE::position position( const iterator_t& it ) const + { + return TAOCPP_PEGTL_NAMESPACE::position( it, m_source ); + } + + protected: + iterator_t m_current; + const char* const m_end; + const Source m_source; + }; + + template< typename Eol, typename Source > + class memory_input_base< tracking_mode::LAZY, Eol, Source > + { + public: + using iterator_t = const char*; + + template< typename T > + memory_input_base( const internal::iterator& in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value ) + : m_begin( in_begin ), + m_current( in_begin.data ), + m_end( in_end ), + m_source( std::forward< T >( in_source ) ) + { + } + + template< typename T > + memory_input_base( const char* in_begin, const char* in_end, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value ) + : m_begin( in_begin ), + m_current( in_begin ), + m_end( in_end ), + m_source( std::forward< T >( in_source ) ) + { + } + + memory_input_base( const memory_input_base& ) = delete; + memory_input_base operator=( const memory_input_base& ) = delete; + + const char* current() const noexcept + { + return m_current; + } + + const char* end( const std::size_t = 0 ) const noexcept + { + return m_end; + } + + std::size_t byte() const noexcept + { + return std::size_t( current() - m_begin.data ); + } + + void bump( const std::size_t in_count = 1 ) noexcept + { + m_current += in_count; + } + + void bump_in_this_line( const std::size_t in_count = 1 ) noexcept + { + m_current += in_count; + } + + void bump_to_next_line( const std::size_t in_count = 1 ) noexcept + { + m_current += in_count; + } + + TAOCPP_PEGTL_NAMESPACE::position position( const iterator_t it ) const + { + internal::iterator c( m_begin ); + internal::bump( c, std::size_t( it - m_begin.data ), Eol::ch ); + return TAOCPP_PEGTL_NAMESPACE::position( c, m_source ); + } + + protected: + const internal::iterator m_begin; + iterator_t m_current; + const char* const m_end; + const Source m_source; + }; + + } // namespace internal + + template< tracking_mode P = tracking_mode::IMMEDIATE, typename Eol = eol::lf_crlf, typename Source = std::string > + class memory_input + : public internal::memory_input_base< P, Eol, Source > + { + public: + static constexpr tracking_mode tracking_mode_v = P; + + using eol_t = Eol; + using source_t = Source; + + using typename internal::memory_input_base< P, Eol, Source >::iterator_t; + + using action_t = internal::action_input< memory_input >; + + using internal::memory_input_base< P, Eol, Source >::memory_input_base; + + template< typename T > + memory_input( const char* in_begin, const std::size_t in_size, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value ) + : memory_input( in_begin, in_begin + in_size, std::forward< T >( in_source ) ) + { + } + + template< typename T > + memory_input( const std::string& in_string, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value ) + : memory_input( in_string.data(), in_string.size(), std::forward< T >( in_source ) ) + { + } + + template< typename T > + memory_input( const char* in_begin, T&& in_source ) noexcept( std::is_nothrow_constructible< Source, T&& >::value ) + : memory_input( in_begin, std::strlen( in_begin ), std::forward< T >( in_source ) ) + { + } + + template< typename T > + memory_input( const char* in_begin, const char* in_end, T&& in_source, const std::size_t in_byte, const std::size_t in_line, const std::size_t in_byte_in_line ) noexcept( std::is_nothrow_constructible< Source, T&& >::value ) + : memory_input( { in_begin, in_byte, in_line, in_byte_in_line }, in_end, std::forward< T >( in_source ) ) + { + } + + memory_input( const memory_input& ) = delete; + memory_input operator=( const memory_input& ) = delete; + + const Source& source() const noexcept + { + return this->m_source; + } + + bool empty() const noexcept + { + return this->current() == this->end(); + } + + std::size_t size( const std::size_t = 0 ) const noexcept + { + return std::size_t( this->end() - this->current() ); + } + + char peek_char( const std::size_t offset = 0 ) const noexcept + { + return this->current()[ offset ]; + } + + unsigned char peek_byte( const std::size_t offset = 0 ) const noexcept + { + return static_cast< unsigned char >( peek_char( offset ) ); + } + + iterator_t& iterator() noexcept + { + return this->m_current; + } + + const iterator_t& iterator() const noexcept + { + return this->m_current; + } + + using internal::memory_input_base< P, Eol, Source >::position; + + TAOCPP_PEGTL_NAMESPACE::position position() const + { + return position( iterator() ); + } + + void discard() const noexcept + { + } + + void require( const std::size_t ) const noexcept + { + } + + template< rewind_mode M > + internal::marker< iterator_t, M > mark() noexcept + { + return internal::marker< iterator_t, M >( iterator() ); + } + }; + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/mmap_input.hpp b/MoonParser/pegtl/mmap_input.hpp new file mode 100644 index 0000000..0a112ef --- /dev/null +++ b/MoonParser/pegtl/mmap_input.hpp @@ -0,0 +1,55 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_MMAP_INPUT_HPP +#define TAOCPP_PEGTL_INCLUDE_MMAP_INPUT_HPP + +#include +#include + +#include "config.hpp" +#include "eol.hpp" +#include "memory_input.hpp" +#include "tracking_mode.hpp" + +#include "internal/file_mapper.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + struct mmap_holder + { + const std::string filename; + const file_mapper data; + + template< typename T > + mmap_holder( T&& in_filename ) + : filename( std::forward< T >( in_filename ) ), + data( filename.c_str() ) + { + } + }; + + } // namespace internal + + template< tracking_mode P = tracking_mode::IMMEDIATE, typename Eol = eol::lf_crlf > + struct mmap_input + : private internal::mmap_holder, + public memory_input< P, Eol, const char* > + { + template< typename T > + explicit mmap_input( T&& in_filename ) + : internal::mmap_holder( std::forward< T >( in_filename ) ), + memory_input< P, Eol, const char* >( data.begin(), data.end(), filename.c_str() ) + { + } + }; + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/normal.hpp b/MoonParser/pegtl/normal.hpp new file mode 100644 index 0000000..d5752d1 --- /dev/null +++ b/MoonParser/pegtl/normal.hpp @@ -0,0 +1,81 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_NORMAL_HPP +#define TAOCPP_PEGTL_INCLUDE_NORMAL_HPP + +#include "apply_mode.hpp" +#include "config.hpp" +#include "nothing.hpp" +#include "parse_error.hpp" +#include "rewind_mode.hpp" + +#include "internal/demangle.hpp" +#include "internal/dusel_mode.hpp" +#include "internal/duseltronik.hpp" +#include "internal/has_apply0.hpp" +#include "internal/skip_control.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + template< typename Rule > + struct normal + { + template< typename Input, typename... States > + static void start( const Input&, States&&... ) noexcept + { + } + + template< typename Input, typename... States > + static void success( const Input&, States&&... ) noexcept + { + } + + template< typename Input, typename... States > + static void failure( const Input&, States&&... ) noexcept + { + } + + template< typename Input, typename... States > + static void raise( const Input& in, States&&... ) + { + throw parse_error( "parse error matching " + internal::demangle< Rule >(), in ); + } + + template< template< typename... > class Action, typename Input, typename... States > + static void apply0( const Input&, States&&... st ) + { + Action< Rule >::apply0( st... ); + } + + template< template< typename... > class Action, typename Iterator, typename Input, typename... States > + static void apply( const Iterator& begin, const Input& in, States&&... st ) + { + using action_t = typename Input::action_t; + const action_t action_input( begin, in ); + Action< Rule >::apply( action_input, st... ); + } + + template< apply_mode A, + rewind_mode M, + template< typename... > class Action, + template< typename... > class Control, + typename Input, + typename... States > + static bool match( Input& in, States&&... st ) + { + constexpr bool use_control = !internal::skip_control< Rule >::value; + constexpr bool use_action = use_control && ( A == apply_mode::ACTION ) && ( !is_nothing< Action, Rule >::value ); + constexpr bool use_apply0 = use_action && internal::has_apply0< Action< Rule >, internal::type_list< States... > >::value; + constexpr dusel_mode mode = static_cast< dusel_mode >( static_cast< char >( use_control ) + static_cast< char >( use_action ) + static_cast< char >( use_apply0 ) ); + return internal::duseltronik< Rule, A, M, Action, Control, mode >::match( in, st... ); + } + }; + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/nothing.hpp b/MoonParser/pegtl/nothing.hpp new file mode 100644 index 0000000..9b121a2 --- /dev/null +++ b/MoonParser/pegtl/nothing.hpp @@ -0,0 +1,27 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_NOTHING_HPP +#define TAOCPP_PEGTL_INCLUDE_NOTHING_HPP + +#include + +#include "config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + template< typename Rule > + struct nothing + { + }; + + template< template< typename... > class Action, typename Rule > + using is_nothing = std::is_base_of< nothing< Rule >, Action< Rule > >; + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/parse.hpp b/MoonParser/pegtl/parse.hpp new file mode 100644 index 0000000..c478cfa --- /dev/null +++ b/MoonParser/pegtl/parse.hpp @@ -0,0 +1,53 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_PARSE_HPP +#define TAOCPP_PEGTL_INCLUDE_PARSE_HPP + +#include "apply_mode.hpp" +#include "config.hpp" +#include "normal.hpp" +#include "nothing.hpp" +#include "parse_error.hpp" +#include "rewind_mode.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + template< typename Rule, + template< typename... > class Action = nothing, + template< typename... > class Control = normal, + apply_mode A = apply_mode::ACTION, + rewind_mode M = rewind_mode::REQUIRED, + typename Input, + typename... States > + bool parse( Input&& in, States&&... st ) + { + return Control< Rule >::template match< A, M, Action, Control >( in, st... ); + } + + template< typename Rule, + template< typename... > class Action = nothing, + template< typename... > class Control = normal, + apply_mode A = apply_mode::ACTION, + rewind_mode M = rewind_mode::REQUIRED, + typename Outer, + typename Input, + typename... States > + bool parse_nested( const Outer& oi, Input&& in, States&&... st ) + { + try { + return parse< Rule, Action, Control, A, M >( in, st... ); + } + catch( parse_error& e ) { + e.positions.push_back( oi.position() ); + throw; + } + } + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/parse_error.hpp b/MoonParser/pegtl/parse_error.hpp new file mode 100644 index 0000000..e015efb --- /dev/null +++ b/MoonParser/pegtl/parse_error.hpp @@ -0,0 +1,45 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_PARSE_ERROR_HPP +#define TAOCPP_PEGTL_INCLUDE_PARSE_ERROR_HPP + +#include +#include + +#include "config.hpp" +#include "position.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + struct parse_error + : public std::runtime_error + { + parse_error( const std::string& msg, std::vector< position >&& in_positions ) + : std::runtime_error( msg ), + positions( std::move( in_positions ) ) + { + } + + template< typename Input > + parse_error( const std::string& msg, const Input& in ) + : parse_error( msg, in.position() ) + { + } + + parse_error( const std::string& msg, const position& pos ) + : std::runtime_error( to_string( pos ) + ": " + msg ), + positions( 1, pos ) + { + } + + std::vector< position > positions; + }; + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/position.hpp b/MoonParser/pegtl/position.hpp new file mode 100644 index 0000000..c25225c --- /dev/null +++ b/MoonParser/pegtl/position.hpp @@ -0,0 +1,54 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_POSITION_HPP +#define TAOCPP_PEGTL_INCLUDE_POSITION_HPP + +#include +#include +#include +#include +#include + +#include "config.hpp" + +#include "internal/iterator.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + struct position + { + template< typename T > + position( const internal::iterator& in_iter, T&& in_source ) + : byte( in_iter.byte ), + line( in_iter.line ), + byte_in_line( in_iter.byte_in_line ), + source( std::forward< T >( in_source ) ) + { + } + + std::size_t byte; + std::size_t line; + std::size_t byte_in_line; + std::string source; + }; + + inline std::ostream& operator<<( std::ostream& o, const position& p ) + { + return o << p.source << ':' << p.line << ':' << p.byte_in_line << '(' << p.byte << ')'; + } + + inline std::string to_string( const position& p ) + { + std::ostringstream o; + o << p; + return o.str(); + } + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/read_input.hpp b/MoonParser/pegtl/read_input.hpp new file mode 100644 index 0000000..9ebfaca --- /dev/null +++ b/MoonParser/pegtl/read_input.hpp @@ -0,0 +1,52 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_READ_INPUT_HPP +#define TAOCPP_PEGTL_INCLUDE_READ_INPUT_HPP + +#include + +#include "config.hpp" +#include "eol.hpp" +#include "string_input.hpp" +#include "tracking_mode.hpp" + +#include "internal/file_reader.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + struct filename_holder + { + const std::string filename; + + template< typename T > + explicit filename_holder( T&& in_filename ) + : filename( std::forward< T >( in_filename ) ) + { + } + }; + + } // namespace internal + + template< tracking_mode P = tracking_mode::IMMEDIATE, typename Eol = eol::lf_crlf > + struct read_input + : private internal::filename_holder, + public string_input< P, Eol, const char* > + { + template< typename T > + explicit read_input( T&& in_filename ) + : internal::filename_holder( std::forward< T >( in_filename ) ), + string_input< P, Eol, const char* >( internal::file_reader( filename.c_str() ).read(), filename.c_str() ) + { + } + }; + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/rewind_mode.hpp b/MoonParser/pegtl/rewind_mode.hpp new file mode 100644 index 0000000..f78edb9 --- /dev/null +++ b/MoonParser/pegtl/rewind_mode.hpp @@ -0,0 +1,24 @@ +// Copyright (c) 2016-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_REWIND_MODE_HPP +#define TAOCPP_PEGTL_INCLUDE_REWIND_MODE_HPP + +#include "config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + enum class rewind_mode : char + { + ACTIVE, + REQUIRED, + DONTCARE + }; + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/rules.hpp b/MoonParser/pegtl/rules.hpp new file mode 100644 index 0000000..e1c50b2 --- /dev/null +++ b/MoonParser/pegtl/rules.hpp @@ -0,0 +1,69 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_RULES_HPP +#define TAOCPP_PEGTL_INCLUDE_RULES_HPP + +#include "config.hpp" +#include "parse_error.hpp" + +#include "internal/rules.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + // clang-format off + template< typename... Actions > struct apply : internal::apply< Actions... > {}; + template< typename... Actions > struct apply0 : internal::apply0< Actions... > {}; + template< template< typename... > class Action, typename... Rules > struct action : internal::action< Action, Rules... > {}; + template< typename... Rules > struct at : internal::at< Rules... > {}; + struct bof : internal::bof {}; + struct bol : internal::bol {}; + 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... > {}; + struct discard : internal::discard {}; + template< typename... Rules > struct enable : internal::enable< Rules... > {}; + struct eof : internal::eof {}; + struct failure : internal::trivial< false > {}; + template< typename Rule, typename... Actions > struct if_apply : internal::if_apply< Rule, Actions... > {}; + 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 M, typename S > struct minus : internal::minus< M, S > {}; + 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< unsigned Amount > struct require : internal::require< Amount > {}; + 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... > {}; + // clang-format on + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/string_input.hpp b/MoonParser/pegtl/string_input.hpp new file mode 100644 index 0000000..a1c1f98 --- /dev/null +++ b/MoonParser/pegtl/string_input.hpp @@ -0,0 +1,51 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_STRING_INPUT_HPP +#define TAOCPP_PEGTL_INCLUDE_STRING_INPUT_HPP + +#include +#include + +#include "config.hpp" +#include "eol.hpp" +#include "memory_input.hpp" +#include "tracking_mode.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace internal + { + struct string_holder + { + const std::string data; + + template< typename T > + explicit string_holder( T&& in_data ) + : data( std::forward< T >( in_data ) ) + { + } + }; + + } // namespace internal + + template< tracking_mode P = tracking_mode::IMMEDIATE, typename Eol = eol::lf_crlf, typename Source = std::string > + struct string_input + : private internal::string_holder, + public memory_input< P, Eol, Source > + { + template< typename T, typename... Ts > + explicit string_input( T&& in_data, Ts&&... ts ) + : internal::string_holder( std::forward< T >( in_data ) ), + memory_input< P, Eol, Source >( data.data(), data.size(), std::forward< Ts >( ts )... ) + { + } + }; + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/tracking_mode.hpp b/MoonParser/pegtl/tracking_mode.hpp new file mode 100644 index 0000000..7ed945b --- /dev/null +++ b/MoonParser/pegtl/tracking_mode.hpp @@ -0,0 +1,23 @@ +// Copyright (c) 2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_TRACKING_MODE_HPP +#define TAOCPP_PEGTL_INCLUDE_TRACKING_MODE_HPP + +#include "config.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + enum class tracking_mode : bool + { + IMMEDIATE, + LAZY + }; + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/utf16.hpp b/MoonParser/pegtl/utf16.hpp new file mode 100644 index 0000000..faa7180 --- /dev/null +++ b/MoonParser/pegtl/utf16.hpp @@ -0,0 +1,35 @@ +// Copyright (c) 2015-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_UTF16_HPP +#define TAOCPP_PEGTL_INCLUDE_UTF16_HPP + +#include "config.hpp" + +#include "internal/peek_utf16.hpp" +#include "internal/result_on_found.hpp" +#include "internal/rules.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace utf16 + { + // clang-format off + 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... > {}; + template< char32_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::SUCCESS, internal::peek_utf16, Cs >... > {}; + // clang-format on + + } // namespace utf16 + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/utf32.hpp b/MoonParser/pegtl/utf32.hpp new file mode 100644 index 0000000..848137b --- /dev/null +++ b/MoonParser/pegtl/utf32.hpp @@ -0,0 +1,35 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_UTF32_HPP +#define TAOCPP_PEGTL_INCLUDE_UTF32_HPP + +#include "config.hpp" + +#include "internal/peek_utf32.hpp" +#include "internal/result_on_found.hpp" +#include "internal/rules.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace utf32 + { + // clang-format off + 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... > {}; + template< char32_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::SUCCESS, internal::peek_utf32, Cs >... > {}; + // clang-format on + + } // namespace utf32 + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/utf8.hpp b/MoonParser/pegtl/utf8.hpp new file mode 100644 index 0000000..9ec046e --- /dev/null +++ b/MoonParser/pegtl/utf8.hpp @@ -0,0 +1,35 @@ +// Copyright (c) 2014-2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_UTF8_HPP +#define TAOCPP_PEGTL_INCLUDE_UTF8_HPP + +#include "config.hpp" + +#include "internal/peek_utf8.hpp" +#include "internal/result_on_found.hpp" +#include "internal/rules.hpp" + +namespace tao +{ + namespace TAOCPP_PEGTL_NAMESPACE + { + namespace utf8 + { + // clang-format off + 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... > {}; + template< char32_t... Cs > struct string : internal::seq< internal::one< internal::result_on_found::SUCCESS, internal::peek_utf8, Cs >... > {}; + // clang-format on + + } // namespace utf8 + + } // namespace TAOCPP_PEGTL_NAMESPACE + +} // namespace tao + +#endif diff --git a/MoonParser/pegtl/version.hpp b/MoonParser/pegtl/version.hpp new file mode 100644 index 0000000..867d5e4 --- /dev/null +++ b/MoonParser/pegtl/version.hpp @@ -0,0 +1,13 @@ +// Copyright (c) 2017 Dr. Colin Hirsch and Daniel Frey +// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/ + +#ifndef TAOCPP_PEGTL_INCLUDE_VERSION_HPP +#define TAOCPP_PEGTL_INCLUDE_VERSION_HPP + +#define TAOCPP_PEGTL_VERSION "2.1.2" + +#define TAOCPP_PEGTL_VERSION_MAJOR 2 +#define TAOCPP_PEGTL_VERSION_MINOR 1 +#define TAOCPP_PEGTL_VERSION_PATCH 2 + +#endif diff --git a/MoonParser/slice.cpp b/MoonParser/slice.cpp new file mode 100644 index 0000000..7caddbc --- /dev/null +++ b/MoonParser/slice.cpp @@ -0,0 +1,119 @@ +/** + * Copyright (C) 2017, IppClub. All rights reserved. + * + * 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. + */ + +#include "Slice.h" +#include + +namespace silly { + +namespace slice { + +const std::string Slice::Empty; + +int Slice::compare(const Slice &rhs) const { + int ret = 0; + + // It's illegal to pass nullptr to memcmp. + if (str_ && rhs.str_) + ret = memcmp(str_, rhs.str_, len_); + + if (ret == 0) { + // Use len_ - rhs.len_ as returned value may cause overflow + // of size_t type length. Therefore +1, -1 are returned here. + if (len_ < rhs.len_) + return -1; + else if (len_ > rhs.len_) + return 1; + } + return ret; +} + +std::string Slice::getFilePath() const { + std::string filename = toString(); + size_t pos = filename.find_last_of("/\\"); + if (pos == std::string::npos) + { + return Slice::Empty; + } + return filename.substr(0, pos) + "/"; +} + +std::string Slice::getFileName() const { + std::string filename = toString(); + size_t pos = filename.find_last_of("/\\"); + if (pos == std::string::npos) { + return Slice::Empty; + } + return filename.substr(pos+1); +} + +std::string Slice::toLower() const { + std::string tmp = toString(); + for (size_t i = 0; i < tmp.length(); i++) { + tmp[i] = (char)tolower(tmp[i]); + } + return tmp; +} + +std::string Slice::toUpper() const { + std::string tmp = toString(); + for (size_t i = 0; i < tmp.length(); i++) { + tmp[i] = (char)toupper(tmp[i]); + } + return tmp; +} + +std::string Slice::getFileExtension() const { + std::string filename = toString(); + size_t pos = filename.rfind('.'); + if (pos == std::string::npos) { + return Slice::Empty; + } + return Slice(filename.substr(pos + 1)).toLower(); +} + +std::list Slice::split(const Slice& delims) const { + std::string text = toString(); + std::string delimers = delims.toString(); + std::list tokens; + std::size_t start = text.find_first_not_of(delimers), end = 0; + while ((end = text.find_first_of(delimers, start)) != std::string::npos) { + tokens.push_back(Slice(str_ + start, end - start)); + start = text.find_first_not_of(delimers, end); + } + if (start != std::string::npos) { + tokens.push_back(Slice(str_ + start)); + } + return tokens; +} + +float Slice::stof(const Slice& str) { + return static_cast(std::atof(str.toString().c_str())); +} + +int Slice::stoi(const Slice& str) { + return std::atoi(str.toString().c_str()); +} + +} // namespace slice + +} // namespace silly diff --git a/MoonParser/slice.h b/MoonParser/slice.h new file mode 100644 index 0000000..60e0ae1 --- /dev/null +++ b/MoonParser/slice.h @@ -0,0 +1,157 @@ +/** + * Copyright (C) 2017, IppClub. All rights reserved. + * + * 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. + */ + +#pragma once + +#include +#include +#include +#include + +namespace silly { + +namespace slice { +// A Slice object wraps a "const char *" or a "const std::string&" but +// without copying their contents. +class Slice { + private: + struct TrustedInitTag {}; + constexpr Slice(const char* s, size_t n, TrustedInitTag) : str_(s), len_(n) {} + + public: + // implicit conversion from std::string to Slice + Slice(const std::string &s) : Slice(s.data(), s.size()) {} + + Slice(const char *s) : Slice(s, s ? strlen(s) : 0) {} + + Slice(const char *s, size_t n) : str_(s), len_(n) {} + + Slice(std::pair sp) : str_(sp.first), len_(sp.second) {} + + constexpr Slice(std::nullptr_t p = nullptr) : str_(nullptr), len_(0) {} + + operator std::string() const { + return std::string(str_, len_); + } + + const char &operator[](size_t n) const { + return str_[n]; + } + + size_t size() const { + return len_; + } + + const char *rawData() const { + return str_; + } + + std::string toString() const { + return std::string(str_, len_); + } + + bool empty() const { + return len_ == 0; + } + + // similar with std::string::compare + // http://en.cppreference.com/w/cpp/string/basic_string/compare + int compare(const Slice &rhs) const; + + void skip(size_t n) { + assert(n <= len_); + str_ += n; + len_ -= n; + } + + void copyTo(char *dest, bool appendEndingNull = true) const { + memcpy(dest, str_, len_); + if (appendEndingNull) { + dest[len_] = '\0'; + } + } + + Slice &trimSpace() { + assert(len_ > 0); + size_t start = 0, end = len_ - 1; + while (start < end && isspace(str_[start])) { + start++; + } + while (start < end && isspace(str_[end])) { + end--; + } + str_ += start; + len_ = end - start + 1; + return *this; + } + + typedef const char *const_iterator; + + const_iterator begin() const { + return str_; + } + + const_iterator end() const { + return str_ + len_; + } + + std::string getFilePath() const; + std::string getFileName() const; + std::string getFileExtension() const; + std::string toLower() const; + std::string toUpper() const; + std::list split(const Slice& delimer) const; + + static const std::string Empty; + static float stof(const Slice& str); + static int stoi(const Slice& str); + + constexpr friend Slice operator"" _slice(const char* s, size_t n); + private: + const char *str_; + size_t len_; +}; + +inline Slice trimSpace(const Slice &s) { + Slice tmp = s; + return tmp.trimSpace(); +} + +inline bool operator==(const Slice &lhs, const Slice &rhs) { + return lhs.compare(rhs) == 0; +} + +inline bool operator!=(const Slice &lhs, const Slice &rhs) { + return !(lhs == rhs); +} + +inline std::string operator+(const std::string& lhs, const Slice &rhs) { + return lhs + rhs.toString(); +} + +constexpr Slice operator"" _slice(const char* s, size_t n) { + return Slice(s, n, Slice::TrustedInitTag{}); +} + +} // namespace slice + +} // namespace silly -- cgit v1.2.3-55-g6feb