How to use the pyleri.List function in pyleri

To help you get started, we’ve selected a few pyleri examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github transceptor-technology / pyleri / test / test_pyleri.py View on Github external
Sequence(THIS, Keyword('or'), THIS))


class _TestGrammar3(Grammar):
    s_tic_tac = Sequence(Keyword('tic'), Keyword('tac'))
    s_tic_tac_toe = Sequence(Keyword('tic'), Keyword('tac'), Keyword('toe'))

    START = Sequence(
        Choice(s_tic_tac, s_tic_tac_toe),
        Choice(s_tic_tac, s_tic_tac_toe, most_greedy=False))


class _TestGrammar4(Grammar):
    START = Ref()
    ni_item = Choice(Keyword('ni'), START)
    START = Sequence('[', List(ni_item), ']')


class TestPyleri(unittest.TestCase):

    def setUp(self):
        gc.collect()

    def test_parse_keyword(self):
        tg = _TestGrammar1()
        self.assertTrue(tg.parse('test ignore_case').is_valid)
        self.assertTrue(tg.parse('test Ignore_Case').is_valid)
        # test is not case insensitive
        self.assertFalse(tg.parse('Test ignore_case').is_valid)
        # - is not _
        self.assertFalse(tg.parse('test ignore-case').is_valid)
github SiriDB / siridb-server / grammar / grammar.py View on Github external
k_open_files,
        k_received_points,
        k_reindex_progress,
        k_selected_points,
        k_sync_progress,
        k_tee_pipe_name,
        k_uptime,
        most_greedy=False), ',', 1)

    group_columns = List(Choice(
        k_expression,
        k_name,
        k_series,
        most_greedy=False), ',', 1)

    user_columns = List(Choice(
        k_name,
        k_access,
        most_greedy=False), ',', 1)

    pool_props = Choice(
        k_pool,
        k_servers,
        k_series,
        most_greedy=False)
    pool_columns = List(pool_props, ',', 1)

    bool_operator = Tokens('== !=')
    int_operator = Tokens('< > == != <= >=')
    str_operator = Tokens('< > == != <= >= ~ !~')

    # where group
github SiriDB / siridb-server / grammar / grammar.py View on Github external
prefix_expr = Sequence(k_prefix, string)
    suffix_expr = Sequence(k_suffix, string)

    f_all = Choice(Token('*'), k_all, most_greedy=False)

    f_points = Repeat(k_points, 1, 1)  # DEPRECATED

    f_difference = Sequence(
        k_difference,
        '(',
        Optional(time_expr),
        ')')
    f_derivative = Sequence(
        k_derivative,
        '(',
        List(time_expr, ',', 0, 2),
        ')')
    f_mean = Sequence(
        k_mean,
        '(', Optional(time_expr), ')')
    f_median = Sequence(
        k_median,
        '(', Optional(time_expr), ')')
    f_median_low = Sequence(
        k_median_low,
        '(', Optional(time_expr), ')')
    f_median_high = Sequence(
        k_median_high,
        '(', Optional(time_expr), ')')
    f_sum = Sequence(
        k_sum,
        '(', Optional(time_expr), ')')
github SiriDB / siridb-server / grammar / grammar.py View on Github external
k_now,
        string,
        r_integer,
        Sequence('(', THIS, ')'),
        Sequence(THIS, Tokens('+ - * % /'), THIS))

    series_columns = List(Choice(
        k_name,
        k_type,
        k_length,
        k_start,
        k_end,
        k_pool,
        most_greedy=False), ',', 1)

    shard_columns = List(Choice(
        k_sid,
        k_pool,
        k_server,
        k_size,
        k_start,
        k_end,
        k_type,
        k_status,
        most_greedy=False), ',', 1)

    server_columns = List(Choice(
        # Local properties
        k_address,
        k_buffer_path,
        k_buffer_size,
        k_dbpath,
github transceptor-technology / pyleri / examples / json_grammar.py View on Github external
# 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)
github SiriDB / siridb-server / grammar / grammar.py View on Github external
k_fifo_files,
        k_idle_percentage,
        k_idle_time,
        k_log_level,
        k_max_open_files,
        k_mem_usage,
        k_open_files,
        k_received_points,
        k_reindex_progress,
        k_selected_points,
        k_sync_progress,
        k_tee_pipe_name,
        k_uptime,
        most_greedy=False), ',', 1)

    group_columns = List(Choice(
        k_expression,
        k_name,
        k_series,
        most_greedy=False), ',', 1)

    user_columns = List(Choice(
        k_name,
        k_access,
        most_greedy=False), ',', 1)

    pool_props = Choice(
        k_pool,
        k_servers,
        k_series,
        most_greedy=False)
    pool_columns = List(pool_props, ',', 1)
