nilac 0.0.4.0.1 → 0.0.4.1
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/LICENSE +16 -18
- data/README.md +2 -1
- data/bin/nilac +535 -123
- data/lib/nilac/version.rb +1 -1
- data/shark/features/regular_if.feature +11 -0
- data/shark/features/unless_until.feature +11 -0
- data/shark/test_files/correct_default_parameters.js +6 -1
- data/shark/test_files/correct_regular_if.js +14 -0
- data/shark/test_files/correct_unless_until.js +21 -0
- data/shark/test_files/default_parameters.nila +3 -1
- data/shark/test_files/regular_if.nila +19 -0
- data/shark/test_files/unless_until.nila +10 -0
- data/src/nilac.rb +535 -123
- metadata +8 -4
- data/bin/.gitignore +0 -2
data/src/nilac.rb
CHANGED
@@ -327,29 +327,37 @@ def compile(input_file_path,*output_file_name)
|
|
327
327
|
|
328
328
|
finder_location = current_location
|
329
329
|
|
330
|
-
|
330
|
+
begin
|
331
331
|
|
332
|
-
|
332
|
+
while current_string.index(nila_regexp) == nil
|
333
333
|
|
334
|
-
|
334
|
+
finder_location -= 1
|
335
335
|
|
336
|
-
|
336
|
+
current_string = modified_file_contents[finder_location]
|
337
|
+
|
338
|
+
end
|
339
|
+
|
340
|
+
code_block_begin = finder_location
|
337
341
|
|
338
|
-
|
342
|
+
code_block_end = current_location
|
339
343
|
|
340
|
-
|
344
|
+
start_blocks << code_block_begin
|
341
345
|
|
342
|
-
|
346
|
+
end_blocks << code_block_end
|
343
347
|
|
344
|
-
|
348
|
+
code_block_begin_string_split = modified_file_contents[code_block_begin].split(" ")
|
345
349
|
|
346
|
-
|
350
|
+
code_block_begin_string_split[0] = code_block_begin_string_split[0].reverse
|
347
351
|
|
348
|
-
|
352
|
+
code_block_begin_string = code_block_begin_string_split.join(" ")
|
349
353
|
|
350
|
-
|
354
|
+
modified_file_contents[code_block_begin] = code_block_begin_string
|
351
355
|
|
352
|
-
|
356
|
+
rescue NoMethodError
|
357
|
+
|
358
|
+
puts "Function compilation failed!"
|
359
|
+
|
360
|
+
end
|
353
361
|
|
354
362
|
end
|
355
363
|
|
@@ -399,6 +407,7 @@ def compile(input_file_path,*output_file_name)
|
|
399
407
|
|
400
408
|
end
|
401
409
|
|
410
|
+
|
402
411
|
file_id = open(temporary_nila_file, 'w')
|
403
412
|
|
404
413
|
file_id.write(joined_file_contents)
|
@@ -476,8 +485,6 @@ def compile(input_file_path,*output_file_name)
|
|
476
485
|
|
477
486
|
def parse_default_values(input_function_definition)
|
478
487
|
|
479
|
-
puts input_function_definition
|
480
|
-
|
481
488
|
split1,split2 = input_function_definition.split("(")
|
482
489
|
|
483
490
|
split2,split3 = split2.split(")")
|
@@ -546,13 +553,17 @@ def compile(input_file_path,*output_file_name)
|
|
546
553
|
|
547
554
|
def get_variables(input_file_contents,temporary_nila_file)
|
548
555
|
|
549
|
-
|
550
|
-
#Since Javascript is a dynamic language, Nila doesn't have to worry about following up on those variables.
|
556
|
+
variables = []
|
551
557
|
|
552
|
-
|
553
|
-
#variable usage statements.
|
558
|
+
input_file_contents = input_file_contents.collect {|element| element.gsub("+=","plusequal")}
|
554
559
|
|
555
|
-
|
560
|
+
input_file_contents = input_file_contents.collect {|element| element.gsub("-=","minusequal")}
|
561
|
+
|
562
|
+
input_file_contents = input_file_contents.collect {|element| element.gsub("*=","multiequal")}
|
563
|
+
|
564
|
+
input_file_contents = input_file_contents.collect {|element| element.gsub("/=","divequal")}
|
565
|
+
|
566
|
+
input_file_contents = input_file_contents.collect {|element| element.gsub("%=","modequal")}
|
556
567
|
|
557
568
|
for x in 0...input_file_contents.length
|
558
569
|
|
@@ -600,6 +611,16 @@ def compile(input_file_path,*output_file_name)
|
|
600
611
|
|
601
612
|
end
|
602
613
|
|
614
|
+
line_by_line_contents = line_by_line_contents.collect {|element| element.gsub("plusequal","+=")}
|
615
|
+
|
616
|
+
line_by_line_contents = line_by_line_contents.collect {|element| element.gsub("minusequal","-=")}
|
617
|
+
|
618
|
+
line_by_line_contents = line_by_line_contents.collect {|element| element.gsub("multiequal","*=")}
|
619
|
+
|
620
|
+
line_by_line_contents = line_by_line_contents.collect {|element| element.gsub("divequal","/=")}
|
621
|
+
|
622
|
+
line_by_line_contents = line_by_line_contents.collect {|element| element.gsub("modequal","%=")}
|
623
|
+
|
603
624
|
return variables.uniq,line_by_line_contents
|
604
625
|
|
605
626
|
end
|
@@ -730,13 +751,6 @@ def compile(input_file_path,*output_file_name)
|
|
730
751
|
|
731
752
|
def compile_array_indexing(input_file_contents)
|
732
753
|
|
733
|
-
#Nila allows two different kinds of indexing operations on arrays and strings. They are
|
734
|
-
|
735
|
-
#1. Using Ranges => numbers[0...5]
|
736
|
-
#2. Using Start and End Indexes => numbers[0,5]
|
737
|
-
|
738
|
-
#This method implements this Nila feature
|
739
|
-
|
740
754
|
possible_indexing_operation = input_file_contents.dup.reject {|element| !element.include?"[" and !element.include?"]"}
|
741
755
|
|
742
756
|
possible_range_indexing = possible_indexing_operation.reject {|element| !element.include?".."}
|
@@ -978,13 +992,21 @@ def compile(input_file_path,*output_file_name)
|
|
978
992
|
|
979
993
|
rejected_array = reversed_input_array.reject {|content| content.lstrip.eql?("")}
|
980
994
|
|
981
|
-
rejected_array = rejected_array
|
995
|
+
rejected_array = rejected_array[1..-1]
|
996
|
+
|
997
|
+
if !rejected_array[0].strip.eql?("}")
|
982
998
|
|
983
|
-
|
999
|
+
if !rejected_array[0].strip.eql?("end")
|
984
1000
|
|
985
|
-
|
1001
|
+
last_statement = rejected_array[0]
|
986
1002
|
|
987
|
-
|
1003
|
+
replacement_string = "return #{last_statement.lstrip}"
|
1004
|
+
|
1005
|
+
input_array[input_array.index(last_statement)] = replacement_string
|
1006
|
+
|
1007
|
+
end
|
1008
|
+
|
1009
|
+
end
|
988
1010
|
|
989
1011
|
end
|
990
1012
|
|
@@ -1270,7 +1292,7 @@ def compile(input_file_path,*output_file_name)
|
|
1270
1292
|
|
1271
1293
|
"puts" => "console.log",
|
1272
1294
|
|
1273
|
-
"print" => "
|
1295
|
+
"print" => "process.stdout.write"
|
1274
1296
|
|
1275
1297
|
}
|
1276
1298
|
|
@@ -1336,30 +1358,38 @@ def compile(input_file_path,*output_file_name)
|
|
1336
1358
|
|
1337
1359
|
end
|
1338
1360
|
|
1339
|
-
|
1361
|
+
begin
|
1340
1362
|
|
1341
|
-
|
1363
|
+
input_file_contents[-1] = input_file_contents[-1] + "\n" if !input_file_contents[-1].include?("\n")
|
1364
|
+
|
1365
|
+
joined_file_contents = input_file_contents.join
|
1342
1366
|
|
1343
|
-
|
1367
|
+
function_names.each do |list_of_functions|
|
1344
1368
|
|
1345
|
-
|
1369
|
+
list_of_functions.each do |function|
|
1346
1370
|
|
1347
|
-
|
1371
|
+
matching_strings = extract(joined_file_contents,function+" ","\n")
|
1348
1372
|
|
1349
|
-
|
1373
|
+
matching_strings.each do |string|
|
1350
1374
|
|
1351
|
-
|
1375
|
+
modified_string = string.dup
|
1352
1376
|
|
1353
|
-
|
1377
|
+
modified_string = modified_string.sub(function+" ",function+"(")
|
1354
1378
|
|
1355
|
-
|
1379
|
+
modified_string = modified_string.sub("\n",")\n")
|
1356
1380
|
|
1357
|
-
|
1381
|
+
joined_file_contents = joined_file_contents.sub(string,modified_string)
|
1382
|
+
|
1383
|
+
end
|
1358
1384
|
|
1359
1385
|
end
|
1360
1386
|
|
1361
1387
|
end
|
1362
1388
|
|
1389
|
+
rescue NoMethodError
|
1390
|
+
|
1391
|
+
puts "Whitespace delimitation exited with errors!"
|
1392
|
+
|
1363
1393
|
end
|
1364
1394
|
|
1365
1395
|
file_id = open(temporary_nila_file, 'w')
|
@@ -1382,9 +1412,9 @@ def compile(input_file_path,*output_file_name)
|
|
1382
1412
|
|
1383
1413
|
def compile_inline_conditionals(input_file_contents,temporary_nila_file)
|
1384
1414
|
|
1385
|
-
conditionals = [/( if )/,/( while )/]
|
1415
|
+
conditionals = [/( if )/,/( while )/,/( unless )/,/( until )/]
|
1386
1416
|
|
1387
|
-
plain_conditionals = [" if "," while "]
|
1417
|
+
plain_conditionals = [" if "," while "," unless "," until "]
|
1388
1418
|
|
1389
1419
|
joined_file_contents = input_file_contents.join
|
1390
1420
|
|
@@ -1392,7 +1422,7 @@ def compile(input_file_path,*output_file_name)
|
|
1392
1422
|
|
1393
1423
|
conditionals.each_with_index do |regex,index|
|
1394
1424
|
|
1395
|
-
matching_lines = input_file_contents.reject {|content|
|
1425
|
+
matching_lines = input_file_contents.reject {|content| content.index(regex).nil?}
|
1396
1426
|
|
1397
1427
|
matching_lines.each do |line|
|
1398
1428
|
|
@@ -1400,11 +1430,19 @@ def compile(input_file_path,*output_file_name)
|
|
1400
1430
|
|
1401
1431
|
if index == 0
|
1402
1432
|
|
1403
|
-
output_statement = "if (#{line_split[1].lstrip.rstrip}) {\n\n#{line_split[0]}\n}\n"
|
1433
|
+
output_statement = "if (#{line_split[1].lstrip.rstrip.gsub("?","")}) {\n\n#{line_split[0]}\n}\n"
|
1404
1434
|
|
1405
1435
|
elsif index == 1
|
1406
1436
|
|
1407
|
-
output_statement = "while (#{line_split[1].lstrip.rstrip}) {\n\n#{line_split[0]}\n}\n"
|
1437
|
+
output_statement = "while (#{line_split[1].lstrip.rstrip.gsub("?","")}) {\n\n#{line_split[0]}\n}\n"
|
1438
|
+
|
1439
|
+
elsif index == 2
|
1440
|
+
|
1441
|
+
output_statement = "if (!(#{line_split[1].lstrip.rstrip.gsub("?","")})) {\n\n#{line_split[0]}\n}\n"
|
1442
|
+
|
1443
|
+
elsif index == 3
|
1444
|
+
|
1445
|
+
output_statement = "while (!(#{line_split[1].lstrip.rstrip.gsub("?","")})) {\n\n#{line_split[0]}\n}\n"
|
1408
1446
|
|
1409
1447
|
end
|
1410
1448
|
|
@@ -1426,7 +1464,263 @@ def compile(input_file_path,*output_file_name)
|
|
1426
1464
|
|
1427
1465
|
end
|
1428
1466
|
|
1429
|
-
|
1467
|
+
def compile_regular_if(input_file_contents,temporary_nila_file)
|
1468
|
+
|
1469
|
+
def convert_string_to_array(input_string,temporary_nila_file)
|
1470
|
+
|
1471
|
+
file_id = open(temporary_nila_file, 'w')
|
1472
|
+
|
1473
|
+
file_id.write(input_string)
|
1474
|
+
|
1475
|
+
file_id.close()
|
1476
|
+
|
1477
|
+
line_by_line_contents = read_file_line_by_line(temporary_nila_file)
|
1478
|
+
|
1479
|
+
return line_by_line_contents
|
1480
|
+
|
1481
|
+
end
|
1482
|
+
|
1483
|
+
def extract_if_blocks(if_statement_indexes,input_file_contents)
|
1484
|
+
|
1485
|
+
possible_if_blocks = []
|
1486
|
+
|
1487
|
+
if_block_counter = 0
|
1488
|
+
|
1489
|
+
extracted_blocks = []
|
1490
|
+
|
1491
|
+
controlregexp = /(if |while |def )/
|
1492
|
+
|
1493
|
+
rejectionregexp = /( if | while )/
|
1494
|
+
|
1495
|
+
for x in 0...if_statement_indexes.length-1
|
1496
|
+
|
1497
|
+
possible_if_blocks << input_file_contents[if_statement_indexes[x]..if_statement_indexes[x+1]]
|
1498
|
+
|
1499
|
+
end
|
1500
|
+
|
1501
|
+
end_counter = 0
|
1502
|
+
|
1503
|
+
end_index = []
|
1504
|
+
|
1505
|
+
current_block = []
|
1506
|
+
|
1507
|
+
possible_if_blocks.each_with_index do |block|
|
1508
|
+
|
1509
|
+
current_block += block
|
1510
|
+
|
1511
|
+
current_block.each_with_index do |line,index|
|
1512
|
+
|
1513
|
+
if line.lstrip.eql? "end\n"
|
1514
|
+
|
1515
|
+
end_counter += 1
|
1516
|
+
|
1517
|
+
end_index << index
|
1518
|
+
|
1519
|
+
end
|
1520
|
+
|
1521
|
+
end
|
1522
|
+
|
1523
|
+
if end_counter > 0
|
1524
|
+
|
1525
|
+
until end_index.empty?
|
1526
|
+
|
1527
|
+
array_extract = current_block[0..end_index[0]].reverse
|
1528
|
+
|
1529
|
+
index_counter = 0
|
1530
|
+
|
1531
|
+
array_extract.each_with_index do |line|
|
1532
|
+
|
1533
|
+
break if (line.lstrip.index(controlregexp) != nil and line.lstrip.index(rejectionregexp).nil?)
|
1534
|
+
|
1535
|
+
index_counter += 1
|
1536
|
+
|
1537
|
+
end
|
1538
|
+
|
1539
|
+
block_extract = array_extract[0..index_counter].reverse
|
1540
|
+
|
1541
|
+
extracted_blocks << block_extract
|
1542
|
+
|
1543
|
+
block_start = current_block.index(block_extract[0])
|
1544
|
+
|
1545
|
+
block_end = current_block.index(block_extract[-1])
|
1546
|
+
|
1547
|
+
current_block[block_start..block_end] = "--ifblock#{if_block_counter}"
|
1548
|
+
|
1549
|
+
if_block_counter += 1
|
1550
|
+
|
1551
|
+
end_counter = 0
|
1552
|
+
|
1553
|
+
end_index = []
|
1554
|
+
|
1555
|
+
current_block.each_with_index do |line,index|
|
1556
|
+
|
1557
|
+
if line.lstrip.eql? "end\n"
|
1558
|
+
|
1559
|
+
end_counter += 1
|
1560
|
+
|
1561
|
+
end_index << index
|
1562
|
+
|
1563
|
+
end
|
1564
|
+
|
1565
|
+
end
|
1566
|
+
|
1567
|
+
end
|
1568
|
+
|
1569
|
+
end
|
1570
|
+
|
1571
|
+
end
|
1572
|
+
|
1573
|
+
return current_block,extracted_blocks
|
1574
|
+
|
1575
|
+
end
|
1576
|
+
|
1577
|
+
def compile_if_syntax(input_block)
|
1578
|
+
|
1579
|
+
starting_line = input_block[0]
|
1580
|
+
|
1581
|
+
starting_line = starting_line + "\n" if starting_line.lstrip == starting_line
|
1582
|
+
|
1583
|
+
junk,condition = starting_line.split("if")
|
1584
|
+
|
1585
|
+
input_block[0] = "Euuf (#{condition.lstrip.rstrip.gsub("?","")}) {\n"
|
1586
|
+
|
1587
|
+
input_block[-1] = input_block[-1].lstrip.sub("end","}")
|
1588
|
+
|
1589
|
+
elsif_statements = input_block.reject {|element| !element.include?("elsuf")}
|
1590
|
+
|
1591
|
+
elsif_statements.each do |statement|
|
1592
|
+
|
1593
|
+
junk,condition = statement.split("elsuf")
|
1594
|
+
|
1595
|
+
input_block[input_block.index(statement)] = "} elsuf (#{condition.lstrip.rstrip.gsub("?","")}) {\n"
|
1596
|
+
|
1597
|
+
end
|
1598
|
+
|
1599
|
+
else_statements = input_block.reject {|element| !element.include?("else")}
|
1600
|
+
|
1601
|
+
else_statements.each do |statement|
|
1602
|
+
|
1603
|
+
input_block[input_block.index(statement)] = "} else {\n"
|
1604
|
+
|
1605
|
+
end
|
1606
|
+
|
1607
|
+
return input_block
|
1608
|
+
|
1609
|
+
end
|
1610
|
+
|
1611
|
+
input_file_contents = input_file_contents.collect {|element| element.sub("elsif","elsuf")}
|
1612
|
+
|
1613
|
+
possible_if_statements = input_file_contents.reject {|element| !element.include?("if")}
|
1614
|
+
|
1615
|
+
possible_if_statements = possible_if_statements.reject {|element| element.include?("else")}
|
1616
|
+
|
1617
|
+
possible_if_statements = possible_if_statements.reject {|element| element.lstrip.include?(" if ")}
|
1618
|
+
|
1619
|
+
if !possible_if_statements.empty?
|
1620
|
+
|
1621
|
+
if_statement_indexes = []
|
1622
|
+
|
1623
|
+
possible_if_statements.each do |statement|
|
1624
|
+
|
1625
|
+
if_statement_indexes << input_file_contents.dup.each_index.select {|index| input_file_contents[index] == statement}
|
1626
|
+
|
1627
|
+
end
|
1628
|
+
|
1629
|
+
if_statement_indexes = if_statement_indexes.flatten + [-1]
|
1630
|
+
|
1631
|
+
controlregexp = /(while |def )/
|
1632
|
+
|
1633
|
+
modified_input_contents,extracted_statements = extract_if_blocks(if_statement_indexes,input_file_contents.clone)
|
1634
|
+
|
1635
|
+
joined_blocks = extracted_statements.collect {|element| element.join}
|
1636
|
+
|
1637
|
+
if_statements = joined_blocks.reject {|element| element.index(controlregexp) != nil}
|
1638
|
+
|
1639
|
+
rejected_elements = joined_blocks - if_statements
|
1640
|
+
|
1641
|
+
rejected_elements_index = []
|
1642
|
+
|
1643
|
+
rejected_elements.each do |element|
|
1644
|
+
|
1645
|
+
rejected_elements_index << joined_blocks.each_index.select {|index| joined_blocks[index] == element}
|
1646
|
+
|
1647
|
+
end
|
1648
|
+
|
1649
|
+
if_blocks_index = (0...extracted_statements.length).to_a
|
1650
|
+
|
1651
|
+
rejected_elements_index = rejected_elements_index.flatten
|
1652
|
+
|
1653
|
+
if_blocks_index -= rejected_elements_index
|
1654
|
+
|
1655
|
+
modified_if_statements = if_statements.collect {|string| convert_string_to_array(string,temporary_nila_file)}
|
1656
|
+
|
1657
|
+
modified_if_statements = modified_if_statements.collect {|block| compile_if_syntax(block)}.reverse
|
1658
|
+
|
1659
|
+
if_blocks_index = if_blocks_index.collect {|element| "--ifblock#{element}"}.reverse
|
1660
|
+
|
1661
|
+
rejected_elements_index = rejected_elements_index.collect {|element| "--ifblock#{element}"}.reverse
|
1662
|
+
|
1663
|
+
rejected_elements = rejected_elements.reverse
|
1664
|
+
|
1665
|
+
joined_file_contents = modified_input_contents.join
|
1666
|
+
|
1667
|
+
until if_blocks_index.empty? and rejected_elements_index.empty?
|
1668
|
+
|
1669
|
+
if !if_blocks_index.empty?
|
1670
|
+
|
1671
|
+
if joined_file_contents.include?(if_blocks_index[0])
|
1672
|
+
|
1673
|
+
joined_file_contents = joined_file_contents.sub(if_blocks_index[0],modified_if_statements[0].join)
|
1674
|
+
|
1675
|
+
if_blocks_index.delete_at(0)
|
1676
|
+
|
1677
|
+
modified_if_statements.delete_at(0)
|
1678
|
+
|
1679
|
+
else
|
1680
|
+
|
1681
|
+
joined_file_contents = joined_file_contents.sub(rejected_elements_index[0],rejected_elements[0])
|
1682
|
+
|
1683
|
+
rejected_elements_index.delete_at(0)
|
1684
|
+
|
1685
|
+
rejected_elements.delete_at(0)
|
1686
|
+
|
1687
|
+
end
|
1688
|
+
|
1689
|
+
else
|
1690
|
+
|
1691
|
+
joined_file_contents = joined_file_contents.sub(rejected_elements_index[0],rejected_elements[0])
|
1692
|
+
|
1693
|
+
rejected_elements_index.delete_at(0)
|
1694
|
+
|
1695
|
+
rejected_elements.delete_at(0)
|
1696
|
+
|
1697
|
+
end
|
1698
|
+
|
1699
|
+
end
|
1700
|
+
|
1701
|
+
else
|
1702
|
+
|
1703
|
+
joined_file_contents = input_file_contents.join
|
1704
|
+
|
1705
|
+
end
|
1706
|
+
|
1707
|
+
file_id = open(temporary_nila_file, 'w')
|
1708
|
+
|
1709
|
+
file_id.write(joined_file_contents)
|
1710
|
+
|
1711
|
+
file_id.close()
|
1712
|
+
|
1713
|
+
line_by_line_contents = read_file_line_by_line(temporary_nila_file)
|
1714
|
+
|
1715
|
+
return line_by_line_contents
|
1716
|
+
|
1717
|
+
end
|
1718
|
+
|
1719
|
+
file_contents = compile_regular_if(input_file_contents,temporary_nila_file)
|
1720
|
+
|
1721
|
+
file_contents = compile_inline_conditionals(file_contents,temporary_nila_file)
|
1722
|
+
|
1723
|
+
return file_contents
|
1430
1724
|
|
1431
1725
|
end
|
1432
1726
|
|
@@ -1694,6 +1988,10 @@ def compile(input_file_path,*output_file_name)
|
|
1694
1988
|
|
1695
1989
|
puts "Whitespace was left unfixed!"
|
1696
1990
|
|
1991
|
+
rescue ArgumentError
|
1992
|
+
|
1993
|
+
puts "Whitespace was left unfixed!"
|
1994
|
+
|
1697
1995
|
end
|
1698
1996
|
|
1699
1997
|
return modified_file_contents,code_blocks
|
@@ -1731,141 +2029,254 @@ def compile(input_file_path,*output_file_name)
|
|
1731
2029
|
|
1732
2030
|
end
|
1733
2031
|
|
1734
|
-
|
2032
|
+
def roll_blocks(input_file_contents,code_block_starting_locations)
|
1735
2033
|
|
1736
|
-
|
2034
|
+
if !code_block_starting_locations.empty?
|
1737
2035
|
|
1738
|
-
|
2036
|
+
controlregexp = /(if |while |function |function\()/
|
1739
2037
|
|
1740
|
-
|
2038
|
+
code_block_starting_locations = [0,code_block_starting_locations,-1].flatten
|
1741
2039
|
|
1742
|
-
|
2040
|
+
possible_blocks = []
|
1743
2041
|
|
1744
|
-
|
2042
|
+
block_counter = 0
|
1745
2043
|
|
1746
|
-
|
2044
|
+
extracted_blocks = []
|
1747
2045
|
|
1748
|
-
|
2046
|
+
for x in 0...code_block_starting_locations.length-1
|
1749
2047
|
|
1750
|
-
|
2048
|
+
possible_blocks << input_file_contents[code_block_starting_locations[x]..code_block_starting_locations[x+1]]
|
1751
2049
|
|
1752
|
-
|
2050
|
+
end
|
1753
2051
|
|
1754
|
-
|
2052
|
+
end_counter = 0
|
1755
2053
|
|
1756
|
-
|
2054
|
+
end_index = []
|
1757
2055
|
|
1758
|
-
|
2056
|
+
current_block = []
|
1759
2057
|
|
1760
|
-
|
2058
|
+
possible_blocks.each_with_index do |block|
|
1761
2059
|
|
1762
|
-
|
2060
|
+
current_block += block
|
1763
2061
|
|
1764
|
-
|
2062
|
+
current_block.each_with_index do |line,index|
|
1765
2063
|
|
1766
|
-
|
2064
|
+
if line.lstrip.eql? "}\n"
|
1767
2065
|
|
1768
|
-
|
2066
|
+
end_counter += 1
|
1769
2067
|
|
1770
|
-
|
2068
|
+
end_index << index
|
1771
2069
|
|
1772
|
-
|
2070
|
+
end
|
1773
2071
|
|
1774
|
-
|
2072
|
+
end
|
1775
2073
|
|
1776
|
-
|
2074
|
+
if end_counter > 0
|
1777
2075
|
|
1778
|
-
|
2076
|
+
until end_index.empty?
|
1779
2077
|
|
1780
|
-
|
2078
|
+
array_extract = current_block[0..end_index[0]].reverse
|
1781
2079
|
|
1782
|
-
|
2080
|
+
index_counter = 0
|
1783
2081
|
|
1784
|
-
|
2082
|
+
array_extract.each_with_index do |line|
|
1785
2083
|
|
1786
|
-
|
2084
|
+
break if line.index(controlregexp) != nil
|
1787
2085
|
|
1788
|
-
|
2086
|
+
index_counter += 1
|
1789
2087
|
|
1790
|
-
|
2088
|
+
end
|
1791
2089
|
|
1792
|
-
|
2090
|
+
block_extract = array_extract[0..index_counter].reverse
|
1793
2091
|
|
1794
|
-
|
2092
|
+
extracted_blocks << block_extract
|
1795
2093
|
|
1796
|
-
|
2094
|
+
block_start = current_block.index(block_extract[0])
|
1797
2095
|
|
1798
|
-
|
2096
|
+
block_end = current_block.index(block_extract[-1])
|
1799
2097
|
|
1800
|
-
|
2098
|
+
current_block[block_start..block_end] = "--block#{block_counter}"
|
1801
2099
|
|
1802
|
-
|
2100
|
+
block_counter += 1
|
1803
2101
|
|
1804
|
-
|
2102
|
+
end_counter = 0
|
1805
2103
|
|
1806
|
-
|
2104
|
+
end_index = []
|
2105
|
+
|
2106
|
+
current_block.each_with_index do |line,index|
|
2107
|
+
|
2108
|
+
if line.lstrip.eql? "}\n"
|
2109
|
+
|
2110
|
+
end_counter += 1
|
2111
|
+
|
2112
|
+
end_index << index
|
2113
|
+
|
2114
|
+
end
|
2115
|
+
|
2116
|
+
end
|
2117
|
+
|
2118
|
+
end
|
2119
|
+
|
2120
|
+
end
|
2121
|
+
|
2122
|
+
end
|
2123
|
+
|
2124
|
+
return current_block,extracted_blocks
|
2125
|
+
|
2126
|
+
else
|
2127
|
+
|
2128
|
+
return input_file_contents,[]
|
1807
2129
|
|
1808
2130
|
end
|
1809
2131
|
|
2132
|
+
end
|
2133
|
+
|
2134
|
+
def fix_syntax_indentation(input_file_contents)
|
1810
2135
|
|
2136
|
+
fixableregexp = /(else |elsuf )/
|
2137
|
+
|
2138
|
+
need_fixes = input_file_contents.reject {|line| line.index(fixableregexp).nil?}
|
2139
|
+
|
2140
|
+
need_fixes.each do |fix|
|
2141
|
+
|
2142
|
+
input_file_contents[input_file_contents.index(fix)] = input_file_contents[input_file_contents.index(fix)].sub(" ","")
|
2143
|
+
|
2144
|
+
end
|
2145
|
+
|
2146
|
+
return input_file_contents
|
1811
2147
|
|
1812
2148
|
end
|
1813
2149
|
|
1814
|
-
|
2150
|
+
javascript_regexp = /(if |while |function |function\()/
|
1815
2151
|
|
1816
|
-
|
2152
|
+
javascript_file_contents = javascript_file_contents.collect {|element| element.sub("Euuf","if")}
|
2153
|
+
|
2154
|
+
javascript_file_contents = reset_tabs(javascript_file_contents)
|
1817
2155
|
|
1818
|
-
|
2156
|
+
starting_locations = []
|
2157
|
+
|
2158
|
+
javascript_file_contents.each_with_index do |line,index|
|
2159
|
+
|
2160
|
+
if line.index(javascript_regexp) != nil
|
2161
|
+
|
2162
|
+
starting_locations << index
|
2163
|
+
|
2164
|
+
end
|
1819
2165
|
|
1820
2166
|
end
|
1821
2167
|
|
1822
|
-
|
2168
|
+
remaining_file_contents,blocks = roll_blocks(javascript_file_contents,starting_locations)
|
1823
2169
|
|
1824
|
-
|
2170
|
+
joined_file_contents = ""
|
1825
2171
|
|
1826
|
-
|
2172
|
+
if !blocks.empty?
|
1827
2173
|
|
1828
|
-
|
2174
|
+
remaining_file_contents = remaining_file_contents.collect {|element| " " + element}
|
1829
2175
|
|
1830
|
-
|
2176
|
+
main_blocks = remaining_file_contents.reject {|element| !element.include?("--block")}
|
1831
2177
|
|
1832
|
-
|
2178
|
+
main_block_numbers = main_blocks.collect {|element| element.split("--block")[1]}
|
1833
2179
|
|
1834
|
-
|
2180
|
+
modified_blocks = main_blocks.dup
|
1835
2181
|
|
1836
|
-
|
2182
|
+
soft_tabs = " "
|
1837
2183
|
|
1838
|
-
|
2184
|
+
for x in (0...main_blocks.length)
|
1839
2185
|
|
1840
|
-
|
2186
|
+
soft_tabs_counter = 1
|
1841
2187
|
|
1842
|
-
|
2188
|
+
current_block = blocks[main_block_numbers[x].to_i]
|
1843
2189
|
|
1844
|
-
|
2190
|
+
current_block = [soft_tabs + current_block[0]] + current_block[1...-1] + [soft_tabs*(soft_tabs_counter)+current_block[-1]]
|
1845
2191
|
|
1846
|
-
|
2192
|
+
soft_tabs_counter += 1
|
1847
2193
|
|
1848
|
-
|
2194
|
+
current_block = [current_block[0]] + current_block[1...-1].collect {|element| soft_tabs*(soft_tabs_counter)+element} + [current_block[-1]]
|
1849
2195
|
|
1850
|
-
|
2196
|
+
nested_block = current_block.reject {|row| !row.include?("--block")}
|
1851
2197
|
|
1852
|
-
|
2198
|
+
nested_block = nested_block.collect {|element| element.split("--block")[1]}
|
1853
2199
|
|
1854
|
-
|
2200
|
+
nested_block = nested_block.collect {|element| element.rstrip.to_i}
|
2201
|
+
|
2202
|
+
modified_nested_block = nested_block.clone
|
2203
|
+
|
2204
|
+
current_block = current_block.join
|
2205
|
+
|
2206
|
+
until modified_nested_block.empty?
|
2207
|
+
|
2208
|
+
nested_block.each do |block_index|
|
2209
|
+
|
2210
|
+
nested_block_contents = blocks[block_index]
|
2211
|
+
|
2212
|
+
nested_block_contents = nested_block_contents[0...-1] + [soft_tabs*(soft_tabs_counter)+nested_block_contents[-1]]
|
2213
|
+
|
2214
|
+
soft_tabs_counter += 1
|
2215
|
+
|
2216
|
+
nested_block_contents = [nested_block_contents[0]] + nested_block_contents[1...-1].collect {|element| soft_tabs*(soft_tabs_counter)+element} + [nested_block_contents[-1]]
|
2217
|
+
|
2218
|
+
nested_block_contents = nested_block_contents.reject {|element| element.gsub(" ","").eql?("")}
|
2219
|
+
|
2220
|
+
current_block = current_block.sub("--block#{block_index}",nested_block_contents.join)
|
2221
|
+
|
2222
|
+
blocks[block_index] = nested_block_contents
|
2223
|
+
|
2224
|
+
modified_nested_block.delete_at(0)
|
2225
|
+
|
2226
|
+
soft_tabs_counter -= 1
|
2227
|
+
|
2228
|
+
end
|
2229
|
+
|
2230
|
+
current_block = convert_string_to_array(current_block,temporary_nila_file)
|
2231
|
+
|
2232
|
+
nested_block = current_block.reject {|element| !element.include?("--block")}
|
2233
|
+
|
2234
|
+
nested_block = nested_block.collect {|element| element.split("--block")[1]}
|
2235
|
+
|
2236
|
+
nested_block = nested_block.collect {|element| element.rstrip.to_i}
|
1855
2237
|
|
1856
|
-
|
2238
|
+
modified_nested_block = nested_block.clone
|
2239
|
+
|
2240
|
+
current_block = current_block.join
|
2241
|
+
|
2242
|
+
if !nested_block.empty?
|
2243
|
+
|
2244
|
+
soft_tabs_counter += 1
|
2245
|
+
|
2246
|
+
end
|
1857
2247
|
|
1858
2248
|
end
|
1859
2249
|
|
1860
|
-
|
2250
|
+
modified_blocks[x] = current_block
|
1861
2251
|
|
1862
2252
|
end
|
1863
2253
|
|
2254
|
+
|
2255
|
+
|
2256
|
+
remaining_file_contents = ["(function() {\n",remaining_file_contents,"\n}).call(this);"].flatten
|
2257
|
+
|
2258
|
+
joined_file_contents = remaining_file_contents.join
|
2259
|
+
|
2260
|
+
main_blocks.each_with_index do |block_id,index|
|
2261
|
+
|
2262
|
+
joined_file_contents = joined_file_contents.sub(block_id,modified_blocks[index])
|
2263
|
+
|
2264
|
+
end
|
2265
|
+
|
2266
|
+
else
|
2267
|
+
|
2268
|
+
remaining_file_contents = remaining_file_contents.collect {|element| " " + element}
|
2269
|
+
|
2270
|
+
remaining_file_contents = ["(function() {\n",remaining_file_contents,"\n}).call(this);"].flatten
|
2271
|
+
|
2272
|
+
joined_file_contents = remaining_file_contents.join
|
2273
|
+
|
1864
2274
|
end
|
1865
2275
|
|
2276
|
+
|
1866
2277
|
file_id = open(temporary_nila_file, 'w')
|
1867
2278
|
|
1868
|
-
file_id.write(
|
2279
|
+
file_id.write(joined_file_contents)
|
1869
2280
|
|
1870
2281
|
file_id.close()
|
1871
2282
|
|
@@ -1873,30 +2284,31 @@ def compile(input_file_path,*output_file_name)
|
|
1873
2284
|
|
1874
2285
|
line_by_line_contents = fix_newlines(line_by_line_contents)
|
1875
2286
|
|
2287
|
+
line_by_line_contents = fix_syntax_indentation(line_by_line_contents)
|
2288
|
+
|
1876
2289
|
return line_by_line_contents
|
1877
2290
|
|
1878
2291
|
end
|
1879
2292
|
|
1880
|
-
def
|
2293
|
+
def compile_operators(input_file_contents)
|
1881
2294
|
|
1882
|
-
|
2295
|
+
input_file_contents = input_file_contents.collect {|element| element.sub(" and "," && ")}
|
1883
2296
|
|
1884
|
-
|
2297
|
+
input_file_contents = input_file_contents.collect {|element| element.sub(" or "," || ")}
|
1885
2298
|
|
1886
|
-
|
2299
|
+
input_file_contents = input_file_contents.collect {|element| element.sub("==","===")}
|
1887
2300
|
|
1888
|
-
|
2301
|
+
input_file_contents = input_file_contents.collect {|element| element.sub("!=","!==")}
|
1889
2302
|
|
1890
|
-
|
2303
|
+
input_file_contents = input_file_contents.collect {|element| element.sub("elsuf","else if")}
|
1891
2304
|
|
1892
|
-
|
2305
|
+
return input_file_contents
|
1893
2306
|
|
1894
|
-
|
1895
|
-
# and prevents global variables from leaking.
|
2307
|
+
end
|
1896
2308
|
|
1897
|
-
|
2309
|
+
def pretty_print_nila(input_file_contents)
|
1898
2310
|
|
1899
|
-
|
2311
|
+
#Implementation is pending
|
1900
2312
|
|
1901
2313
|
end
|
1902
2314
|
|
@@ -1928,6 +2340,8 @@ def compile(input_file_path,*output_file_name)
|
|
1928
2340
|
|
1929
2341
|
file_contents = compile_interpolated_strings(file_contents)
|
1930
2342
|
|
2343
|
+
file_contents = compile_conditional_structures(file_contents,temp_file)
|
2344
|
+
|
1931
2345
|
file_contents = compile_arrays(file_contents)
|
1932
2346
|
|
1933
2347
|
file_contents = compile_default_values(file_contents,temp_file)
|
@@ -1940,8 +2354,6 @@ def compile(input_file_path,*output_file_name)
|
|
1940
2354
|
|
1941
2355
|
list_of_variables,file_contents = get_variables(file_contents,temp_file)
|
1942
2356
|
|
1943
|
-
file_contents = compile_conditional_structures(file_contents,temp_file)
|
1944
|
-
|
1945
2357
|
file_contents, function_names = compile_named_functions(file_contents,named_functions,nested_functions,temp_file)
|
1946
2358
|
|
1947
2359
|
file_contents, ruby_functions = compile_custom_function_map(file_contents)
|
@@ -1956,10 +2368,10 @@ def compile(input_file_path,*output_file_name)
|
|
1956
2368
|
|
1957
2369
|
file_contents = compile_comments(file_contents,comments,temp_file)
|
1958
2370
|
|
1959
|
-
file_contents = create_self_invoking_function(file_contents)
|
1960
|
-
|
1961
2371
|
file_contents = pretty_print_javascript(file_contents,temp_file)
|
1962
2372
|
|
2373
|
+
file_contents = compile_operators(file_contents)
|
2374
|
+
|
1963
2375
|
output_javascript(file_contents,output_js_file,temp_file)
|
1964
2376
|
|
1965
2377
|
puts "Compilation is successful!"
|
@@ -2026,7 +2438,7 @@ def find_file_path(input_path,file_extension)
|
|
2026
2438
|
|
2027
2439
|
end
|
2028
2440
|
|
2029
|
-
nilac_version = "0.0.4.
|
2441
|
+
nilac_version = "0.0.4.1"
|
2030
2442
|
|
2031
2443
|
opts = Slop.parse do
|
2032
2444
|
on :c, :compile=, 'Compile Nila File', as:Array, delimiter:":"
|