-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
define inside struct fails #50
Comments
Yes, that is not supported by c2nim's parser. It's not a bug. By design #define is parsed as a statement. |
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. |
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. |
The text was updated successfully, but these errors were encountered: