Comments (3)
Yes, that is not supported by c2nim's parser. It's not a bug. By design #define is parsed as a statement.
from c2nim.
I started on a patch that produces the following for the example above:
type
test* = object
field*: cint
const
SIZE* = 123
ary*: array[SIZE, cint]
Here's the patch for posterity:
diff --git a/cparse.nim b/cparse.nim
index 48c1305..8434e33 100644
--- a/cparse.nim
+++ b/cparse.nim
@@ -76,7 +76,9 @@ type
ERetryParsing = object of Exception
+ SectionParser = proc(p: var Parser): PNode {.nimcall.}
+proc parseDir(p: var Parser; sectionParser: SectionParser): PNode
proc addTypeDef(section, name, t, genericParams: PNode)
proc parseStruct(p: var Parser, stmtList: PNode, isUnion: bool): PNode
proc parseStructBody(p: var Parser, stmtList: PNode, isUnion: bool,
@@ -766,6 +768,10 @@ proc parseStructBody(p: var Parser, stmtList: PNode, isUnion: bool,
addSon(result, def)
getTok(p, nil)
continue
+ elif p.tok.xkind == pxDirective or p.tok.xkind == pxDirectiveParLe:
+ var define = parseDir(p, statement)
+ addSon(result, define)
+ baseTyp = typeAtom(p)
else:
baseTyp = typeAtom(p)
diff --git a/cpp.nim b/cpp.nim
index 84f378d..c8bc90a 100644
--- a/cpp.nim
+++ b/cpp.nim
@@ -12,9 +12,6 @@
const
c2nimSymbol = "C2NIM"
-type
- SectionParser = proc(p: var Parser): PNode {.nimcall.}
-
proc eatNewLine(p: var Parser, n: PNode) =
if p.tok.xkind == pxLineComment:
skipCom(p, n)
I'm not going to pursue this, as making it actually compile would be a lot harder and it sounds like this is a WONTFIX.
from c2nim.
Nah, that's good. Moving the const out of the type is easy to do in a post-processing pass of the AST. We already have one, we can extend it or create a second one.
from c2nim.
Related Issues (20)
- Type after enum identifier not parsed in C++
- Unused imports and other warnings
- A failing construct will fail an entire statement list within an if directive.
- Infinite loop / memory leak
- SIGSEGV: Illegal storage access. (Attempt to read from nil?) HOT 4
- Computer freeze: c2nim on Linux, translating AnsiC header file HOT 8
- c2nim chokes on static arrays in parameters
- fails to parse `typedef struct` with ifdef inside
- fails to recognise stdint types HOT 2
- invalid code generated for `extern const` HOT 2
- `importc` not generated for typedef
- generated `proc` types should be `raises: []`
- c2nim fails to remove "LL" suffixes on types
- Mark generated enums with `size: sizeof(cint)`
- Translate __attribute__ tags
- typedef struct { ... } xx [error bug?] because have #ifdef ... #endif before
- Cant generate: gl3.h have 183KB out of range
- C `enum` should not be translated to Nim enum
- Implicit Forward Declared Struct incorrectly Converted HOT 1
- Error: unhandled exception: index 1 not in 0 .. 0 [IndexDefect]
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 c2nim.