bison_lex.conf 4.9 KB

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