nim-lang / c2nim

c2nim is a tool to translate Ansi C code to Nim. The output is human-readable Nim code that is meant to be tweaked by hand before and after the translation process.
MIT License
508 stars 63 forks source link

C enum and then constant array declaration with uncommon syntax fails #41

Closed Xe closed 3 years ago

Xe commented 9 years ago
enum message_type {
       MESSAGE_TYPE_NOTICE,
       MESSAGE_TYPE_PRIVMSG,
       MESSAGE_TYPE_COUNT
};

const char *cmdname[MESSAGE_TYPE_COUNT] = {
    [MESSAGE_TYPE_PRIVMSG] = "PRIVMSG",
    [MESSAGE_TYPE_NOTICE] = "NOTICE",
};
➜  c2nim foo.h
/home/xena/foo.h(8, 26) Error: did not expect [
Xe commented 9 years ago

worth noting that

enum message_type {
    MESSAGE_TYPE_NOTICE,
    MESSAGE_TYPE_PRIVMSG,
    MESSAGE_TYPE_COUNT
};

const char *cmdname[MESSAGE_TYPE_COUNT] = {
    "PRIVMSG",
    "NOTICE",
};

fixes it.

Expected output:

type
  message_type* = enum
    MESSAGE_TYPE_NOTICE, MESSAGE_TYPE_PRIVMSG, MESSAGE_TYPE_COUNT

var cmdname*: array[MESSAGE_TYPE_COUNT, cstring] = ["PRIVMSG", "NOTICE"]