diff --git a/CMakeLists.txt b/CMakeLists.txt index 530839d1a..60f55d2d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,14 +125,14 @@ add_library(re2c_objects_autogen OBJECT "${CMAKE_CURRENT_BINARY_DIR}/src/parse/lex.h" "${CMAKE_CURRENT_BINARY_DIR}/src/parse/lex_conf.cc" "${CMAKE_CURRENT_BINARY_DIR}/src/options/parse_opts.cc" + "${CMAKE_CURRENT_BINARY_DIR}/src/default_syntax_c.cc" + "${CMAKE_CURRENT_BINARY_DIR}/src/default_syntax_go.cc" + "${CMAKE_CURRENT_BINARY_DIR}/src/default_syntax_rust.cc" "${re2c_docs}" ) add_library(re2c_objects_autogen_ver_to_vernum OBJECT "${CMAKE_CURRENT_BINARY_DIR}/src/msg/ver_to_vernum.cc" ) -add_library(re2c_objects_autogen_syntax_c OBJECT - "${CMAKE_CURRENT_BINARY_DIR}/src/default_syntax_c.cc" -) set(re2c_sources src/codegen/helpers.cc @@ -209,28 +209,23 @@ re2c_bootstrap_parser( "src/codegen/syntax_parser.ypp" "src/codegen/syntax_parser.cc" "src/codegen/syntax_parser.h") + re2c_bootstrap_syntax("include/syntax/c" "src/default_syntax_c.cc") +re2c_bootstrap_syntax("include/syntax/go" "src/default_syntax_go.cc") +re2c_bootstrap_syntax("include/syntax/rust" "src/default_syntax_rust.cc") # re2c -add_executable(re2c ${re2c_sources} $) +add_executable(re2c ${re2c_sources}) # re2go if (RE2C_BUILD_RE2GO) - re2c_bootstrap_syntax("include/syntax/go" "src/default_syntax_go.cc") - add_library(re2c_objects_autogen_syntax_go OBJECT - "${CMAKE_CURRENT_BINARY_DIR}/src/default_syntax_go.cc" - ) - add_executable(re2go ${re2c_sources} $) + add_executable(re2go ${re2c_sources}) target_compile_definitions(re2go PUBLIC "RE2C_LANG=Lang::GO") endif() # re2rust if (RE2C_BUILD_RE2RUST) - re2c_bootstrap_syntax("include/syntax/rust" "src/default_syntax_rust.cc") - add_library(re2c_objects_autogen_syntax_rust OBJECT - "${CMAKE_CURRENT_BINARY_DIR}/src/default_syntax_rust.cc" - ) - add_executable(re2rust ${re2c_sources} $) + add_executable(re2rust ${re2c_sources}) target_compile_definitions(re2rust PUBLIC "RE2C_LANG=Lang::RUST") endif() diff --git a/Makefile.am b/Makefile.am index e7b0bb865..eb2a8c040 100644 --- a/Makefile.am +++ b/Makefile.am @@ -145,8 +145,10 @@ re2c_GEN_SRC = \ src/codegen/syntax_lexer.cc \ src/codegen/syntax_parser.cc \ src/parse/lex_conf.cc \ - src/options/parse_opts.cc - src/default_syntax_c.cc + src/options/parse_opts.cc \ + src/default_syntax_c.cc \ + src/default_syntax_go.cc \ + src/default_syntax_rust.cc re2c_GEN_HDR = \ src/codegen/syntax_parser.h \ src/parse/lex.h \ @@ -154,7 +156,7 @@ re2c_GEN_HDR = \ re2c_GEN = \ $(re2c_GEN_SRC) \ $(re2c_GEN_HDR) -nodist_re2c_SOURCES = $(re2c_GEN) src/default_syntax_c.cc +nodist_re2c_SOURCES = $(re2c_GEN) # custom rules create headers and must go before normal rules BUILT_SOURCES = $(re2c_GEN_SRC) @@ -528,7 +530,7 @@ if WITH_GOLANG bin_PROGRAMS += re2go re2go_CXXFLAGS = $(AM_CXXFLAGS) -DRE2C_LANG=Lang::GO re2go_SOURCES = $(re2c_SOURCES) -nodist_re2go_SOURCES = $(re2c_GEN) src/default_syntax_go.cc +nodist_re2go_SOURCES = $(nodist_re2c_SOURCES) endif # re2rust @@ -536,5 +538,5 @@ if WITH_RUST bin_PROGRAMS += re2rust re2rust_CXXFLAGS = $(AM_CXXFLAGS) -DRE2C_LANG=Lang::RUST re2rust_SOURCES = $(re2c_SOURCES) -nodist_re2rust_SOURCES = $(re2c_GEN) src/default_syntax_rust.cc +nodist_re2rust_SOURCES = $(nodist_re2c_SOURCES) endif diff --git a/bootstrap/src/default_syntax_c.cc b/bootstrap/src/default_syntax_c.cc index 9a7535624..38ddbb3ee 100644 --- a/bootstrap/src/default_syntax_c.cc +++ b/bootstrap/src/default_syntax_c.cc @@ -1,4 +1,4 @@ -const char* DEFAULT_SYNTAX = +const char* DEFAULT_SYNTAX_C = "api = [pointers, generic];\n" "api_style = [functions, freeform];\n" "jump_model = [goto_label, loop_switch];\n" diff --git a/bootstrap/src/default_syntax_go.cc b/bootstrap/src/default_syntax_go.cc index 16c48f752..e9cdb482b 100644 --- a/bootstrap/src/default_syntax_go.cc +++ b/bootstrap/src/default_syntax_go.cc @@ -1,4 +1,4 @@ -const char* DEFAULT_SYNTAX = +const char* DEFAULT_SYNTAX_GO = "api = [generic];\n" "api_style = [freeform, functions];\n" "jump_model = [goto_label, loop_switch];\n" diff --git a/bootstrap/src/default_syntax_rust.cc b/bootstrap/src/default_syntax_rust.cc index 62452da26..9e27e38d9 100644 --- a/bootstrap/src/default_syntax_rust.cc +++ b/bootstrap/src/default_syntax_rust.cc @@ -1,4 +1,4 @@ -const char* DEFAULT_SYNTAX = +const char* DEFAULT_SYNTAX_RUST = "api = [generic];\n" "api_style = [freeform, functions];\n" "jump_model = [loop_switch];\n" diff --git a/build/stx2cpp.py b/build/stx2cpp.py index 47e088a03..1cd9f7b99 100644 --- a/build/stx2cpp.py +++ b/build/stx2cpp.py @@ -4,6 +4,7 @@ Encodes the contents of a syntax file as C++ source code. """ +import os import sys if len(sys.argv) != 3: @@ -14,7 +15,7 @@ output = sys.argv[2] with open(output, 'w') as output_file: - output_file.write("const char* DEFAULT_SYNTAX =\n") + output_file.write("const char* DEFAULT_SYNTAX_" + os.path.basename(input).upper() + " =\n") # write input file line by line as a string, escaping characters as needed with open(input, 'r') as input_file: