bison_lex.conf 6.3 KB

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