Browse Source

Fix run_antlr semantics, add run_antlr4 semantic

Add run_antlr4 semantic

Add semantic for run antlr4
commit_hash:55ff8945c64f798c87399822344b24b5bd6c7b16
dimdim11 6 months ago
parent
commit
a4578ad8ed

+ 6 - 7
build/export_generators/cmake/cmake/antlr.cmake

@@ -1,7 +1,6 @@
 function(ensure_antlr)
     if(NOT ANTLR3_EXECUTABLE)
-        find_program(ANTLR3_EXECUTABLE
-                     NAMES antlr3)
+        find_program(ANTLR3_EXECUTABLE NAMES antlr3)
         if (NOT ANTLR3_EXECUTABLE)
             message(FATAL_ERROR "Unable to find antlr3 program. Please install antlr3 and make sure executable file present in the $PATH env.")
         endif()
@@ -14,7 +13,7 @@ function(run_antlr)
     set(oneValueArgs WORKING_DIRECTORY)
     set(multiValueArgs OUTPUT DEPENDS ANTLER_ARGS)
     cmake_parse_arguments(
-        RUN_ANTLR
+        RUN_ANTLR3
          "${options}"
          "${oneValueArgs}"
          "${multiValueArgs}"
@@ -22,10 +21,10 @@ function(run_antlr)
     )
 
     add_custom_command(
-        OUTPUT ${RUN_ANTLR_OUTPUT}
-        COMMAND ${ANTLR3_EXECUTABLE} ${RUN_ANTLR_ANTLER_ARGS}
-        WORKING_DIRECTORY ${RUN_ANTLR_WORKING_DIRECTORY}
-        DEPENDS ${RUN_ANTLR_DEPENDS}
+        OUTPUT ${RUN_ANTLR3_OUTPUT}
+        COMMAND ${ANTLR3_EXECUTABLE} ${RUN_ANTLR3_ANTLER_ARGS}
+        WORKING_DIRECTORY ${RUN_ANTLR3_WORKING_DIRECTORY}
+        DEPENDS ${RUN_ANTLR3_DEPENDS}
     )
 
 endfunction()

+ 30 - 0
build/export_generators/cmake/cmake/antlr4.cmake

@@ -0,0 +1,30 @@
+function(ensure_antlr4)
+    if(NOT ANTLR4_EXECUTABLE)
+        find_program(ANTLR4_EXECUTABLE NAMES antlr4)
+        if (NOT ANTLR4_EXECUTABLE)
+            message(FATAL_ERROR "Unable to find antlr4 program. Please install antlr4 and make sure executable file present in the $PATH env.")
+        endif()
+    endif()
+endfunction()
+
+function(run_antlr4)
+    ensure_antlr4()
+    set(options "")
+    set(oneValueArgs WORKING_DIRECTORY)
+    set(multiValueArgs OUTPUT DEPENDS ANTLER_ARGS)
+    cmake_parse_arguments(
+        RUN_ANTLR4
+         "${options}"
+         "${oneValueArgs}"
+         "${multiValueArgs}"
+         ${ARGN}
+    )
+
+    add_custom_command(
+        OUTPUT ${RUN_ANTLR4_OUTPUT}
+        COMMAND ${ANTLR4_EXECUTABLE} ${RUN_ANTLR4_ANTLER_ARGS}
+        WORKING_DIRECTORY ${RUN_ANTLR4_WORKING_DIRECTORY}
+        DEPENDS ${RUN_ANTLR4_DEPENDS}
+    )
+
+endfunction()

+ 7 - 1
build/export_generators/cmake/generator.toml

@@ -188,6 +188,7 @@ set_yunittest_property="skip"
 copy_file="skip"
 configure_file="skip"
 run_antlr="skip"
+run_antlr4="skip"
 set_property="skip"
 add_jar="skip"
 set_property_escaped="skip"
@@ -270,10 +271,15 @@ copy=["cmake/FindJNITarget.cmake"]
 add_values=[{attr="includes", values=["cmake/FindJNITarget.cmake"]}]
 
 [[rules]]
-attrs=["run_antlr"]
+attrs=["target_commands-macro=run_antlr"]
 copy=["cmake/antlr.cmake"]
 add_values=[{attr="includes", values=["cmake/antlr.cmake"]}]
 
