本文整理汇总了Python中ListOps.src.parser.Parser.parse方法的典型用法代码示例。如果您正苦于以下问题:Python Parser.parse方法的具体用法?Python Parser.parse怎么用?Python Parser.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ListOps.src.parser.Parser
的用法示例。
在下文中一共展示了Parser.parse方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_parse_combined_statements
# 需要导入模块: from ListOps.src.parser import Parser [as 别名]
# 或者: from ListOps.src.parser.Parser import parse [as 别名]
def test_parse_combined_statements(self):
value = """
var a = {1,2,3,4}
a.print()
a=a.map(b->b*2)
a.print()
for (r in a : r>4){r.print()}
var b = a.filter(b->b>6)
var d = b.length()
if (d <= 1)
{
b.print()
a.print()
}
else
{
d.print()
}
"""
scanner = Scanner(value)
parser = Parser(scanner)
program = parser.parse()
self.assertEqual(len(program.statements), 8)
program.run()
output = self.out.getvalue().strip()
assert output == '[1, 2, 3, 4]\n[2, 4, 6, 8]\n6\n8\n[8]\n[2, 4, 6, 8]'
示例2: test_parse_combined_statements
# 需要导入模块: from ListOps.src.parser import Parser [as 别名]
# 或者: from ListOps.src.parser.Parser import parse [as 别名]
def test_parse_combined_statements(self):
value = """if(a>4){a=12}else{a=15}
for (a in b : a>4){a=a+1}
a=2+2
var a=2+2
"""
scanner = Scanner(value)
parser = Parser(scanner)
statements = parser.parse()
self.assertEqual(len(statements.statements), 4)
示例3: test_complex_calculation
# 需要导入模块: from ListOps.src.parser import Parser [as 别名]
# 或者: from ListOps.src.parser.Parser import parse [as 别名]
def test_complex_calculation(self):
value = """
var a = 8
var b = 5
var c = 1
c = (a+b)*((3+13)/2)
c.print()
"""
scanner = Scanner(value)
parser = Parser(scanner)
program = parser.parse()
program.run()
output = self.out.getvalue().strip()
assert output == '104.0'
示例4: test_types
# 需要导入模块: from ListOps.src.parser import Parser [as 别名]
# 或者: from ListOps.src.parser.Parser import parse [as 别名]
def test_types(self):
value = """
var b = 5
var e = b.filter(b->b>4)
var c = b.map(a->a+5)
var d = b.length()
c.print()
d.print()
e.print()
"""
scanner = Scanner(value)
parser = Parser(scanner)
program = parser.parse()
program.run()
output = self.out.getvalue().strip()
assert output == '10\n1\n5'
示例5: test_parse_combined_more_statements
# 需要导入模块: from ListOps.src.parser import Parser [as 别名]
# 或者: from ListOps.src.parser.Parser import parse [as 别名]
def test_parse_combined_more_statements(self):
value = """
var a = {1,2,3,4}
a=a.map(b->b*2).print()
var b = a[1:8]
b.print()
def x(y)
{
y = y*2
return y
}
a = x(5)
a.print()
"""
scanner = Scanner(value)
parser = Parser(scanner)
program = parser.parse()
program.run()
output = self.out.getvalue().strip()
assert output == '[2, 4, 6, 8]\n[4, 6, 8]\n10'
示例6: test_complex_logic
# 需要导入模块: from ListOps.src.parser import Parser [as 别名]
# 或者: from ListOps.src.parser.Parser import parse [as 别名]
def test_complex_logic(self):
value = """
var a = 8
var b = 5
var c = 1
if (a>b && (a!=b || c <= b) && (!(a<b)))
{
c.print()
}
else
{
b.print()
}
"""
scanner = Scanner(value)
parser = Parser(scanner)
program = parser.parse()
program.run()
output = self.out.getvalue().strip()
assert output == '1'
示例7: test_func
# 需要导入模块: from ListOps.src.parser import Parser [as 别名]
# 或者: from ListOps.src.parser.Parser import parse [as 别名]
def test_func(self):
value = """
var a = {1,2,3,4}
def medium(a)
{
var sum = 0
for (x in a)
{
sum = sum + x
}
var len
len = a.length()
sum = sum / len
return sum
}
var med = medium(a)
med.print()
"""
scanner = Scanner(value)
parser = Parser(scanner)
program = parser.parse()
program.run()
output = self.out.getvalue().strip()
assert output == '2.5'
示例8: test_parse
# 需要导入模块: from ListOps.src.parser import Parser [as 别名]
# 或者: from ListOps.src.parser.Parser import parse [as 别名]
def test_parse(self):
value = "if(a>4){a=12}else{a=15}"
scanner = Scanner(value)
parser = Parser(scanner)
statements = parser.parse()
self.assertEqual(len(statements.statements), 1)