From: Dag Sverre Seljebotn Date: Tue, 5 Aug 2008 12:25:31 +0000 (+0200) Subject: Treating cython: comments as regular comments when not at top X-Git-Tag: 0.9.8.1~49^2~16 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=40f52c129697834cf0dad0f1f0d35ae6eb8a8528;p=cython.git Treating cython: comments as regular comments when not at top --- diff --git a/Cython/Compiler/Lexicon.py b/Cython/Compiler/Lexicon.py index f1282c87..8fe3724f 100644 --- a/Cython/Compiler/Lexicon.py +++ b/Cython/Compiler/Lexicon.py @@ -97,13 +97,13 @@ def make_lexicon(): #(stringlit, 'STRING'), (beginstring, Method('begin_string_action')), - (option_comment, 'option_comment'), + (option_comment, Method('option_comment')), (comment, IGNORE), (spaces, IGNORE), (escaped_newline, IGNORE), State('INDENT', [ - (option_comment + lineterm, 'option_comment'), + (option_comment + lineterm, Method('option_comment')), (Opt(spaces) + Opt(comment) + lineterm, IGNORE), (indentation, Method('indentation_action')), (Eof, Method('eof_action')) diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index 908a91c6..731116b2 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -507,8 +507,6 @@ def p_atom(s): elif sy == 'NULL': s.next() return ExprNodes.NullNode(pos) - elif sy == 'option_comment': - s.error("#cython option comments only allowed at beginning of file") else: s.error("Expected an identifier or literal") @@ -2342,6 +2340,7 @@ def p_module(s, pxd, full_module_name): level = 'module' option_comments = p_option_comments(s) + s.parse_option_comments = False body = p_statement_list(s, Ctx(level = level), first_statement = 1) if s.sy != 'EOF': s.error("Syntax error in statement [%s,%s]" % ( diff --git a/Cython/Compiler/Scanning.py b/Cython/Compiler/Scanning.py index ee01e08f..bdf7eb4b 100644 --- a/Cython/Compiler/Scanning.py +++ b/Cython/Compiler/Scanning.py @@ -303,6 +303,7 @@ class PyrexScanner(Scanner): self.compile_time_env = initial_compile_time_env() self.compile_time_eval = 1 self.compile_time_expr = 0 + self.parse_option_comments = True self.source_encoding = source_encoding self.trace = trace_scanner self.indentation_stack = [0] @@ -311,6 +312,13 @@ class PyrexScanner(Scanner): self.begin('INDENT') self.sy = '' self.next() + + def option_comment(self, text): + # #cython:-comments should be treated as literals until + # parse_option_comments is set to False, at which point + # they should be ignored. + if self.parse_option_comments: + self.produce('option_comment', text) def current_level(self): return self.indentation_stack[-1] diff --git a/tests/compile/c_options.pyx b/tests/compile/c_options.pyx index e653a284..8f7dac7c 100644 --- a/tests/compile/c_options.pyx +++ b/tests/compile/c_options.pyx @@ -10,6 +10,9 @@ def f(object[int, 2] buf): @cy.boundscheck(True) def g(object[int, 2] buf): + # Please leave this comment, +#cython: this should have no special meaning + # even if the above line doesn't follow indentation. print buf[3, 2] def h(object[int, 2] buf): diff --git a/tests/errors/e_options.pyx b/tests/errors/e_options.pyx index a100e4cc..0c82adc8 100644 --- a/tests/errors/e_options.pyx +++ b/tests/errors/e_options.pyx @@ -17,6 +17,5 @@ _ERRORS = u""" 2:0: Expected "=" in option "nonexistant" 3:0: Unknown option: "some" 10:0: Must pass a boolean value for option "boundscheck" -14:0: #cython option comments only allowed at beginning of file """