From 373e9decf333ec65c14d7c36a0d1d33e9eb2a803 Mon Sep 17 00:00:00 2001 From: Ganesh Viswanathan Date: Wed, 26 Dec 2018 18:49:46 -0600 Subject: Support arrays in structs --- nimterop/grammar.nim | 26 ++++++++++++++++++++++++-- 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) ) ) ) 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', -- cgit v1.2.3