Comments (4)
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.
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.
The problem seem to be here :
cplusplus/src/parser/cxx/preprocessor.cc
Lines 2658 to 2665 in 3b93d2b
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.
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)
- Can't parse "va_arg" HOT 7
- Changing "specs/grammar.txt" to an EBNF understood by https://www.bottlecaps.de/rr/ui HOT 8
- Can't parse sizeof properly HOT 2
- Do not recognize "#pragma one" HOT 8
- cxx doesn't report missing file passed for parsing HOT 1
- cxx can't handle string concatenation in macros correctly
- Fail to parse cppfront HOT 3
- expected a declaration "_Noreturn void __wasi_proc_exit(" HOT 2
- Bad preprocessing behavior HOT 12
- expected a declaration HOT 3
- Carbon "using Nonnull = T _Nonnull;"
- expected a declaration HOT 2
- Segmentation fault when parsing JUCE HOT 4
- expected a statement HOT 5
- Add "-M" and "-MM" command line options HOT 2
- Testing with examples from https://en.cppreference.com/w/ HOT 5
- return __extension__ (__m128){ 0.0f, 0.0f, 0.0f, 0.0f }; HOT 8
- Testing with https://github.com/duneroadrunner/SaferCPlusPlus
- Memory usage and permissive parsing with sqlite3 HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cplusplus.