Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Scanning for all of these at once is faster than scanning for them individually.
keywords = ['inherit', 'if', 'then', 'else', 'include', 'null', 'for', 'in', 'private', 'required']
scanner = sparse.Scanner([
sparse.WHITESPACE,
sparse.Syntax('comment', '#$|#[^.].*$'),
sparse.Syntax('doc_comment', '#\.(.*)$', lambda s: s[2:].strip()),
# Keywords
sparse.Syntax('bool_op', r'\band\b|\bor\b'),
sparse.Syntax('minus', r'-(?!\d)'),
sparse.Syntax('not', r'\bnot\b'),
sparse.Syntax('keyword', '|'.join(r'\b' + k + r'\b' for k in keywords)),
sparse.Syntax('bool_literal', r'\btrue\b|\bfalse\b'),
# Identifiers (must come after keywords for matching priority)
sparse.Syntax('identifier', sparse.quoted_string_regex('`'), sparse.quoted_string_process),
sparse.Syntax('identifier', r'[a-zA-Z_]([a-zA-Z0-9_:-]*[a-zA-Z0-9_])?'),
# Other atoms
sparse.Syntax('string_literal', sparse.quoted_string_regex('"'), sparse.quoted_string_process),
sparse.Syntax('string_literal', sparse.quoted_string_regex("'"), sparse.quoted_string_process),
sparse.Syntax('compare_op', '|'.join(['<=', '>=', '==', '!=', '<', '>'])),
sparse.Syntax('mul_op', '[*/%]'),
sparse.Syntax('plus', '\+'),
sparse.Syntax('float_literal', r'-?\d*\.\d+'),
sparse.Syntax('int_literal', r'-?\d+'),
# Symbols
sparse.Syntax('symbol', '[' + ''.join('\\' + s for s in '[](){}=,;:.') + ']'),
])
def listMembers(t_sep, expr):
return sparse.delimited_list(expr, sparse.Q(t_sep))
return dict2tuple(x)
#----------------------------------------------------------------------
# PARSING
# Scanning for all of these at once is faster than scanning for them individually.
keywords = ['inherit', 'if', 'then', 'else', 'include', 'null', 'for', 'in', 'private', 'required']
scanner = sparse.Scanner([
sparse.WHITESPACE,
sparse.Syntax('comment', '#$|#[^.].*$'),
sparse.Syntax('doc_comment', '#\.(.*)$', lambda s: s[2:].strip()),
# Keywords
sparse.Syntax('bool_op', r'\band\b|\bor\b'),
sparse.Syntax('minus', r'-(?!\d)'),
sparse.Syntax('not', r'\bnot\b'),
sparse.Syntax('keyword', '|'.join(r'\b' + k + r'\b' for k in keywords)),
sparse.Syntax('bool_literal', r'\btrue\b|\bfalse\b'),
# Identifiers (must come after keywords for matching priority)
sparse.Syntax('identifier', sparse.quoted_string_regex('`'), sparse.quoted_string_process),
sparse.Syntax('identifier', r'[a-zA-Z_]([a-zA-Z0-9_:-]*[a-zA-Z0-9_])?'),
# Other atoms
sparse.Syntax('string_literal', sparse.quoted_string_regex('"'), sparse.quoted_string_process),
sparse.Syntax('string_literal', sparse.quoted_string_regex("'"), sparse.quoted_string_process),
sparse.Syntax('compare_op', '|'.join(['<=', '>=', '==', '!=', '<', '>'])),
sparse.Syntax('mul_op', '[*/%]'),
sparse.Syntax('plus', '\+'),
sparse.Syntax('float_literal', r'-?\d*\.\d+'),
sparse.Syntax('int_literal', r'-?\d+'),
# Symbols
sparse.Syntax('symbol', '[' + ''.join('\\' + s for s in '[](){}=,;:.') + ']'),
#----------------------------------------------------------------------
# PARSING
# Scanning for all of these at once is faster than scanning for them individually.
keywords = ['inherit', 'if', 'then', 'else', 'include', 'null', 'for', 'in', 'private', 'required']
scanner = sparse.Scanner([
sparse.WHITESPACE,
sparse.Syntax('comment', '#$|#[^.].*$'),
sparse.Syntax('doc_comment', '#\.(.*)$', lambda s: s[2:].strip()),
# Keywords
sparse.Syntax('bool_op', r'\band\b|\bor\b'),
sparse.Syntax('minus', r'-(?!\d)'),
sparse.Syntax('not', r'\bnot\b'),
sparse.Syntax('keyword', '|'.join(r'\b' + k + r'\b' for k in keywords)),
sparse.Syntax('bool_literal', r'\btrue\b|\bfalse\b'),
# Identifiers (must come after keywords for matching priority)
sparse.Syntax('identifier', sparse.quoted_string_regex('`'), sparse.quoted_string_process),
sparse.Syntax('identifier', r'[a-zA-Z_]([a-zA-Z0-9_:-]*[a-zA-Z0-9_])?'),
# Other atoms
sparse.Syntax('string_literal', sparse.quoted_string_regex('"'), sparse.quoted_string_process),
sparse.Syntax('string_literal', sparse.quoted_string_regex("'"), sparse.quoted_string_process),
sparse.Syntax('compare_op', '|'.join(['<=', '>=', '==', '!=', '<', '>'])),
sparse.Syntax('mul_op', '[*/%]'),
sparse.Syntax('plus', '\+'),
sparse.Syntax('float_literal', r'-?\d*\.\d+'),
sparse.Syntax('int_literal', r'-?\d+'),
# Symbols
sparse.Syntax('symbol', '[' + ''.join('\\' + s for s in '[](){}=,;:.') + ']'),
])
# Keywords
sparse.Syntax('bool_op', r'\band\b|\bor\b'),
sparse.Syntax('minus', r'-(?!\d)'),
sparse.Syntax('not', r'\bnot\b'),
sparse.Syntax('keyword', '|'.join(r'\b' + k + r'\b' for k in keywords)),
sparse.Syntax('bool_literal', r'\btrue\b|\bfalse\b'),
# Identifiers (must come after keywords for matching priority)
sparse.Syntax('identifier', sparse.quoted_string_regex('`'), sparse.quoted_string_process),
sparse.Syntax('identifier', r'[a-zA-Z_]([a-zA-Z0-9_:-]*[a-zA-Z0-9_])?'),
# Other atoms
sparse.Syntax('string_literal', sparse.quoted_string_regex('"'), sparse.quoted_string_process),
sparse.Syntax('string_literal', sparse.quoted_string_regex("'"), sparse.quoted_string_process),
sparse.Syntax('compare_op', '|'.join(['<=', '>=', '==', '!=', '<', '>'])),
sparse.Syntax('mul_op', '[*/%]'),
sparse.Syntax('plus', '\+'),
sparse.Syntax('float_literal', r'-?\d*\.\d+'),
sparse.Syntax('int_literal', r'-?\d+'),
# Symbols
sparse.Syntax('symbol', '[' + ''.join('\\' + s for s in '[](){}=,;:.') + ']'),
])
def listMembers(t_sep, expr):
return sparse.delimited_list(expr, sparse.Q(t_sep))
def braced_list(t_l, t_r, t_sep, expr, allow_missing_close=False):
"""Parse bracketed list.
Empty list is possible, as is a trailing separator.
"""
return braced_expression(t_l, listMembers(t_sep, expr), t_r, allow_missing_close=allow_missing_close)
sparse.Syntax('comment', '#$|#[^.].*$'),
sparse.Syntax('doc_comment', '#\.(.*)$', lambda s: s[2:].strip()),
# Keywords
sparse.Syntax('bool_op', r'\band\b|\bor\b'),
sparse.Syntax('minus', r'-(?!\d)'),
sparse.Syntax('not', r'\bnot\b'),
sparse.Syntax('keyword', '|'.join(r'\b' + k + r'\b' for k in keywords)),
sparse.Syntax('bool_literal', r'\btrue\b|\bfalse\b'),
# Identifiers (must come after keywords for matching priority)
sparse.Syntax('identifier', sparse.quoted_string_regex('`'), sparse.quoted_string_process),
sparse.Syntax('identifier', r'[a-zA-Z_]([a-zA-Z0-9_:-]*[a-zA-Z0-9_])?'),
# Other atoms
sparse.Syntax('string_literal', sparse.quoted_string_regex('"'), sparse.quoted_string_process),
sparse.Syntax('string_literal', sparse.quoted_string_regex("'"), sparse.quoted_string_process),
sparse.Syntax('compare_op', '|'.join(['<=', '>=', '==', '!=', '<', '>'])),
sparse.Syntax('mul_op', '[*/%]'),
sparse.Syntax('plus', '\+'),
sparse.Syntax('float_literal', r'-?\d*\.\d+'),
sparse.Syntax('int_literal', r'-?\d+'),
# Symbols
sparse.Syntax('symbol', '[' + ''.join('\\' + s for s in '[](){}=,;:.') + ']'),
])
def listMembers(t_sep, expr):
return sparse.delimited_list(expr, sparse.Q(t_sep))
def braced_list(t_l, t_r, t_sep, expr, allow_missing_close=False):
"""Parse bracketed list.
Empty list is possible, as is a trailing separator.
#----------------------------------------------------------------------
# PARSING
# Scanning for all of these at once is faster than scanning for them individually.
keywords = ['inherit', 'if', 'then', 'else', 'include', 'null', 'for', 'in', 'private', 'required']
scanner = sparse.Scanner([
sparse.WHITESPACE,
sparse.Syntax('comment', '#$|#[^.].*$'),
sparse.Syntax('doc_comment', '#\.(.*)$', lambda s: s[2:].strip()),
# Keywords
sparse.Syntax('bool_op', r'\band\b|\bor\b'),
sparse.Syntax('minus', r'-(?!\d)'),
sparse.Syntax('not', r'\bnot\b'),
sparse.Syntax('keyword', '|'.join(r'\b' + k + r'\b' for k in keywords)),
sparse.Syntax('bool_literal', r'\btrue\b|\bfalse\b'),
# Identifiers (must come after keywords for matching priority)
sparse.Syntax('identifier', sparse.quoted_string_regex('`'), sparse.quoted_string_process),
sparse.Syntax('identifier', r'[a-zA-Z_]([a-zA-Z0-9_:-]*[a-zA-Z0-9_])?'),
# Other atoms
sparse.Syntax('string_literal', sparse.quoted_string_regex('"'), sparse.quoted_string_process),
sparse.Syntax('string_literal', sparse.quoted_string_regex("'"), sparse.quoted_string_process),
sparse.Syntax('compare_op', '|'.join(['<=', '>=', '==', '!=', '<', '>'])),
sparse.Syntax('mul_op', '[*/%]'),
sparse.Syntax('plus', '\+'),
sparse.Syntax('float_literal', r'-?\d*\.\d+'),
sparse.Syntax('int_literal', r'-?\d+'),
# Symbols
sparse.Syntax('symbol', '[' + ''.join('\\' + s for s in '[](){}=,;:.') + ']'),
])
"""Turn a dict-like object into a Tuple."""
if isinstance(x, framework.TupleLike):
return x
return dict2tuple(x)
#----------------------------------------------------------------------
# PARSING
# Scanning for all of these at once is faster than scanning for them individually.
keywords = ['inherit', 'if', 'then', 'else', 'include', 'null', 'for', 'in', 'private', 'required']
scanner = sparse.Scanner([
sparse.WHITESPACE,
sparse.Syntax('comment', '#$|#[^.].*$'),
sparse.Syntax('doc_comment', '#\.(.*)$', lambda s: s[2:].strip()),
# Keywords
sparse.Syntax('bool_op', r'\band\b|\bor\b'),
sparse.Syntax('minus', r'-(?!\d)'),
sparse.Syntax('not', r'\bnot\b'),
sparse.Syntax('keyword', '|'.join(r'\b' + k + r'\b' for k in keywords)),
sparse.Syntax('bool_literal', r'\btrue\b|\bfalse\b'),
# Identifiers (must come after keywords for matching priority)
sparse.Syntax('identifier', sparse.quoted_string_regex('`'), sparse.quoted_string_process),
sparse.Syntax('identifier', r'[a-zA-Z_]([a-zA-Z0-9_:-]*[a-zA-Z0-9_])?'),
# Other atoms
sparse.Syntax('string_literal', sparse.quoted_string_regex('"'), sparse.quoted_string_process),
sparse.Syntax('string_literal', sparse.quoted_string_regex("'"), sparse.quoted_string_process),
sparse.Syntax('compare_op', '|'.join(['<=', '>=', '==', '!=', '<', '>'])),
sparse.Syntax('mul_op', '[*/%]'),
sparse.Syntax('plus', '\+'),
sparse.Syntax('float_literal', r'-?\d*\.\d+'),
scanner = sparse.Scanner([
sparse.WHITESPACE,
sparse.Syntax('comment', '#$|#[^.].*$'),
sparse.Syntax('doc_comment', '#\.(.*)$', lambda s: s[2:].strip()),
# Keywords
sparse.Syntax('bool_op', r'\band\b|\bor\b'),
sparse.Syntax('minus', r'-(?!\d)'),
sparse.Syntax('not', r'\bnot\b'),
sparse.Syntax('keyword', '|'.join(r'\b' + k + r'\b' for k in keywords)),
sparse.Syntax('bool_literal', r'\btrue\b|\bfalse\b'),
# Identifiers (must come after keywords for matching priority)
sparse.Syntax('identifier', sparse.quoted_string_regex('`'), sparse.quoted_string_process),
sparse.Syntax('identifier', r'[a-zA-Z_]([a-zA-Z0-9_:-]*[a-zA-Z0-9_])?'),
# Other atoms
sparse.Syntax('string_literal', sparse.quoted_string_regex('"'), sparse.quoted_string_process),
sparse.Syntax('string_literal', sparse.quoted_string_regex("'"), sparse.quoted_string_process),
sparse.Syntax('compare_op', '|'.join(['<=', '>=', '==', '!=', '<', '>'])),
sparse.Syntax('mul_op', '[*/%]'),
sparse.Syntax('plus', '\+'),
sparse.Syntax('float_literal', r'-?\d*\.\d+'),
sparse.Syntax('int_literal', r'-?\d+'),
# Symbols
sparse.Syntax('symbol', '[' + ''.join('\\' + s for s in '[](){}=,;:.') + ']'),
])
def listMembers(t_sep, expr):
return sparse.delimited_list(expr, sparse.Q(t_sep))
def braced_list(t_l, t_r, t_sep, expr, allow_missing_close=False):
"""Parse bracketed list.
# Scanning for all of these at once is faster than scanning for them individually.
keywords = ['inherit', 'if', 'then', 'else', 'include', 'null', 'for', 'in', 'private', 'required']
scanner = sparse.Scanner([
sparse.WHITESPACE,
sparse.Syntax('comment', '#$|#[^.].*$'),
sparse.Syntax('doc_comment', '#\.(.*)$', lambda s: s[2:].strip()),
# Keywords
sparse.Syntax('bool_op', r'\band\b|\bor\b'),
sparse.Syntax('minus', r'-(?!\d)'),
sparse.Syntax('not', r'\bnot\b'),
sparse.Syntax('keyword', '|'.join(r'\b' + k + r'\b' for k in keywords)),
sparse.Syntax('bool_literal', r'\btrue\b|\bfalse\b'),
# Identifiers (must come after keywords for matching priority)
sparse.Syntax('identifier', sparse.quoted_string_regex('`'), sparse.quoted_string_process),
sparse.Syntax('identifier', r'[a-zA-Z_]([a-zA-Z0-9_:-]*[a-zA-Z0-9_])?'),
# Other atoms
sparse.Syntax('string_literal', sparse.quoted_string_regex('"'), sparse.quoted_string_process),
sparse.Syntax('string_literal', sparse.quoted_string_regex("'"), sparse.quoted_string_process),
sparse.Syntax('compare_op', '|'.join(['<=', '>=', '==', '!=', '<', '>'])),
sparse.Syntax('mul_op', '[*/%]'),
sparse.Syntax('plus', '\+'),
sparse.Syntax('float_literal', r'-?\d*\.\d+'),
sparse.Syntax('int_literal', r'-?\d+'),
# Symbols
sparse.Syntax('symbol', '[' + ''.join('\\' + s for s in '[](){}=,;:.') + ']'),
])
def listMembers(t_sep, expr):
return sparse.delimited_list(expr, sparse.Q(t_sep))
return x
return dict2tuple(x)
#----------------------------------------------------------------------
# PARSING
# Scanning for all of these at once is faster than scanning for them individually.
keywords = ['inherit', 'if', 'then', 'else', 'include', 'null', 'for', 'in', 'private', 'required']
scanner = sparse.Scanner([
sparse.WHITESPACE,
sparse.Syntax('comment', '#$|#[^.].*$'),
sparse.Syntax('doc_comment', '#\.(.*)$', lambda s: s[2:].strip()),
# Keywords
sparse.Syntax('bool_op', r'\band\b|\bor\b'),
sparse.Syntax('minus', r'-(?!\d)'),
sparse.Syntax('not', r'\bnot\b'),
sparse.Syntax('keyword', '|'.join(r'\b' + k + r'\b' for k in keywords)),
sparse.Syntax('bool_literal', r'\btrue\b|\bfalse\b'),
# Identifiers (must come after keywords for matching priority)
sparse.Syntax('identifier', sparse.quoted_string_regex('`'), sparse.quoted_string_process),
sparse.Syntax('identifier', r'[a-zA-Z_]([a-zA-Z0-9_:-]*[a-zA-Z0-9_])?'),
# Other atoms
sparse.Syntax('string_literal', sparse.quoted_string_regex('"'), sparse.quoted_string_process),
sparse.Syntax('string_literal', sparse.quoted_string_regex("'"), sparse.quoted_string_process),
sparse.Syntax('compare_op', '|'.join(['<=', '>=', '==', '!=', '<', '>'])),
sparse.Syntax('mul_op', '[*/%]'),
sparse.Syntax('plus', '\+'),
sparse.Syntax('float_literal', r'-?\d*\.\d+'),
sparse.Syntax('int_literal', r'-?\d+'),
# Symbols