From ff152fe9f936d686026c7f35958d8b3f4b30e31e Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Wed, 8 Oct 2008 16:08:15 -0700 Subject: [PATCH] Better NULL parsing, touchup pure test --- Cython/Compiler/Parsing.py | 5 ++-- Cython/Compiler/Scanning.py | 2 +- tests/run/pure.pyx | 51 ++++++++++++++++++++++++++++++------- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index b96eb64f..2a2a5ac7 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -518,11 +518,10 @@ def p_atom(s): return ExprNodes.BoolNode(pos, value=True) elif name == "False": return ExprNodes.BoolNode(pos, value=False) + elif name == "NULL": + return ExprNodes.NullNode(pos) else: return p_name(s, name) - elif sy == 'NULL': - s.next() - return ExprNodes.NullNode(pos) else: s.error("Expected an identifier or literal") diff --git a/Cython/Compiler/Scanning.py b/Cython/Compiler/Scanning.py index 004a8921..fc7da80d 100644 --- a/Cython/Compiler/Scanning.py +++ b/Cython/Compiler/Scanning.py @@ -145,7 +145,7 @@ reserved_words = [ "raise", "import", "exec", "try", "except", "finally", "while", "if", "elif", "else", "for", "in", "assert", "and", "or", "not", "is", "in", "lambda", "from", - "NULL", "cimport", "by", "with", "cpdef", "DEF", "IF", "ELIF", "ELSE" + "cimport", "by", "with", "cpdef", "DEF", "IF", "ELIF", "ELSE" ] class Method: diff --git a/tests/run/pure.pyx b/tests/run/pure.pyx index b8550364..89688ab0 100644 --- a/tests/run/pure.pyx +++ b/tests/run/pure.pyx @@ -1,8 +1,41 @@ -import sys, os -sys.path.insert(0, "..") +__doc__ = """ +>>> test_sizeof() +True +True +True +True +True -import cython +>>> test_declare(100) +(100, 100) +>>> test_declare(100.5) +(100, 100) +>>> test_declare(None) +Traceback (most recent call last): +... +TypeError: an integer is required + +>>> test_cast(1.5) +1 +>>> test_cast(None) +Traceback (most recent call last): +... +TypeError: a float is required + +>>> test_address(39) +39 + +>>> test_locals(5) +True +>>> test_struct(389, 1.64493) +(389, 1.64493) + +>>> test_imports() +True +""" + +import cython def test_sizeof(): x = cython.declare(cython.bint) @@ -52,15 +85,15 @@ def test_struct(n, x): import cython as cy from cython import declare, cast, locals, address, typedef, p_void, compiled -from cython import declare as my_declare, locals as my_locals, p_void as my_void_star, typedef as my_typedef, my_compiled +from cython import declare as my_declare, locals as my_locals, p_void as my_void_star, typedef as my_typedef, compiled as my_compiled @my_locals(a=cython.p_void) def test_imports(): - a = NULL - b = declare(p_void, NULL) - c = my_declare(my_void_star, NULL) - d = cy.declare(cy.p_void, NULL) - compiled and my_compiled + a = cython.NULL + b = declare(p_void, cython.NULL) + c = my_declare(my_void_star, cython.NULL) + d = cy.declare(cy.p_void, cython.NULL) + return a == d and compiled and my_compiled MyStruct3 = typedef(MyStruct[3]) MyStruct4 = my_typedef(MyStruct[4]) -- 2.26.2