bison_lex.conf 5.1 KB

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