當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。