Giter Club home page Giter Club logo

Comments (3)

Araq avatar Araq commented on August 19, 2024

Yes, that is not supported by c2nim's parser. It's not a bug. By design #define is parsed as a statement.

from c2nim.

tmm1 avatar tmm1 commented on August 19, 2024

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.

Araq avatar Araq commented on August 19, 2024

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)

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.