aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2018-12-26 18:49:46 -0600
committerGanesh Viswanathan <dev@genotrance.com>2018-12-26 18:49:46 -0600
commit373e9decf333ec65c14d7c36a0d1d33e9eb2a803 (patch)
treedfbbfeb7badb20fdbcc5c6db43e633b4c5d1efbf
parent1684e773ad51612ea1034834662049e1228ddad9 (diff)
downloadnimterop-373e9decf333ec65c14d7c36a0d1d33e9eb2a803.tar.gz
nimterop-373e9decf333ec65c14d7c36a0d1d33e9eb2a803.zip
Support arrays in structs
-rw-r--r--nimterop/grammar.nim26
-rw-r--r--toast.nim4
2 files changed, 26 insertions, 4 deletions
diff --git a/nimterop/grammar.nim b/nimterop/grammar.nim
index a8d8eed..c72e29b 100644
--- a/nimterop/grammar.nim
+++ b/nimterop/grammar.nim
@@ -87,8 +87,14 @@ proc initGrammar() =
let
ftyp = gStateRT.data[i].val.getIdentifier()
fname = gStateRT.data[i+1].val.getIdentifier()
- gStateRT.typeStr &= &" {fname}*: {ftyp}\n"
- i += 2
+ if i+2 < gStateRT.data.len-fend and gStateRT.data[i+2].name == "identifier":
+ let
+ flen = gStateRT.data[i+2].val.getIdentifier()
+ gStateRT.typeStr &= &" {fname}*: array[{flen}, {ftyp}]\n"
+ i += 3
+ else:
+ gStateRT.typeStr &= &" {fname}*: {ftyp}\n"
+ i += 2
# struct X {}
gStateRT.grammar.add(("""
@@ -105,7 +111,15 @@ proc initGrammar() =
)
(field_identifier?)
(pointer_declarator?
+ (field_identifier?)
+ (array_declarator?
+ (field_identifier)
+ (identifier)
+ )
+ )
+ (array_declarator?
(field_identifier)
+ (identifier)
)
)
)
@@ -131,7 +145,15 @@ proc initGrammar() =
)
(field_identifier?)
(pointer_declarator?
+ (field_identifier?)
+ (array_declarator?
+ (field_identifier)
+ (identifier)
+ )
+ )
+ (array_declarator?
(field_identifier)
+ (identifier)
)
)
)
diff --git a/toast.nim b/toast.nim
index 3481832..ced3047 100644
--- a/toast.nim
+++ b/toast.nim
@@ -134,10 +134,10 @@ when isMainModule:
dispatch(main, help = {
"past": "print AST output",
"mode": "language; see CompileMode", # TODO: auto-generate valid choices
- "pnim": "run preprocessor on header",
+ "pnim": "print Nim output",
"defines": "definitions to pass to preprocessor",
"includeDirs": "include directory to pass to preprocessor",
- "preprocess": "print Nim output",
+ "preprocess": "run preprocessor on header",
"source" : "C/C++ source/header",
}, short = {
"past": 'a',