当前位置: 首页>>代码示例>>Python>>正文


Python pyparsing.srange函数代码示例

本文整理汇总了Python中pyparsing.srange函数的典型用法代码示例。如果您正苦于以下问题:Python srange函数的具体用法?Python srange怎么用?Python srange使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了srange函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: build_index_parser

def build_index_parser():
    left = pp.Literal('(').suppress()
    right = pp.Literal(')').suppress()
    unique = pp.Optional(pp.CaselessKeyword('unique')).setResultsName('unique')
    index = pp.CaselessKeyword('index').suppress()
    attribute_name = pp.Word(pp.srange('[a-z]'), pp.srange('[a-z0-9_]'))
    return unique + index + left + pp.delimitedList(attribute_name).setResultsName('attr_list') + right
开发者ID:datajoint,项目名称:datajoint-python,代码行数:7,代码来源:declare.py

示例2: build_attribute_parser

def build_attribute_parser():
    quoted = pp.Or(pp.QuotedString('"'), pp.QuotedString("'"))
    colon = pp.Literal(':').suppress()
    attribute_name = pp.Word(pp.srange('[a-z]'), pp.srange('[a-z0-9_]')).setResultsName('name')
    data_type = pp.Combine(pp.Word(pp.alphas) + pp.SkipTo("#", ignore=quoted)).setResultsName('type')
    default = pp.Literal('=').suppress() + pp.SkipTo(colon, ignore=quoted).setResultsName('default')
    comment = pp.Literal('#').suppress() + pp.restOfLine.setResultsName('comment')
    return attribute_name + pp.Optional(default) + colon + data_type + comment
开发者ID:fabiansinz,项目名称:datajoint-python,代码行数:8,代码来源:declare.py

示例3: __init__

 def __init__(self, logger):
   self.salt_client = salt.client.LocalClient()
   self.etcd = Etcd(logger)
   self.logger = logger
   # Parse out the username and formation name 
   # from the ETCD directory string
   self.formation_parser = Literal('/formations/') + \
     Word(srange("[0-9a-zA-Z_-]")).setResultsName('username') + Literal('/') + \
     Word(srange("[0-9a-zA-Z_-]")).setResultsName('formation_name')
开发者ID:Mondego,项目名称:pyreco,代码行数:9,代码来源:allPythonContent.py

示例4: handleMacro

def handleMacro(toks):
    macroChar = toks[0][1]
    if macroChar == "d":
        return CharSetRandomizer(srange("[0-9]"))
    elif macroChar == "w":
        return CharSetRandomizer(srange("[A-Za-z0-9_]"))
    elif macroChar == "s":
        return CharSetRandomizer(" ")
    else:
        raise ParseFatalException("", 0, "unsupported macro character (" + macroChar + ")")
开发者ID:michalwiacek,项目名称:simplegenerator,代码行数:10,代码来源:regenerator.py

示例5: grammer

def grammer():
    lparen = pp.Suppress("(")
    rparen = pp.Suppress(")")
    equal = pp.Suppress("=")
    nl = pp.Suppress(pp.LineEnd())
    reg = pp.Combine("$" + pp.Optional("cr") + pp.Word(pp.srange("[0-7]"),
                                                       max=1))
    num = pp.Word(pp.srange("[0-9]")).setParseAction(
        lambda s, l, t: int(t[0]))
    val = pp.Word(pp.srange("[0-9a-fA-F]")).setParseAction(
        lambda s, l, t: int(t[0], 16))
    values = pp.Dict(pp.OneOrMore(pp.Group(reg + equal + val)))
    return num + lparen + values + rparen + nl
开发者ID:turbana,项目名称:cpu,代码行数:13,代码来源:simtest.py

示例6: build_foreign_key_parser

def build_foreign_key_parser():
    left = pp.Literal('(').suppress()
    right = pp.Literal(')').suppress()
    attribute_name = pp.Word(pp.srange('[a-z]'), pp.srange('[a-z0-9_]'))
    new_attrs = pp.Optional(left + pp.delimitedList(attribute_name) + right).setResultsName('new_attrs')
    arrow = pp.Literal('->').suppress()
    lbracket = pp.Literal('[').suppress()
    rbracket = pp.Literal(']').suppress()
    option = pp.Word(pp.srange('[a-zA-Z]'))
    options = pp.Optional(lbracket + pp.delimitedList(option) + rbracket)
    ref_table = pp.Word(pp.alphas, pp.alphanums + '._').setResultsName('ref_table')
    ref_attrs = pp.Optional(left + pp.delimitedList(attribute_name) + right).setResultsName('ref_attrs')
    return new_attrs + arrow + options + ref_table + ref_attrs
开发者ID:fabiansinz,项目名称:datajoint-python,代码行数:13,代码来源:declare.py

示例7: build_foreign_key_parser_old

def build_foreign_key_parser_old():
    # old-style foreign key parser. Superceded by expression-based syntax. See issue #436
    # This will be deprecated in a future release.
    left = pp.Literal('(').suppress()
    right = pp.Literal(')').suppress()
    attribute_name = pp.Word(pp.srange('[a-z]'), pp.srange('[a-z0-9_]'))
    new_attrs = pp.Optional(left + pp.delimitedList(attribute_name) + right).setResultsName('new_attrs')
    arrow = pp.Literal('->').suppress()
    lbracket = pp.Literal('[').suppress()
    rbracket = pp.Literal(']').suppress()
    option = pp.Word(pp.srange('[a-zA-Z]'))
    options = pp.Optional(lbracket + pp.delimitedList(option) + rbracket).setResultsName('options')
    ref_table = pp.Word(pp.alphas, pp.alphanums + '._').setResultsName('ref_table')
    ref_attrs = pp.Optional(left + pp.delimitedList(attribute_name) + right).setResultsName('ref_attrs')
    return new_attrs + arrow + options + ref_table + ref_attrs
开发者ID:datajoint,项目名称:datajoint-python,代码行数:15,代码来源:declare.py

示例8: _construct_grammar

def _construct_grammar():
    logical_operator = get_logical_operator()
    logical_expression = get_logical_expression()

    facets_expression = get_facet_expression()
    highlight_expression = get_highlight_expression()
    sort_expression = get_sort_expression()
    aggs_expression = get_aggregations_expression()
    nested_expression = get_nested_expression()

    # The below line describes how the type expression should be.
    type_expression = Word('type')\
        + Word(':').suppress()\
        + Word(srange("[a-zA-Z0-9_]"))\
        + Optional(CaselessLiteral('AND')).suppress()
    type_expression.setParseAction(parse_type_expression)

    base_expression = Optional(highlight_expression)\
        + Optional(sort_expression)\
        + Optional(type_expression)\
        + ZeroOrMore(
            (facets_expression
             | aggs_expression
             | nested_expression
             | logical_expression)
            + Optional(logical_operator)
        ).setParseAction(parse_one_or_more_logical_expressions)
    base_expression.setParseAction(parse_type_logical_facets_expression)

    return base_expression
开发者ID:Aplopio,项目名称:plasticparser,代码行数:30,代码来源:tokenizer.py

示例9: parse_commanders

def parse_commanders(x):
    # Grammar
    LBRAK, RBRAK, COMMA = (pp.Literal(x).suppress() for x in "[],")
    AND = pp.Literal("and").suppress()
    and_ = pp.Optional(COMMA) + AND
    RANK = pp.Or(pp.Literal(x) for x in RANKS_LOOKUP.keys())("rank")
    NAME = pp.Word(pp.srange("[A-Z]"), pp.alphas + pp.alphas8bit, min=2)
    ABBR = pp.Regex(r"([A-Z]\.)+")
    SUFFIX = pp.Literal("Jr.")
    NOCMDR = (pp.Literal("None"))("none")
    COMBATANT = pp.oneOf(' '.join(('US', 'CS', 'I')))("combatant")
    
    nametoken = ABBR | pp.quotedString | NAME
    name = (pp.OneOrMore(nametoken) + pp.Optional(pp.Literal(",") + SUFFIX))("fullname")
    name.addParseAction(lambda s,l,t: ' '.join(t))
    
    cmdrname = RANK + name 
    commander = pp.Group(cmdrname | NOCMDR)
    commander_list = pp.Group(pp.delimitedList(commander, ",") +
                              pp.Optional(and_ + commander))("commanders")
    milforce = pp.Group(commander_list + LBRAK + COMBATANT + RBRAK)
    grammar = pp.delimitedList(milforce, ";")
    toks = grammar.parseString(x)

    # A smarter grammar could probably have avoided this
    res = {}
    for _force in toks:
        k = _force['combatant']
        res[k] = [x.asDict() for x in _force['commanders']
                  if "none" not in x.asDict()]
    return res
开发者ID:alanjordan101,项目名称:acw_battle_data,代码行数:31,代码来源:cwsac2.py

示例10: build_foreign_key_parser

def build_foreign_key_parser():
    arrow = pp.Literal('->').suppress()
    lbracket = pp.Literal('[').suppress()
    rbracket = pp.Literal(']').suppress()
    option = pp.Word(pp.srange('[a-zA-Z]'))
    options = pp.Optional(lbracket + pp.delimitedList(option) + rbracket).setResultsName('options')
    ref_table = pp.restOfLine.setResultsName('ref_table')
    return arrow + options + ref_table
开发者ID:datajoint,项目名称:datajoint-python,代码行数:8,代码来源:declare.py

示例11: Syntax

def Syntax():
    op = oneOf( '+ - / *')
    lpar  = Literal('(') .suppress()
    rpar  = Literal( ')' ).suppress()
    num = Word(srange('[1-9]'),nums)
    expr = Forward()
    atom = num | Group( lpar + expr + rpar )
    expr << atom + ZeroOrMore( op + expr )
    return expr
开发者ID:russjohnson09,项目名称:sentential-logic,代码行数:9,代码来源:simple-recursive-decent.py

示例12: get_highlight_expression

def get_highlight_expression():
    field_expression = Word(srange("[a-zA-Z0-9_.*]"))
    field_expression.setParseAction(parse_highlight_field_expression)
    fields_expression = OneOrMore(
        field_expression + Optional(',').suppress())
    fields_expression.setParseAction(parse_highlight_expression)
    highlight_expression = Word('highlight:').suppress() \
        + Word('[').suppress() \
        + fields_expression + Word(']').suppress()
    return highlight_expression
开发者ID:Aplopio,项目名称:plasticparser,代码行数:10,代码来源:tokenizer.py

示例13: handle_macro

def handle_macro(toks):
    macroChar = toks[0][1]
    if macroChar == "d":
        return CharacterRangeEmitter("0123456789")
    elif macroChar == "w":
        return CharacterRangeEmitter(srange("[A-Za-z0-9_]"))
    elif macroChar == "s":
        return LiteralEmitter(" ")
    else:
        raise ParseFatalException("", 0, "unsupported macro character (" + macroChar + ")")
开发者ID:Bernie,项目名称:spyne,代码行数:10,代码来源:invregexp.py

示例14: _query

    def _query(self):
        ## Utility
        ident = pp.Word(pp.srange("[a-zA-Z0-9_.+-]"))

        ## Terms
        ident_term = pp.Word(pp.srange("[a-zA-Z0-9_.+-]")).setParseAction(
                make_IdentTerm)
        quoted_term = ('"' + pp.OneOrMore(ident) + '"').setParseAction(
                make_QuotedTerm)
        not_term = ('-' + (ident_term | quoted_term)).setParseAction(
                make_NotTerm)
        disj_term = pp.Forward()
        disj_term = (ident + pp.OneOrMore(pp.CaselessKeyword('or') + (disj_term | ident))).setParseAction(make_DisjTerm)
        term = quoted_term | disj_term | not_term | ident_term

        ## Selector base
        basic_selector = pp.Forward()
        selector_start = ident + ':'

        ## Selector bodies only
        selector_body = pp.Forward()
        list_selector_body = '[' + pp.delimitedList(selector_body, ',') + ']'
        source_selector_body = ident + pp.Optional('/' + ident)
        generic_selector_body = ident
        selector_body << (
                  list_selector_body
                | source_selector_body
                | generic_selector_body)

        ## Full selectors
        list_selector =  selector_start + list_selector_body
        source_selector = pp.CaselessKeyword('source') + ':' + source_selector_body
        generic_selector = selector_start + generic_selector_body
        basic_selector << (
                   list_selector.setParseAction(make_ListSelector) \
                 | source_selector.setParseAction(make_source) \
                 | generic_selector.setParseAction(make_GenericSelector))
        not_selector = ('!' + basic_selector).setParseAction(make_NotSelector)
        selector = not_selector | basic_selector
        query = pp.ZeroOrMore(selector | term).setParseAction(
                make_Query)
        return query.parseString(self.query)
开发者ID:wyattsam,项目名称:mongo-search,代码行数:42,代码来源:query.py

示例15: check_if_function

def check_if_function(code):
    return_type = Word(alphanums + '_[]') # Bad style to have "_" but syntactically valid
    function_name = Word(alphanums + '_:')
    args = Word(alphanums + ',_[]&* ')
    function_open = Literal("{")
    function_close = Literal("}")
    function_declaration = Optional(srange("[a-z]")) + return_type + function_name + "(" + Optional(args) + ")"
    grammar = function_declaration + Optional(function_open)
    if len(grammar.searchString(code)):
        return True
    return False
开发者ID:maxim123,项目名称:183_style_grader,代码行数:11,代码来源:style_grader_functions.py


注:本文中的pyparsing.srange函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。