diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2020-01-21 09:26:42 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-01-28 16:16:11 (GMT) |
commit | f8c505d4b30aa636b013486913591060b2040716 (patch) | |
tree | 2853577d4c09ff8f11dac45bfd4ba8a2a014dc90 /Source/LexerParser/cmGccDepfileLexer.in.l | |
parent | 306328ace87376dddb2a42bf33c6338aac5d09ad (diff) | |
download | CMake-f8c505d4b30aa636b013486913591060b2040716.zip CMake-f8c505d4b30aa636b013486913591060b2040716.tar.gz CMake-f8c505d4b30aa636b013486913591060b2040716.tar.bz2 |
Add a parser for GCC-style depfiles
Introduce the function cmReadGccDepfile that parses a GCC-style depfile
and returns its content. The implementation uses a lexer that is
modeled after the re2c implementation in Ninja.
The sample files of the autotest have been created with gcc 8.3.0.
This depfile reader is to be used by the Autogen facility to make use
of the depfiles that are generated by Qt's meta object compiler.
Diffstat (limited to 'Source/LexerParser/cmGccDepfileLexer.in.l')
-rw-r--r-- | Source/LexerParser/cmGccDepfileLexer.in.l | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/Source/LexerParser/cmGccDepfileLexer.in.l b/Source/LexerParser/cmGccDepfileLexer.in.l new file mode 100644 index 0000000..08f8577 --- /dev/null +++ b/Source/LexerParser/cmGccDepfileLexer.in.l @@ -0,0 +1,72 @@ +%{ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ + +/* IWYU pragma: no_forward_declare yyguts_t */ + +#ifndef __clang_analyzer__ /* Suppress clang scan-build warnings */ + +#include <cmGccDepfileLexerHelper.h> +#include <string> +%} + +%option prefix="cmGccDepfile_yy" +%option noyywrap +%option reentrant +%pointer + +WSPACE [ \t] +NEWLINE \r?\n + +%% +\${2} { + // Unescape the dollar sign. + yyextra->addToCurrentPath("$"); + } +\\# { + // Unescape the hash. + yyextra->addToCurrentPath("#"); + } +(\\\\)*\\[ ] { + // 2N+1 backslashes plus space -> N backslashes plus space. + size_t c = (strlen(yytext) - 1) / 2; + std::string s(c, '\\'); + s.push_back(' '); + yyextra->addToCurrentPath(s.c_str()); + } +(\\\\)+[ ] { + // 2N backslashes plus space -> 2N backslashes, end of filename. + yytext[strlen(yytext) - 1] = 0; + yyextra->addToCurrentPath(yytext); + yyextra->newDependency(); + } +{WSPACE}*\\{NEWLINE} { + // A line continuation ends the current file name. + yyextra->newDependency(); + } +{NEWLINE} { + // A newline ends the current file name and the current rule. + yyextra->newEntry(); + } +:{WSPACE}+ { + // A colon followed by space ends the rules and starts a new dependency. + yyextra->newDependency(); + } +{WSPACE}+ { + // Rules and dependencies are separated by blocks of whitespace. + yyextra->newRuleOrDependency(); + } +[a-zA-Z0-9+,/_.~()}{%=@\x5B\x5D!\x80-\xFF-]+ { + // Got a span of plain text. + yyextra->addToCurrentPath(yytext); + } +. { + // Got an otherwise unmatched character. + yyextra->addToCurrentPath(yytext); + } + +%% + +/*--------------------------------------------------------------------------*/ + +#endif /* __clang_analyzer__ */ |