+[[rules]]
+attrs=["target_commands-macro=run_antlr4"]
+copy=["cmake/antlr4.cmake"]
+add_values=[{attr="includes", values=["cmake/antlr4.cmake"]}]
+
 [[rules]]
 attrs=[
     "target_bison_parser",

+ 6 - 7
build/export_generators/hardcoded-cmake/cmake/antlr.cmake

@@ -1,7 +1,6 @@
 function(ensure_antlr)
     if(NOT ANTLR3_EXECUTABLE)
-        find_program(ANTLR3_EXECUTABLE
-                     NAMES antlr3)
+        find_program(ANTLR3_EXECUTABLE NAMES antlr3)
         if (NOT ANTLR3_EXECUTABLE)
             message(FATAL_ERROR "Unable to find antlr3 program. Please install antlr3 and make sure executable file present in the $PATH env.")
         endif()
@@ -14,7 +13,7 @@ function(run_antlr)
     set(oneValueArgs WORKING_DIRECTORY)
     set(multiValueArgs OUTPUT DEPENDS ANTLER_ARGS)
     cmake_parse_arguments(
-        RUN_ANTLR
+        RUN_ANTLR3
          "${options}"
          "${oneValueArgs}"
          "${multiValueArgs}"
@@ -22,10 +21,10 @@ function(run_antlr)
     )
 
     add_custom_command(
-        OUTPUT ${RUN_ANTLR_OUTPUT}
-        COMMAND ${ANTLR3_EXECUTABLE} ${RUN_ANTLR_ANTLER_ARGS}
-        WORKING_DIRECTORY ${RUN_ANTLR_WORKING_DIRECTORY}
-        DEPENDS ${RUN_ANTLR_DEPENDS}
+        OUTPUT ${RUN_ANTLR3_OUTPUT}
+        COMMAND ${ANTLR3_EXECUTABLE} ${RUN_ANTLR3_ANTLER_ARGS}
+        WORKING_DIRECTORY ${RUN_ANTLR3_WORKING_DIRECTORY}
+        DEPENDS ${RUN_ANTLR3_DEPENDS}
     )
 
 endfunction()

+ 30 - 0
build/export_generators/hardcoded-cmake/cmake/antlr4.cmake

@@ -0,0 +1,30 @@
+function(ensure_antlr4)
+    if(NOT ANTLR4_EXECUTABLE)
+        find_program(ANTLR4_EXECUTABLE NAMES antlr4)
+        if (NOT ANTLR4_EXECUTABLE)
+            message(FATAL_ERROR "Unable to find antlr4 program. Please install antlr4 and make sure executable file present in the $PATH env.")
+        endif()
+    endif()
+endfunction()
+
+function(run_antlr4)
+    ensure_antlr4()
+    set(options "")
+    set(oneValueArgs WORKING_DIRECTORY)
+    set(multiValueArgs OUTPUT DEPENDS ANTLER_ARGS)
+    cmake_parse_arguments(
+        RUN_ANTLR4
+         "${options}"
+         "${oneValueArgs}"
+         "${multiValueArgs}"
+         ${ARGN}
+    )
+
+    add_custom_command(
+        OUTPUT ${RUN_ANTLR4_OUTPUT}
+        COMMAND ${ANTLR4_EXECUTABLE} ${RUN_ANTLR4_ANTLER_ARGS}
+        WORKING_DIRECTORY ${RUN_ANTLR4_WORKING_DIRECTORY}
+        DEPENDS ${RUN_ANTLR4_DEPENDS}
+    )
+
+endfunction()

+ 5 - 0
build/export_generators/hardcoded-cmake/generator.toml

@@ -71,6 +71,11 @@ attrs=["run_antlr"]
 copy=["cmake/antlr.cmake"]
 add_values=[{attr="includes", values=["cmake/antlr.cmake"]}]
 
+[[rules]]
+attrs=["run_antlr4"]
+copy=["cmake/antlr4.cmake"]
+add_values=[{attr="includes", values=["cmake/antlr4.cmake"]}]
+
 [[rules]]
 attrs=[
     "target_bison_parser",

+ 5 - 5
build/ymake.core.conf

@@ -4605,9 +4605,10 @@ macro RUN_PYTHON3(ScriptPath, IN{input}[], IN_NOPARSE{input}[], OUT{output}[], O
 }
 
 # tag:java-specific
-macro _RUN_JAVA(IN{input}[], IN_NOPARSE{input}[], OUT{output}[], OUT_NOAUTO{output}[], OUTPUT_INCLUDES[], INDUCED_DEPS[], TOOL[], STDOUT="", STDOUT_NOAUTO="", CWD="", ENV[], HIDE_OUTPUT?"stderr2stdout":"stdout2stderr", Args...) {
+macro _RUN_ANTLR_BASE(IN{input}[], IN_NOPARSE{input}[], OUT{output}[], OUT_NOAUTO{output}[], OUTPUT_INCLUDES[], INDUCED_DEPS[], TOOL[], STDOUT="", STDOUT_NOAUTO="", CWD="", JAR[], SEM="run_java", SEM_ARGS_PREFIX="", ENV[], HIDE_OUTPUT?"stderr2stdout":"stdout2stderr", Args...) {
     PEERDIR(build/platform/java/jdk $JDK_RESOURCE_PEERDIR)
-    .CMD=${cwd:CWD} ${env:ENV} $YMAKE_PYTHON ${input;pre=build/scripts/:HIDE_OUTPUT.py} $JDK_RESOURCE/bin/java $Args ${hide;tool:TOOL} ${hide;input:IN} ${input;context=TEXT;hide:IN_NOPARSE} ${output_include;hide:OUTPUT_INCLUDES} $INDUCED_DEPS ${hide;output:OUT} ${hide;noauto;output:OUT_NOAUTO} ${stdout;output:STDOUT} ${stdout;output;noauto:STDOUT_NOAUTO} ${hide;kv:"p JV"} ${hide;kv:"pc light-blue"} ${hide;kv:"show_out"}
+    .CMD=${cwd:CWD} ${env:ENV} $YMAKE_PYTHON ${input;pre=build/scripts/:HIDE_OUTPUT.py} $JDK_RESOURCE/bin/java $JAR $Args ${hide;tool:TOOL} ${hide;input:IN} ${input;context=TEXT;hide:IN_NOPARSE} ${output_include;hide:OUTPUT_INCLUDES} $INDUCED_DEPS ${hide;output:OUT} ${hide;noauto;output:OUT_NOAUTO} ${stdout;output:STDOUT} ${stdout;output;noauto:STDOUT_NOAUTO} ${hide;kv:"p JV"} ${hide;kv:"pc light-blue"} ${hide;kv:"show_out"}
+    .SEM=$SEM OUTPUT ${output:OUT} ${noauto;output:OUT_NOAUTO} DEPENDS ${input:IN} ${pre=WORKING_DIRECTORY :CWD} $SEM_ARGS_PREFIX $Args && target_commands-ITEM && target_commands-macro $SEM && target_commands-args OUTPUT ${output:OUT} ${noauto;output:OUT_NOAUTO} DEPENDS ${input:IN} ${pre=WORKING_DIRECTORY :CWD} $SEM_ARGS_PREFIX $Args
 }
 
 ### @usage: FROM_SANDBOX([FILE] resource_id [AUTOUPDATED script] [RENAME <resource files>] OUT_[NOAUTO] <output files> [EXECUTABLE] [OUTPUT_INCLUDES <include files>] [INDUCED_DEPS $VARs...])
@@ -4961,15 +4962,14 @@ macro ASM_PREINCLUDE(PREINCLUDES...) {
 ###
 ### Macro to invoke ANTLR3 generator (general case)
 macro RUN_ANTLR(IN[], IN_NOPARSE[], OUT[], OUT_NOAUTO[], OUTPUT_INCLUDES[], INDUCED_DEPS[], CWD="", Args...) {
-    _RUN_JAVA(-jar ${input:"contrib/java/antlr/antlr3/antlr.jar"} $Args IN $IN IN_NOPARSE $IN_NOPARSE OUT $OUT OUT_NOAUTO $OUT_NOAUTO OUTPUT_INCLUDES $OUTPUT_INCLUDES INDUCED_DEPS $INDUCED_DEPS ${pre=CWD :CWD})
-    .SEM=run_antlr OUTPUT ${output:OUT} ${noauto;output:OUT_NOAUTO} DEPENDS ${input:IN} ${pre=WORKING_DIRECTORY :CWD} ANTLER_ARGS $Args && target_commands-ITEM && target_commands-macro run_antlr && target_commands-args OUTPUT ${output:OUT} ${noauto;output:OUT_NOAUTO} DEPENDS ${input:IN} ${pre=WORKING_DIRECTORY :CWD} ANTLER_ARGS $Args
+    _RUN_ANTLR_BASE($Args IN $IN IN_NOPARSE $IN_NOPARSE OUT $OUT OUT_NOAUTO $OUT_NOAUTO OUTPUT_INCLUDES $OUTPUT_INCLUDES INDUCED_DEPS $INDUCED_DEPS ${pre=CWD :CWD} JAR -jar ${input:"contrib/java/antlr/antlr3/antlr.jar"} SEM run_antlr SEM_ARGS_PREFIX ANTLER_ARGS)
 }
 
 ### @usage: RUN_ANTLR4(Args...)
 ###
 ### Macro to invoke ANTLR4 generator (general case)
 macro RUN_ANTLR4(IN[], IN_NOPARSE[], OUT[], OUT_NOAUTO[], OUTPUT_INCLUDES[], INDUCED_DEPS[], CWD="", Args...) {
-    _RUN_JAVA(-jar ${input:"contrib/java/antlr/antlr4/antlr.jar"} $Args IN $IN IN_NOPARSE $IN_NOPARSE OUT $OUT OUT_NOAUTO $OUT_NOAUTO OUTPUT_INCLUDES $OUTPUT_INCLUDES INDUCED_DEPS $INDUCED_DEPS ${pre=CWD :CWD})
+    _RUN_ANTLR_BASE($Args IN $IN IN_NOPARSE $IN_NOPARSE OUT $OUT OUT_NOAUTO $OUT_NOAUTO OUTPUT_INCLUDES $OUTPUT_INCLUDES INDUCED_DEPS $INDUCED_DEPS ${pre=CWD :CWD} JAR -jar ${input:"contrib/java/antlr/antlr4/antlr.jar"} SEM run_antlr4 SEM_ARGS_PREFIX ANTLER_ARGS)
 }
 
 _ANTLR4_LISTENER_GRAMMAR=-listener