delorean_lang 0.1.02 → 0.1.03
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/delorean/base.rb +1 -3
- data/lib/delorean/delorean.rb +439 -128
- data/lib/delorean/delorean.treetop +14 -1
- data/lib/delorean/nodes.rb +14 -2
- data/lib/delorean/version.rb +1 -1
- data/spec/eval_spec.rb +31 -0
- metadata +2 -2
data/lib/delorean/base.rb
CHANGED
@@ -114,10 +114,8 @@ module Delorean
|
|
114
114
|
|
115
115
|
def self._node_call(node, mname, _e, params)
|
116
116
|
context = _e[:_engine]
|
117
|
-
node ||= self
|
118
|
-
|
119
117
|
engine = mname ? context.get_import_engine(mname) : context
|
120
|
-
NodeCall.new(engine, node, params)
|
118
|
+
NodeCall.new(engine, node || self, params)
|
121
119
|
end
|
122
120
|
|
123
121
|
######################################################################
|
data/lib/delorean/delorean.rb
CHANGED
@@ -1448,6 +1448,279 @@ module Delorean
|
|
1448
1448
|
r0
|
1449
1449
|
end
|
1450
1450
|
|
1451
|
+
module SetExpr0
|
1452
|
+
def sp
|
1453
|
+
elements[1]
|
1454
|
+
end
|
1455
|
+
|
1456
|
+
def e3
|
1457
|
+
elements[2]
|
1458
|
+
end
|
1459
|
+
|
1460
|
+
end
|
1461
|
+
|
1462
|
+
module SetExpr1
|
1463
|
+
def e2
|
1464
|
+
elements[2]
|
1465
|
+
end
|
1466
|
+
|
1467
|
+
def sp1
|
1468
|
+
elements[3]
|
1469
|
+
end
|
1470
|
+
|
1471
|
+
def sp2
|
1472
|
+
elements[5]
|
1473
|
+
end
|
1474
|
+
|
1475
|
+
def i
|
1476
|
+
elements[6]
|
1477
|
+
end
|
1478
|
+
|
1479
|
+
def sp3
|
1480
|
+
elements[7]
|
1481
|
+
end
|
1482
|
+
|
1483
|
+
def sp4
|
1484
|
+
elements[9]
|
1485
|
+
end
|
1486
|
+
|
1487
|
+
def e1
|
1488
|
+
elements[10]
|
1489
|
+
end
|
1490
|
+
|
1491
|
+
def ifexp
|
1492
|
+
elements[12]
|
1493
|
+
end
|
1494
|
+
|
1495
|
+
end
|
1496
|
+
|
1497
|
+
module SetExpr2
|
1498
|
+
def args
|
1499
|
+
elements[2]
|
1500
|
+
end
|
1501
|
+
|
1502
|
+
end
|
1503
|
+
|
1504
|
+
def _nt_set_expr
|
1505
|
+
start_index = index
|
1506
|
+
if node_cache[:set_expr].has_key?(index)
|
1507
|
+
cached = node_cache[:set_expr][index]
|
1508
|
+
if cached
|
1509
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
1510
|
+
@index = cached.interval.end
|
1511
|
+
end
|
1512
|
+
return cached
|
1513
|
+
end
|
1514
|
+
|
1515
|
+
i0 = index
|
1516
|
+
if has_terminal?('{-}', false, index)
|
1517
|
+
r1 = instantiate_node(SetExpr,input, index...(index + 3))
|
1518
|
+
@index += 3
|
1519
|
+
else
|
1520
|
+
terminal_parse_failure('{-}')
|
1521
|
+
r1 = nil
|
1522
|
+
end
|
1523
|
+
if r1
|
1524
|
+
r0 = r1
|
1525
|
+
else
|
1526
|
+
i2, s2 = index, []
|
1527
|
+
if has_terminal?('{', false, index)
|
1528
|
+
r3 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
1529
|
+
@index += 1
|
1530
|
+
else
|
1531
|
+
terminal_parse_failure('{')
|
1532
|
+
r3 = nil
|
1533
|
+
end
|
1534
|
+
s2 << r3
|
1535
|
+
if r3
|
1536
|
+
r5 = _nt_sp
|
1537
|
+
if r5
|
1538
|
+
r4 = r5
|
1539
|
+
else
|
1540
|
+
r4 = instantiate_node(SyntaxNode,input, index...index)
|
1541
|
+
end
|
1542
|
+
s2 << r4
|
1543
|
+
if r4
|
1544
|
+
r6 = _nt_expression
|
1545
|
+
s2 << r6
|
1546
|
+
if r6
|
1547
|
+
r7 = _nt_sp
|
1548
|
+
s2 << r7
|
1549
|
+
if r7
|
1550
|
+
if has_terminal?('for', false, index)
|
1551
|
+
r8 = instantiate_node(SyntaxNode,input, index...(index + 3))
|
1552
|
+
@index += 3
|
1553
|
+
else
|
1554
|
+
terminal_parse_failure('for')
|
1555
|
+
r8 = nil
|
1556
|
+
end
|
1557
|
+
s2 << r8
|
1558
|
+
if r8
|
1559
|
+
r9 = _nt_sp
|
1560
|
+
s2 << r9
|
1561
|
+
if r9
|
1562
|
+
r10 = _nt_identifier
|
1563
|
+
s2 << r10
|
1564
|
+
if r10
|
1565
|
+
r11 = _nt_sp
|
1566
|
+
s2 << r11
|
1567
|
+
if r11
|
1568
|
+
if has_terminal?('in', false, index)
|
1569
|
+
r12 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
1570
|
+
@index += 2
|
1571
|
+
else
|
1572
|
+
terminal_parse_failure('in')
|
1573
|
+
r12 = nil
|
1574
|
+
end
|
1575
|
+
s2 << r12
|
1576
|
+
if r12
|
1577
|
+
r13 = _nt_sp
|
1578
|
+
s2 << r13
|
1579
|
+
if r13
|
1580
|
+
r14 = _nt_expression
|
1581
|
+
s2 << r14
|
1582
|
+
if r14
|
1583
|
+
r16 = _nt_sp
|
1584
|
+
if r16
|
1585
|
+
r15 = r16
|
1586
|
+
else
|
1587
|
+
r15 = instantiate_node(SyntaxNode,input, index...index)
|
1588
|
+
end
|
1589
|
+
s2 << r15
|
1590
|
+
if r15
|
1591
|
+
i18, s18 = index, []
|
1592
|
+
if has_terminal?('if', false, index)
|
1593
|
+
r19 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
1594
|
+
@index += 2
|
1595
|
+
else
|
1596
|
+
terminal_parse_failure('if')
|
1597
|
+
r19 = nil
|
1598
|
+
end
|
1599
|
+
s18 << r19
|
1600
|
+
if r19
|
1601
|
+
r20 = _nt_sp
|
1602
|
+
s18 << r20
|
1603
|
+
if r20
|
1604
|
+
r21 = _nt_expression
|
1605
|
+
s18 << r21
|
1606
|
+
if r21
|
1607
|
+
r23 = _nt_sp
|
1608
|
+
if r23
|
1609
|
+
r22 = r23
|
1610
|
+
else
|
1611
|
+
r22 = instantiate_node(SyntaxNode,input, index...index)
|
1612
|
+
end
|
1613
|
+
s18 << r22
|
1614
|
+
end
|
1615
|
+
end
|
1616
|
+
end
|
1617
|
+
if s18.last
|
1618
|
+
r18 = instantiate_node(SyntaxNode,input, i18...index, s18)
|
1619
|
+
r18.extend(SetExpr0)
|
1620
|
+
else
|
1621
|
+
@index = i18
|
1622
|
+
r18 = nil
|
1623
|
+
end
|
1624
|
+
if r18
|
1625
|
+
r17 = r18
|
1626
|
+
else
|
1627
|
+
r17 = instantiate_node(SyntaxNode,input, index...index)
|
1628
|
+
end
|
1629
|
+
s2 << r17
|
1630
|
+
if r17
|
1631
|
+
if has_terminal?('}', false, index)
|
1632
|
+
r24 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
1633
|
+
@index += 1
|
1634
|
+
else
|
1635
|
+
terminal_parse_failure('}')
|
1636
|
+
r24 = nil
|
1637
|
+
end
|
1638
|
+
s2 << r24
|
1639
|
+
end
|
1640
|
+
end
|
1641
|
+
end
|
1642
|
+
end
|
1643
|
+
end
|
1644
|
+
end
|
1645
|
+
end
|
1646
|
+
end
|
1647
|
+
end
|
1648
|
+
end
|
1649
|
+
end
|
1650
|
+
end
|
1651
|
+
end
|
1652
|
+
if s2.last
|
1653
|
+
r2 = instantiate_node(SetComprehension,input, i2...index, s2)
|
1654
|
+
r2.extend(SetExpr1)
|
1655
|
+
else
|
1656
|
+
@index = i2
|
1657
|
+
r2 = nil
|
1658
|
+
end
|
1659
|
+
if r2
|
1660
|
+
r0 = r2
|
1661
|
+
else
|
1662
|
+
i25, s25 = index, []
|
1663
|
+
if has_terminal?('{', false, index)
|
1664
|
+
r26 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
1665
|
+
@index += 1
|
1666
|
+
else
|
1667
|
+
terminal_parse_failure('{')
|
1668
|
+
r26 = nil
|
1669
|
+
end
|
1670
|
+
s25 << r26
|
1671
|
+
if r26
|
1672
|
+
r28 = _nt_sp
|
1673
|
+
if r28
|
1674
|
+
r27 = r28
|
1675
|
+
else
|
1676
|
+
r27 = instantiate_node(SyntaxNode,input, index...index)
|
1677
|
+
end
|
1678
|
+
s25 << r27
|
1679
|
+
if r27
|
1680
|
+
r29 = _nt_fn_args
|
1681
|
+
s25 << r29
|
1682
|
+
if r29
|
1683
|
+
r31 = _nt_sp
|
1684
|
+
if r31
|
1685
|
+
r30 = r31
|
1686
|
+
else
|
1687
|
+
r30 = instantiate_node(SyntaxNode,input, index...index)
|
1688
|
+
end
|
1689
|
+
s25 << r30
|
1690
|
+
if r30
|
1691
|
+
if has_terminal?('}', false, index)
|
1692
|
+
r32 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
1693
|
+
@index += 1
|
1694
|
+
else
|
1695
|
+
terminal_parse_failure('}')
|
1696
|
+
r32 = nil
|
1697
|
+
end
|
1698
|
+
s25 << r32
|
1699
|
+
end
|
1700
|
+
end
|
1701
|
+
end
|
1702
|
+
end
|
1703
|
+
if s25.last
|
1704
|
+
r25 = instantiate_node(SetExpr,input, i25...index, s25)
|
1705
|
+
r25.extend(SetExpr2)
|
1706
|
+
else
|
1707
|
+
@index = i25
|
1708
|
+
r25 = nil
|
1709
|
+
end
|
1710
|
+
if r25
|
1711
|
+
r0 = r25
|
1712
|
+
else
|
1713
|
+
@index = i0
|
1714
|
+
r0 = nil
|
1715
|
+
end
|
1716
|
+
end
|
1717
|
+
end
|
1718
|
+
|
1719
|
+
node_cache[:set_expr][start_index] = r0
|
1720
|
+
|
1721
|
+
r0
|
1722
|
+
end
|
1723
|
+
|
1451
1724
|
module HashExpr0
|
1452
1725
|
def sp
|
1453
1726
|
elements[1]
|
@@ -1769,138 +2042,171 @@ module Delorean
|
|
1769
2042
|
end
|
1770
2043
|
|
1771
2044
|
i0 = index
|
1772
|
-
if has_terminal?('
|
1773
|
-
r1 = instantiate_node(SyntaxNode,input, index...(index +
|
1774
|
-
@index +=
|
2045
|
+
if has_terminal?('==', false, index)
|
2046
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
2047
|
+
@index += 2
|
1775
2048
|
else
|
1776
|
-
terminal_parse_failure('
|
2049
|
+
terminal_parse_failure('==')
|
1777
2050
|
r1 = nil
|
1778
2051
|
end
|
1779
2052
|
if r1
|
1780
2053
|
r0 = r1
|
1781
2054
|
else
|
1782
|
-
if has_terminal?('
|
1783
|
-
r2 = instantiate_node(SyntaxNode,input, index...(index +
|
1784
|
-
@index +=
|
2055
|
+
if has_terminal?('!=', false, index)
|
2056
|
+
r2 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
2057
|
+
@index += 2
|
1785
2058
|
else
|
1786
|
-
terminal_parse_failure('
|
2059
|
+
terminal_parse_failure('!=')
|
1787
2060
|
r2 = nil
|
1788
2061
|
end
|
1789
2062
|
if r2
|
1790
2063
|
r0 = r2
|
1791
2064
|
else
|
1792
|
-
if has_terminal?('
|
1793
|
-
r3 = instantiate_node(SyntaxNode,input, index...(index +
|
1794
|
-
@index +=
|
2065
|
+
if has_terminal?('>=', false, index)
|
2066
|
+
r3 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
2067
|
+
@index += 2
|
1795
2068
|
else
|
1796
|
-
terminal_parse_failure('
|
2069
|
+
terminal_parse_failure('>=')
|
1797
2070
|
r3 = nil
|
1798
2071
|
end
|
1799
2072
|
if r3
|
1800
2073
|
r0 = r3
|
1801
2074
|
else
|
1802
|
-
if has_terminal?('
|
1803
|
-
r4 = instantiate_node(SyntaxNode,input, index...(index +
|
1804
|
-
@index +=
|
2075
|
+
if has_terminal?('<=', false, index)
|
2076
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
2077
|
+
@index += 2
|
1805
2078
|
else
|
1806
|
-
terminal_parse_failure('
|
2079
|
+
terminal_parse_failure('<=')
|
1807
2080
|
r4 = nil
|
1808
2081
|
end
|
1809
2082
|
if r4
|
1810
2083
|
r0 = r4
|
1811
2084
|
else
|
1812
|
-
if has_terminal?('
|
1813
|
-
r5 = instantiate_node(SyntaxNode,input, index...(index +
|
1814
|
-
@index +=
|
2085
|
+
if has_terminal?('&&', false, index)
|
2086
|
+
r5 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
2087
|
+
@index += 2
|
1815
2088
|
else
|
1816
|
-
terminal_parse_failure('
|
2089
|
+
terminal_parse_failure('&&')
|
1817
2090
|
r5 = nil
|
1818
2091
|
end
|
1819
2092
|
if r5
|
1820
2093
|
r0 = r5
|
1821
2094
|
else
|
1822
|
-
if has_terminal?('
|
2095
|
+
if has_terminal?('||', false, index)
|
1823
2096
|
r6 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
1824
2097
|
@index += 2
|
1825
2098
|
else
|
1826
|
-
terminal_parse_failure('
|
2099
|
+
terminal_parse_failure('||')
|
1827
2100
|
r6 = nil
|
1828
2101
|
end
|
1829
2102
|
if r6
|
1830
2103
|
r0 = r6
|
1831
2104
|
else
|
1832
|
-
if has_terminal?('
|
1833
|
-
r7 = instantiate_node(SyntaxNode,input, index...(index +
|
1834
|
-
@index +=
|
2105
|
+
if has_terminal?('>', false, index)
|
2106
|
+
r7 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
2107
|
+
@index += 1
|
1835
2108
|
else
|
1836
|
-
terminal_parse_failure('
|
2109
|
+
terminal_parse_failure('>')
|
1837
2110
|
r7 = nil
|
1838
2111
|
end
|
1839
2112
|
if r7
|
1840
2113
|
r0 = r7
|
1841
2114
|
else
|
1842
|
-
if has_terminal?('
|
1843
|
-
r8 = instantiate_node(SyntaxNode,input, index...(index +
|
1844
|
-
@index +=
|
2115
|
+
if has_terminal?('<', false, index)
|
2116
|
+
r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
2117
|
+
@index += 1
|
1845
2118
|
else
|
1846
|
-
terminal_parse_failure('
|
2119
|
+
terminal_parse_failure('<')
|
1847
2120
|
r8 = nil
|
1848
2121
|
end
|
1849
2122
|
if r8
|
1850
2123
|
r0 = r8
|
1851
2124
|
else
|
1852
|
-
if has_terminal?('
|
1853
|
-
r9 = instantiate_node(SyntaxNode,input, index...(index +
|
1854
|
-
@index +=
|
2125
|
+
if has_terminal?('+', false, index)
|
2126
|
+
r9 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
2127
|
+
@index += 1
|
1855
2128
|
else
|
1856
|
-
terminal_parse_failure('
|
2129
|
+
terminal_parse_failure('+')
|
1857
2130
|
r9 = nil
|
1858
2131
|
end
|
1859
2132
|
if r9
|
1860
2133
|
r0 = r9
|
1861
2134
|
else
|
1862
|
-
if has_terminal?('
|
2135
|
+
if has_terminal?('-', false, index)
|
1863
2136
|
r10 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
1864
2137
|
@index += 1
|
1865
2138
|
else
|
1866
|
-
terminal_parse_failure('
|
2139
|
+
terminal_parse_failure('-')
|
1867
2140
|
r10 = nil
|
1868
2141
|
end
|
1869
2142
|
if r10
|
1870
2143
|
r0 = r10
|
1871
2144
|
else
|
1872
|
-
if has_terminal?('
|
2145
|
+
if has_terminal?('*', false, index)
|
1873
2146
|
r11 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
1874
2147
|
@index += 1
|
1875
2148
|
else
|
1876
|
-
terminal_parse_failure('
|
2149
|
+
terminal_parse_failure('*')
|
1877
2150
|
r11 = nil
|
1878
2151
|
end
|
1879
2152
|
if r11
|
1880
2153
|
r0 = r11
|
1881
2154
|
else
|
1882
|
-
if has_terminal?('
|
1883
|
-
r12 = instantiate_node(SyntaxNode,input, index...(index +
|
1884
|
-
@index +=
|
2155
|
+
if has_terminal?('/', false, index)
|
2156
|
+
r12 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
2157
|
+
@index += 1
|
1885
2158
|
else
|
1886
|
-
terminal_parse_failure('
|
2159
|
+
terminal_parse_failure('/')
|
1887
2160
|
r12 = nil
|
1888
2161
|
end
|
1889
2162
|
if r12
|
1890
2163
|
r0 = r12
|
1891
2164
|
else
|
1892
|
-
if has_terminal?('
|
1893
|
-
r13 = instantiate_node(SyntaxNode,input, index...(index +
|
1894
|
-
@index +=
|
2165
|
+
if has_terminal?('%', false, index)
|
2166
|
+
r13 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
2167
|
+
@index += 1
|
1895
2168
|
else
|
1896
|
-
terminal_parse_failure('
|
2169
|
+
terminal_parse_failure('%')
|
1897
2170
|
r13 = nil
|
1898
2171
|
end
|
1899
2172
|
if r13
|
1900
2173
|
r0 = r13
|
1901
2174
|
else
|
1902
|
-
|
1903
|
-
|
2175
|
+
if has_terminal?('&', false, index)
|
2176
|
+
r14 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
2177
|
+
@index += 1
|
2178
|
+
else
|
2179
|
+
terminal_parse_failure('&')
|
2180
|
+
r14 = nil
|
2181
|
+
end
|
2182
|
+
if r14
|
2183
|
+
r0 = r14
|
2184
|
+
else
|
2185
|
+
if has_terminal?('^', false, index)
|
2186
|
+
r15 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
2187
|
+
@index += 1
|
2188
|
+
else
|
2189
|
+
terminal_parse_failure('^')
|
2190
|
+
r15 = nil
|
2191
|
+
end
|
2192
|
+
if r15
|
2193
|
+
r0 = r15
|
2194
|
+
else
|
2195
|
+
if has_terminal?('|', false, index)
|
2196
|
+
r16 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
2197
|
+
@index += 1
|
2198
|
+
else
|
2199
|
+
terminal_parse_failure('|')
|
2200
|
+
r16 = nil
|
2201
|
+
end
|
2202
|
+
if r16
|
2203
|
+
r0 = r16
|
2204
|
+
else
|
2205
|
+
@index = i0
|
2206
|
+
r0 = nil
|
2207
|
+
end
|
2208
|
+
end
|
2209
|
+
end
|
1904
2210
|
end
|
1905
2211
|
end
|
1906
2212
|
end
|
@@ -2022,104 +2328,109 @@ module Delorean
|
|
2022
2328
|
if r6
|
2023
2329
|
r0 = r6
|
2024
2330
|
else
|
2025
|
-
r7 =
|
2331
|
+
r7 = _nt_set_expr
|
2026
2332
|
if r7
|
2027
2333
|
r0 = r7
|
2028
2334
|
else
|
2029
|
-
|
2030
|
-
i10, s10 = index, []
|
2031
|
-
r11 = _nt_class_name
|
2032
|
-
s10 << r11
|
2033
|
-
if r11
|
2034
|
-
if has_terminal?('::', false, index)
|
2035
|
-
r12 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
2036
|
-
@index += 2
|
2037
|
-
else
|
2038
|
-
terminal_parse_failure('::')
|
2039
|
-
r12 = nil
|
2040
|
-
end
|
2041
|
-
s10 << r12
|
2042
|
-
end
|
2043
|
-
if s10.last
|
2044
|
-
r10 = instantiate_node(SyntaxNode,input, i10...index, s10)
|
2045
|
-
r10.extend(Value0)
|
2046
|
-
else
|
2047
|
-
@index = i10
|
2048
|
-
r10 = nil
|
2049
|
-
end
|
2050
|
-
if r10
|
2051
|
-
r9 = r10
|
2052
|
-
else
|
2053
|
-
r9 = instantiate_node(SyntaxNode,input, index...index)
|
2054
|
-
end
|
2055
|
-
s8 << r9
|
2056
|
-
if r9
|
2057
|
-
r13 = _nt_class_name
|
2058
|
-
s8 << r13
|
2059
|
-
end
|
2060
|
-
if s8.last
|
2061
|
-
r8 = instantiate_node(NodeAsValue,input, i8...index, s8)
|
2062
|
-
r8.extend(Value1)
|
2063
|
-
else
|
2064
|
-
@index = i8
|
2065
|
-
r8 = nil
|
2066
|
-
end
|
2335
|
+
r8 = _nt_hash_expr
|
2067
2336
|
if r8
|
2068
2337
|
r0 = r8
|
2069
2338
|
else
|
2070
|
-
|
2071
|
-
|
2072
|
-
|
2073
|
-
|
2339
|
+
i9, s9 = index, []
|
2340
|
+
i11, s11 = index, []
|
2341
|
+
r12 = _nt_class_name
|
2342
|
+
s11 << r12
|
2343
|
+
if r12
|
2344
|
+
if has_terminal?('::', false, index)
|
2345
|
+
r13 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
2346
|
+
@index += 2
|
2347
|
+
else
|
2348
|
+
terminal_parse_failure('::')
|
2349
|
+
r13 = nil
|
2350
|
+
end
|
2351
|
+
s11 << r13
|
2352
|
+
end
|
2353
|
+
if s11.last
|
2354
|
+
r11 = instantiate_node(SyntaxNode,input, i11...index, s11)
|
2355
|
+
r11.extend(Value0)
|
2356
|
+
else
|
2357
|
+
@index = i11
|
2358
|
+
r11 = nil
|
2359
|
+
end
|
2360
|
+
if r11
|
2361
|
+
r10 = r11
|
2074
2362
|
else
|
2075
|
-
|
2076
|
-
|
2363
|
+
r10 = instantiate_node(SyntaxNode,input, index...index)
|
2364
|
+
end
|
2365
|
+
s9 << r10
|
2366
|
+
if r10
|
2367
|
+
r14 = _nt_class_name
|
2368
|
+
s9 << r14
|
2369
|
+
end
|
2370
|
+
if s9.last
|
2371
|
+
r9 = instantiate_node(NodeAsValue,input, i9...index, s9)
|
2372
|
+
r9.extend(Value1)
|
2373
|
+
else
|
2374
|
+
@index = i9
|
2375
|
+
r9 = nil
|
2077
2376
|
end
|
2078
|
-
|
2079
|
-
|
2080
|
-
|
2081
|
-
|
2082
|
-
|
2377
|
+
if r9
|
2378
|
+
r0 = r9
|
2379
|
+
else
|
2380
|
+
i15, s15 = index, []
|
2381
|
+
if has_terminal?('(', false, index)
|
2382
|
+
r16 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
2383
|
+
@index += 1
|
2083
2384
|
else
|
2084
|
-
|
2385
|
+
terminal_parse_failure('(')
|
2386
|
+
r16 = nil
|
2085
2387
|
end
|
2086
|
-
|
2388
|
+
s15 << r16
|
2087
2389
|
if r16
|
2088
|
-
r18 =
|
2089
|
-
s14 << r18
|
2390
|
+
r18 = _nt_sp
|
2090
2391
|
if r18
|
2091
|
-
|
2092
|
-
|
2093
|
-
|
2094
|
-
|
2095
|
-
|
2096
|
-
|
2097
|
-
|
2392
|
+
r17 = r18
|
2393
|
+
else
|
2394
|
+
r17 = instantiate_node(SyntaxNode,input, index...index)
|
2395
|
+
end
|
2396
|
+
s15 << r17
|
2397
|
+
if r17
|
2398
|
+
r19 = _nt_expression
|
2399
|
+
s15 << r19
|
2098
2400
|
if r19
|
2099
|
-
|
2100
|
-
|
2101
|
-
|
2401
|
+
r21 = _nt_sp
|
2402
|
+
if r21
|
2403
|
+
r20 = r21
|
2102
2404
|
else
|
2103
|
-
|
2104
|
-
|
2405
|
+
r20 = instantiate_node(SyntaxNode,input, index...index)
|
2406
|
+
end
|
2407
|
+
s15 << r20
|
2408
|
+
if r20
|
2409
|
+
if has_terminal?(')', false, index)
|
2410
|
+
r22 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
2411
|
+
@index += 1
|
2412
|
+
else
|
2413
|
+
terminal_parse_failure(')')
|
2414
|
+
r22 = nil
|
2415
|
+
end
|
2416
|
+
s15 << r22
|
2105
2417
|
end
|
2106
|
-
s14 << r21
|
2107
2418
|
end
|
2108
2419
|
end
|
2109
2420
|
end
|
2110
|
-
|
2111
|
-
|
2112
|
-
|
2113
|
-
|
2114
|
-
|
2115
|
-
|
2116
|
-
|
2117
|
-
|
2118
|
-
|
2119
|
-
|
2120
|
-
|
2121
|
-
|
2122
|
-
|
2421
|
+
if s15.last
|
2422
|
+
r15 = instantiate_node(Expr,input, i15...index, s15)
|
2423
|
+
r15.extend(Value2)
|
2424
|
+
else
|
2425
|
+
@index = i15
|
2426
|
+
r15 = nil
|
2427
|
+
end
|
2428
|
+
if r15
|
2429
|
+
r0 = r15
|
2430
|
+
else
|
2431
|
+
@index = i0
|
2432
|
+
r0 = nil
|
2433
|
+
end
|
2123
2434
|
end
|
2124
2435
|
end
|
2125
2436
|
end
|
@@ -66,6 +66,17 @@ grammar Delorean
|
|
66
66
|
'[' sp? args:fn_args sp? ']' <ListExpr>
|
67
67
|
end
|
68
68
|
|
69
|
+
rule set_expr
|
70
|
+
'{-}' <SetExpr>
|
71
|
+
/
|
72
|
+
'{' sp? e2:expression sp
|
73
|
+
'for' sp i:identifier sp 'in' sp e1:expression sp?
|
74
|
+
ifexp:('if' sp e3:expression sp?)?
|
75
|
+
'}' <SetComprehension>
|
76
|
+
/
|
77
|
+
'{' sp? args:fn_args sp? '}' <SetExpr>
|
78
|
+
end
|
79
|
+
|
69
80
|
rule hash_expr
|
70
81
|
'{}' <HashExpr>
|
71
82
|
/
|
@@ -80,7 +91,8 @@ grammar Delorean
|
|
80
91
|
# NOTE: some operations such as << have side-effects (e.g. on
|
81
92
|
# Arrays). So, be cautious about which opertaions are added.
|
82
93
|
rule binary_op
|
83
|
-
'
|
94
|
+
'==' / '!=' / '>=' / '<=' / '&&' / '||' /
|
95
|
+
'>' / '<' / '+' / '-' / '*' / '/' / '%' / '&' / '^' / '|'
|
84
96
|
end
|
85
97
|
|
86
98
|
rule unary_op
|
@@ -94,6 +106,7 @@ grammar Delorean
|
|
94
106
|
nil_val /
|
95
107
|
identifier /
|
96
108
|
list_expr /
|
109
|
+
set_expr /
|
97
110
|
hash_expr /
|
98
111
|
mod:(m:class_name '::')? c:class_name <NodeAsValue> /
|
99
112
|
'(' sp? e:expression sp? ')' <Expr>
|
data/lib/delorean/nodes.rb
CHANGED
@@ -29,7 +29,7 @@ module Delorean
|
|
29
29
|
<<eos
|
30
30
|
class #{cname}
|
31
31
|
def self.#{aname}#{POST}(_e)
|
32
|
-
_e['
|
32
|
+
_e[self.name+'.#{aname}'] ||=
|
33
33
|
begin
|
34
34
|
_e.fetch('#{aname}')
|
35
35
|
rescue KeyError
|
@@ -101,7 +101,7 @@ eos
|
|
101
101
|
# an attr is defined as a class function on the node class.
|
102
102
|
"class #{context.last_node}; " +
|
103
103
|
"def self.#{i.text_value}#{POST}(_e); " +
|
104
|
-
"_e['
|
104
|
+
"_e[self.name+'.#{i.text_value}'] ||= " +
|
105
105
|
e.rewrite(context) + "; end; end;"
|
106
106
|
end
|
107
107
|
end
|
@@ -396,6 +396,18 @@ eos
|
|
396
396
|
end
|
397
397
|
end
|
398
398
|
|
399
|
+
class SetExpr < ListExpr
|
400
|
+
def rewrite(context)
|
401
|
+
"Set#{super}"
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
405
|
+
class SetComprehension < ListComprehension
|
406
|
+
def rewrite(context)
|
407
|
+
"Set[*#{super}]"
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
399
411
|
class HashComprehension < SNode
|
400
412
|
def check(context, *)
|
401
413
|
vname = i.text_value
|
data/lib/delorean/version.rb
CHANGED
data/spec/eval_spec.rb
CHANGED
@@ -474,6 +474,16 @@ eof
|
|
474
474
|
]
|
475
475
|
end
|
476
476
|
|
477
|
+
it "should eval sets and set comprehension" do
|
478
|
+
engine.parse defn("A:",
|
479
|
+
" a = {-}",
|
480
|
+
" b = {i*5 for i in {1,2,3}}",
|
481
|
+
" c = {1,2,3} | {4,5}",
|
482
|
+
)
|
483
|
+
engine.evaluate_attrs("A", ["a", "b", "c"]).should ==
|
484
|
+
[Set[], Set[5,10,15], Set[1,2,3,4,5]]
|
485
|
+
end
|
486
|
+
|
477
487
|
it "should eval list comprehension" do
|
478
488
|
engine.parse defn("A:",
|
479
489
|
" b = [i*5 for i in [1,2,3]]",
|
@@ -739,4 +749,25 @@ eof
|
|
739
749
|
r = engine.evaluate_attrs("A", ["a", "b", "c", "d"])
|
740
750
|
r.should == [1, {"x"=>123, "y"=>456}, {"a"=>1, "b"=>{"x"=>123, "y"=>456}}, -333]
|
741
751
|
end
|
752
|
+
|
753
|
+
it "should properly eval overridden attrs" do
|
754
|
+
engine.parse defn("A:",
|
755
|
+
" a = 5",
|
756
|
+
" b = a",
|
757
|
+
"B: A",
|
758
|
+
" a = 2",
|
759
|
+
" x = A.b - B.b",
|
760
|
+
" k = [A.b, B.b]",
|
761
|
+
" l = [x.b for x in [A, B]]",
|
762
|
+
" m = [x().b for x in [A, B]]",
|
763
|
+
)
|
764
|
+
|
765
|
+
engine.evaluate("A", "b").should == 5
|
766
|
+
engine.evaluate("B", "b").should == 2
|
767
|
+
engine.evaluate("B", "x").should == 3
|
768
|
+
engine.evaluate("B", "k").should == [5, 2]
|
769
|
+
engine.evaluate("B", "l").should == [5, 2]
|
770
|
+
engine.evaluate("B", "m").should == [5, 2]
|
771
|
+
end
|
772
|
+
|
742
773
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delorean_lang
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.03
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: treetop
|