regenerate-lexers.bash 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env bash
  2. set -e
  3. forced=1
  4. if [[ "${1}" = "make" ]]; then
  5. forced=0
  6. fi
  7. pushd "${BASH_SOURCE%/*}/../../Source/LexerParser" > /dev/null
  8. for lexer in \
  9. CommandArgument \
  10. CTestResourceGroups \
  11. DependsJava \
  12. Expr \
  13. Fortran \
  14. GccDepfile
  15. do
  16. cxx_file=cm${lexer}Lexer.cxx
  17. h_file=cm${lexer}Lexer.h
  18. in_file=cm${lexer}Lexer.in.l
  19. if [[ (${in_file} -nt ${cxx_file}) || (${in_file} -nt ${h_file}) || (${forced} -gt 0) ]]; then
  20. echo "Generating Lexer ${lexer}"
  21. flex --nounistd -DFLEXINT_H --noline --header-file=${h_file} -o${cxx_file} ${in_file}
  22. sed -i 's/\s*$//' ${h_file} ${cxx_file} # remove trailing whitespaces
  23. sed -i '${/^$/d;}' ${h_file} ${cxx_file} # remove blank line at the end
  24. sed -i '1i#include "cmStandardLexer.h"' ${cxx_file} # add cmStandardLexer.h include
  25. else
  26. echo "Skipped generating Lexer ${lexer}"
  27. fi
  28. done
  29. # these lexers (at the moment only the ListFileLexer) are compiled as C and do not generate a header
  30. for lexer in ListFile
  31. do
  32. c_file=cm${lexer}Lexer.c
  33. in_file=cm${lexer}Lexer.in.l
  34. if [[ (${in_file} -nt ${c_file}) || (${forced} -gt 0) ]]; then
  35. echo "Generating Lexer ${lexer}"
  36. flex --nounistd -DFLEXINT_H --noline -o${c_file} ${in_file}
  37. sed -i 's/\s*$//' ${c_file} # remove trailing whitespaces
  38. sed -i '${/^$/d;}' ${c_file} # remove blank line at the end
  39. sed -i '1i#include "cmStandardLexer.h"' ${c_file} # add cmStandardLexer.h include
  40. else
  41. echo "Skipped generating Lexer ${lexer}"
  42. fi
  43. done
  44. popd > /dev/null