~ubuntu-branches/ubuntu/raring/vala-0.18/raring

« back to all changes in this revision

Viewing changes to vala/valageniescanner.vala

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2012-09-17 09:17:39 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20120917091739-xg3rrdvc3wmzsn9w
Tags: 0.17.7-0ubuntu1
* New upstream bugfix release
* debian/libvala-0.18-0.symbols:
  - Updated

Show diffs side-by-side

added added

removed removed

Lines of Context:
283
283
                state_stack = null;
284
284
        }
285
285
 
286
 
        TokenType get_identifier_or_keyword (char* begin, int len) {
 
286
        public static TokenType get_identifier_or_keyword (char* begin, int len) {
287
287
                switch (len) {
288
288
                case 2:
289
289
                        switch (begin[0]) {
538
538
                                break;
539
539
                        case 's':
540
540
                                switch (begin[1]) {
 
541
                                case 'e':
 
542
                                        if (matches (begin, "sealed")) return TokenType.SEALED;
 
543
                                        break;
541
544
                                case 'i':
542
545
                                        if (matches (begin, "sizeof")) return TokenType.SIZEOF;
543
546
                                        break;
736
739
                                                        break;
737
740
                                                }
738
741
                                        } else if (current[0] == '\n') {
739
 
                                                break;
 
742
                                                current++;
 
743
                                                line++;
 
744
                                                column = 1;
 
745
                                                token_length_in_chars = 1;
740
746
                                        } else {
741
747
                                                unichar u = ((string) current).get_char_validated ((long) (end - current));
742
748
                                                if (u != (unichar) (-1)) {
748
754
                                                }
749
755
                                        }
750
756
                                }
751
 
                                if (current >= end || current[0] == '\n') {
 
757
                                if (current >= end) {
752
758
                                        Report.error (get_source_reference (token_length_in_chars), "syntax error, expected \"");
753
759
                                        state_stack.length--;
754
760
                                        return read_token (out token_begin, out token_end);
817
823
                
818
824
                /* handle automatic line continuations (when inside parens or braces) */
819
825
                while (current < end && current[0] == '\n' && (open_parens_count > 0 || open_brace_count > 0)) {
820
 
                    current++;
 
826
                        current++;
821
827
                        line++;
822
828
                        skip_space_tabs ();
823
829
                }
941
947
                                }
942
948
                                type = TokenType.REAL_LITERAL;
943
949
                        } else if (current < end && current == begin + 1
944
 
                                   && begin[0] == '0' && begin[1] == 'x' && begin[2].isxdigit ()) {
 
950
                                           && begin[0] == '0' && begin[1] == 'x' && begin[2].isxdigit ()) {
945
951
                                // hexadecimal integer literal
946
952
                                current++;
947
953
                                while (current < end && current[0].isxdigit ()) {
1176
1182
                                case TokenType.COMMA:
1177
1183
                                case TokenType.MINUS:
1178
1184
                                case TokenType.OP_AND:
1179
 
                                case TokenType.OP_DEC:
1180
1185
                                case TokenType.OP_EQ:
1181
1186
                                case TokenType.OP_GE:
1182
1187
                                case TokenType.OP_GT:
1222
1227
                                        token_length_in_chars = 6;
1223
1228
                                        current += 3;
1224
1229
                                        while (current < end - 4) {
1225
 
                                                if (current[0] == '"' && current[1] == '"' && current[2] == '"') {
 
1230
                                                if (current[0] == '"' && current[1] == '"' && current[2] == '"' && current[3] != '"') {
1226
1231
                                                        break;
1227
1232
                                                } else if (current[0] == '\n') {
1228
1233
                                                        current++;
1285
1290
                                                        break;
1286
1291
                                                }
1287
1292
                                        } else if (current[0] == '\n') {
1288
 
                                                break;
 
1293
                                                current++;
 
1294
                                                line++;
 
1295
                                                column = 1;
 
1296
                                                token_length_in_chars = 1;
1289
1297
                                        } else {
1290
1298
                                                unichar u = ((string) current).get_char_validated ((long) (end - current));
1291
1299
                                                if (u != (unichar) (-1)) {
1296
1304
                                                        Report.error (get_source_reference (token_length_in_chars), "invalid UTF-8 character");
1297
1305
                                                }
1298
1306
                                        }
 
1307
                                        if (current < end && begin[0] == '\'' && current[0] != '\'') {
 
1308
                                                // multiple characters in single character literal
 
1309
                                                Report.error (get_source_reference (token_length_in_chars), "invalid character literal");
 
1310
                                        }
1299
1311
                                }
1300
 
                                if (current < end && current[0] != '\n') {
 
1312
                                if (current < end) {
1301
1313
                                        current++;
1302
1314
                                } else {
1303
1315
                                        Report.error (get_source_reference (token_length_in_chars), "syntax error, expected %c".printf (begin[0]));
1313
1325
                                        Report.error (get_source_reference (0), "invalid UTF-8 character");
1314
1326
                                }
1315
1327
                                column++;
1316
 
                                last_token = TokenType.STRING_LITERAL;
1317
1328
                                return read_token (out token_begin, out token_end);
1318
1329
                        }
1319
1330
                }
1363
1374
                return tab_count;
1364
1375
        }
1365
1376
 
1366
 
        bool matches (char* begin, string keyword) {
 
1377
        static bool matches (char* begin, string keyword) {
1367
1378
                char* keyword_array = (char *) keyword;
1368
1379
                long len = keyword.length;
1369
1380
                for (int i = 0; i < len; i++) {
1416
1427
        }
1417
1428
 
1418
1429
        bool comment (bool file_comment = false) {
1419
 
                if (current > end - 2
1420
 
                    || current[0] != '/'
1421
 
                    || (current[1] != '/' && current[1] != '*')) {
 
1430
                if (current == null
 
1431
                        || current > end - 2
 
1432
                        || current[0] != '/'
 
1433
                        || (current[1] != '/' && current[1] != '*')) {
1422
1434
                        return false;
1423
1435
                }
1424
1436
 
1457
1469
                                return false;
1458
1470
                        }
1459
1471
 
1460
 
            if (current[2] == '*' || file_comment) {
 
1472
                        if (current[2] == '*' || file_comment) {
1461
1473
                                source_reference = get_source_reference (0);
1462
1474
                        }
1463
1475
 
1465
1477
                        char* begin = current;
1466
1478
 
1467
1479
                        while (current < end - 1
1468
 
                               && (current[0] != '*' || current[1] != '/')) {
 
1480
                                   && (current[0] != '*' || current[1] != '/')) {
1469
1481
                                if (current[0] == '\n') {
1470
1482
                                        line++;
1471
1483
                                        column = 0;
1512
1524
                }
1513
1525
        }
1514
1526
 
1515
 
    public void parse_file_comments () {
 
1527
        public void parse_file_comments () {
1516
1528
                while (whitespace () || comment (true)) {
1517
1529
                }
1518
1530
                
1520
1532
 
1521
1533
        void push_comment (string comment_item, SourceReference source_reference, bool file_comment) {
1522
1534
                if (comment_item[0] == '*') {
 
1535
                        if (_comment != null) {
 
1536
                                // extra doc comment, add it to source file comments
 
1537
                                source_file.add_comment (_comment);
 
1538
                        }
1523
1539
                        _comment = new Comment (comment_item, source_reference);
1524
1540
                }
1525
1541
 
1554
1570
                return found;
1555
1571
        }
1556
1572
 
 
1573
        void pp_space () {
 
1574
                while (pp_whitespace () || comment ()) {
 
1575
                }
 
1576
        }
 
1577
 
1557
1578
        void pp_directive () {
1558
1579
                // hash sign
1559
1580
                current++;
1560
1581
                column++;
1561
1582
 
1562
 
                pp_whitespace ();
 
1583
                pp_space ();
1563
1584
 
1564
1585
                char* begin = current;
1565
1586
                int len = 0;
1582
1603
                }
1583
1604
 
1584
1605
                if (conditional_stack.length > 0
1585
 
                    && conditional_stack[conditional_stack.length - 1].skip_section) {
 
1606
                        && conditional_stack[conditional_stack.length - 1].skip_section) {
1586
1607
                        // skip lines until next preprocessing directive
1587
1608
                        bool bol = false;
1588
1609
                        while (current < end) {
1589
 
                                if (bol && current[0] == '#') {
 
1610
                                if (bol && current < end && current[0] == '#') {
1590
1611
                                        // go back to begin of line
1591
1612
                                        current -= (column - 1);
1592
1613
                                        column = 1;
1606
1627
        }
1607
1628
 
1608
1629
        void pp_eol () {
1609
 
                pp_whitespace ();
 
1630
                pp_space ();
1610
1631
                if (current >= end || current[0] != '\n') {
1611
1632
                        Report.error (get_source_reference (0), "syntax error, expected newline");
1612
1633
                }
1613
1634
        }
1614
1635
 
1615
1636
        void parse_pp_if () {
1616
 
                pp_whitespace ();
 
1637
                pp_space ();
1617
1638
 
1618
1639
                bool condition = parse_pp_expression ();
1619
1640
 
1631
1652
        }
1632
1653
 
1633
1654
        void parse_pp_elif () {
1634
 
                pp_whitespace ();
 
1655
                pp_space ();
1635
1656
 
1636
1657
                bool condition = parse_pp_expression ();
1637
1658
 
1643
1664
                }
1644
1665
 
1645
1666
                if (condition && !conditional_stack[conditional_stack.length - 1].matched
1646
 
                    && (conditional_stack.length == 1 || !conditional_stack[conditional_stack.length - 2].skip_section)) {
 
1667
                        && (conditional_stack.length == 1 || !conditional_stack[conditional_stack.length - 2].skip_section)) {
1647
1668
                        // condition true => process code within if
1648
1669
                        conditional_stack[conditional_stack.length - 1].matched = true;
1649
1670
                        conditional_stack[conditional_stack.length - 1].skip_section = false;
1662
1683
                }
1663
1684
 
1664
1685
                if (!conditional_stack[conditional_stack.length - 1].matched
1665
 
                    && (conditional_stack.length == 1 || !conditional_stack[conditional_stack.length - 2].skip_section)) {
 
1686
                        && (conditional_stack.length == 1 || !conditional_stack[conditional_stack.length - 2].skip_section)) {
1666
1687
                        // condition true => process code within if
1667
1688
                        conditional_stack[conditional_stack.length - 1].matched = true;
1668
1689
                        conditional_stack[conditional_stack.length - 1].skip_section = false;
1717
1738
                } else if (current[0] == '(') {
1718
1739
                        current++;
1719
1740
                        column++;
1720
 
                        pp_whitespace ();
 
1741
                        pp_space ();
1721
1742
                        bool result = parse_pp_expression ();
1722
 
                        pp_whitespace ();
 
1743
                        pp_space ();
1723
1744
                        if (current < end && current[0] ==  ')') {
1724
1745
                                current++;
1725
1746
                                column++;
1737
1758
                if (current < end && current[0] == '!') {
1738
1759
                        current++;
1739
1760
                        column++;
1740
 
                        pp_whitespace ();
 
1761
                        pp_space ();
1741
1762
                        return !parse_pp_unary_expression ();
1742
1763
                }
1743
1764
 
1746
1767
 
1747
1768
        bool parse_pp_equality_expression () {
1748
1769
                bool left = parse_pp_unary_expression ();
1749
 
                pp_whitespace ();
 
1770
                pp_space ();
1750
1771
                while (true) {
1751
1772
                        if (current < end - 1 && current[0] == '=' && current[1] == '=') {
1752
1773
                                current += 2;
1753
1774
                                column += 2;
1754
 
                                pp_whitespace ();
 
1775
                                pp_space ();
1755
1776
                                bool right = parse_pp_unary_expression ();
1756
1777
                                left = (left == right);
1757
1778
                        } else if (current < end - 1 && current[0] == '!' && current[1] == '=') {
1758
1779
                                current += 2;
1759
1780
                                column += 2;
1760
 
                                pp_whitespace ();
 
1781
                                pp_space ();
1761
1782
                                bool right = parse_pp_unary_expression ();
1762
1783
                                left = (left != right);
1763
1784
                        } else {
1769
1790
 
1770
1791
        bool parse_pp_and_expression () {
1771
1792
                bool left = parse_pp_equality_expression ();
1772
 
                pp_whitespace ();
 
1793
                pp_space ();
1773
1794
                while (current < end - 1 && current[0] == '&' && current[1] == '&') {
1774
1795
                        current += 2;
1775
1796
                        column += 2;
1776
 
                        pp_whitespace ();
 
1797
                        pp_space ();
1777
1798
                        bool right = parse_pp_equality_expression ();
1778
1799
                        left = left && right;
1779
1800
                }
1782
1803
 
1783
1804
        bool parse_pp_or_expression () {
1784
1805
                bool left = parse_pp_and_expression ();
1785
 
                pp_whitespace ();
 
1806
                pp_space ();
1786
1807
                while (current < end - 1 && current[0] == '|' && current[1] == '|') {
1787
1808
                        current += 2;
1788
1809
                        column += 2;
1789
 
                        pp_whitespace ();
 
1810
                        pp_space ();
1790
1811
                        bool right = parse_pp_and_expression ();
1791
1812
                        left = left || right;
1792
1813
                }