diff options
author | alexv-smirnov <alex@ydb.tech> | 2023-06-13 11:05:01 +0300 |
---|---|---|
committer | alexv-smirnov <alex@ydb.tech> | 2023-06-13 11:05:01 +0300 |
commit | bf0f13dd39ee3e65092ba3572bb5b1fcd125dcd0 (patch) | |
tree | 1d1df72c0541a59a81439842f46d95396d3e7189 /build/conf/bison_lex.conf | |
parent | 8bfdfa9a9bd19bddbc58d888e180fbd1218681be (diff) | |
download | ydb-bf0f13dd39ee3e65092ba3572bb5b1fcd125dcd0.tar.gz |
add ymake export to ydb
Diffstat (limited to 'build/conf/bison_lex.conf')
-rw-r--r-- | build/conf/bison_lex.conf | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/build/conf/bison_lex.conf b/build/conf/bison_lex.conf new file mode 100644 index 0000000000..9e195c7138 --- /dev/null +++ b/build/conf/bison_lex.conf @@ -0,0 +1,147 @@ +# This defines macros and rules for Bison and Flex source processing +# +# This specilizes _SRC() macro, so should be imported after generic version definition +# Thus uses _ADD_HIDDEN_INPUTS() macro from ymake.core.conf + +LEX_FLAGS= +BISON_FLAGS=-v + +_BISON_DATA_DIR=contrib/tools/bison/bison/data +_CPP_BISON_SKELS=\ + ${_BISON_DATA_DIR}/bison.m4 \ + ${_BISON_DATA_DIR}/c++-skel.m4 \ + ${_BISON_DATA_DIR}/c++.m4 \ + ${_BISON_DATA_DIR}/c-like.m4 \ + ${_BISON_DATA_DIR}/c-skel.m4 \ + ${_BISON_DATA_DIR}/c.m4 \ + ${_BISON_DATA_DIR}/glr.cc \ + ${_BISON_DATA_DIR}/lalr1.cc \ + ${_BISON_DATA_DIR}/location.cc \ + ${_BISON_DATA_DIR}/m4sugar/foreach.m4 \ + ${_BISON_DATA_DIR}/m4sugar/m4sugar.m4 \ + ${_BISON_DATA_DIR}/stack.hh \ + ${_BISON_DATA_DIR}/variant.hh \ + ${_BISON_DATA_DIR}/yacc.c \ + +_BISON_GEN_EXT=.cpp +_FLEX_GEN_EXT=.cpp + +_BISON_HEADER=--defines=${nopath;noext;output;main;addincl;norel;suf=.h:SRC} +_BISON_PP=$YMAKE_PYTHON ${input:"build/scripts/preprocess.py"} $_ADD_HIDDEN_INPUTS($_CPP_BISON_SKELS) ${nopath;noext;tmp:SRC.h} + +_FLEX_TOOL=${tool:"contrib/tools/flex-old"} +_FLEX_TOOL_DIR=contrib/tools/flex-old +_FLEX_HEADER= + +### @usage: FLEX_FLAGS(<flags>) +### +### Set flags for Lex tool (flex) invocations. +macro FLEX_FLAGS(Flags...) { + SET_APPEND(LEX_FLAGS $Flags) +} + +### @usage: BISON_FLAGS(<flags>) +### +### Set flags for Bison tool invocations. +macro BISON_FLAGS(Flags...) { + SET_APPEND(BISON_FLAGS $Flags) +} + +### @usage: BISON_GEN_C() +### +### Generate C from Bison grammar. The C++ is generated by default. +macro BISON_GEN_C() { + SET(_BISON_GEN_EXT .c) + SET(_BISON_PP) +} + +### @usage: BISON_GEN_CPP() +### +### Generate C++ from Bison grammar. This is current default. +macro BISON_GEN_CPP() { + SET(_BISON_GEN_EXT .cpp) +} + + +### @usage: FLEX_GEN_C() +### +### Generate C from Lex grammar. The C++ is generated by default. +macro FLEX_GEN_C() { + SET(_FLEX_GEN_EXT .c) +} + +### @usage: FLEX_GEN_CPP() +### +### Generate C++ from Lex grammar. This is current default. +macro FLEX_GEN_CPP() { + SET(_FLEX_GEN_EXT .cpp) +} + +### @usage: BISON_HEADER(<header_suffix>) +### +### Use SUFF (including extension) to name Bison defines header file. The default is just `.h`. +macro BISON_HEADER(Suffix) { + SET(_BISON_HEADER --defines=\${nopath;noext;output;main;addincl;norel;suf=$Suffix:SRC}) +} + +### @usage: BISON_NO_HEADER() +### +### Don't emit Bison defines header file. +macro BISON_NO_HEADER() { + SET(_BISON_HEADER) +} + +### @usage: USE_MODERN_FLEX() +### +### Use `contrib/tools/flex` as flex tool. Default is `contrib/tools/flex-old`. +### @note: by default no header is emitted. Use `USE_MODERN_FLEX_WITH_HEADER` to add header emission. +macro USE_MODERN_FLEX() { + SET(_FLEX_TOOL \${tool:"contrib/tools/flex"} --m4=\${tool:"contrib/tools/bison/m4"}) + SET(_FLEX_TOOL_DIR contrib/tools/flex) +} + +### @usage: USE_MODERN_FLEX_WITH_HEADER(<header_suffix>) +### +### Use `contrib/tools/flex` as flex tool. Default is `contrib/tools/flex-old`. +### Additionally emit headers with suffix provided. Header suffix should include extension `.h`. +### +### @example: USE_MODERN_FLEX_WITH_HEADER(_lexer.h) +macro USE_MODERN_FLEX_WITH_HEADER(Suffix) { + SET(_FLEX_TOOL \${tool:"contrib/tools/flex"} --m4=\${tool:"contrib/tools/bison/m4"}) + SET(_FLEX_TOOL_DIR contrib/tools/flex) + SET(_FLEX_HEADER --header-file=\${nopath;noext;output;main;addincl;norel;suf=$Suffix:SRC}) +} + +### @usage: USE_OLD_FLEX() +### +### Use `contrib/tools/flex-old` as flex tool. This is current default. +macro USE_OLD_FLEX() { + SET(_FLEX_TOOL \${tool:"contrib/tools/flex-old"}) + SET(_FLEX_TOOL_DIR contrib/tools/flex-old) +} + +macro _SRC("y", SRC, SRCFLAGS...) { + .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 + .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"' +} + +macro _SRC("ypp", SRC, SRCFLAGS...) { + .CMD=$_SRC(y $SRC $SRCFLAGS) + .SEM=$_SRC(y $SRC $SRCFLAGS) +} + +macro _SRC("l", SRC, SRCFLAGS...) { + .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"} + .ADDINCL=$_FLEX_TOOL_DIR + .SEM=target_flex_lexers ${tool;hide:_FLEX_TOOL} ${output;hide;suf=${OBJ_SUF}.o:SRC} ${input:SRC} && set_global_flags LEX_FLAGS $LEX_FLAGS +} + +# tag:src-processing +macro _SRC("lex", SRC, SRCFLAGS...) { + .CMD=$_SRC(l $SRC $SRCFLAGS) +} + +# tag:src-processing +macro _SRC("lpp", SRC, SRCFLAGS...) { + .CMD=$_SRC(l $SRC $SRCFLAGS) +} |