Array ptr, numeric length, tests

This commit is contained in:
Ganesh Viswanathan 2018-12-26 20:18:38 -06:00
commit e59e34a7be
4 changed files with 16 additions and 10 deletions

View file

@ -34,12 +34,12 @@ proc saveNodeData(node: TSNode): bool =
let
nparent = node.tsNodeParent()
if not nparent.tsNodeIsNull():
if not nparent.tsNodeIsNull() and node.tsNodePrevNamedSibling().tsNodeIsNull():
let
npname = nparent.tsNodeType()
npparent = nparent.tsNodeParent()
if npname == "pointer_declarator" or
(npname == "function_declarator" and
($npname in ["function_declarator", "array_declarator"] and
not npparent.tsNodeIsNull() and npparent.tsNodeType() == "pointer_declarator"):
if gStateRT.data[^1].val != "object":

View file

@ -34,7 +34,7 @@ proc initGrammar() =
(sized_type_specifier?
(primitive_type?)
)
(struct_specifier?
(struct_specifier|union_specifier|enum_specifier?
(type_identifier)
)
(type_identifier?)
@ -87,7 +87,7 @@ proc initGrammar() =
let
ftyp = gStateRT.data[i].val.getIdentifier()
fname = gStateRT.data[i+1].val.getIdentifier()
if i+2 < gStateRT.data.len-fend and gStateRT.data[i+2].name == "identifier":
if i+2 < gStateRT.data.len-fend and gStateRT.data[i+2].name in ["identifier", "number_literal"]:
let
flen = gStateRT.data[i+2].val.getIdentifier()
gStateRT.typeStr &= &" {fname}*: array[{flen}, {ftyp}]\n"
@ -106,7 +106,7 @@ proc initGrammar() =
(sized_type_specifier?
(primitive_type?)
)
(struct_specifier?
(struct_specifier|union_specifier|enum_specifier?
(type_identifier)
)
(field_identifier?)
@ -114,12 +114,12 @@ proc initGrammar() =
(field_identifier?)
(array_declarator?
(field_identifier)
(identifier)
(identifier|number_literal)
)
)
(array_declarator?
(field_identifier)
(identifier)
(identifier|number_literal)
)
)
)
@ -140,7 +140,7 @@ proc initGrammar() =
(sized_type_specifier?
(primitive_type?)
)
(struct_specifier?
(struct_specifier|union_specifier|enum_specifier?
(type_identifier)
)
(field_identifier?)
@ -148,12 +148,12 @@ proc initGrammar() =
(field_identifier?)
(array_declarator?
(field_identifier)
(identifier)
(identifier|number_literal)
)
)
(array_declarator?
(field_identifier)
(identifier)
(identifier|number_literal)
)
)
)

View file

@ -46,6 +46,10 @@ typedef int * INTPTR;
typedef struct {
int *field;
int field2[TEST_INT];
enum ENUM field3[TEST_INT];
int *field4[TEST_INT];
ENUM4 *field5[TEST_INT];
} STRUCT4;
union UNION1 {

View file

@ -39,6 +39,8 @@ ct = 4
s.field1 = 5
s2.field1 = 6
s3.field1 = 7
s4.field2[2] = 5
s4.field3[3] = enum1
e = enum1
e2 = enum4