Git Product home page Git Product logo

Comments (4)

mingodad avatar mingodad commented on August 19, 2024

I've been testing this C++ parser https://github.com/panda3d/panda3d/tree/master/dtool/src/cppparser and we had a bit of work done with it's preprocessor here panda3d/panda3d#1638 probably it's worth for you to now about it and maybe even collaborate both ways with then.

from cplusplus.

mingodad avatar mingodad commented on August 19, 2024

Even when adding other text at the end of the macro the output miss the closing brace:

#define FOO(x)  {x}

FOO(
#if 1
    bar
#else
    qux
#endif
)
int x;

Output:

# 1 "foo-if.c"
                {
    bar
int x;

from cplusplus.

mingodad avatar mingodad commented on August 19, 2024

The problem seem to be here :

auto Preprocessor::Private::skipLine(TokIterator it,
TokIterator last) -> TokIterator {
for (; it != last; ++it) {
if (it->kind == TokenKind::T_EOF_SYMBOL) break;
if (it->bol) break;
}
return it;
}

When skipping the endif you are only breaking the loop when it->bol is true but when tokenizing the } is not marked with bol equals true and is skipped, we need another way to manage it here.

from cplusplus.

mingodad avatar mingodad commented on August 19, 2024

With this hack it seems to work, all tests pass and it parses sqlite3.c so far:

------------------------ src/parser/cxx/preprocessor.cc ------------------------
index c07548e..2fe9d51 100644
@@ -1651,7 +1651,8 @@ auto Preprocessor::Private::expand(
 
     if (const auto start = it; it->bol && match(it, last, TokenKind::T_HASH)) {
       // skip the rest of the line
-      it = skipLine(it, last);
+      if (it->kind == TokenKind::T_IDENTIFIER && it->text == "endif") ++it;
+      else it = skipLine(it, last);
 
       if (auto parsedInclude = parseDirective(source, start.toTokList())) {
         NeedToResolveInclude status{

Output:

# 1 "foo-if.c"
                {
    bar }
int x;

from cplusplus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.