Commit 40f52c12 authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Treating cython: comments as regular comments when not at top

parent b629f965
......@@ -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'))
......
......@@ -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]" % (
......
......@@ -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]
......
......@@ -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):
......
......@@ -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
"""
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