本文整理汇总了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))
示例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())
示例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))
示例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))
示例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))
示例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))
示例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)
示例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)
示例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))
示例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))
示例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))
示例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))
示例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))
示例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))
示例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))