diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2018-12-26 18:49:46 -0600 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2018-12-26 18:49:46 -0600 |
| commit | 373e9decf333ec65c14d7c36a0d1d33e9eb2a803 (patch) | |
| tree | dfbbfeb7badb20fdbcc5c6db43e633b4c5d1efbf | |
| parent | 1684e773ad51612ea1034834662049e1228ddad9 (diff) | |
| download | nimterop-373e9decf333ec65c14d7c36a0d1d33e9eb2a803.tar.gz nimterop-373e9decf333ec65c14d7c36a0d1d33e9eb2a803.zip | |
Support arrays in structs
| -rw-r--r-- | nimterop/grammar.nim | 26 | ||||
| -rw-r--r-- | toast.nim | 4 |
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) ) ) ) @@ -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', |