github alastairreid / mra_tools / bin / asm.py View on Github external
def _walk(self, element, pos, tree, rule, is_required):
        if self._pos != pos:
            self._s = self._string[pos:] #.lstrip() # don't strip whitespace
            self._pos = self._len_string - len(self._s)
        node = Node(element, self._string, self._pos)
        self._expecting.set_mode_required(node.start, is_required)
        return element._get_node_result(self, tree, rule, self._s, node)

asm_grammar = ASMTemplateGrammar()

class BitConcatsGrammar(Grammar):
    START = Ref()
    arg = Regex('[A-Za-z][A-Za-z0-9]*')
    brackets = Sequence('(', START, ')')
    literal = Regex('0b[01]+')
    concat = pyleri.List(Choice(brackets, arg, literal), delimiter='@')
    START = Choice(brackets, arg, literal, concat)

bit_concats_grammar = BitConcatsGrammar()

def fst_by_snd(pairs, target):
    for fst, snd in pairs:
        if target == snd:
            return fst
    raise KeyError(target)

def process_bitconcat_node_get_bits(types, node):
    assert hasattr(node.element, 'name')
    if node.element.name == 'START':
        return process_bitconcat_node_get_bits(types, node.children[0])
    elif node.element.name == 'literal':
        return len(node.string) - 2 # remove the '0b'
github SiriDB / siridb-server / grammar / grammar.py View on Github external
f_pvariance,
        f_stddev,
        f_first,
        f_last,
        f_difference,
        f_derivative,
        f_filter,
        f_points,
        most_greedy=False), '=>', 1)

    select_aggregate = Sequence(
        aggregate_functions,
        Optional(prefix_expr),
        Optional(suffix_expr))

    select_aggregates = List(select_aggregate, ',', 1)

    merge_as = Sequence(
        k_merge,
        k_as,
        string,
        Optional(Sequence(k_using, aggregate_functions)))

    set_address = Sequence(k_set, k_address, string)
    set_tee_pipe_name = Sequence(k_set, k_tee_pipe_name, Choice(
        k_false,
        string,
        most_greedy=False))
    set_backup_mode = Sequence(k_set, k_backup_mode, _boolean)
    set_drop_threshold = Sequence(k_set, k_drop_threshold, r_float)
    set_expression = Sequence(k_set, k_expression, r_regex)
    set_ignore_threshold = Sequence(k_set, k_ignore_threshold, _boolean)
github SiriDB / siridb-server / grammar / grammar.py View on Github external
k_expression,
        k_name,
        k_series,
        most_greedy=False), ',', 1)

    user_columns = List(Choice(
        k_name,
        k_access,
        most_greedy=False), ',', 1)

    pool_props = Choice(
        k_pool,
        k_servers,
        k_series,
        most_greedy=False)
    pool_columns = List(pool_props, ',', 1)

    bool_operator = Tokens('== !=')
    int_operator = Tokens('< > == != <= >=')
    str_operator = Tokens('< > == != <= >= ~ !~')

    # where group
    where_group = Sequence(k_where, Prio(
        Sequence(k_series, int_operator, int_expr),
        Sequence(
            Choice(k_expression, k_name, most_greedy=False),
            str_operator,
            string),
        Sequence('(', THIS, ')'),
        Sequence(THIS, k_and, THIS),
        Sequence(THIS, k_or, THIS)))