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


Python Forward.setName方法代码示例

本文整理汇总了Python中pyparsing.Forward.setName方法的典型用法代码示例。如果您正苦于以下问题:Python Forward.setName方法的具体用法?Python Forward.setName怎么用?Python Forward.setName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyparsing.Forward的用法示例。


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

示例1: Word

# 需要导入模块: from pyparsing import Forward [as 别名]
# 或者: from pyparsing.Forward import setName [as 别名]
O = Optional
S = Suppress

number = Word(nums)
point = Literal('.')
e = CaselessLiteral('E')
plusorminus = Literal('+') | Literal('-')
integer = Combine(O(plusorminus) + number)
floatnumber = Combine(integer + (point + O(number)) ^ (e + integer))
integer.setParseAction(lambda tokens: SimpleRValue(int(tokens[0])))
floatnumber.setParseAction(lambda tokens: SimpleRValue(float(tokens[0])))
pi = Keyword('pi').setParseAction(lambda tokens: SimpleRValue(math.pi, 'pi')) #@UnusedVariable
isnumber = lambda x: isinstance(x, Number)

rvalue = Forward()
rvalue.setName('rvalue')
contract_expression = Forward()
contract_expression.setName('contract')
simple_contract = Forward()
simple_contract.setName('simple_contract')

# Import all expressions -- they will call add_contract()
from .library import (EqualTo, Unary, Binary, composite_contract,
                      identifier_contract, misc_variables_contract,
                      int_variables_contract, int_variables_ref,
                      misc_variables_ref, SimpleRValue)


number = pi | floatnumber | integer
operand = number | int_variables_ref | misc_variables_ref
operand.setName('r-value')
开发者ID:Xion,项目名称:contracts,代码行数:33,代码来源:syntax.py

示例2: Suppress

# 需要导入模块: from pyparsing import Forward [as 别名]
# 或者: from pyparsing.Forward import setName [as 别名]
not_ = Suppress(Literal('!')) + filter_
not_.setParseAction(lambda s, l, t: pureldap.LDAPFilter_not(t[0]))
not_.setName('not')
filterlist = OneOrMore(filter_)
or_ = Suppress(Literal('|')) + filterlist
or_.setParseAction(lambda s, l, t: pureldap.LDAPFilter_or(t))
or_.setName('or')
and_ = Suppress(Literal('&')) + filterlist
and_.setParseAction(lambda s, l, t: pureldap.LDAPFilter_and(t))
and_.setName('and')
filtercomp = and_ | or_ | not_ | item
filtercomp.setName('filtercomp')
filter_ << (Suppress(Literal('(').leaveWhitespace())
            + filtercomp
            + Suppress(Literal(')').leaveWhitespace()))
filter_.setName('filter')
filtercomp.leaveWhitespace()
filter_.leaveWhitespace()

toplevel = (StringStart().leaveWhitespace()
            + filter_
            + StringEnd().leaveWhitespace())
toplevel.leaveWhitespace()
toplevel.setName('toplevel')


def parseFilter(s):
    try:
        x = toplevel.parseString(s)
    except ParseException as e:
        raise InvalidLDAPFilter(e.msg,
开发者ID:cwaldbieser,项目名称:ldaptor,代码行数:33,代码来源:ldapfilter.py

示例3: Group

# 需要导入模块: from pyparsing import Forward [as 别名]
# 或者: from pyparsing.Forward import setName [as 别名]
)

join = ((CROSSJOIN | FULLJOIN | FULLOUTERJOIN | INNERJOIN | JOIN | LEFTJOIN | LEFTOUTERJOIN | RIGHTJOIN | RIGHTOUTERJOIN)("op") + Group(tableName)("join") + Optional(ON + expr("on"))).addParseAction(to_join_call)

sortColumn = expr("value").setName("sort1").setDebugActions(*debug) + Optional(DESC("sort") | ASC("sort")) | \
             expr("value").setName("sort2").setDebugActions(*debug)

# define SQL tokens
selectStmt << Group(
    Group(Group(
        delimitedList(
            Group(
                SELECT.suppress().setDebugActions(*debug) + delimitedList(selectColumn)("select") +
                Optional(
                    FROM.suppress().setDebugActions(*debug) + (delimitedList(Group(tableName)) + ZeroOrMore(join))("from") +
                    Optional(WHERE.suppress().setDebugActions(*debug) + expr.setName("where"))("where") +
                    Optional(GROUPBY.suppress().setDebugActions(*debug) + delimitedList(Group(selectColumn))("groupby").setName("groupby")) +
                    Optional(HAVING.suppress().setDebugActions(*debug) + expr("having").setName("having")) +
                    Optional(LIMIT.suppress().setDebugActions(*debug) + expr("limit")) +
                    Optional(OFFSET.suppress().setDebugActions(*debug) + expr("offset"))
                )
            ),
            delim=(UNION | UNIONALL)
        )
    )("union"))("from") +
    Optional(ORDERBY.suppress().setDebugActions(*debug) + delimitedList(Group(sortColumn))("orderby").setName("orderby")) +
    Optional(LIMIT.suppress().setDebugActions(*debug) + expr("limit")) +
    Optional(OFFSET.suppress().setDebugActions(*debug) + expr("offset"))
).addParseAction(to_union_call)

开发者ID:klahnakoski,项目名称:pyLibrary,代码行数:31,代码来源:sql_parser.py

示例4: Keyword

# 需要导入模块: from pyparsing import Forward [as 别名]
# 或者: from pyparsing.Forward import setName [as 别名]
# VarOrIRIref:
VarOrIRIref = Var | IRIref
if DEBUG:
    VarOrIRIref.setName('VarOrIRIref')

# Verb:
Verb = (VarOrIRIref | Keyword('a').setParseAction(
  refer_component(getattr, [rdflib.namespace.RDF, 'type'], [0, 1])))
if DEBUG:
    Verb.setName('Verb')


# Expression:
Expression = Forward()
if DEBUG:
    Expression.setName('Expression')

# BuiltInCall:
STR = Suppress(CaselessKeyword('STR'))
LANG = Suppress(CaselessKeyword('LANG'))
LANGMATCHES = Suppress(CaselessKeyword('LANGMATCHES'))
DATATYPE = Suppress(CaselessKeyword('DATATYPE'))
BOUND = Suppress(CaselessKeyword('BOUND'))
isIRI = Suppress(CaselessKeyword('isIRI'))
isURI = Suppress(CaselessKeyword('isURI'))
isBLANK = Suppress(CaselessKeyword('isBLANK'))
isLITERAL = Suppress(CaselessKeyword('isLITERAL'))
sameTerm = Suppress(CaselessKeyword('sameTERM'))

# RegexExpression
REGEX = Suppress(CaselessKeyword('REGEX'))
开发者ID:gjhiggins,项目名称:django-rdflib,代码行数:33,代码来源:parser.py

示例5: K

# 需要导入模块: from pyparsing import Forward [as 别名]
# 或者: from pyparsing.Forward import setName [as 别名]
m_not = K('not')
m_not.setName('NOT')

test('m_and', 'and')
test('m_or', 'or')

m_logical_operator = m_and ^ m_or

test('m_logical_operator', '''
and
or
''')


m_expression = Forward()
m_expression.setName('EXPR')
m_infix_operator = m_logical_operator
m_prefix_operator = m_not
m_subexpression = nestedExpr(content=m_expression)

m_term = m_literal ^ m_identifier ^ m_subexpression

m_infix_expression = (
    (m_term + m_infix_operator + m_expression)
    #^
    #(m_expression + m_infix_operator + m_term)
    ^
    (m_term + m_infix_operator + m_term)
)

m_prefix_expression = m_prefix_operator + m_expression
开发者ID:sjbrown,项目名称:misc_work,代码行数:33,代码来源:boolean.py

示例6: parser

# 需要导入模块: from pyparsing import Forward [as 别名]
# 或者: from pyparsing.Forward import setName [as 别名]
    def parser(self):
        """
        Sed Parser Generator
        """
        # Forward declaration of the pattern and replacemnt text as the delimter
        # can be any character and will we not know it's value until parse time
        # https://pythonhosted.org/pyparsing/pyparsing.Forward-class.html
        text = Forward()

        def define_text(token):
            """
            Closes round the scope of the text Forward and defines the
            pattern and replacement tokens after the delimter is known

            https://pythonhosted.org/pyparsing/pyparsing.ParserElement-class.html#setParseAction
            """
            text << Word(printables + ' \t', excludeChars=token[0])

        flags = oneOf('g p i d').setName('flags')('flags')

        delimiter = Word(printables, exact=1).setName('delimiter')('delimiter')
        delimiter.setParseAction(define_text)

        step = Regex('~[0-9]+').setName('step')('step')

        num_address = (Word(nums + '$') + Optional(step)).setName('num_address')('num_address')

        regex_address = reduce(operator.add, [
            Suppress(Literal('/')),
            Word(printables, excludeChars='/').setName('regex')('regex*'),
            Suppress(Literal('/'))
        ])

        address = reduce(operator.add, [
            (num_address ^ regex_address).setName('address1')('address1'),
            Optional(Suppress(Literal(',')) + (num_address ^ regex_address).setName('address2')('address2')),
        ])

        address.setParseAction(self.check_condition)

        subsitution = reduce(operator.add, [
            Literal('s').setName('sflag')('sflag'),
            delimiter,
            Optional(text, '').setName('pattern')('pattern'),
            delimiter,
            Optional(text, '').setName('replacement')('replacement'),
            delimiter,
            ZeroOrMore(flags).setName('flags')('flags')
        ]).leaveWhitespace()('subsitution')

        subsitution.setParseAction(self.compileRegex)

        translate = reduce(operator.add, [
            Literal('y').setName('translate')('translate'),
            delimiter,
            text.setName('pattern')('pattern'),
            delimiter,
            text.setName('replacement')('replacement'),
            delimiter,
        ]).leaveWhitespace()('translateF')

        translate.setParseAction(self.translateF)

        actions = (subsitution | translate)
        return Optional(address) + actions
开发者ID:iiSeymour,项目名称:sedpy,代码行数:67,代码来源:sed.py

示例7: Forward

# 需要导入模块: from pyparsing import Forward [as 别名]
# 或者: from pyparsing.Forward import setName [as 别名]
from .interface import TypsyType
from contracts import ContractsMeta, contract
from contracts.backported import getfullargspec
from contracts.interface import describe_type
from contracts.main import get_all_arg_names
from contracts.pyparsing_utils import myOperatorPrecedence
from contracts.utils import indent
from pyparsing import Forward, ParserElement, opAssoc, Suppress, Literal
from typsy.pyparsing_add import MyOr, wrap_parse_action
import traceback

ParserElement.enablePackrat()
# ParserElement.verbose_stacktrace = True

sts_type = Forward()
sts_type.setName('sts_type')
sts_type_final = None

simple_sts_type = Forward()

def get_sts_type():
    global sts_type_final
    if sts_type_final is not None:
        # print('reusing')
        return sts_type_final
    else:
        simple_exprs = []
        complex_exprs = []
        operators = []
        
        S = Suppress
开发者ID:AndreaCensi,项目名称:typsy,代码行数:33,代码来源:has_comps.py

示例8: Keyword

# 需要导入模块: from pyparsing import Forward [as 别名]
# 或者: from pyparsing.Forward import setName [as 别名]
# VarOrIRIref:
VarOrIRIref = Var | IRIref
if DEBUG:
    VarOrIRIref.setName("VarOrIRIref")

# Verb:
Verb = VarOrIRIref | Keyword("a").setParseAction(refer_component(getattr, [rdflib.namespace.RDF, "type"], [0, 1]))
if DEBUG:
    Verb.setName("Verb")


# Expression:
Expression = Forward()
if DEBUG:
    Expression.setName("Expression")

# BuiltInCall:
STR = Suppress(CaselessKeyword("STR"))
LANG = Suppress(CaselessKeyword("LANG"))
LANGMATCHES = Suppress(CaselessKeyword("LANGMATCHES"))
DATATYPE = Suppress(CaselessKeyword("DATATYPE"))
BOUND = Suppress(CaselessKeyword("BOUND"))
isIRI = Suppress(CaselessKeyword("isIRI"))
isURI = Suppress(CaselessKeyword("isURI"))
isBLANK = Suppress(CaselessKeyword("isBLANK"))
isLITERAL = Suppress(CaselessKeyword("isLITERAL"))
sameTerm = Suppress(CaselessKeyword("sameTERM"))

# RegexExpression
REGEX = Suppress(CaselessKeyword("REGEX"))
开发者ID:jbofill,项目名称:rdflib,代码行数:32,代码来源:parser.py


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