Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Utilities/Scripts/regenerate-lexers.bash
3148 views
1
#!/usr/bin/env bash
2
3
set -e
4
5
forced=1
6
if [[ "${1}" = "make" ]]; then
7
forced=0
8
fi
9
10
pushd "${BASH_SOURCE%/*}/../../Source/LexerParser" > /dev/null
11
12
extra_args_CommandArgument="--never-interactive --batch"
13
14
for lexer in \
15
CommandArgument \
16
CTestResourceGroups \
17
DependsJava \
18
Expr \
19
Fortran \
20
GccDepfile
21
do
22
cxx_file=cm${lexer}Lexer.cxx
23
h_file=cm${lexer}Lexer.h
24
in_file=cm${lexer}Lexer.in.l
25
26
if [[ (${in_file} -nt ${cxx_file}) || (${in_file} -nt ${h_file}) || (${forced} -gt 0) ]]; then
27
extra_args=`eval echo \\${extra_args_\${lexer}}`
28
echo "Generating Lexer ${lexer}"
29
flex --nounistd ${extra_args} -DFLEXINT_H --noline --header-file=${h_file} -o${cxx_file} ${in_file}
30
sed -i 's/\s*$//' ${h_file} ${cxx_file} # remove trailing whitespaces
31
sed -i '${/^$/d;}' ${h_file} ${cxx_file} # remove blank line at the end
32
sed -i '1i#include "cmStandardLexer.h"' ${cxx_file} # add cmStandardLexer.h include
33
else
34
echo "Skipped generating Lexer ${lexer}"
35
fi
36
done
37
38
39
# these lexers (at the moment only the ListFileLexer) are compiled as C and do not generate a header
40
for lexer in ListFile
41
do
42
c_file=cm${lexer}Lexer.c
43
in_file=cm${lexer}Lexer.in.l
44
45
if [[ (${in_file} -nt ${c_file}) || (${forced} -gt 0) ]]; then
46
echo "Generating Lexer ${lexer}"
47
flex --nounistd -DFLEXINT_H --noline -o${c_file} ${in_file}
48
sed -i 's/\s*$//' ${c_file} # remove trailing whitespaces
49
sed -i '${/^$/d;}' ${c_file} # remove blank line at the end
50
sed -i '1i#include "cmStandardLexer.h"' ${c_file} # add cmStandardLexer.h include
51
else
52
echo "Skipped generating Lexer ${lexer}"
53
fi
54
55
done
56
57
popd > /dev/null
58
59