Commit 422a77f8 authored by Peter Alexander's avatar Peter Alexander

naming references changed from 'option' to 'directive'

parent 49ef0f6b
...@@ -126,7 +126,7 @@ def parse_command_line(args): ...@@ -126,7 +126,7 @@ def parse_command_line(args):
options.emit_linenums = True options.emit_linenums = True
elif option in ("-X", "--directive"): elif option in ("-X", "--directive"):
try: try:
options.compiler_directives = Options.parse_option_list(pop_arg()) options.compiler_directives = Options.parse_directive_list(pop_arg())
except ValueError, e: except ValueError, e:
sys.stderr.write("Error in compiler directive: %s\n" % e.message) sys.stderr.write("Error in compiler directive: %s\n" % e.message)
sys.exit(1) sys.exit(1)
......
...@@ -55,7 +55,7 @@ embed = False ...@@ -55,7 +55,7 @@ embed = False
# Declare compiler directives # Declare compiler directives
option_defaults = { directive_defaults = {
'boundscheck' : True, 'boundscheck' : True,
'nonecheck' : False, 'nonecheck' : False,
'embedsignature' : False, 'embedsignature' : False,
...@@ -77,35 +77,35 @@ option_defaults = { ...@@ -77,35 +77,35 @@ option_defaults = {
} }
# Override types possibilities above, if needed # Override types possibilities above, if needed
option_types = {} directive_types = {}
for key, val in option_defaults.items(): for key, val in directive_defaults.items():
if key not in option_types: if key not in directive_types:
option_types[key] = type(val) directive_types[key] = type(val)
option_scopes = { # defaults to available everywhere directive_scopes = { # defaults to available everywhere
# 'module', 'function', 'class', 'with statement' # 'module', 'function', 'class', 'with statement'
'autotestdict' : ('module',), 'autotestdict' : ('module',),
'test_assert_path_exists' : ('function',), 'test_assert_path_exists' : ('function',),
'test_fail_if_path_exists' : ('function',), 'test_fail_if_path_exists' : ('function',),
} }
def parse_option_value(name, value): def parse_directive_value(name, value):
""" """
Parses value as an option value for the given name and returns Parses value as an option value for the given name and returns
the interpreted value. None is returned if the option does not exist. the interpreted value. None is returned if the option does not exist.
>>> print parse_option_value('nonexisting', 'asdf asdfd') >>> print parse_directive_value('nonexisting', 'asdf asdfd')
None None
>>> parse_option_value('boundscheck', 'True') >>> parse_directive_value('boundscheck', 'True')
True True
>>> parse_option_value('boundscheck', 'true') >>> parse_directive_value('boundscheck', 'true')
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: boundscheck directive must be set to True or False ValueError: boundscheck directive must be set to True or False
""" """
type = option_types.get(name) type = directive_types.get(name)
if not type: return None if not type: return None
if type is bool: if type is bool:
if value == "True": return True if value == "True": return True
...@@ -119,25 +119,25 @@ def parse_option_value(name, value): ...@@ -119,25 +119,25 @@ def parse_option_value(name, value):
else: else:
assert False assert False
def parse_option_list(s): def parse_directive_list(s):
""" """
Parses a comma-seperated list of pragma options. Whitespace Parses a comma-seperated list of pragma options. Whitespace
is not considered. is not considered.
>>> parse_option_list(' ') >>> parse_directive_list(' ')
{} {}
>>> (parse_option_list('boundscheck=True') == >>> (parse_directive_list('boundscheck=True') ==
... {'boundscheck': True}) ... {'boundscheck': True})
True True
>>> parse_option_list(' asdf') >>> parse_directive_list(' asdf')
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Expected "=" in option "asdf" ValueError: Expected "=" in option "asdf"
>>> parse_option_list('boundscheck=hey') >>> parse_directive_list('boundscheck=hey')
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Must pass a boolean value for option "boundscheck" ValueError: Must pass a boolean value for option "boundscheck"
>>> parse_option_list('unknown=True') >>> parse_directive_list('unknown=True')
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Unknown option: "unknown" ValueError: Unknown option: "unknown"
...@@ -149,7 +149,7 @@ def parse_option_list(s): ...@@ -149,7 +149,7 @@ def parse_option_list(s):
if not '=' in item: raise ValueError('Expected "=" in option "%s"' % item) if not '=' in item: raise ValueError('Expected "=" in option "%s"' % item)
name, value = item.strip().split('=') name, value = item.strip().split('=')
try: try:
type = option_types[name] type = directive_types[name]
except KeyError: except KeyError:
raise ValueError('Unknown option: "%s"' % name) raise ValueError('Unknown option: "%s"' % name)
if type is bool: if type is bool:
......
This diff is collapsed.
...@@ -2582,7 +2582,7 @@ def p_compiler_directive_comments(s): ...@@ -2582,7 +2582,7 @@ def p_compiler_directive_comments(s):
if m: if m:
name = m.group(1) name = m.group(1)
try: try:
value = Options.parse_option_value(str(name), str(m.group(2).strip())) value = Options.parse_directive_value(str(name), str(m.group(2).strip()))
if value is not None: # can be False! if value is not None: # can be False!
result[name] = value result[name] = value
except ValueError, e: except ValueError, e:
...@@ -2593,7 +2593,7 @@ def p_compiler_directive_comments(s): ...@@ -2593,7 +2593,7 @@ def p_compiler_directive_comments(s):
def p_module(s, pxd, full_module_name): def p_module(s, pxd, full_module_name):
pos = s.position() pos = s.position()
option_comments = p_compiler_directive_comments(s) directive_comments = p_compiler_directive_comments(s)
s.parse_comments = False s.parse_comments = False
doc = p_doc_string(s) doc = p_doc_string(s)
...@@ -2608,7 +2608,7 @@ def p_module(s, pxd, full_module_name): ...@@ -2608,7 +2608,7 @@ def p_module(s, pxd, full_module_name):
repr(s.sy), repr(s.systring))) repr(s.sy), repr(s.systring)))
return ModuleNode(pos, doc = doc, body = body, return ModuleNode(pos, doc = doc, body = body,
full_module_name = full_module_name, full_module_name = full_module_name,
option_comments = option_comments) directive_comments = directive_comments)
#---------------------------------------------- #----------------------------------------------
# #
......
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