diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..f42ec5a --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,16 @@ +name: Lint + +on: pull_request + +jobs: + clang-format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: jidicula/clang-format-action@v4.6.1 + + yapf: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: AlexanderMelde/yapf-action@v1.0 diff --git a/configure b/configure index 8120bc1..a9ead3d 100755 --- a/configure +++ b/configure @@ -39,18 +39,28 @@ def main(): os.chdir(config_dir) progname = sys.argv[0] parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter) - parser.add_argument("-m", "--mode", metavar="MODE", - type=str, choices="dbg dev opt".split(), default="opt", + parser.add_argument("-m", + "--mode", + metavar="MODE", + type=str, + choices="dbg dev opt".split(), + default="opt", help="set build configuration:\n" " - opt: compile for fast binaries (default)\n" " - dev: compile for fast builds\n" " - dbg: add debugging symbols") - parser.add_argument("-o", "--target-os", metavar="OS", + parser.add_argument("-o", + "--target-os", + metavar="OS", type=str, help="target os (default: host os)") - parser.add_argument("--prefix", type=str, default="/usr/local", + parser.add_argument("--prefix", + type=str, + default="/usr/local", help="installation prefix (default: /usr/local)") - parser.add_argument("--sanitizer", choices="memory address undefined".split(), default="", + parser.add_argument("--sanitizer", + choices="memory address undefined".split(), + default="", help="run sanitizer (memory, address, or undefined)") args = parser.parse_args() @@ -127,10 +137,9 @@ def check_mac(args): missing = collections.OrderedDict() if not (cfg.check_clang() and cfg.check_libcxx()): - missing["xcode"] = ( - "* Xcode can be installed via the App Store:\n" - " https://itunes.apple.com/en/app/xcode/id497799835\n" - " After installing, open it and accept the license agreement\n") + missing["xcode"] = ("* Xcode can be installed via the App Store:\n" + " https://itunes.apple.com/en/app/xcode/id497799835\n" + " After installing, open it and accept the license agreement\n") if missing: print("\nmissing dependencies: %s\n" % " ".join(missing.keys())) @@ -138,7 +147,9 @@ def check_mac(args): sys.stdout.write(step) if any("Homebrew" in v for v in missing.values()): print("* Homebrew can be installed like so:") - print(' $ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"') + print( + ' $ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"' + ) sys.exit(1) @@ -184,12 +195,11 @@ def check_linux_native(args): def check_mac_on_linux(args): missing = collections.OrderedDict() - if not (cfg.check_clang("x86_64-apple-darwin15-clang++") and - cfg.check_libcxx("x86_64-apple-darwin15-clang++")): - missing["osxcross"] = ( - "* OSXCross can be found here:\n" - " https://github.com/tpoechtrager/osxcross\n" - " Download and build it, and ensure target/bin is in your $PATH\n") + if not (cfg.check_clang("x86_64-apple-darwin15-clang++") + and cfg.check_libcxx("x86_64-apple-darwin15-clang++")): + missing["osxcross"] = ("* OSXCross can be found here:\n" + " https://github.com/tpoechtrager/osxcross\n" + " Download and build it, and ensure target/bin is in your $PATH\n") if missing: print("\nmissing dependencies: %s\n" % " ".join(missing.keys())) diff --git a/misc/pygments/procyonlexer.py b/misc/pygments/procyonlexer.py index 62ac98d..903f4bf 100644 --- a/misc/pygments/procyonlexer.py +++ b/misc/pygments/procyonlexer.py @@ -42,10 +42,10 @@ class ProcyonLexer(RegexLexer): (r"\*", Punctuation), (r"([>|])([ \t])?(.+)?$", bygroups(Punctuation, Text, String.Other)), (r"(!)([ \t])?(.+)?$", bygroups(Punctuation, Text, Error)), - (r"([A-Za-z0-9_./+-]*)(:)([ \t]+)?(.+)?$", bygroups(Name.Tag, Punctuation, Text, - using(this, state="value"))), - (r'("(?:[^"\\]|\\.)*")(:)([ \t]+)?(.+)?$', bygroups(Name.Tag, Punctuation, Text, - using(this, state="value"))), + (r"([A-Za-z0-9_./+-]*)(:)([ \t]+)?(.+)?$", + bygroups(Name.Tag, Punctuation, Text, using(this, state="value"))), + (r'("(?:[^"\\]|\\.)*")(:)([ \t]+)?(.+)?$', + bygroups(Name.Tag, Punctuation, Text, using(this, state="value"))), (r"#.*$", Comment), include("value"), (r".+$", Error), diff --git a/misc/pygments/setup.py b/misc/pygments/setup.py index 32883a4..8adcde7 100644 --- a/misc/pygments/setup.py +++ b/misc/pygments/setup.py @@ -31,4 +31,5 @@ "Topic :: Text Processing :: Filters", "Topic :: Text Processing :: Markup", "Topic :: Utilities", - ], ) + ], +) diff --git a/src/bin/src/pnfmt.cpp b/src/bin/src/pnfmt.cpp index 69fb2a1..738d34d 100644 --- a/src/bin/src/pnfmt.cpp +++ b/src/bin/src/pnfmt.cpp @@ -170,16 +170,19 @@ static void usage(pn::output_view out, int status) { static pn::value repr(const token& t) { pn::map m{ - {"type", t.type}, {"column", t.column}, {"content", t.content.copy()}, + {"type", t.type}, + {"column", t.column}, + {"content", t.content.copy()}, }; return std::move(m); } static pn::value repr(const line& l) { - pn::map m{{"indent", l.indent}, - {"lineno", l.lineno}, - {"width", l.width}, - {"extra_nl_before", l.extra_nl_before}}; + pn::map m{ + {"indent", l.indent}, + {"lineno", l.lineno}, + {"width", l.width}, + {"extra_nl_before", l.extra_nl_before}}; if (!l.tokens.empty()) { pn::array_ref a = m["tokens"].to_array(); for (const token& token : l.tokens) { diff --git a/src/c/scripts/gen.py b/src/c/scripts/gen.py index 2d32d51..915132c 100755 --- a/src/c/scripts/gen.py +++ b/src/c/scripts/gen.py @@ -65,6 +65,7 @@ def output_c(lex, parser): yield "#include \"gen_table.h\"" yield + yield "// clang-format off" yield "const uint8_t lex_classes[256] = {" for i in range(0, 256, 16): line = " " @@ -137,6 +138,7 @@ def output_python(lex, parser): yield "from .error import Error" yield "from .parse_enums import Acc, Emit, Key" yield + yield "# yapf: disable" lines = [] for i in range(0, 256, 16): @@ -198,6 +200,7 @@ def lex_transition_value(kind, value): class Lexer: + def __init__(self, spec): lex = OrderedDict() for s, t in spec["lex"].items(): @@ -296,6 +299,7 @@ def list_chars(char_set): class Parser: + def __init__(self, spec): parse_states = OrderedDict((state, i) for i, state in enumerate(spec["parse"])) self.defs = OrderedDict() diff --git a/src/c/src/dtoa.c b/src/c/src/dtoa.c index 001199c..a5e224a 100644 --- a/src/c/src/dtoa.c +++ b/src/c/src/dtoa.c @@ -582,33 +582,34 @@ static int16_t Lhint[2098] = { 642, 642, 642, 643, 643, 643, 644, 644, 644, 644, 645, 645, 645, 646, 646, 646, 647, 647, 647, 647, 648, 648, 648, 649, 649, 649, 650, 650}; -static uint64_t pfive[27] = {5ll, - 25ll, - 125ll, - 625ll, - 3125ll, - 15625ll, - 78125ll, - 390625ll, - 1953125ll, - 9765625ll, - 48828125ll, - 244140625ll, - 1220703125ll, - 6103515625ll, - 30517578125ll, - 152587890625ll, - 762939453125ll, - 3814697265625ll, - 19073486328125ll, - 95367431640625ll, - 476837158203125ll, - 2384185791015625ll, - 11920928955078125ll, - 59604644775390625ll, - 298023223876953125ll, - 1490116119384765625ll, - 7450580596923828125ll}; +static uint64_t pfive[27] = { + 5ll, + 25ll, + 125ll, + 625ll, + 3125ll, + 15625ll, + 78125ll, + 390625ll, + 1953125ll, + 9765625ll, + 48828125ll, + 244140625ll, + 1220703125ll, + 6103515625ll, + 30517578125ll, + 152587890625ll, + 762939453125ll, + 3814697265625ll, + 19073486328125ll, + 95367431640625ll, + 476837158203125ll, + 2384185791015625ll, + 11920928955078125ll, + 59604644775390625ll, + 298023223876953125ll, + 1490116119384765625ll, + 7450580596923828125ll}; static int pfivebits[25] = {3, 5, 7, 10, 12, 14, 17, 19, 21, 24, 26, 28, 31, 33, 35, 38, 40, 42, 45, 47, 49, 52, 54, 56, 59}; @@ -682,9 +683,7 @@ typedef struct ThInfo { #ifdef _MSC_VER static __declspec(thread) ThInfo ti_instance; -static ThInfo* get_TI(void) { - return &ti_instance; -} +static ThInfo* get_TI(void) { return &ti_instance; } #else static pthread_key_t ti_key; static pthread_once_t ti_once; diff --git a/src/c/src/dump.c b/src/c/src/dump.c index 9db0f16..3865cfa 100644 --- a/src/c/src/dump.c +++ b/src/c/src/dump.c @@ -109,7 +109,7 @@ static bool dump_bool(pn_bool_t b, pn_output_t* out) { } static bool dump_int(pn_int_t i, pn_output_t* out) { - char buf[32]; + char buf[32]; ptrdiff_t len; return ((len = sprintf(buf, "%" PRId64, i)) > 0) && pn_raw_write(out, buf, len); } diff --git a/src/c/src/format.c b/src/c/src/format.c index f50efcb..3fc37e4 100644 --- a/src/c/src/format.c +++ b/src/c/src/format.c @@ -109,7 +109,7 @@ static void set_arg(char format, struct format_arg* dst, va_list* vl) { } static bool print_u(pn_output_t* out, uint64_t u) { - char buf[32]; + char buf[32]; ptrdiff_t len; return ((len = sprintf(buf, "%" PRIu64, u)) > 0) && pn_write(out, "S", buf, (size_t)len); } diff --git a/src/c/src/gen_table.c b/src/c/src/gen_table.c index c4895b4..e49a442 100644 --- a/src/c/src/gen_table.c +++ b/src/c/src/gen_table.c @@ -1,5 +1,6 @@ #include "gen_table.h" +// clang-format off const uint8_t lex_classes[256] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/src/c/src/io.c b/src/c/src/io.c index d2dd2c5..8b40a1b 100644 --- a/src/c/src/io.c +++ b/src/c/src/io.c @@ -30,18 +30,18 @@ #include "./io.h" union pn_primitive { - int i; - unsigned I; - int16_t h; - uint16_t H; - int32_t l; - uint32_t L; - int64_t q; - uint64_t Q; - intptr_t p; - uintptr_t P; - size_t z; - ptrdiff_t Z; + int i; + unsigned I; + int16_t h; + uint16_t H; + int32_t l; + uint32_t L; + int64_t q; + uint64_t Q; + intptr_t p; + uintptr_t P; + size_t z; + ptrdiff_t Z; float f; double d; @@ -118,13 +118,13 @@ bool pn_read_arg(pn_input_t* in, char format, va_list* vl) { case 's': return read_bytes_strlen(in, va_arg(*vl, char*)); case 'S': { - char* data_ptr = va_arg(*vl, char*); + char* data_ptr = va_arg(*vl, char*); size_t data_size = va_arg(*vl, size_t); return pn_raw_read(in, data_ptr, data_size); } case '$': { uint8_t* data_ptr = va_arg(*vl, uint8_t*); - size_t data_size = va_arg(*vl, size_t); + size_t data_size = va_arg(*vl, size_t); return pn_raw_read(in, data_ptr, data_size); } case 'c': return PN_READ_BYTE(char); @@ -201,13 +201,13 @@ static bool pn_write_arg(pn_output_t* out, char format, va_list* vl) { case 's': return write_bytes_strlen(out, va_arg(*vl, const char*)); case 'S': { - const char* data_ptr = va_arg(*vl, const char*); + const char* data_ptr = va_arg(*vl, const char*); const size_t data_size = va_arg(*vl, size_t); return pn_raw_write(out, data_ptr, data_size); } case '$': { - const uint8_t* data_ptr = va_arg(*vl, const uint8_t*); - const size_t data_size = va_arg(*vl, size_t); + const uint8_t* data_ptr = va_arg(*vl, const uint8_t*); + const size_t data_size = va_arg(*vl, size_t); return pn_raw_write(out, data_ptr, data_size); } case 'c': return write_byte(out, va_arg(*vl, int)); @@ -359,7 +359,7 @@ ptrdiff_t pn_getline(pn_input_t* in, char** data, size_t* size) { } memmove(*data, in->view->data, out_size); (*data)[out_size] = '\0'; - in->view->data = (char*)in->view->data + out_size; + in->view->data = (char*)in->view->data + out_size; in->view->size -= out_size; return out_size; } diff --git a/src/c/src/io.h b/src/c/src/io.h index 11917e9..e510318 100644 --- a/src/c/src/io.h +++ b/src/c/src/io.h @@ -26,11 +26,11 @@ struct pn_input_view { size_t size; }; -int pn_getc(pn_input_t* in); -int pn_putc(int ch, pn_output_t* out); -bool pn_raw_read(pn_input_t* in, void* data, size_t size); -bool pn_raw_write(pn_output_t* out, const void* data, size_t size); -ptrdiff_t pn_getline(pn_input_t* in, char** data, size_t* size); +int pn_getc(pn_input_t* in); +int pn_putc(int ch, pn_output_t* out); +bool pn_raw_read(pn_input_t* in, void* data, size_t size); +bool pn_raw_write(pn_output_t* out, const void* data, size_t size); +ptrdiff_t pn_getline(pn_input_t* in, char** data, size_t* size); #ifdef __cplusplus } // extern "C" diff --git a/src/c/src/lex.h b/src/c/src/lex.h index 7393415..63f4639 100644 --- a/src/c/src/lex.h +++ b/src/c/src/lex.h @@ -75,10 +75,10 @@ typedef struct { char* begin; char* end; } token; - size_t lineno; + size_t lineno; ptrdiff_t indent; - size_t prev_width; - bool eq; + size_t prev_width; + bool eq; struct { char* begin; // data in current line (not NUL-terminated) @@ -91,8 +91,8 @@ typedef struct { } buffer; struct { - size_t count; - size_t size; + size_t count; + size_t size; ptrdiff_t values[]; } * levels; } pn_lexer_t; diff --git a/src/c/src/parse.c b/src/c/src/parse.c index 21f1efc..632915e 100644 --- a/src/c/src/parse.c +++ b/src/c/src/parse.c @@ -144,8 +144,9 @@ static void parse_short_string_value(pn_string_t** s, const char* begin, const c char utf[] = {0340 | ((u >> 12) & 0017), 0200 | ((u >> 6) & 0077), 0200 | (u & 0077)}; pn_strncat(s, utf, 3); } else { - char utf[] = {0360 | ((u >> 18) & 0x007), 0200 | ((u >> 12) & 0077), - 0200 | ((u >> 6) & 0077), 0200 | (u & 0077)}; + char utf[] = { + 0360 | ((u >> 18) & 0x007), 0200 | ((u >> 12) & 0077), + 0200 | ((u >> 6) & 0077), 0200 | (u & 0077)}; pn_strncat(s, utf, 4); } } diff --git a/src/cpp/include/pn/arg b/src/cpp/include/pn/arg index f88b186..26c4134 100644 --- a/src/cpp/include/pn/arg +++ b/src/cpp/include/pn/arg @@ -43,11 +43,11 @@ struct read_arg : arg {}; template <> struct arg { - static constexpr char code = '#'; + static constexpr char code = '#'; typedef std::tuple write_args_type; typedef std::tuple read_args_type; - static std::tuple write_args(pad p) { return std::make_tuple(p.size); } - static std::tuple read_args(pad p) { return std::make_tuple(p.size); } + static std::tuple write_args(pad p) { return std::make_tuple(p.size); } + static std::tuple read_args(pad p) { return std::make_tuple(p.size); } }; template <> struct read_arg : arg {}; @@ -55,8 +55,8 @@ struct read_arg : arg {}; template <> struct arg { static constexpr char code = 'n'; - typedef std::tuple<> write_args_type; - typedef std::tuple<> read_args_type; + typedef std::tuple<> write_args_type; + typedef std::tuple<> read_args_type; static std::tuple<> write_args(std::nullptr_t) { return std::make_tuple(); } }; @@ -65,7 +65,7 @@ struct pod_arg { static constexpr char code = C; typedef std::tuple write_args_type; typedef std::tuple read_args_type; - static std::tuple write_args(T t) { return std::make_tuple(t); } + static std::tuple write_args(T t) { return std::make_tuple(t); } static std::tuple read_args(T* t) { return std::make_tuple(t); } }; @@ -108,41 +108,45 @@ struct arg : pod_arg {}; template <> struct arg : pod_arg {}; template <> -struct arg::value> : pod_arg {}; +struct arg::value> : pod_arg { +}; template <> -struct arg::value> : pod_arg {}; +struct arg::value> + : pod_arg {}; template <> -struct arg::value> : pod_arg {}; +struct arg::value> + : pod_arg {}; template <> -struct arg::value> : pod_arg {}; +struct arg::value> + : pod_arg {}; template <> struct arg : pod_arg {}; template <> struct arg { - static constexpr char code = 's'; + static constexpr char code = 's'; typedef std::tuple write_args_type; typedef std::tuple read_args_type; - static std::tuple write_args(const char* s) { return std::make_tuple(s); } + static std::tuple write_args(const char* s) { return std::make_tuple(s); } }; template <> struct arg : arg {}; template <> struct arg { - static constexpr char code = '$'; + static constexpr char code = '$'; typedef std::tuple write_args_type; - static std::tuple write_args(data_view d) { + static std::tuple write_args(data_view d) { return std::make_tuple(d.data(), d.size()); } }; template <> struct arg { - static constexpr char code = '$'; + static constexpr char code = '$'; typedef std::tuple write_args_type; - typedef std::tuple read_args_type; - static std::tuple write_args(const data& d) { + typedef std::tuple read_args_type; + static std::tuple write_args(const data& d) { return std::make_tuple(d.data(), d.size()); } static std::tuple read_args(data* d) { @@ -152,10 +156,10 @@ struct arg { template <> struct arg { - static constexpr char code = '$'; + static constexpr char code = '$'; typedef std::tuple write_args_type; - typedef std::tuple read_args_type; - static std::tuple write_args(const data_ref& d) { + typedef std::tuple read_args_type; + static std::tuple write_args(const data_ref& d) { return std::make_tuple(d.data(), d.size()); } static std::tuple read_args(data_ref* d) { @@ -165,9 +169,9 @@ struct arg { template <> struct arg { - static constexpr char code = 'S'; + static constexpr char code = 'S'; typedef std::tuple write_args_type; - static std::tuple write_args(string_view s) { + static std::tuple write_args(string_view s) { return std::make_tuple(s.data(), s.size()); } }; @@ -182,9 +186,9 @@ struct arg : arg {}; template <> struct arg { - static constexpr char code = 'a'; + static constexpr char code = 'a'; typedef std::tuple write_args_type; - static std::tuple write_args(array_cref a) { + static std::tuple write_args(array_cref a) { return std::make_tuple(*a.c_obj()); } }; @@ -195,9 +199,9 @@ struct arg : arg {}; template <> struct arg { - static constexpr char code = 'm'; + static constexpr char code = 'm'; typedef std::tuple write_args_type; - static std::tuple write_args(map_cref m) { + static std::tuple write_args(map_cref m) { return std::make_tuple(*m.c_obj()); } }; @@ -208,9 +212,9 @@ struct arg : arg {}; template <> struct arg { - static constexpr char code = 'x'; + static constexpr char code = 'x'; typedef std::tuple write_args_type; - static std::tuple write_args(value_cref x) { + static std::tuple write_args(value_cref x) { return std::make_tuple(x.c_obj()); } }; diff --git a/src/cpp/include/pn/map b/src/cpp/include/pn/map index e8cc141..0b63154 100644 --- a/src/cpp/include/pn/map +++ b/src/cpp/include/pn/map @@ -56,8 +56,8 @@ class key_value { key_reference key() { return key_reference{&c_obj()->key}; } key_const_reference key() const { - return key_const_reference{c_obj()->key->values, - static_cast(c_obj()->key->count) - 1}; + return key_const_reference{ + c_obj()->key->values, static_cast(c_obj()->key->count) - 1}; } value_reference value() { return value_reference{&c_obj()->value}; } value_const_reference value() const { return value_const_reference{&c_obj()->value}; } diff --git a/src/cpp/include/pn/output b/src/cpp/include/pn/output index 7670348..745d8a0 100644 --- a/src/cpp/include/pn/output +++ b/src/cpp/include/pn/output @@ -22,109 +22,108 @@ #include #include #include -#include #include +#include #include namespace pn { namespace internal { - -template -struct write_and_concat_args -{ - static typename tuple_type_cat::type>::write_args_type...>::type process(const args&... arg); +template +struct write_and_concat_args { + static typename tuple_type_cat< + typename internal::arg::type>::write_args_type...>::type + process(const args&... arg); }; -template<> -struct write_and_concat_args<> -{ +template <> +struct write_and_concat_args<> { static typename std::tuple<> process(); }; #ifdef _MSC_VER // Workaround for VS internal compiler error in pack expander -template -void tuple_copy_element(dest_tuple& dest, const src_tuple& src) -{ +template +void tuple_copy_element(dest_tuple& dest, const src_tuple& src) { std::get(dest) = std::get(src); } -template -struct tuple_copy_range_part -{ +template +struct tuple_copy_range_part { static void copy(dest_tuple& dest, const src_tuple& src); }; -template -struct tuple_copy_range_part -{ +template +struct tuple_copy_range_part { static void copy(dest_tuple& dest, const src_tuple& src) {} }; - -template -void tuple_copy_range_part::copy(dest_tuple& dest, const src_tuple& src) -{ +template +void tuple_copy_range_part::copy( + dest_tuple& dest, const src_tuple& src) { tuple_copy_element(dest, src); - tuple_copy_range_part::copy(dest, src); + tuple_copy_range_part< + dest_tuple, dest_index + 1, src_tuple, src_index + 1, remaining - 1>::copy(dest, src); } -template -void insert_tuple(dest_tuple& dest, const src_tuple& src) -{ - tuple_copy_range_part::value>::copy(dest, src); +template +void insert_tuple(dest_tuple& dest, const src_tuple& src) { + tuple_copy_range_part< + dest_tuple, dest_index, src_tuple, 0, + std::tuple_size::value>::copy(dest, src); } -template -void write_one_arg(dest_tuple& dest, const arg_type& arg) -{ - typedef typename internal::arg::type>::write_args_type arg_write_type_t; - insert_tuple(dest, internal::arg::type>::write_args(arg)); +template +void write_one_arg(dest_tuple& dest, const arg_type& arg) { + typedef typename internal::arg::type>::write_args_type + arg_write_type_t; + insert_tuple( + dest, internal::arg::type>::write_args(arg)); } -template +template void write_args(dest_tuple& dest, const args&... arg); -template -void write_args(dest_tuple& dest, const args& arg) -{ +template +void write_args(dest_tuple& dest, const args& arg) { write_one_arg(dest, arg); } -template -void write_args(dest_tuple& dest, const arg0_type& arg0, const args&... arg) -{ - typedef typename internal::arg::type>::write_args_type arg0_write_type_t; +template +void write_args(dest_tuple& dest, const arg0_type& arg0, const args&... arg) { + typedef typename internal::arg::type>::write_args_type + arg0_write_type_t; write_one_arg(dest, arg0); - write_args::value, args...>(dest, arg...); + write_args::value, args...>( + dest, arg...); } -template -typename tuple_type_cat::type>::write_args_type...>::type write_and_concat_args::process(const args&... arg) -{ - typedef typename tuple_type_cat::type>::write_args_type...>::type dest_tuple_t; - dest_tuple_t result; - write_args(result, arg...); - return result; +template +typename tuple_type_cat< + typename internal::arg::type>::write_args_type...>::type +write_and_concat_args::process(const args&... arg) { + typedef typename tuple_type_cat< + typename internal::arg::type>::write_args_type...>::type + dest_tuple_t; + dest_tuple_t result; + write_args(result, arg...); + return result; } #else -template -typename tuple_type_cat::type>::write_args_type...>::type write_and_concat_args::process(const args&... arg) -{ +template +typename tuple_type_cat< + typename internal::arg::type>::write_args_type...>::type +write_and_concat_args::process(const args&... arg) { return std::tuple_cat(internal::arg::type>::write_args(arg)...); } #endif -inline std::tuple<> write_and_concat_args<>::process() -{ - return std::tuple<>(); -} +inline std::tuple<> write_and_concat_args<>::process() { return std::tuple<>(); } } // namespace internal @@ -265,19 +264,14 @@ string dump(const arg& x, int flags) { template output& output::write(const args&... arg) { const char str[] = {internal::arg::type>::code..., '\0'}; - internal::write( - c_obj(), str, - internal::write_and_concat_args::process(arg...)); + internal::write(c_obj(), str, internal::write_and_concat_args::process(arg...)); return *this; } - template output_view& output_view::write(const args&... arg) { const char str[] = {internal::arg::type>::code..., '\0'}; - internal::write( - c_obj(), str, - internal::write_and_concat_args::process(arg...)); + internal::write(c_obj(), str, internal::write_and_concat_args::process(arg...)); return *this; } @@ -300,18 +294,14 @@ output_view& output_view::dump(const arg& x, int flags) { template output& output::format(const char* fmt, const args&... arg) { const char str[] = {internal::arg::type>::code..., '\0'}; - internal::format( - c_obj(), fmt, str, - internal::write_and_concat_args::process(arg...)); + internal::format(c_obj(), fmt, str, internal::write_and_concat_args::process(arg...)); return *this; } template output_view& output_view::format(const char* fmt, const args&... arg) { const char str[] = {internal::arg::type>::code..., '\0'}; - internal::format( - c_obj(), fmt, str, - internal::write_and_concat_args::process(arg...)); + internal::format(c_obj(), fmt, str, internal::write_and_concat_args::process(arg...)); return *this; } diff --git a/src/cpp/include/pn/string b/src/cpp/include/pn/string index 593f33e..9b94ad9 100644 --- a/src/cpp/include/pn/string +++ b/src/cpp/include/pn/string @@ -18,10 +18,10 @@ #include #include +#include #include #include #include -#include namespace pn { diff --git a/src/cpp/include/pn/tuple_type_cat b/src/cpp/include/pn/tuple_type_cat index 11fd9ca..62c5a7f 100644 --- a/src/cpp/include/pn/tuple_type_cat +++ b/src/cpp/include/pn/tuple_type_cat @@ -24,22 +24,20 @@ template struct tuple_type_cat; template -struct tuple_type_cat -{ +struct tuple_type_cat { typedef ty type; }; template -struct tuple_type_cat, std::tuple> -{ +struct tuple_type_cat, std::tuple> { typedef std::tuple type; }; template struct tuple_type_cat, std::tuple, ty_more...> - : public tuple_type_cat, typename tuple_type_cat, ty_more...>::type> -{ -}; + : public tuple_type_cat< + std::tuple, + typename tuple_type_cat, ty_more...>::type> {}; } // namespace internal } // namespace pn diff --git a/src/cpp/src/value.cpp b/src/cpp/src/value.cpp index d3be9d1..177d8ce 100644 --- a/src/cpp/src/value.cpp +++ b/src/cpp/src/value.cpp @@ -68,9 +68,9 @@ struct helper { } template static string_view as(const value_api& x) { - return x.is_string() ? string_view{x.c_obj()->s->values, - static_cast(x.c_obj()->s->count) - 1} - : string_view{}; + return x.is_string() + ? string_view{x.c_obj()->s->values, static_cast(x.c_obj()->s->count) - 1} + : string_view{}; } }; diff --git a/src/cpp/test/data.test.cpp b/src/cpp/test/data.test.cpp index a91d71a..1aa7237 100644 --- a/src/cpp/test/data.test.cpp +++ b/src/cpp/test/data.test.cpp @@ -23,11 +23,11 @@ using DataTest = ::testing::Test; using ::testing::Eq; -using ::testing::Ne; -using ::testing::Lt; -using ::testing::Le; -using ::testing::Gt; using ::testing::Ge; +using ::testing::Gt; +using ::testing::Le; +using ::testing::Lt; +using ::testing::Ne; namespace pntest { diff --git a/src/cpp/test/float.test.cpp b/src/cpp/test/float.test.cpp index 9dcd105..bdbf6d4 100644 --- a/src/cpp/test/float.test.cpp +++ b/src/cpp/test/float.test.cpp @@ -157,20 +157,21 @@ TEST_F(FloatTest, ParseSpecial) { char sign; int fp_type; const char* s; - } tests[] = {{'+', FP_ZERO, "0"}, - {'+', FP_ZERO, "0.0"}, - {'+', FP_ZERO, "0e0"}, - {'+', FP_ZERO, "0.0e0"}, - {'+', FP_ZERO, "0.00000000000000000000000"}, - {'-', FP_ZERO, "-0"}, - {'-', FP_ZERO, "-0.0"}, - {'-', FP_ZERO, "-0e0"}, - {'-', FP_ZERO, "-0.0e0"}, - {'-', FP_ZERO, "-0.00000000000000000000000"}, - {'+', FP_INFINITE, "inf"}, - {'+', FP_INFINITE, "+inf"}, - {'-', FP_INFINITE, "-inf"}, - {'+', FP_NAN, "nan"}}; + } tests[] = { + {'+', FP_ZERO, "0"}, + {'+', FP_ZERO, "0.0"}, + {'+', FP_ZERO, "0e0"}, + {'+', FP_ZERO, "0.0e0"}, + {'+', FP_ZERO, "0.00000000000000000000000"}, + {'-', FP_ZERO, "-0"}, + {'-', FP_ZERO, "-0.0"}, + {'-', FP_ZERO, "-0e0"}, + {'-', FP_ZERO, "-0.0e0"}, + {'-', FP_ZERO, "-0.00000000000000000000000"}, + {'+', FP_INFINITE, "inf"}, + {'+', FP_INFINITE, "+inf"}, + {'-', FP_INFINITE, "-inf"}, + {'+', FP_NAN, "nan"}}; for (const auto& test : tests) { double d = 0.0; pn_error_code_t err = PN_OK; diff --git a/src/cpp/test/io.test.cpp b/src/cpp/test/io.test.cpp index 101b4b5..680afcc 100644 --- a/src/cpp/test/io.test.cpp +++ b/src/cpp/test/io.test.cpp @@ -192,8 +192,8 @@ TEST_F(IoTest, ReadExtrema) { int64_t i64min, i64max; EXPECT_THAT( - (pn::string_view{"\200\000\000\000\000\000\000\000\177\377\377\377\377\377\377\377", - 16}) + (pn::string_view{ + "\200\000\000\000\000\000\000\000\177\377\377\377\377\377\377\377", 16}) .input() .read(&i64min, &i64max) . @@ -204,8 +204,8 @@ TEST_F(IoTest, ReadExtrema) { uint64_t u64min, u64max; EXPECT_THAT( - (pn::string_view{"\000\000\000\000\000\000\000\000\377\377\377\377\377\377\377\377", - 16}) + (pn::string_view{ + "\000\000\000\000\000\000\000\000\377\377\377\377\377\377\377\377", 16}) .input() .read(&u64min, &u64max) . diff --git a/src/cpp/test/lex.test.cpp b/src/cpp/test/lex.test.cpp index 8d53e9c..a50ed7e 100644 --- a/src/cpp/test/lex.test.cpp +++ b/src/cpp/test/lex.test.cpp @@ -199,7 +199,8 @@ TEST_F(LexTest, Bad) { "\037\n" "\177\n" "\310\n"), - LexesTo({line_in, error("\001", {PN_ERROR_CTRL, 1, 1}), line_eq, + LexesTo( + {line_in, error("\001", {PN_ERROR_CTRL, 1, 1}), line_eq, error("\037", {PN_ERROR_CTRL, 2, 1}), line_eq, error("\177", {PN_ERROR_CTRL, 3, 1}), line_eq, error("\310", {PN_ERROR_NONASCII, 4, 1}), line_out})); @@ -247,7 +248,8 @@ TEST_F(LexTest, Indent) { lex("1\n" " 2\n" " 3\n"), - LexesTo({line_in, i("1"), line_in, i("2"), line_in, i("3"), line_out, line_out, + LexesTo( + {line_in, i("1"), line_in, i("2"), line_in, i("3"), line_out, line_out, line_out})); EXPECT_THAT( @@ -255,7 +257,8 @@ TEST_F(LexTest, Indent) { " 2\n" " 3\n" " \t4\n"), - LexesTo({line_in, i("1"), line_in, i("2"), line_in, i("3"), line_out, line_eq, i("4"), + LexesTo( + {line_in, i("1"), line_in, i("2"), line_in, i("3"), line_out, line_eq, i("4"), line_out, line_out})); EXPECT_THAT( @@ -269,14 +272,16 @@ TEST_F(LexTest, Indent) { " 2\n" "3\n" " 4\n"), - LexesTo({line_in, i("1"), line_in, i("2"), line_out, line_eq, i("3"), line_in, i("4"), + LexesTo( + {line_in, i("1"), line_in, i("2"), line_out, line_eq, i("3"), line_in, i("4"), line_out, line_out})); EXPECT_THAT( lex("1\n" " 2\n" "3\n" " 4\n"), - LexesTo({line_in, i("1"), line_in, i("2"), line_out, line_eq, i("3"), line_in, i("4"), + LexesTo( + {line_in, i("1"), line_in, i("2"), line_out, line_eq, i("3"), line_in, i("4"), line_out, line_out})); EXPECT_THAT( @@ -286,7 +291,8 @@ TEST_F(LexTest, Indent) { "4\n" "5\n" " 6\n"), - LexesTo({line_in, i("1"), line_in, i("2"), line_in, i("3"), line_out, line_out, + LexesTo( + {line_in, i("1"), line_in, i("2"), line_in, i("3"), line_out, line_out, line_eq, i("4"), line_eq, i("5"), line_in, i("6"), line_out, line_out})); EXPECT_THAT( @@ -294,14 +300,16 @@ TEST_F(LexTest, Indent) { " \n" " 2\n" " 3\n"), - LexesTo({line_in, i("1"), line_in, i("2"), line_in, i("3"), line_out, line_out, + LexesTo( + {line_in, i("1"), line_in, i("2"), line_in, i("3"), line_out, line_out, line_out})); EXPECT_THAT( lex("1\n" " 2\n" " 3\n"), - LexesTo({line_in, i("1"), line_in, i("2"), line_out, + LexesTo( + {line_in, i("1"), line_in, i("2"), line_out, error(" 3", {PN_ERROR_OUTDENT, 3, 3}), line_out})); } @@ -425,13 +433,15 @@ TEST_F(LexTest, Data) { EXPECT_THAT( lex("[$, $1f, $ffff, $ 0f 1e 2d 3c]"), - LexesTo({line_in, array_in, data("$"), comma, data("$1f"), comma, data("$ffff"), comma, + LexesTo( + {line_in, array_in, data("$"), comma, data("$1f"), comma, data("$ffff"), comma, data("$ 0f 1e 2d 3c"), array_out, line_out})); EXPECT_THAT( lex("[$abcd\n" "$1234]\n"), - LexesTo({line_in, array_in, data("$abcd"), line_eq, data("$1234"), array_out, + LexesTo( + {line_in, array_in, data("$abcd"), line_eq, data("$1234"), array_out, line_out})); EXPECT_THAT(lex("$a"), LexesTo({line_in, error("$a", {PN_ERROR_PARTIAL, 1, 2}), line_out})); @@ -508,7 +518,8 @@ TEST_F(LexTest, String) { EXPECT_THAT( lex("[\"a\", \"b\", \"c\"]"), - LexesTo({line_in, array_in, str("\"a\""), comma, str("\"b\""), comma, str("\"c\""), + LexesTo( + {line_in, array_in, str("\"a\""), comma, str("\"b\""), comma, str("\"c\""), array_out, line_out})); } @@ -562,7 +573,8 @@ TEST_F(LexTest, XString) { "| two\n" "| three\n" "!\n"), - LexesTo({line_in, wrap("> one"), line_eq, pipe("| two"), line_eq, pipe("| three"), + LexesTo( + {line_in, wrap("> one"), line_eq, pipe("| two"), line_eq, pipe("| three"), line_eq, bang, line_out})); } @@ -573,7 +585,8 @@ TEST_F(LexTest, XList) { lex("***"), LexesTo({line_in, star, line_in, star, line_in, star, line_out, line_out, line_out})); EXPECT_THAT( - lex("***0"), LexesTo({line_in, star, line_in, star, line_in, star, line_in, i("0"), + lex("***0"), LexesTo( + {line_in, star, line_in, star, line_in, star, line_in, i("0"), line_out, line_out, line_out, line_out})); EXPECT_THAT(lex("* *"), LexesTo({line_in, star, line_in, star, line_out, line_out})); @@ -595,12 +608,14 @@ TEST_F(LexTest, XList) { lex("***\n" " **\n" " *\n"), - LexesTo({line_in, star, line_in, star, line_in, star, line_out, line_eq, star, line_in, + LexesTo( + {line_in, star, line_in, star, line_in, star, line_out, line_eq, star, line_in, star, line_eq, star, line_out, line_out, line_out})); EXPECT_THAT( lex("* \t *\t*\n" " *\n"), - LexesTo({line_in, star, line_in, star, line_in, star, line_eq, star, line_out, + LexesTo( + {line_in, star, line_in, star, line_in, star, line_eq, star, line_out, line_out, line_out})); } @@ -619,13 +634,15 @@ TEST_F(LexTest, Map) { lex("1:2\n3:4"), LexesTo({line_in, key("1:"), i("2"), line_eq, key("3:"), i("4"), line_out})); EXPECT_THAT( - lex("{1:2,3:4}"), LexesTo({line_in, map_in, key("1:"), i("2"), comma, key("3:"), + lex("{1:2,3:4}"), LexesTo( + {line_in, map_in, key("1:"), i("2"), comma, key("3:"), i("4"), map_out, line_out})); EXPECT_THAT( lex("1: 2\n3: 4"), LexesTo({line_in, key("1:"), i("2"), line_eq, key("3:"), i("4"), line_out})); EXPECT_THAT( - lex("{1: 2, 3: 4}"), LexesTo({line_in, map_in, key("1:"), i("2"), comma, key("3:"), + lex("{1: 2, 3: 4}"), LexesTo( + {line_in, map_in, key("1:"), i("2"), comma, key("3:"), i("4"), map_out, line_out})); } diff --git a/src/cpp/test/matchers.cpp b/src/cpp/test/matchers.cpp index 7757776..098d9b8 100644 --- a/src/cpp/test/matchers.cpp +++ b/src/cpp/test/matchers.cpp @@ -20,9 +20,9 @@ using ValueTest = ::testing::Test; using ::testing::Eq; using ::testing::MakeMatcher; using ::testing::MakePolymorphicMatcher; -using ::testing::MatchResultListener; using ::testing::Matcher; using ::testing::MatcherInterface; +using ::testing::MatchResultListener; using ::testing::Ne; using ::testing::Not; using ::testing::PolymorphicMatcher; diff --git a/src/cpp/test/string.test.cpp b/src/cpp/test/string.test.cpp index 19e23c2..8811ed5 100644 --- a/src/cpp/test/string.test.cpp +++ b/src/cpp/test/string.test.cpp @@ -23,11 +23,11 @@ using StringTest = ::testing::Test; using ::testing::ElementsAre; using ::testing::Eq; -using ::testing::Ne; -using ::testing::Lt; -using ::testing::Le; -using ::testing::Gt; using ::testing::Ge; +using ::testing::Gt; +using ::testing::Le; +using ::testing::Lt; +using ::testing::Ne; namespace pntest { diff --git a/src/cpp/test/valuepp.test.cpp b/src/cpp/test/valuepp.test.cpp index 71a6fad..92206d3 100644 --- a/src/cpp/test/valuepp.test.cpp +++ b/src/cpp/test/valuepp.test.cpp @@ -273,20 +273,22 @@ TEST_F(ValueppTest, Nested) { } EXPECT_THAT( - pn::value(pn::array{pn::map{{"name", "Jane Doe"}, - {"number", "555-1234"}, - {"born", pn::array{1980, 10, 10}}}, - pn::map{{"name", "John Doe"}, - {"number", "555-6789"}, - {"born", pn::array{1981, 2, 3}}}}), + pn::value(pn::array{ + pn::map{{"name", "Jane Doe"}, + {"number", "555-1234"}, + {"born", pn::array{1980, 10, 10}}}, + pn::map{{"name", "John Doe"}, + {"number", "555-6789"}, + {"born", pn::array{1981, 2, 3}}}}), matches); - pn::value orig = pn::array{pn::map{{"name", "Jane Doe"}, - {"number", "555-1234"}, - {"born", pn::array{1980, 10, 10}}}, - pn::map{{"name", "John Doe"}, - {"number", "555-6789"}, - {"born", pn::array{1981, 2, 3}}}}; + pn::value orig = pn::array{ + pn::map{{"name", "Jane Doe"}, + {"number", "555-1234"}, + {"born", pn::array{1980, 10, 10}}}, + pn::map{{"name", "John Doe"}, + {"number", "555-6789"}, + {"born", pn::array{1981, 2, 3}}}}; pn::value copy = orig.copy(); orig = nullptr; EXPECT_THAT(copy, matches); diff --git a/src/python/procyon/decode.py b/src/python/procyon/decode.py index 10f3114..01d180b 100644 --- a/src/python/procyon/decode.py +++ b/src/python/procyon/decode.py @@ -29,6 +29,7 @@ class ProcyonDecoder(object): + def parse(self, lines): return self._decode(ProcyonParser(Lexer(lines))) diff --git a/src/python/procyon/dump.py b/src/python/procyon/dump.py index cb5a2ea..6d00614 100644 --- a/src/python/procyon/dump.py +++ b/src/python/procyon/dump.py @@ -42,6 +42,7 @@ class MinifiedStyle(object): class ProcyonEncoder(object): + def __init__(self, style, converter): self.always_short = style.always_short self.colon, self.comma = style.separators diff --git a/src/python/procyon/error.py b/src/python/procyon/error.py index 2b29426..1ebd358 100644 --- a/src/python/procyon/error.py +++ b/src/python/procyon/error.py @@ -87,6 +87,7 @@ class Error(enum.Enum): class ProcyonDecodeError(ValueError): + def __init__(self, code, lineno, column): ValueError.__init__(self, "{0}:{1}: {2}".format(lineno, column, error_message[code])) self.code = code diff --git a/src/python/procyon/parse.py b/src/python/procyon/parse.py index d0cf86d..4d873cf 100644 --- a/src/python/procyon/parse.py +++ b/src/python/procyon/parse.py @@ -56,6 +56,7 @@ def _parse_short_string(s): class ProcyonParser(object): + def __init__(self, l): self.l = l self.stack = [0] diff --git a/src/python/procyon/spec.py b/src/python/procyon/spec.py index 8177bca..acd57d3 100644 --- a/src/python/procyon/spec.py +++ b/src/python/procyon/spec.py @@ -3,6 +3,7 @@ from .error import Error from .parse_enums import Acc, Emit, Key +# yapf: disable LEX_BYTE_CLASSES = bytearray(b"\000\000\000\000\000\000\000\000\000\001\002\000\000\000\000\000" b"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" b"\001\003\004\005\006\007\007\007\007\007\010\011\012\013\014\015" diff --git a/src/python/setup.py b/src/python/setup.py index 909c904..00e7da0 100644 --- a/src/python/setup.py +++ b/src/python/setup.py @@ -23,13 +23,12 @@ with open("../../LICENSE") as f: license = f.read() -setup( - name="procyon", - version="1.0.0", - description="Procyon object notation", - long_description=readme, - author="Chris Pickel", - author_email="sfiera@twotaled.com", - url="https://github.com/arescentral/procyon", - license=license, - packages=find_packages(exclude=("test", ))) +setup(name="procyon", + version="1.0.0", + description="Procyon object notation", + long_description=readme, + author="Chris Pickel", + author_email="sfiera@twotaled.com", + url="https://github.com/arescentral/procyon", + license=license, + packages=find_packages(exclude=("test", )))