本文整理匯總了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)