]> granicus.if.org Git - clang/commit
Add a new mode to the lexer which enables it to return all characters,
authorChris Lattner <sabre@nondot.org>
Sun, 12 Oct 2008 04:05:48 +0000 (04:05 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 12 Oct 2008 04:05:48 +0000 (04:05 +0000)
commitd88dc48e33d71732708960170e57a3d1bdc8f847
treef9b755c065acd7a8cac2b629d79d55f7e354f45a
parentaea3ad073793f7764aa914bd9e551f858a0b5739
Add a new mode to the lexer which enables it to return all characters,
even whitespace, as tokens from the file.  This is enabled with
L->SetKeepWhitespaceMode(true) on a raw lexer.  In this mode, you too
can use clang as a really complex version of 'cat' with code like this:

  Lexer RawLex(SourceLocation::getFileLoc(SM.getMainFileID(), 0),
               PP.getLangOptions(), File.first, File.second);

  RawLex.SetKeepWhitespaceMode(true);

  Token RawTok;
  RawLex.LexFromRawLexer(RawTok);
  while (RawTok.isNot(tok::eof)) {
    std::cout << PP.getSpelling(RawTok);
    RawLex.LexFromRawLexer(RawTok);
  }

This will emit exactly the input file, with no canonicalization or other
translation.  Realistic clients actually do something with the tokens of
course :)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57401 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/Lex/Lexer.h
lib/Lex/Lexer.cpp