diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1810dc8..8a87fef 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,6 +19,7 @@ repos: entry: ruff language: system types: [python] + args: ["check"] require_serial: true - id: check-added-large-files name: Check for added large files diff --git a/CMakeLists.txt b/CMakeLists.txt index 4edc200..e2dc0e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,8 +3,9 @@ cmake_minimum_required(VERSION 3.7...3.29) project(pya2l_extensions LANGUAGES C CXX) cmake_policy(SET CMP0135 NEW) +cmake_policy(SET CMP0094 NEW) -find_package(Python COMPONENTS Interpreter Development) +find_package(Python3 COMPONENTS Interpreter Development) find_package(pybind11 REQUIRED) set(ANTLR4_TAG 4.13.1) diff --git a/build_ext.py b/build_ext.py index 4b70c61..ab203c5 100644 --- a/build_ext.py +++ b/build_ext.py @@ -6,19 +6,63 @@ import re import subprocess # nosec import sys -from typing import Optional +import sysconfig from pathlib import Path - -# from pprint import pprint from tempfile import TemporaryDirectory +from typing import Optional -print("Platform", platform.system()) - TOP_DIR = Path(__file__).parent GIT_TAG_RE = re.compile(r"refs/tags/v?(\d\.\d{1,3}.\d{1,3})") +print("Platform", platform.system()) +uname = platform.uname() +if uname.system == "Darwin": + os.environ["MACOSX_DEPLOYMENT_TARGET"] = "11.0" + +VARS = sysconfig.get_config_vars() + + +def get_python_base() -> str: + # Applies in this form only to Windows. + if "base" in VARS and VARS["base"]: # noqa: RUF019 + return VARS["base"] + if "installed_base" in VARS and VARS["installed_base"]: # noqa: RUF019 + return VARS["installed_base"] + + +def alternate_libdir(pth: str): + base = Path(pth).parent + libdir = Path(base) / "libs" + if libdir.exists(): + # available_libs = os.listdir(libdir) + return str(libdir) + else: + return "" + + +def get_py_config() -> dict: + pynd = VARS["py_version_nodot"] # Should always be present. + include = sysconfig.get_path("include") # Seems to be cross-platform. + library = f"python{pynd}.lib" + if uname.system == "Windows": + base = get_python_base() + libdir = Path(base) / "libs" + if libdir.exists(): + available_libs = os.listdir(libdir) + if library in available_libs: + libdir = str(libdir) + else: + libdir = "" + else: + libdir = alternate_libdir(include) + else: + libdir = VARS["LIBDIR"] + library = VARS["LDLIBRARY"] + + return dict(exe=sys.executable, include=include, libdir=libdir, library=library) + def sort_by_version(version: str) -> tuple[int]: h, m, s = version.split(".") @@ -37,7 +81,7 @@ def fetch_tags(repo: str) -> list[str]: return sorted(tag_set, key=sort_by_version) -def most_recent_tag(repo: str) -> Optional[str]: +def most_recent_tag(repo: str) -> Optional[str]: # noqa: UP007 tags = fetch_tags(repo) return tags[-1] if tags else None @@ -57,15 +101,15 @@ def build_extension(debug: bool = False, use_temp_dir=True) -> None: debug = int(os.environ.get("DEBUG", 0)) or debug cfg = "Debug" if debug else "Release" - # Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON - # EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code - # from Python. + py_cfg = get_py_config() + cmake_args = [ - # f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}", - # "-G Ninja", - f"-DPYTHON_EXECUTABLE={sys.executable}", + f"-DPython3_EXECUTABLE={py_cfg['exe']}", + f"-DPython3_INCLUDE_DIR={py_cfg['include']}", + f"-DPython3_LIBRARY={str(Path(py_cfg['libdir']) / Path(py_cfg['library']))}", # noqa: RUF010 f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm ] + build_args = ["--config Release", "--verbose"] # Adding CMake arguments set as environment variable # (needed e.g. to build for ARM OSx on conda-forge) @@ -90,8 +134,7 @@ def build_extension(debug: bool = False, use_temp_dir=True) -> None: banner("Step #1: Configure") # cmake_args += ["--debug-output"] - print("aufruf:", ["cmake", str(TOP_DIR), *cmake_args]) - subprocess.run(["cmake", str(TOP_DIR), *cmake_args], cwd=build_temp, check=True) # nosec + subprocess.run(["cmake", "-S", str(TOP_DIR), *cmake_args], cwd=build_temp, check=True) # nosec cmake_args += [f"--parallel {mp.cpu_count()}"] diff --git a/pya2l/aml.g4 b/pya2l/aml.g4 index 5cb6126..c6167f2 100644 --- a/pya2l/aml.g4 +++ b/pya2l/aml.g4 @@ -65,8 +65,7 @@ predefined_type_name: ; block_definition: - //block_definition | 'block' tag = tagValue tn = type_name - 'block' tag = tagValue (blk = block_definition | tn = type_name) + 'block' tag = tagValue (/* blk = block_definition | */ tn = type_name) ; enum_type_name: @@ -83,12 +82,12 @@ enumerator: ; struct_type_name: - 'struct' t0 = identifierValue? '{' l += struct_member* '}' + 'struct' t0 = identifierValue? '{' l += struct_member* '}' ';'? | 'struct' t1 = identifierValue ; struct_member: - m = member';' + m = member ';'? ; member: @@ -101,20 +100,20 @@ array_specifier: ; taggedstruct_type_name: - 'taggedstruct' t0 = identifierValue? '{' (l += taggedstruct_member)* '}' + 'taggedstruct' t0 = identifierValue? '{' (l += taggedstruct_member)* '}' ';'? | 'taggedstruct' t1 = identifierValue ; taggedstruct_member: - ts1 = taggedstruct_definition ';' + ts1 = taggedstruct_definition ';'? | '(' ts0 = taggedstruct_definition ';'? ')' '*' ';' - | bl1 = block_definition ';' + | bl1 = block_definition ';'? | '(' bl0 = block_definition ';'? ')' '*' ';' ; taggedstruct_definition: tag = tagValue mem = member? - | tag = tagValue '(' mem = member ';'? ')' '*' // ';' + | tag = tagValue '(' mem = member ';'? ')' '*' ; taggedunion_type_name: @@ -123,8 +122,8 @@ taggedunion_type_name: ; tagged_union_member: - t = tagValue m = member? ';' - | b = block_definition ';' + t = tagValue m = member? ';'? + | b = block_definition ';'? ; numericValue: diff --git a/pya2l/aml/aml_visitor.cpp b/pya2l/aml/aml_visitor.cpp index 12f2edf..fe8b889 100644 --- a/pya2l/aml/aml_visitor.cpp +++ b/pya2l/aml/aml_visitor.cpp @@ -120,22 +120,12 @@ std::any AmlVisitor::visitType_definition(amlParser::Type_definitionContext *ctx } std::any AmlVisitor::visitType_name(amlParser::Type_nameContext *ctx) { - //const auto ctx_t = ctx->t; const auto ctx_pr = ctx->pr; const auto ctx_st = ctx->st; const auto ctx_ts = ctx->ts; const auto ctx_tu = ctx->tu; const auto ctx_en = ctx->en; -#if 0 - std::string tag_text{}; - if (ctx_t) { - const auto tag_opt = std::any_cast(visit(ctx_t)); - if (tag_opt) { - tag_text = *tag_opt; - } - } -#endif if (ctx_pr) { auto pdt = std::any_cast(visit(ctx_pr)); return make_type(pdt); @@ -169,13 +159,9 @@ std::any AmlVisitor::visitPredefined_type_name(amlParser::Predefined_type_nameCo std::any AmlVisitor::visitBlock_definition(amlParser::Block_definitionContext *ctx) { const auto ctx_tag = ctx->tag; const auto ctx_tn = ctx->tn; - //const auto ctx_mem = ctx->mem; - //const auto ctx_mult = ctx->mult; std::string tag_text; - //bool multiple{ false }; Type *tn = nullptr; - //Member member; if (ctx_tag) { const auto tag_opt = std::any_cast(visit(ctx_tag)); @@ -187,17 +173,7 @@ std::any AmlVisitor::visitBlock_definition(amlParser::Block_definitionContext *c if (ctx_tn) { tn = std::any_cast(visit(ctx_tn)); } -#if 0 - if (ctx_mem) { - member = std::any_cast(visit(ctx_mem)); - } - if (ctx_mult) { - if (ctx_mult->getText() == "*") { - multiple = true; - } - } -#endif return BlockDefinition(tag_text, tn/*, member, multiple*/); } @@ -307,51 +283,49 @@ std::any AmlVisitor::visitStruct_type_name(amlParser::Struct_type_nameContext *c std::any AmlVisitor::visitStruct_member(amlParser::Struct_memberContext *ctx) { const auto ctx_m = ctx->m; - //const auto ctx_mstar = ctx->mstar; - //const auto ctx_m0 = ctx->m0; if (ctx_m) { const auto mem = std::any_cast(visit(ctx_m)); return StructMember(mem); } -#if 0 - if (ctx_m0) { - if (ctx_m0->getText() == "*") { - if (ctx_mstar) { - const auto mem = std::any_cast(visit(ctx_mstar)); - return StructMember(mem, true); - } - } - } -#endif + return {}; } std::any AmlVisitor::visitMember(amlParser::MemberContext *ctx) { const auto ctx_t = ctx->t; const auto ctx_a = ctx->a; - std::vector arrary_specifier; + const auto ctx_b = ctx->b; + std::vector arrary_specifier{}; std::int64_t value{ 0 }; Type *tp = nullptr; + std::optional block{std::nullopt}; - if (ctx_t) { - const auto type_name = visit(ctx_t); - if (type_name.has_value()) { - tp = std::any_cast(type_name); - } + if (ctx_b) { + block = std::any_cast(visit(ctx_b)); } + else { - for (const auto &elem : ctx_a) { - const auto value_cont = std::any_cast(visit(elem)); + if (ctx_t) { + const auto type_name = visit(ctx_t); + if (type_name.has_value()) { + tp = std::any_cast(type_name); + } + } + + for (const auto& elem : ctx_a) { + const auto value_cont = std::any_cast(visit(elem)); - if (std::holds_alternative(value_cont)) { - value = std::get(value_cont); - } else if (std::holds_alternative(value_cont)) { - value = static_cast(std::get(value_cont)); + if (std::holds_alternative(value_cont)) { + value = std::get(value_cont); + } + else if (std::holds_alternative(value_cont)) { + value = static_cast(std::get(value_cont)); + } + arrary_specifier.push_back(value); } - arrary_specifier.push_back(value); } - return Member(tp, arrary_specifier); + return Member(block, tp, arrary_specifier); } std::any AmlVisitor::visitArray_specifier(amlParser::Array_specifierContext *ctx) { diff --git a/pya2l/aml/klasses.hpp b/pya2l/aml/klasses.hpp index 25e30f1..02e5e84 100644 --- a/pya2l/aml/klasses.hpp +++ b/pya2l/aml/klasses.hpp @@ -169,81 +169,72 @@ using EnumerationOrReferrer = std::variant& arr_spec) : m_type(type), m_arr_spec(arr_spec) { + explicit BlockDefinition(const std::string& tag, Type* type) : + m_tag(tag), m_type(type) { } - const Type* get_type() const noexcept { - return m_type; + const std::string& get_tag() const noexcept { + return m_tag; } - const std::vector& get_array_spec() const noexcept { - return m_arr_spec; + const Type* get_type() const noexcept { + return m_type; } - private: +private: - Type* m_type; - std::vector m_arr_spec{}; + std::string m_tag; + Type* m_type; }; -class BlockDefinition { +class Member { public: - BlockDefinition() : m_tag(), m_type(nullptr)/*, m_member(), m_multiple(false)*/ { + Member() : m_block(std::nullopt), m_type(nullptr) { } - explicit BlockDefinition(const std::string& tag, Type* type/*, const Member& member, bool multiple*/) : - m_tag(tag), m_type(type) /*, m_member(member), m_multiple(multiple)*/ { + explicit Member(std::optional block, Type* type, const std::vector& arr_spec) : + m_block(block), m_type(type), m_arr_spec(arr_spec) { } - const std::string& get_tag() const noexcept { - return m_tag; - } + const std::optional get_block() const noexcept { + return m_block; + }; const Type* get_type() const noexcept { return m_type; } - #if 0 - const Member& get_member() const noexcept { - return m_member; - } - bool get_multiple() const noexcept { - return m_multiple; + const std::vector& get_array_spec() const noexcept { + return m_arr_spec; } - #endif + private: - std::string m_tag; - Type* m_type; - //Member m_member; - //bool m_multiple; + std::optional m_block; + Type* m_type; + std::vector m_arr_spec{}; }; class StructMember { public: - explicit StructMember(const Member& member/*, bool multiple*/) : m_member(member) /*, m_multiple(multiple)*/ { + explicit StructMember(const Member& member) : m_member(member) { } const Member& get_member() const noexcept { return m_member; } -#if 0 - bool get_multiple() const noexcept { - return m_multiple; - } -#endif + private: Member m_member; - // bool m_multiple; }; class Struct { diff --git a/pya2l/aml/marshal.cpp b/pya2l/aml/marshal.cpp index f552f33..c789c51 100644 --- a/pya2l/aml/marshal.cpp +++ b/pya2l/aml/marshal.cpp @@ -10,24 +10,6 @@ void dumps(std::stringstream& ss, const AMLPredefinedType& pdt) { ss << to_binary(value); } -// Member. -void dumps(std::stringstream& ss, const Member& mem) { - const auto& arr_spec = mem.get_array_spec(); - const std::size_t array_size = std::size(arr_spec); - ss << to_binary(array_size); - for (std::uint32_t arr : arr_spec) { - ss << to_binary(arr); - } - const auto& tp = mem.get_type(); - if (tp != nullptr) { - dumps(ss, tp); - } - else { - std::cout << "nullptr\n"; - } - -} - // Referrer. void dumps(std::stringstream& ss, const Referrer& ref) { ss << to_binary("R"); @@ -37,26 +19,39 @@ void dumps(std::stringstream& ss, const Referrer& ref) { ss << to_binary(idf); } + // BlockDefinition. void dumps(std::stringstream& ss, const BlockDefinition& block) { ss << to_binary("B"); - const auto& tag = block.get_tag(); - const auto type = block.get_type(); - //const auto& member = block.get_member(); - //const auto& multiple = block.get_multiple(); + const auto& tag = block.get_tag(); + const auto type = block.get_type(); ss << to_binary(tag); if (type) { ss << to_binary("T"); dumps(ss, type); } -#if 0 - else if (member.get_type()) { - ss << to_binary("M"); - dumps(ss, member); +} + +// Member. +void dumps(std::stringstream& ss, const Member& mem) { + const auto& tp = mem.get_type(); + if (tp != nullptr) { + ss << to_binary("T"); + + const auto& arr_spec = mem.get_array_spec(); + const std::size_t array_size = std::size(arr_spec); + ss << to_binary(array_size); + for (std::uint32_t arr : arr_spec) { + ss << to_binary(arr); + } + + dumps(ss, tp); + } + else { + const auto& blk = *mem.get_block(); + dumps(ss, blk); } - ss << to_binary(multiple); -#endif } // TaggedStructDefinition. @@ -67,8 +62,7 @@ void dumps(std::stringstream& ss, const TaggedStructDefinition& tsd) { ss << to_binary(multiple); if (tp) { ss << to_binary(true); // available. - //dumps(ss, tp); - dumps(ss, member); // FIXED!!! + dumps(ss, member); } else { // Tag-only. ss << to_binary(false); // NOT available. diff --git a/pya2l/aml/unmarshal.hpp b/pya2l/aml/unmarshal.hpp index 93539af..6093916 100644 --- a/pya2l/aml/unmarshal.hpp +++ b/pya2l/aml/unmarshal.hpp @@ -94,31 +94,24 @@ class Node { } const Node* find_block(const std::string& name) const noexcept { + + + if (m_aml_type == AmlType::BLOCK) { - if (m_map.contains("TAG")) { - if (get_tag() == name) { - return this; - } else { - return nullptr; + const auto& tp = map().at("TYPE").map(); + const auto& members = tp.at("MEMBERS").list(); + for (const auto& member : members) { + const auto& tag = member.get_tag(); + std::cout << "tag: " << tag << std::endl; + if (name == tag) { + return &member; } - } else { - return nullptr; - } - } else { - for (auto entry : get_members()) { - std::cout << static_cast(entry->node_type()) << " " << static_cast(entry->aml_type()) << std::endl; - //if (entry->aml_type() == Node::AmlType::BLOCK) { - if (entry->get_tag() == name) { - return entry; - } - //} } } return nullptr; } std::tuple, std::optional> member_or_type() const noexcept { - //if (m_aml_type == AmlType::BLOCK) { auto multiple = is_multiple(); const auto& member = m_map.at("MEMBER"); if (member.aml_type() == Node::AmlType::NONE) { @@ -127,7 +120,6 @@ class Node { } else { return { multiple, &member, std::nullopt }; } - //} return { false, {}, {} }; } @@ -352,7 +344,7 @@ inline Node make_tagged_struct(const std::string& name, std::vector& array_spec, const Node& type) { +inline Node make_member(const std::vector& array_spec, const Node& node, bool is_block) { Node::list_t lst{}; for (const auto& arrs : array_spec) { @@ -360,7 +352,8 @@ inline Node make_member(const std::vector& array_spec, const Node } Node::map_t map = { - { "TYPE", type }, + {"IS_BLOCK", Node(Node::AmlType::TERMINAL, is_block)}, + { "NODE", node }, { "ARR_SPEC", Node(Node::AmlType::MEMBERS, lst) }, }; @@ -368,20 +361,17 @@ inline Node make_member(const std::vector& array_spec, const Node return res; } -inline Node make_block(const std::string& tag /*, bool multiple*/, const Node& type/*, const Node& member*/) { +inline Node make_block(const std::string& tag , const Node& type) { Node::map_t map = { { "TAG", Node(Node::AmlType::TERMINAL, tag) }, - //{ "MULTIPLE", Node(Node::AmlType::TERMINAL, multiple) }, { "TYPE", type }, - //{ "MEMBER", member }, }; auto res = Node(Node::AmlType::BLOCK, map); return res; } -inline Node make_struct_member(/* bool multiple, */ const Node & member) { +inline Node make_struct_member(const Node & member) { Node::map_t map = { - // { "MULTIPLE", Node(Node::AmlType::TERMINAL, multiple) }, { "MEMBER", member }, }; auto res = Node(Node::AmlType::STRUCT_MEMBER, map); @@ -522,7 +512,6 @@ class Unmarshaller { } Node load_type() { - // const auto& tag = m_reader.from_binary_str(); // "PD" - AMLPredefinedType // "TS" - TaggedStruct // "TU" - TaggedUnion @@ -548,12 +537,23 @@ class Unmarshaller { } Node load_member() { - auto arr_count = m_reader.from_binary(); - std::vector array_spec; - for (auto idx = 0UL; idx < arr_count; ++idx) { - array_spec.push_back(m_reader.from_binary()); + const auto& disc = m_reader.from_binary_str(); + + if (disc == "T") { + auto arr_count = m_reader.from_binary(); + std::vector array_spec; + for (auto idx = 0UL; idx < arr_count; ++idx) { + array_spec.push_back(m_reader.from_binary()); + } + return make_member(array_spec, load_type(), false); + } + else if (disc == "B") { + return make_member({}, load_block(), true); } - return make_member(array_spec, load_type()); + else { + + } + } Node load_struct() { diff --git a/pya2l/aml_parser.cpp b/pya2l/aml_parser.cpp index f2a1f33..793913b 100644 --- a/pya2l/aml_parser.cpp +++ b/pya2l/aml_parser.cpp @@ -12,8 +12,8 @@ using namespace antlr4; void marshal(std::stringstream& ss, const AmlFile& amlf); -// const std::string BASE{ "C:/csProjects/" }; -const std::string BASE{ "C:/Users/HP/PycharmProjects/" }; +const std::string BASE{ "C:/csProjects/" }; +//const std::string BASE{ "C:/Users/HP/PycharmProjects/" }; int main(int argc, const char* argv[]) { std::ifstream stream; @@ -50,7 +50,6 @@ int main(int argc, const char* argv[]) { std::stringstream ss; marshal(ss, res); - // std::cout << ss.str(); const auto FNAME{ BASE + "pyA2L/pya2l/examples/aml_dump.bin" }; diff --git a/pya2l/if_data_parser.cpp b/pya2l/if_data_parser.cpp index 6fd56c3..6757c09 100644 --- a/pya2l/if_data_parser.cpp +++ b/pya2l/if_data_parser.cpp @@ -31,22 +31,45 @@ class IfDataParser { } void parse() { - do_type(); -#if 0 + const auto root = get_root(); + if (root) { + m_grammar.push(root); + consume(); + do_type(); + } + } + + const Node * get_root() { auto token = current_token(); - if (token) { - auto [type, text] = *token; - switch (type) { - case a2llg::BEGIN: - consume(); - block_type(); - break; - default: - std::cerr << "Unknown token type: " << type << std::endl; + const auto [type, text] = *token; + consume(); + const auto [type2, text2] = *current_token(); + + if (type == a2llg::BEGIN) { + if ((type2 == a2llg::IDENT) && (text2 == "IF_DATA")) { + for (const auto& member: top()->map().at("MEMBERS").list()) { + const auto& mmap = member.map(); + + if (member.aml_type() == Node::AmlType::BLOCK) { + const auto tag = std::get(mmap.at("TAG").value()); + if (tag == "IF_DATA") { + return &member; + } + } + else { + const auto name = std::get(mmap.at("NAME").value()); + std::cout << "Name: " << name << std::endl; + if (name == "if_data") { + return &member; + } + } + + + } } - parse(); } -#endif + + return nullptr; } token_t next_token() { @@ -210,6 +233,9 @@ class IfDataParser { case Node::AmlType::PDT: pdt_type(); break; + case Node::AmlType::BLOCK: + block_type(); + break; default: std::cerr << "Unknown type: " << std::endl; break; @@ -232,8 +258,8 @@ class IfDataParser { token_t m_current_token; }; -// const std::string BASE{ "C:/csProjects/" }; -const std::string BASE{ "C:/Users/HP/PycharmProjects/" }; +const std::string BASE{ "C:/csProjects/" }; +//const std::string BASE{ "C:/Users/HP/PycharmProjects/" }; const std::string CPLX_TEXT{ "" " /begin IF_DATA ASAP1B_CCP" @@ -359,7 +385,106 @@ const std::string CPLX_TEXT{ "" " /end TP_BLOB" " /end IF_DATA" }; +const std::string CPLX_TEXT2{ +" /begin IF_DATA ASAP1B_KWP2000 " \ +" /begin SOURCE " \ +" \"timeslot\" " \ +" 0 " \ +" 0 " \ +" QP_BLOB " \ +" 0 " \ +" BLOCKMODE " \ +" 0xF0 " \ +" 0 " \ +" 20 " \ +" /end SOURCE " \ +" " \ +" /begin TP_BLOB " \ +" 0x100 " \ +" 0x11 " \ +" 0xF1 " \ +" WuP " \ +" MSB_LAST " \ +" 1 " \ +" 0x00000 " \ +" " \ +" SERAM " \ +" 0x10000 " \ +" 0x10000 " \ +" 0x13FFF " \ +" 0x17FFF " \ +" 0x000000 " \ +" 0x000000 " \ +" 1 " \ +" 1 " \ +" 1 " \ +" 1 " \ +" " \ +" /begin CHECKSUM " \ +" 0x010201 " \ +" 1 " \ +" 1 " \ +" RequestRoutineResults " \ +" RNC_RESULT 0x23 " \ +" /end CHECKSUM " \ +" " \ +" /begin FLASH_COPY " \ +" TOOLFLASHBACK " \ +" 3 " \ +" RequestRoutineResults " \ +" RAM_InitByECU " \ +" 0x86 " \ +" COPY_FRAME 1 " \ +" RNC_RESULT 0x23 0xFB 0xFC " \ +" COPY_PARA 1 " \ +" /end FLASH_COPY " \ +" " \ +" BAUD_DEF " \ +" 105600 " \ +" 0x86 " \ +" 0x81 " \ +" BAUD_DEF " \ +" 211200 " \ +" 0x86 " \ +" 0xA1 " \ +" BAUD_DEF " \ +" 156250 " \ +" 0x86 " \ +" 0x91 " \ +" BAUD_DEF " \ +" 125000 " \ +" 0x86 " \ +" 0x87 " \ +" BAUD_DEF " \ +" 10400 " \ +" 0x86 " \ +" 0x14 " \ +" " \ +" TIME_DEF " \ +" 0x0001 " \ +" 0x0000 " \ +" 0x0032 " \ +" 0x0003 " \ +" 0x0200 " \ +" 0x0000 " \ +" TIME_DEF " \ +" 0x0001 " \ +" 0x0000 " \ +" 0x0032 " \ +" 0x0003 " \ +" 0x0200 " \ +" 0x0001 " \ +" " \ +" SECURITY_ACCESS " \ +" 1 " \ +" 1 " \ +" 0 " \ +" " \ +" /end TP_BLOB " \ +" /end IF_DATA "}; + int main() { +#if 0 std::ifstream stream; stream.open(BASE + "pyA2L/pya2l/examples/some_if_data.txt"); @@ -367,6 +492,7 @@ int main() { ANTLRInputStream input(stream); auto ifd_lexer = a2llg(&input); +#endif auto root = load_grammar(BASE + "pyA2L/pya2l/examples/aml_dump.bin"); @@ -377,7 +503,7 @@ int main() { "0x1E8\n" "/end IF_DATA"); // auto lex = IfDataParser(root, TEXT); - auto lex = IfDataParser(root, CPLX_TEXT); + auto lex = IfDataParser(root, CPLX_TEXT2); lex.parse(); diff --git a/setup.py b/setup.py index 1527c9d..03ce842 100644 --- a/setup.py +++ b/setup.py @@ -1,21 +1,14 @@ # pylint: disable=C0111 import os import platform -import subprocess -import sys -from itertools import chain +import subprocess # nosec from pathlib import Path import setuptools.command.build_py import setuptools.command.develop from pkg_resources import parse_requirements -from pybind11.setup_helpers import build_ext -from pybind11.setup_helpers import naive_recompile -from pybind11.setup_helpers import ParallelCompile -from pybind11.setup_helpers import Pybind11Extension -from setuptools import Command -from setuptools import find_namespace_packages -from setuptools import setup +from pybind11.setup_helpers import Pybind11Extension, build_ext +from setuptools import Command, find_namespace_packages, setup def _parse_requirements(filepath): @@ -31,15 +24,13 @@ def _parse_requirements(filepath): TEST_REQUIREMENTS = _parse_requirements(ROOT_DIRPATH / "requirements.test.txt") ANTLR_VERSION = next(req.specs[0][1] for req in BASE_REQUIREMENTS if req.project_name == "antlr4-python3-runtime") -PB11_INCLUDE_DIRS = subprocess.getoutput("pybind11-config --include") +PB11_INCLUDE_DIRS = subprocess.getoutput("pybind11-config --include") # nosec EXT_NAMES = ["pya2l.preprocessor", "pya2l.a2lparser_ext"] uname = platform.uname() if uname.system == "Linux": extra_compile_args = ["-fcoroutines"] # At least required on Raspberry PIs. -elif uname.system == "Darwin": - os.environ["MACOSX_DEPLOYMENT_TARGET"] = "11.0" extra_compile_args = [] else: extra_compile_args = [] @@ -68,9 +59,7 @@ class AntlrAutogen(Command): """Custom command to autogenerate Python code using ANTLR.""" description = "generate python code using antlr" - user_options = [ - ("target-dir=", None, "(optional) output directory for antlr artifacts"), - ] + user_options = (("target-dir=", None, "(optional) output directory for antlr artifacts"),) def initialize_options(self): """Set default values for options.""" @@ -93,16 +82,16 @@ def finalize_options(self): def run(self): """Run ANTLR.""" pwd = Path(os.environ.get("PWD", ".")) - antlrJar = pwd / Path("antlr-{}-complete.jar".format(ANTLR_VERSION)) + antlrJar = pwd / Path(f"antlr-{ANTLR_VERSION}-complete.jar") if not antlrJar.exists(): # https://www.antlr.org/download/antlr4-cpp-runtime-4.13.1-source.zip - os.system("curl -O -C - -L https://www.antlr.org/download/antlr-{}-complete.jar".format(ANTLR_VERSION)) + os.system(f"curl -O -C - -L https://www.antlr.org/download/antlr-{ANTLR_VERSION}-complete.jar") # nosec # print(f"{antlrJar} not found in '{pwd}'") # sys.exit(2) antlrJar = str(antlrJar) antlrCmd = ["java", "-Xmx500M", "-cp", antlrJar, "org.antlr.v4.Tool"] self.announce(" ".join(antlrCmd + self.arguments)) - subprocess.check_call(antlrCmd + self.arguments) + subprocess.check_call(antlrCmd + self.arguments) # nosec clean()