Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Prio,
Choice,
THIS,
Ref,
List,
Grammar,
KeywordError,
ReKeywordsChangedError,
NameAssignedError,
MissingStartError,
UnusedElementError) # nopep8
from examples import JsonGrammar # nopep8
class _TestGrammar1(Grammar):
k_test = Keyword('test')
k_ignore_case = Keyword('ignore_case', ign_case=True)
START = Sequence(k_test, k_ignore_case)
class _TestGrammar2(Grammar):
k_ni = Keyword('ni')
s_seq = Sequence('(', THIS, ')')
START = Prio(
k_ni,
s_seq,
Sequence(THIS, Keyword('and'), THIS),
Sequence(THIS, Keyword('or'), THIS))
class _TestGrammar3(Grammar):
s_tic_tac = Sequence(Keyword('tic'), Keyword('tac'))
k_between = Keyword('between')
k_count = Keyword('count')
k_create = Keyword('create')
k_critical = Keyword('critical')
k_database = Keyword('database')
k_dbname = Keyword('dbname')
k_dbpath = Keyword('dbpath')
k_debug = Keyword('debug')
k_derivative = Keyword('derivative')
k_difference = Keyword('difference')
k_drop = Keyword('drop')
k_drop_threshold = Keyword('drop_threshold')
k_duration_log = Keyword('duration_log')
k_duration_num = Keyword('duration_num')
k_end = Keyword('end')
k_error = Keyword('error')
k_expression = Keyword('expression')
k_false = Keyword('false')
k_fifo_files = Keyword('fifo_files')
k_filter = Keyword('filter')
k_first = Keyword('first')
k_float = Keyword('float')
k_for = Keyword('for')
k_from = Keyword('from')
k_full = Keyword('full')
k_grant = Keyword('grant')
k_group = Keyword('group')
k_groups = Keyword('groups')
k_help = Choice(Keyword('help'), Token('?'))
k_idle_percentage = Keyword('idle_percentage')
k_idle_time = Keyword('idle_time')
k_inf = Keyword('inf')
class JsonGrammar(Grammar):
START = Ref()
# JSON strings should be enclosed in double quotes.
# A backslash can be used as escape character.
r_string = Regex(r'(")(?:(?=(\\?))\2.)*?\1')
# JSON does not support floats or integers prefixed with a + sign
# and floats must start with a number, for example .5 is not allowed
# but should be written like 0.5
r_float = Regex(r'-?[0-9]+\.?[0-9]+')
r_integer = Regex('-?[0-9]+')
k_true = Keyword('true')
k_false = Keyword('false')
k_null = Keyword('null')
json_map_item = Sequence(r_string, ':', START)
json_map = Sequence('{', List(json_map_item), '}')
json_array = Sequence('[', List(START), ']')
START = Choice(
r_string,
r_float,
r_integer,
k_true,
k_false,
k_null,
json_map,
json_array)
Keyword('FPREG_64'),
Keyword('FPREG_32'),
Keyword('FPREG_16'),
Keyword('FPREG_8'),
Keyword('IMMEDIATE'),
Keyword('SIGNED_IMMEDIATE'),
Keyword('BITMASK_IMMEDIATE_32'),
Keyword('BITMASK_IMMEDIATE_64'),
Keyword('CONDITION'),
Keyword('INVERTED_CONDITION'),
Keyword('SYSREG'),
Keyword('PREFETCH_OP'),
Keyword('AT_INSTRUCTION'),
Keyword('TLBI_INSTRUCTION'),
Keyword('IC_INSTRUCTION'),
Keyword('DC_INSTRUCTION'),
Keyword('CONSTANT'),
Keyword('BARRIER_SCOPE'))
type_property = Sequence(Keyword('TYPE'), types)
bits = Regex('\'[0-9]+\'')
integer = Regex('[0-9]+')
number = Choice(bits, integer)
multiple = Sequence(name, Token('*'), number)
division = Sequence(name, Token('/'), number)
addition = Sequence(name, Token('+'), number)
subtraction = Sequence(name, Token('-'), number)
subtraction_from = Sequence(number, Token('-'), name)
encoded_property = Sequence(Keyword('ENCODED'), Choice(name, multiple, division, addition, subtraction, subtraction_from))
default_property = Sequence(Keyword('DEFAULT'), Choice(name, number))
multiple_of_property = Sequence(Keyword('MULTIPLE_OF'), number)
constant_value_property = Sequence(Keyword('CONSTANT_VALUE'), imm_name)
expr_property = Sequence(Keyword('EXPR'), Choice(name, multiple, division, addition, subtraction, subtraction_from, Keyword('PRESENCE')))
k_name = Keyword('name')
k_ninf = Sequence('-', k_inf)
k_now = Keyword('now')
k_number = Keyword('number')
k_online = Keyword('online')
k_open_files = Keyword('open_files')
k_or = Keyword('or')
k_password = Keyword('password')
k_points = Keyword('points')
k_pool = Keyword('pool')
k_pools = Keyword('pools')
k_port = Keyword('port')
k_prefix = Keyword('prefix')
k_pvariance = Keyword('pvariance')
k_read = Keyword('read')
k_received_points = Keyword('received_points')
k_reindex_progress = Keyword('reindex_progress')
k_revoke = Keyword('revoke')
k_select = Keyword('select')
k_select_points_limit = Keyword('select_points_limit')
k_selected_points = Keyword('selected_points')
k_series = Keyword('series')
k_server = Keyword('server')
k_servers = Keyword('servers')
k_set = Keyword('set')
k_sid = Keyword('sid')
k_shards = Keyword('shards')
k_show = Keyword('show')
k_size = Keyword('size')
k_start = Keyword('start')
k_startup_time = Keyword('startup_time')
k_status = Keyword('status')
most_greedy=False)
k_sync_progress = Keyword('sync_progress')
k_tee_pipe_name = Keyword('tee_pipe_name')
k_timeit = Keyword('timeit')
k_timezone = Keyword('timezone')
k_time_precision = Keyword('time_precision')
k_to = Keyword('to')
k_true = Keyword('true')
k_type = Keyword('type')
k_union = Choice(
Tokens(', |'),
Keyword('union'),
most_greedy=False)
k_uptime = Keyword('uptime')
k_user = Keyword('user')
k_users = Keyword('users')
k_using = Keyword('using')
k_uuid = Keyword('uuid')
k_variance = Keyword('variance')
k_version = Keyword('version')
k_warning = Keyword('warning')
k_where = Keyword('where')
k_who_am_i = Keyword('who_am_i')
k_write = Keyword('write')
c_difference = Choice(
Token('-'),
k_difference,
most_greedy=False)
access_keywords = Choice(
k_read,
k_write,
k_status = Keyword('status')
k_stddev = Keyword('stddev')
k_string = Keyword('string')
k_suffix = Keyword('suffix')
k_sum = Keyword('sum')
k_symmetric_difference = Choice(
Token('^'),
Keyword('symmetric_difference'),
most_greedy=False)
k_sync_progress = Keyword('sync_progress')
k_tee_pipe_name = Keyword('tee_pipe_name')
k_timeit = Keyword('timeit')
k_timezone = Keyword('timezone')
k_time_precision = Keyword('time_precision')
k_to = Keyword('to')
k_true = Keyword('true')
k_type = Keyword('type')
k_union = Choice(
Tokens(', |'),
Keyword('union'),
most_greedy=False)
k_uptime = Keyword('uptime')
k_user = Keyword('user')
k_users = Keyword('users')
k_using = Keyword('using')
k_uuid = Keyword('uuid')
k_variance = Keyword('variance')
k_version = Keyword('version')
k_warning = Keyword('warning')
k_where = Keyword('where')
k_who_am_i = Keyword('who_am_i')
k_write = Keyword('write')
k_integer = Keyword('integer')
k_intersection = Choice(
Token('&'),
Keyword('intersection'),
most_greedy=False)
k_ip_support = Keyword('ip_support')
k_last = Keyword('last')
k_length = Keyword('length')
k_libuv = Keyword('libuv')
k_limit = Keyword('limit')
k_list = Keyword('list')
k_list_limit = Keyword('list_limit')
k_log = Keyword('log')
k_log_level = Keyword('log_level')
k_max = Keyword('max')
k_max_open_files = Keyword('max_open_files')
k_mean = Keyword('mean')
k_median = Keyword('median')
k_median_low = Keyword('median_low')
k_median_high = Keyword('median_high')
k_mem_usage = Keyword('mem_usage')
k_merge = Keyword('merge')
k_min = Keyword('min')
k_modify = Keyword('modify')
k_nan = Keyword('nan')
k_name = Keyword('name')
k_ninf = Sequence('-', k_inf)
k_now = Keyword('now')
k_number = Keyword('number')
k_online = Keyword('online')
k_open_files = Keyword('open_files')
k_or = Keyword('or')
k_mean = Keyword('mean')
k_median = Keyword('median')
k_median_low = Keyword('median_low')
k_median_high = Keyword('median_high')
k_mem_usage = Keyword('mem_usage')
k_merge = Keyword('merge')
k_min = Keyword('min')
k_modify = Keyword('modify')
k_nan = Keyword('nan')
k_name = Keyword('name')
k_ninf = Sequence('-', k_inf)
k_now = Keyword('now')
k_number = Keyword('number')
k_online = Keyword('online')
k_open_files = Keyword('open_files')
k_or = Keyword('or')
k_password = Keyword('password')
k_points = Keyword('points')
k_pool = Keyword('pool')
k_pools = Keyword('pools')
k_port = Keyword('port')
k_prefix = Keyword('prefix')
k_pvariance = Keyword('pvariance')
k_read = Keyword('read')
k_received_points = Keyword('received_points')
k_reindex_progress = Keyword('reindex_progress')
k_revoke = Keyword('revoke')
k_select = Keyword('select')
k_select_points_limit = Keyword('select_points_limit')
k_selected_points = Keyword('selected_points')
k_series = Keyword('series')
k_server = Keyword('server')
k_expression = Keyword('expression')
k_false = Keyword('false')
k_fifo_files = Keyword('fifo_files')
k_filter = Keyword('filter')
k_first = Keyword('first')
k_float = Keyword('float')
k_for = Keyword('for')
k_from = Keyword('from')
k_full = Keyword('full')
k_grant = Keyword('grant')
k_group = Keyword('group')
k_groups = Keyword('groups')
k_help = Choice(Keyword('help'), Token('?'))
k_idle_percentage = Keyword('idle_percentage')
k_idle_time = Keyword('idle_time')
k_inf = Keyword('inf')
k_info = Keyword('info')
k_ignore_threshold = Keyword('ignore_threshold')
k_insert = Keyword('insert')
k_integer = Keyword('integer')
k_intersection = Choice(
Token('&'),
Keyword('intersection'),
most_greedy=False)
k_ip_support = Keyword('ip_support')
k_last = Keyword('last')
k_length = Keyword('length')
k_libuv = Keyword('libuv')
k_limit = Keyword('limit')
k_list = Keyword('list')
k_list_limit = Keyword('list_limit')
k_log = Keyword('log')