How to use the pyleri.Choice 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 SiriDB / siridb-server / grammar / grammar.py View on Github external
set_log_level = Sequence(k_set, k_log_level, log_keywords)
    set_name = Sequence(k_set, k_name, string)
    set_password = Sequence(k_set, k_password, string)
    set_port = Sequence(k_set, k_port, r_uinteger)
    set_select_points_limit = Sequence(
        k_set, k_select_points_limit, r_uinteger)
    set_timezone = Sequence(k_set, k_timezone, string)

    alter_database = Sequence(k_database, Choice(
        set_drop_threshold,
        set_list_limit,
        set_select_points_limit,
        set_timezone,
        most_greedy=False))

    alter_group = Sequence(k_group, group_name, Choice(
        set_expression,
        set_name,
        most_greedy=False))

    alter_server = Sequence(k_server, uuid, Choice(
        set_log_level,
        set_backup_mode,
        set_tee_pipe_name,
        set_address,
        set_port,
        most_greedy=False))

    alter_servers = Sequence(k_servers, Optional(where_server), Choice(
        set_log_level,
        set_tee_pipe_name,
        most_greedy=False))
github SiriDB / siridb-server / grammar / grammar.py View on Github external
int_expr = Prio(
        r_integer,
        Sequence('(', THIS, ')'),
        Sequence(THIS, Tokens('+ - * % /'), THIS))

    string = Choice(r_singleq_str, r_doubleq_str, most_greedy=False)

    time_expr = Prio(
        r_time_str,
        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,
github SiriDB / siridb-server / grammar / grammar.py View on Github external
_boolean = Choice(k_true, k_false, most_greedy=False)

    log_keywords = Choice(
        k_debug,
        k_info,
        k_warning,
        k_error,
        k_critical,
        most_greedy=False)

    int_expr = Prio(
        r_integer,
        Sequence('(', THIS, ')'),
        Sequence(THIS, Tokens('+ - * % /'), THIS))

    string = Choice(r_singleq_str, r_doubleq_str, most_greedy=False)

    time_expr = Prio(
        r_time_str,
        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,
github SiriDB / siridb-server / grammar / grammar.py View on Github external
count_pools,
        count_series,
        count_servers,
        count_servers_received,
        count_servers_selected,
        count_shards,
        count_shards_size,
        count_users,
        count_series_length,
        most_greedy=True))

    create_stmt = Sequence(k_create, Choice(
        create_group,
        create_user))

    drop_stmt = Sequence(k_drop, Choice(
        drop_group,
        drop_series,
        drop_shards,
        drop_server,
        drop_user,
        most_greedy=False))

    grant_stmt = Sequence(k_grant, access_expr, k_to, Choice(
        grant_user,
        most_greedy=False))

    list_stmt = Sequence(k_list, Choice(
        list_series,
        list_users,
        list_shards,
        list_groups,
github SiriDB / siridb-server / grammar / grammar.py View on Github external
most_greedy=False),
        series_parentheses,
        Sequence(THIS, series_setopr, THIS),
    )

    limit_expr = Sequence(k_limit, int_expr)

    before_expr = Sequence(k_before, time_expr)
    after_expr = Sequence(k_after, time_expr)
    between_expr = Sequence(k_between, time_expr, k_and, time_expr)
    access_expr = List(access_keywords, ',', 1)

    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), ')')
github SiriDB / siridb-server / grammar / grammar.py View on Github external
Sequence(k_name, str_operator, string),
        Sequence(
            Choice(k_start, k_end, most_greedy=False),
            int_operator,
            time_expr),
        Sequence(
            k_type,
            bool_operator,
            Choice(k_string, k_integer, k_float, most_greedy=False)),
        Sequence('(', THIS, ')'),
        Sequence(THIS, k_and, THIS),
        Sequence(THIS, k_or, THIS)))

    # where server
    where_server = Sequence(k_where, Prio(
        Sequence(Choice(
            k_active_handles,
            k_active_tasks,
            k_buffer_size,
            k_fifo_files,
            k_idle_percentage,
            k_idle_time,
            k_port,
            k_pool,
            k_startup_time,
            k_max_open_files,
            k_mem_usage,
            k_open_files,
            k_received_points,
            k_selected_points,
            k_uptime,
            most_greedy=False), int_operator, int_expr),
github SiriDB / siridb-server / grammar / grammar.py View on Github external
k_union,
        c_difference,
        k_intersection,
        k_symmetric_difference,
        most_greedy=False)

    series_parentheses = Sequence('(', THIS, ')')

    series_all = Choice(Token('*'), k_all, most_greedy=False)
    series_name = Repeat(string, 1, 1)
    group_name = Repeat(r_grave_str, 1, 1)
    series_re = Repeat(r_regex, 1, 1)
    uuid = Choice(r_uuid_str, string, most_greedy=False)
    group_match = Repeat(r_grave_str, 1, 1)
    series_match = Prio(
        List(Choice(
            series_all,
            series_name,
            group_match,
            series_re,
            most_greedy=False), series_setopr, 1),
        Choice(
            series_all,
            series_name,
            group_match,
            series_re,
            most_greedy=False),
        series_parentheses,
        Sequence(THIS, series_setopr, THIS),
    )

    limit_expr = Sequence(k_limit, int_expr)
github alastairreid / mra_tools / bin / explanations.py View on Github external
import copy
import itertools
import math
import re
import string
from collections import defaultdict, OrderedDict
from pyleri import Grammar, Regex, Choice, Sequence, Token, Keyword, Repeat, Ref

import explanation_rewrites

class ExplanationGrammar(Grammar):
    name_inner = Regex('[A-Za-z0-9:\'_#]+')
    quoted_name = Regex('"[A-Za-z0-9:\'_ #]+"')
    angle_name = Regex('<[A-Za-z0-9:\'_ #]+>')
    imm_name = Regex('#[0-9]+')
    name = Choice(quoted_name, angle_name, imm_name, name_inner)
    types = Choice(Keyword('WREG_ZR'),
                   Keyword('XREG_ZR'),
                   Keyword('WREG_SP'),
                   Keyword('XREG_SP'),
                   Keyword('FPREG'),
                   Keyword('FPREG_128'),
                   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'),
github SiriDB / siridb-server / grammar / grammar.py View on Github external
k_pools, Optional(pool_columns), Optional(where_pool))
    list_series = Sequence(
        k_series,
        Optional(series_columns),
        Optional(series_match),
        Optional(where_series))
    list_servers = Sequence(
        k_servers, Optional(server_columns), Optional(where_server))
    list_shards = Sequence(
        k_shards, Optional(shard_columns), Optional(where_shard))
    list_users = Sequence(
        k_users, Optional(user_columns), Optional(where_user))

    revoke_user = Sequence(k_user, string)

    alter_stmt = Sequence(k_alter, Choice(
        alter_user,
        alter_group,
        alter_server,
        alter_servers,
        alter_database,
        most_greedy=False))

    calc_stmt = Repeat(time_expr, 1, 1)

    count_stmt = Sequence(k_count, Choice(
        count_groups,
        count_pools,
        count_series,
        count_servers,
        count_servers_received,
        count_servers_selected,