bison_lex.conf 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. # This defines macros and rules for Bison and Flex source processing
  2. #
  3. # This specilizes _SRC() macro, so should be imported after generic version definition
  4. # Thus uses _ADD_HIDDEN_INPUTS() macro from ymake.core.conf
  5. LEX_FLAGS=
  6. BISON_FLAGS=-v
  7. _BISON_DATA_DIR=contrib/tools/bison/data
  8. _CPP_BISON_SKELS=\
  9. ${_BISON_DATA_DIR}/bison.m4 \
  10. ${_BISON_DATA_DIR}/c++-skel.m4 \
  11. ${_BISON_DATA_DIR}/c++.m4 \
  12. ${_BISON_DATA_DIR}/c-like.m4 \
  13. ${_BISON_DATA_DIR}/c-skel.m4 \
  14. ${_BISON_DATA_DIR}/c.m4 \
  15. ${_BISON_DATA_DIR}/glr.cc \
  16. ${_BISON_DATA_DIR}/lalr1.cc \
  17. ${_BISON_DATA_DIR}/location.cc \
  18. ${_BISON_DATA_DIR}/m4sugar/foreach.m4 \
  19. ${_BISON_DATA_DIR}/m4sugar/m4sugar.m4 \
  20. ${_BISON_DATA_DIR}/stack.hh \
  21. ${_BISON_DATA_DIR}/variant.hh \
  22. ${_BISON_DATA_DIR}/yacc.c \
  23. _BISON_GEN_EXT=.cpp
  24. _FLEX_GEN_EXT=.cpp
  25. _BISON_HEADER_SUFFIX=.h
  26. _BISON_HEADER=
  27. _BISON_PP=
  28. _FLEX_TOOL=
  29. _FLEX_TOOL_DIR=
  30. _FLEX_HEADER=
  31. when ($_BISON_FLEX_SET_DEFAULTS == "yes") {
  32. _BISON_HEADER=--defines=${nopath;noext;output;main;addincl;norel;suf=$_BISON_HEADER_SUFFIX:SRC}
  33. _BISON_PP=$YMAKE_PYTHON ${input:"build/scripts/preprocess.py"} $_ADD_HIDDEN_INPUTS($_CPP_BISON_SKELS) ${nopath;noext;tmp;suf=$_BISON_HEADER_SUFFIX:SRC}
  34. _FLEX_TOOL=${tool:"contrib/tools/flex-old"}
  35. _FLEX_TOOL_DIR=contrib/tools/flex-old
  36. _FLEX_HEADER=
  37. }
  38. ### @usage: FLEX_FLAGS(<flags>)
  39. ###
  40. ### Set flags for Lex tool (flex) invocations.
  41. macro FLEX_FLAGS(Flags...) {
  42. SET_APPEND(LEX_FLAGS $Flags)
  43. }
  44. ### @usage: BISON_FLAGS(<flags>)
  45. ###
  46. ### Set flags for Bison tool invocations.
  47. macro BISON_FLAGS(Flags...) {
  48. SET_APPEND(BISON_FLAGS $Flags)
  49. }
  50. ### @usage: BISON_GEN_C()
  51. ###
  52. ### Generate C from Bison grammar. The C++ is generated by default.
  53. macro BISON_GEN_C() {
  54. SET(_BISON_GEN_EXT .c)
  55. SET(_BISON_PP)
  56. }
  57. ### @usage: BISON_GEN_CPP()
  58. ###
  59. ### Generate C++ from Bison grammar. This is current default.
  60. macro BISON_GEN_CPP() {
  61. SET(_BISON_GEN_EXT .cpp)
  62. }
  63. ### @usage: FLEX_GEN_C()
  64. ###
  65. ### Generate C from Lex grammar. The C++ is generated by default.
  66. macro FLEX_GEN_C() {
  67. SET(_FLEX_GEN_EXT .c)
  68. }
  69. ### @usage: FLEX_GEN_CPP()
  70. ###
  71. ### Generate C++ from Lex grammar. This is current default.
  72. macro FLEX_GEN_CPP() {
  73. SET(_FLEX_GEN_EXT .cpp)
  74. }
  75. ### @usage: BISON_HEADER(<header_suffix>)
  76. ###
  77. ### Use SUFF (including extension) to name Bison defines header file. The default is just `.h`.
  78. macro BISON_HEADER(Suffix) {
  79. SET(_BISON_HEADER_SUFFIX $Suffix)
  80. SET(_BISON_HEADER --defines=\${nopath;noext;output;main;addincl;norel;suf=$_BISON_HEADER_SUFFIX:SRC})
  81. SET(_BISON_PP $YMAKE_PYTHON \${input:"build/scripts/preprocess.py"} $_ADD_HIDDEN_INPUTS($_CPP_BISON_SKELS) \${nopath;noext;tmp;suf=$_BISON_HEADER_SUFFIX:SRC})
  82. }
  83. ### @usage: BISON_NO_HEADER()
  84. ###
  85. ### Don't emit Bison defines header file.
  86. macro BISON_NO_HEADER() {
  87. SET(_BISON_HEADER)
  88. }
  89. ### @usage: USE_MODERN_FLEX()
  90. ###
  91. ### Use `contrib/tools/flex` as flex tool. Default is `contrib/tools/flex-old`.
  92. ### @note: by default no header is emitted. Use `USE_MODERN_FLEX_WITH_HEADER` to add header emission.
  93. macro USE_MODERN_FLEX() {
  94. SET(_FLEX_TOOL \${tool:"contrib/tools/flex"} --m4=\${tool:"contrib/tools/m4"})
  95. SET(_FLEX_TOOL_DIR contrib/tools/flex)
  96. }
  97. ### @usage: USE_MODERN_FLEX_WITH_HEADER(<header_suffix>)
  98. ###
  99. ### Use `contrib/tools/flex` as flex tool. Default is `contrib/tools/flex-old`.
  100. ### Additionally emit headers with suffix provided. Header suffix should include extension `.h`.
  101. ###
  102. ### @example: USE_MODERN_FLEX_WITH_HEADER(_lexer.h)
  103. macro USE_MODERN_FLEX_WITH_HEADER(Suffix) {
  104. SET(_FLEX_TOOL \${tool:"contrib/tools/flex"} --m4=\${tool:"contrib/tools/m4"})
  105. SET(_FLEX_TOOL_DIR contrib/tools/flex)
  106. SET(_FLEX_HEADER --header-file=\${nopath;noext;output;main;addincl;norel;suf=$Suffix:SRC})
  107. }
  108. ### @usage: USE_OLD_FLEX()
  109. ###
  110. ### Use `contrib/tools/flex-old` as flex tool. This is current default.
  111. macro USE_OLD_FLEX() {
  112. SET(_FLEX_TOOL \${tool:"contrib/tools/flex-old"})
  113. SET(_FLEX_TOOL_DIR contrib/tools/flex-old)
  114. }
  115. macro _SRC("y", SRC, SRCFLAGS...) {
  116. .PEERDIR=build/induced/by_bison
  117. .CMD=${tool:"contrib/tools/bison"} $BISON_FLAGS --m4=${tool:"contrib/tools/m4"} $_BISON_HEADER ${hide:_BISON_GEN_EXT} -o ${nopath;output;suf=$_BISON_GEN_EXT:SRC} ${input:SRC} ${SRCFLAGS} ${kv;hide:"p YC"} ${kv;hide:"pc light-green"} && $_BISON_PP
  118. .SEM=target_bison_parser PRIVATE ${input:SRC} ${output;nopath;noext;hide;suf=${OBJ_SUF}.o:SRC} ${nopath;noext;output;hide:SRC.h} ${nopath;noext;output;addincl;hide:SRC.h} && set_global_flags BISON_FLAGS $BISON_FLAGS && conan_require_tool m4/1.4.19 && conan_import '"bin, m4* -> ./bin/m4/bin"' && conan_require_tool bison/3.8.2 && conan_import '"bin, bison* -> ./bin/bison/bin"' && conan_import '"res, * -> ./bin/bison/res"' && target_macroses-ITEM && target_macroses-macro target_bison_parser && target_macroses-args PRIVATE ${input:SRC} ${output;nopath;noext;hide;suf=${OBJ_SUF}.o:SRC} ${nopath;noext;output;hide:SRC.h} ${nopath;noext;output;addincl;hide:SRC.h} && platform_vars-BISON_FLAGS ${quo:BISON_FLAGS} && conan-tool_requires m4/1.4.19 && conan-imports 'bin, m4* -> ./bin/m4/bin' && conan-tool_requires bison/3.8.2 && conan-imports 'bin, bison* -> ./bin/bison/bin' && conan-imports 'res, * -> ./bin/bison/res'
  119. }
  120. macro _SRC("ypp", SRC, SRCFLAGS...) {
  121. .PEERDIR=build/induced/by_bison
  122. .CMD=$_SRC(y $SRC $SRCFLAGS)
  123. .SEM=$_SRC(y $SRC $SRCFLAGS)
  124. }
  125. macro _SRC("l", SRC, SRCFLAGS...) {
  126. .CMD=$_FLEX_TOOL $LEX_FLAGS ${SRCFLAGS} $_FLEX_HEADER ${hide:_FLEX_GEN_EXT} -o${output;suf=$_FLEX_GEN_EXT:SRC} ${output_include;hide:"util/system/compiler.h"} ${input:SRC} ${kv;hide:"p LX"} ${kv;hide:"pc yellow"}
  127. .ADDINCL=$_FLEX_TOOL_DIR
  128. .SEM=target_flex_lexers ${tool;hide:_FLEX_TOOL} ${output;hide;suf=${OBJ_SUF}.o:SRC} ${input:SRC} && target_macroses-ITEM && target_macroses-macro target_flex_lexers && target_macroses-args ${tool;hide:_FLEX_TOOL} ${output;hide;suf=${OBJ_SUF}.o:SRC} ${input:SRC} && set_global_flags LEX_FLAGS $LEX_FLAGS && platform_vars-LEX_FLAGS ${quo:LEX_FLAGS}
  129. }
  130. # tag:src-processing
  131. macro _SRC("lex", SRC, SRCFLAGS...) {
  132. .CMD=$_SRC(l $SRC $SRCFLAGS)
  133. }
  134. # tag:src-processing
  135. macro _SRC("lpp", SRC, SRCFLAGS...) {
  136. .CMD=$_SRC(l $SRC $SRCFLAGS)
  137. }