Commit 573f3fe4 authored by Stefan Behnel's avatar Stefan Behnel

Allow the short form "cdef struct xyz: pass" instead of always requiring a block for it.

Closes #2802.
parent 0907d71f
......@@ -3184,18 +3184,22 @@ def p_c_struct_or_union_definition(s, pos, ctx):
attributes = None
if s.sy == ':':
s.next()
s.expect('NEWLINE')
s.expect_indent()
attributes = []
body_ctx = Ctx()
while s.sy != 'DEDENT':
if s.sy != 'pass':
attributes.append(
p_c_func_or_var_declaration(s, s.position(), body_ctx))
else:
s.next()
s.expect_newline("Expected a newline")
s.expect_dedent()
if s.sy == 'pass':
s.next()
s.expect_newline("Expected a newline", ignore_semicolon=True)
else:
s.expect('NEWLINE')
s.expect_indent()
body_ctx = Ctx()
while s.sy != 'DEDENT':
if s.sy != 'pass':
attributes.append(
p_c_func_or_var_declaration(s, s.position(), body_ctx))
else:
s.next()
s.expect_newline("Expected a newline")
s.expect_dedent()
else:
s.expect_newline("Syntax error in struct or union definition")
return Nodes.CStructOrUnionDefNode(pos,
......
cdef extern from "cdefemptysue.h":
cdef struct spam:
pass
ctypedef union eggs:
pass
cdef enum ham:
pass
cdef extern spam s
cdef extern eggs e
cdef extern ham h
# mode: compile
# tag: struct, union, enum, cdefextern
cdef extern from *:
"""
struct spam { int a; };
struct flat_spam { int a; };
typedef struct { int a; } flat_spam_type;
typedef union { int a; long b; } eggs;
typedef union { int a; long b; } flat_eggs;
enum ham { TOAST };
enum flat_ham { FLAT_TOAST };
"""
cdef struct spam:
pass
cdef struct flat_spam: pass
ctypedef struct flat_spam_type: pass
ctypedef union eggs:
pass
ctypedef union flat_eggs: pass
cdef enum ham:
pass
cdef enum flat_ham: pass
cdef extern spam s
cdef extern flat_spam fs
cdef extern flat_spam_type fst
cdef extern eggs e
cdef extern flat_eggs fe
cdef extern ham h
cdef extern flat_ham fh
# mode: compile
# tag: struct, union, enum, cdefextern
cdef extern from "cheese.h":
ctypedef int camembert
......@@ -9,11 +12,12 @@ cdef extern from "cheese.h":
void cheddar()
class external.runny [object runny_obj]:
cdef int a
def __init__(self):
pass
# FIXME: find a real declaration here.
#class external.runny [object runny_obj]:
# cdef int a
# def __init__(self):
# pass
cdef runny r
r = x
r.a = 42
#cdef runny r = runny()
#r.a = 42
......@@ -8,8 +8,21 @@ ctypedef union eggs:
cdef enum ham:
pass
cdef struct flat_spam: pass
ctypedef union flat_eggs: pass
cdef enum flat_ham: pass
_ERRORS = u"""
3:5: Empty struct or union definition not allowed outside a 'cdef extern from' block
6:0: Empty struct or union definition not allowed outside a 'cdef extern from' block
9:5: Empty enum definition not allowed outside a 'cdef extern from' block
13:5: Empty struct or union definition not allowed outside a 'cdef extern from' block
15:0: Empty struct or union definition not allowed outside a 'cdef extern from' block
17:5: Empty enum definition not allowed outside a 'cdef extern from' block
"""
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment