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


Python parsers.Parser类代码示例

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


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

示例1: test_exact_match

 def test_exact_match(self):
     src = u'[ abc="xyz" ]'
     parser = Parser(src)
     self.assertTrue(parser.match(tokens.START))
     sel = parser.attrib_selector()
     expected = "AttributeSelector(attr=u'abc', op=AttrExactMatchOp(), val=StringNode(string=u'xyz'))"
     self.assertEqual(expected, dump(sel))
开发者ID:colossalbit,项目名称:cssypy,代码行数:7,代码来源:test_parsers.py

示例2: test_ambiguous3_no_expr

 def test_ambiguous3_no_expr(self):
     src = u'abc:{this is silly}  '
     parser = Parser(src)
     self.assertTrue(parser.match(tokens.START))
     # should return None as indicator the parse may still be valid, even 
     # though parsing as declaration failed.
     self.assertEqual(None, parser.declaration())
开发者ID:colossalbit,项目名称:cssypy,代码行数:7,代码来源:test_parsers.py

示例3: test_noargs

 def test_noargs(self):
     src = u'[ abc ]'
     parser = Parser(src)
     self.assertTrue(parser.match(tokens.START))
     sel = parser.attrib_selector()
     expected = "AttributeSelector(attr=u'abc', op=None, val=None)"
     self.assertEqual(expected, dump(sel))
开发者ID:colossalbit,项目名称:cssypy,代码行数:7,代码来源:test_parsers.py

示例4: test_simple

 def test_simple(self):
     src = u' + '
     parser = Parser(src)
     self.assertTrue(parser.match(tokens.START))
     op = parser.math_expr_operator()
     self.assertTrue(op is not None)
     self.assertEqual("AddOp()", dump(op))
开发者ID:colossalbit,项目名称:cssypy,代码行数:7,代码来源:test_parsers.py

示例5: test_naryop

 def test_naryop(self):
     src = u'$a $b $c, $d $e $f, $g $h $i'
     parser = Parser(src)
     self.assertTrue(parser.match(tokens.START))
     expr = parser.comma_expr()
     expected = NaryOpExpr(
                     op=CommaOp(),
                     operands=[
                         NaryOpExpr(
                             op=WhitespaceOp(),
                             operands=[
                                 VarName(name=u'a'),
                                 VarName(name=u'b'),
                                 VarName(name=u'c'),
                             ]
                         ),
                         NaryOpExpr(
                             op=WhitespaceOp(),
                             operands=[
                                 VarName(name=u'd'),
                                 VarName(name=u'e'),
                                 VarName(name=u'f'),
                             ]
                         ),
                         NaryOpExpr(
                             op=WhitespaceOp(),
                             operands=[
                                 VarName(name=u'g'),
                                 VarName(name=u'h'),
                                 VarName(name=u'i'),
                             ]
                         ),
                     ]
                )
     self.assertEqual(dump(expected), dump(expr))
开发者ID:colossalbit,项目名称:cssypy,代码行数:35,代码来源:test_parsers.py

示例6: test_suffix_match

 def test_suffix_match(self):
     src = u'[ abc$=xyz ]'
     parser = Parser(src)
     self.assertTrue(parser.match(tokens.START))
     sel = parser.attrib_selector()
     expected = "AttributeSelector(attr=u'abc', op=AttrSuffixMatchOp(), val=IdentExpr(name=u'xyz'))"
     self.assertEqual(expected, dump(sel))
开发者ID:colossalbit,项目名称:cssypy,代码行数:7,代码来源:test_parsers.py

示例7: test_unnested_combine_ancestor_selector

 def test_unnested_combine_ancestor_selector(self):
     src = u'a &'
     parser = Parser(src)
     self.assertTrue(parser.match(tokens.START))
     with self.assertRaises(errors.CSSSyntaxError) as cm:
         parser.selector()
     self.assertEqual("The '&' selector is only allowed within nested ruleset scopes.", 
                      cm.exception.msg)
开发者ID:colossalbit,项目名称:cssypy,代码行数:8,代码来源:test_parsers.py

示例8: test_vardef_at_end2

 def test_vardef_at_end2(self):
     src = u'$x: 5 a {}'
     parser = Parser(src)
     self.assertTrue(parser.match(tokens.START))
     with self.assertRaises(errors.CSSSyntaxError) as cm:
         parser.toplevel_statement()
     self.assertEqual("Variable definitions must end with a semicolon.", 
                      cm.exception.msg)
开发者ID:colossalbit,项目名称:cssypy,代码行数:8,代码来源:test_parsers.py

示例9: test_fwdslash_op4

 def test_fwdslash_op4(self):
     src = u'3/$a'
     parser = Parser(src)
     self.assertTrue(parser.match(tokens.START))
     expr = parser.comma_expr()
     expected = BinaryOpExpr(
                     op=DivisionOp(),
                     lhs=NumberNode(number=u'3'),
                     rhs=VarName(name=u'a'),
                )
     self.assertEqual(dump(expected), dump(expr))
开发者ID:colossalbit,项目名称:cssypy,代码行数:11,代码来源:test_parsers.py

示例10: test_fwdslash_op1

 def test_fwdslash_op1(self):
     src = u'3/2'
     parser = Parser(src)
     self.assertTrue(parser.match(tokens.START))
     expr = parser.comma_expr()
     expected = BinaryOpExpr(
                     op=FwdSlashOp(),
                     lhs=NumberNode(number=u'3'),
                     rhs=NumberNode(number=u'2'),
                )
     self.assertEqual(dump(expected), dump(expr))
开发者ID:colossalbit,项目名称:cssypy,代码行数:11,代码来源:test_parsers.py

示例11: test_vardef_at_end1

 def test_vardef_at_end1(self):
     # Variable definition at the end of a stylesheet is legal, though 
     # useless.
     src = u'$x: 5'
     parser = Parser(src)
     self.assertTrue(parser.match(tokens.START))
     stmt = parser.toplevel_statement()
     expected = \
         VarDef(
             name=u'x',
             expr=NumberNode(number=u'5')
         )
     self.assertEqual(dump(expected), dump(stmt))
开发者ID:colossalbit,项目名称:cssypy,代码行数:13,代码来源:test_parsers.py

示例12: test_whitespaceop

 def test_whitespaceop(self):
     src = '$a $b $c'
     parser = Parser(src)
     self.assertTrue(parser.match(tokens.START))
     expr = parser.comma_expr()
     expected = NaryOpExpr(
                     op=WhitespaceOp(),
                     operands=[
                         VarName(name='a'),
                         VarName(name='b'),
                         VarName(name='c'),
                     ]
                )
     self.assertEqual(dump(expected), dump(expr))
开发者ID:colossalbit,项目名称:cssypy,代码行数:14,代码来源:test_parsers.py

示例13: test_class_selector

 def test_class_selector(self):
     src = u'.myclass'
     parser = Parser(src)
     self.assertTrue(parser.match(tokens.START))
     sel = parser.selector()
     expected = \
         Selector(
             children=[
                 SimpleSelectorSequence(
                     head=None,
                     tail=[ClassSelector(name=u'myclass')]
                 ),
             ]
         )
     self.assertEqual(dump(expected), dump(sel))
开发者ID:colossalbit,项目名称:cssypy,代码行数:15,代码来源:test_parsers.py

示例14: test_type_selector

 def test_type_selector(self):
     src = u'div'
     parser = Parser(src)
     self.assertTrue(parser.match(tokens.START))
     sel = parser.selector()
     expected = \
         Selector(
             children=[
                 SimpleSelectorSequence(
                     head=TypeSelector(name=u'div'),
                     tail=[]
                 ),
             ]
         )
     self.assertEqual(dump(expected), dump(sel))
开发者ID:colossalbit,项目名称:cssypy,代码行数:15,代码来源:test_parsers.py

示例15: test_division_op1

 def test_division_op1(self):
     src = u'3/2/1'
     parser = Parser(src)
     self.assertTrue(parser.match(tokens.START))
     expr = parser.comma_expr()
     expected = BinaryOpExpr(
                     op=DivisionOp(),
                     lhs=BinaryOpExpr(
                         op=DivisionOp(),
                         lhs=NumberNode(number=u'3'),
                         rhs=NumberNode(number=u'2'),
                     ),
                     rhs=NumberNode(number=u'1'),
                )
     self.assertEqual(dump(expected), dump(expr))
开发者ID:colossalbit,项目名称:cssypy,代码行数:15,代码来源:test_parsers.py


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