comparison src/luan/impl/LuanParser.java @ 1093:a656fa45e315

fix multiline statements
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 08 Jan 2017 21:13:45 -0700
parents 20d5968e65cc
children 5dc601c4ed6d
comparison
equal deleted inserted replaced
1092:a26fbde7ee28 1093:a656fa45e315
1353 Spaces(); 1353 Spaces();
1354 ExpList(in,builder); // optional 1354 ExpList(in,builder); // optional
1355 if( !parser.match(')') ) 1355 if( !parser.match(')') )
1356 throw parser.exception("Expression or ')' expected"); 1356 throw parser.exception("Expression or ')' expected");
1357 Spaces(); 1357 Spaces();
1358 parser.upSb();
1358 return parser.success(); 1359 return parser.success();
1359 } 1360 }
1360 Expr exp = TableExpr(); 1361 Expr exp = TableExpr();
1361 if( exp != null ) { 1362 if( exp != null ) {
1362 builder.add(exp); 1363 builder.add(exp);
1393 if( exp != null ) { 1394 if( exp != null ) {
1394 builder.add(exp); 1395 builder.add(exp);
1395 return parser.success(); 1396 return parser.success();
1396 } 1397 }
1397 exp = RequiredExpr(in); 1398 exp = RequiredExpr(in);
1398 exp.addNewLines(); 1399 exp.prependNewLines();
1399 builder.add(exp); 1400 builder.add(exp);
1400 } 1401 }
1401 return parser.success(); 1402 return parser.success();
1402 } 1403 }
1403 1404
1471 private boolean Keyword(String keyword) throws ParseException { 1472 private boolean Keyword(String keyword) throws ParseException {
1472 parser.begin(); 1473 parser.begin();
1473 if( !parser.match(keyword) || NameChar() ) 1474 if( !parser.match(keyword) || NameChar() )
1474 return parser.failure(); 1475 return parser.failure();
1475 Spaces(); 1476 Spaces();
1477 parser.upSb();
1476 return parser.success(); 1478 return parser.success();
1477 } 1479 }
1478 1480
1479 private static final Set<String> keywords = new HashSet<String>(Arrays.asList( 1481 private static final Set<String> keywords = new HashSet<String>(Arrays.asList(
1480 "and", 1482 "and",
1506 "while" 1508 "while"
1507 )); 1509 ));
1508 1510
1509 private Expr Literal() throws ParseException { 1511 private Expr Literal() throws ParseException {
1510 parser.begin(); 1512 parser.begin();
1513 Expr exp = new Expr(Val.SINGLE,false);
1511 if( NilLiteral() ) { 1514 if( NilLiteral() ) {
1512 Expr exp = new Expr(Val.SINGLE,false);
1513 exp.add( "null" ); 1515 exp.add( "null" );
1516 exp.addNewLines();
1514 return parser.success(exp); 1517 return parser.success(exp);
1515 } 1518 }
1516 Boolean b = BooleanLiteral(); 1519 Boolean b = BooleanLiteral();
1517 if( b != null ) { 1520 if( b != null ) {
1518 Expr exp = new Expr(Val.SINGLE,false);
1519 exp.add( b.toString() ); 1521 exp.add( b.toString() );
1522 exp.addNewLines();
1520 return parser.success(exp); 1523 return parser.success(exp);
1521 } 1524 }
1522 Number n = NumberLiteral(); 1525 Number n = NumberLiteral();
1523 if( n != null ) { 1526 if( n != null ) {
1524 String s = n.toString(); 1527 String s = n.toString();
1525 if( n instanceof Long ) 1528 if( n instanceof Long )
1526 s += "L"; 1529 s += "L";
1527 Expr exp = new Expr(Val.SINGLE,false);
1528 exp.add( s ); 1530 exp.add( s );
1531 exp.addNewLines();
1529 return parser.success(exp); 1532 return parser.success(exp);
1530 } 1533 }
1531 Expr s = StringLiteral(); 1534 Expr s = StringLiteral();
1532 if( s != null ) 1535 if( s != null )
1533 return parser.success(s); 1536 return parser.success(s);
1587 n = DecNumber(); 1590 n = DecNumber();
1588 } 1591 }
1589 if( n==null || NameChar() ) 1592 if( n==null || NameChar() )
1590 return parser.failure(null); 1593 return parser.failure(null);
1591 Spaces(); 1594 Spaces();
1595 parser.upSb();
1592 return parser.success(n); 1596 return parser.success(n);
1593 } 1597 }
1594 1598
1595 private Number DecNumber() { 1599 private Number DecNumber() {
1596 int start = parser.begin(); 1600 int start = parser.begin();
1694 && (s=QuotedString('\''))==null 1698 && (s=QuotedString('\''))==null
1695 && (s=LongString())==null 1699 && (s=LongString())==null
1696 ) 1700 )
1697 return null; 1701 return null;
1698 Spaces(); 1702 Spaces();
1703 s.addNewLines();
1699 return s; 1704 return s;
1700 } 1705 }
1701 1706
1702 private Expr LongString() throws ParseException { 1707 private Expr LongString() throws ParseException {
1703 parser.begin(); 1708 parser.begin();
1839 } 1844 }
1840 */ 1845 */
1841 } 1846 }
1842 } 1847 }
1843 1848
1849 void prependNewLines() {
1850 if( parser.sb().length() > 0 ) {
1851 add( 0, parser.sb().toString() );
1852 parser.sb().setLength(0);
1853 }
1854 }
1855
1844 ParseList() { 1856 ParseList() {
1845 addNewLines(); 1857 addNewLines();
1846 } 1858 }
1847 1859
1848 @Override public boolean add(Object obj) { 1860 @Override public boolean add(Object obj) {