iv-phonic 0.0.3 → 0.0.5
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/Manifest.txt +2 -3
- data/Rakefile +1 -1
- data/ext/include/iv/alloc.h +11 -4
- data/ext/include/iv/ast-factory.h +15 -6
- data/ext/include/iv/ast-fwd.h +2 -0
- data/ext/include/iv/ast-info.h +21 -0
- data/ext/include/iv/ast-serializer.h +6 -0
- data/ext/include/iv/ast-visitor.h +1 -0
- data/ext/include/iv/ast.h +522 -105
- data/ext/include/iv/conversions.h +79 -11
- data/ext/include/iv/keyword.h +460 -0
- data/ext/include/iv/lexer.h +77 -464
- data/ext/include/iv/location.h +6 -0
- data/ext/include/iv/parser.h +100 -43
- data/ext/include/iv/token.h +2 -0
- data/ext/iv/phonic/ast-fwd.h +17 -1
- data/ext/iv/phonic/creator.h +8 -0
- data/ext/iv/phonic/factory.h +10 -1
- data/ext/iv/phonic/parser.h +2 -1
- data/ext/iv/phonic/rparser.h +3 -4
- data/ext/iv/phonic/source.h +4 -5
- metadata +5 -6
- data/ext/include/iv/source.h +0 -27
- data/ext/iv/phonic/ast.h +0 -10
- data/ext/iv/phonic/rnode.h +0 -15
data/ext/include/iv/location.h
CHANGED
@@ -15,6 +15,12 @@ struct Location {
|
|
15
15
|
inline std::size_t end_position() const {
|
16
16
|
return end_position_;
|
17
17
|
}
|
18
|
+
inline void set_begin_position(std::size_t begin) {
|
19
|
+
begin_position_ = begin;
|
20
|
+
}
|
21
|
+
inline void set_end_position(std::size_t end) {
|
22
|
+
end_position_ = end;
|
23
|
+
}
|
18
24
|
};
|
19
25
|
|
20
26
|
IV_STATIC_ASSERT(std::tr1::is_pod<Location>::value);
|
data/ext/include/iv/parser.h
CHANGED
@@ -9,10 +9,10 @@
|
|
9
9
|
#include "static_assert.h"
|
10
10
|
#include "ast.h"
|
11
11
|
#include "ast-factory.h"
|
12
|
-
#include "source.h"
|
13
12
|
#include "lexer.h"
|
14
13
|
#include "noncopyable.h"
|
15
14
|
#include "utils.h"
|
15
|
+
#include "ustring.h"
|
16
16
|
#include "none.h"
|
17
17
|
|
18
18
|
#define IS(token)\
|
@@ -42,6 +42,15 @@
|
|
42
42
|
} while (0)
|
43
43
|
|
44
44
|
#define RAISE(str)\
|
45
|
+
do {\
|
46
|
+
*res = false;\
|
47
|
+
error_state_ |= kNotRecoverable;\
|
48
|
+
SetErrorHeader(lexer_.line_number());\
|
49
|
+
error_.append(str);\
|
50
|
+
return NULL;\
|
51
|
+
} while (0)
|
52
|
+
|
53
|
+
#define RAISE_RECOVERVABLE(str)\
|
45
54
|
do {\
|
46
55
|
*res = false;\
|
47
56
|
SetErrorHeader(lexer_.line_number());\
|
@@ -52,6 +61,7 @@
|
|
52
61
|
#define RAISE_WITH_NUMBER(str, line)\
|
53
62
|
do {\
|
54
63
|
*res = false;\
|
64
|
+
error_state_ |= kNotRecoverable;\
|
55
65
|
SetErrorHeader(line);\
|
56
66
|
error_.append(str);\
|
57
67
|
return NULL;\
|
@@ -124,11 +134,12 @@ const UString ParserData<T>::kSet(
|
|
124
134
|
|
125
135
|
typedef detail::ParserData<None> ParserData;
|
126
136
|
|
127
|
-
template<typename Factory>
|
128
|
-
class Parser : private Noncopyable<Parser<Factory> >::type {
|
137
|
+
template<typename Factory, typename Source>
|
138
|
+
class Parser : private Noncopyable<Parser<Factory, Source> >::type {
|
129
139
|
public:
|
130
|
-
typedef Parser<Factory> this_type;
|
131
|
-
typedef Parser<Factory> parser_type;
|
140
|
+
typedef Parser<Factory, Source> this_type;
|
141
|
+
typedef Parser<Factory, Source> parser_type;
|
142
|
+
typedef Lexer<Source> lexer_type;
|
132
143
|
#define V(AST) typedef typename ast::AST<Factory> AST;
|
133
144
|
AST_NODE_LIST(V)
|
134
145
|
#undef V
|
@@ -138,6 +149,11 @@ class Parser : private Noncopyable<Parser<Factory> >::type {
|
|
138
149
|
#define V(S) typedef typename SpaceUString<Factory>::type S;
|
139
150
|
AST_STRING(V)
|
140
151
|
#undef V
|
152
|
+
|
153
|
+
enum ErrorState {
|
154
|
+
kNotRecoverable = 1
|
155
|
+
};
|
156
|
+
|
141
157
|
class Target : private Noncopyable<Target>::type {
|
142
158
|
public:
|
143
159
|
typedef typename SpaceVector<Factory, Identifier*>::type Identifiers;
|
@@ -174,7 +190,9 @@ class Parser : private Noncopyable<Parser<Factory> >::type {
|
|
174
190
|
return !IsAnonymous();
|
175
191
|
}
|
176
192
|
inline BreakableStatement** node() {
|
177
|
-
|
193
|
+
if (!node_) {
|
194
|
+
node_ = parser_->factory()->template NewPtr<BreakableStatement>();
|
195
|
+
}
|
178
196
|
return node_;
|
179
197
|
}
|
180
198
|
inline Identifiers* labels() const {
|
@@ -193,10 +211,30 @@ class Parser : private Noncopyable<Parser<Factory> >::type {
|
|
193
211
|
int type_;
|
194
212
|
};
|
195
213
|
|
196
|
-
|
214
|
+
class TargetScope : private Noncopyable<Target>::type {
|
215
|
+
public:
|
216
|
+
TargetScope(parser_type* parser)
|
217
|
+
: parser_(parser),
|
218
|
+
target_(parser->target()),
|
219
|
+
labels_(parser->labels()) {
|
220
|
+
parser_->set_target(NULL);
|
221
|
+
parser_->set_labels(NULL);
|
222
|
+
}
|
223
|
+
~TargetScope() {
|
224
|
+
parser_->set_target(target_);
|
225
|
+
parser_->set_labels(labels_);
|
226
|
+
}
|
227
|
+
private:
|
228
|
+
parser_type* parser_;
|
229
|
+
Target* target_;
|
230
|
+
Identifiers* labels_;
|
231
|
+
};
|
232
|
+
|
233
|
+
Parser(Factory* space, const Source* source)
|
197
234
|
: lexer_(source),
|
198
235
|
error_(),
|
199
236
|
strict_(false),
|
237
|
+
error_state_(0),
|
200
238
|
factory_(space),
|
201
239
|
scope_(NULL),
|
202
240
|
target_(NULL),
|
@@ -206,8 +244,9 @@ class Parser : private Noncopyable<Parser<Factory> >::type {
|
|
206
244
|
// Program
|
207
245
|
// : SourceElements
|
208
246
|
FunctionLiteral* ParseProgram() {
|
209
|
-
FunctionLiteral* global = factory_->NewFunctionLiteral(
|
247
|
+
FunctionLiteral* const global = factory_->NewFunctionLiteral(
|
210
248
|
FunctionLiteral::GLOBAL);
|
249
|
+
global->set_strict(strict_);
|
211
250
|
assert(target_ == NULL);
|
212
251
|
bool error_flag = true;
|
213
252
|
bool *res = &error_flag;
|
@@ -402,7 +441,7 @@ class Parser : private Noncopyable<Parser<Factory> >::type {
|
|
402
441
|
FunctionLiteral::GENERAL, CHECK);
|
403
442
|
// define named function as FunctionDeclaration
|
404
443
|
scope_->AddFunctionDeclaration(expr);
|
405
|
-
return factory_->
|
444
|
+
return factory_->NewFunctionDeclaration(expr);
|
406
445
|
}
|
407
446
|
|
408
447
|
// Block
|
@@ -552,7 +591,14 @@ class Parser : private Noncopyable<Parser<Factory> >::type {
|
|
552
591
|
|
553
592
|
EXPECT(Token::RPAREN);
|
554
593
|
|
555
|
-
|
594
|
+
// ex:
|
595
|
+
// do {
|
596
|
+
// print("valid syntax");
|
597
|
+
// } while (0) return true;
|
598
|
+
// is syntax valid
|
599
|
+
if (token_ == Token::SEMICOLON) {
|
600
|
+
Next();
|
601
|
+
}
|
556
602
|
DoWhileStatement* const dowhile = factory_->NewDoWhileStatement(stmt, expr);
|
557
603
|
target.set_node(dowhile);
|
558
604
|
return dowhile;
|
@@ -845,6 +891,7 @@ class Parser : private Noncopyable<Parser<Factory> >::type {
|
|
845
891
|
Next();
|
846
892
|
// Throw requires Expression
|
847
893
|
if (lexer_.has_line_terminator_before_next()) {
|
894
|
+
// TODO(Constellation) more refined parse error system
|
848
895
|
RAISE("missing expression between throw and newline");
|
849
896
|
}
|
850
897
|
Expression* const expr = ParseExpression(true, CHECK);
|
@@ -1410,7 +1457,7 @@ class Parser : private Noncopyable<Parser<Factory> >::type {
|
|
1410
1457
|
// | MemberExpression '[' Expression ']'
|
1411
1458
|
// | NEW MemberExpression Arguments
|
1412
1459
|
Expression* ParseMemberExpression(bool allow_call, bool *res) {
|
1413
|
-
Expression
|
1460
|
+
Expression* expr;
|
1414
1461
|
if (token_ != Token::NEW) {
|
1415
1462
|
if (token_ == Token::FUNCTION) {
|
1416
1463
|
// FunctionExpression
|
@@ -1421,8 +1468,8 @@ class Parser : private Noncopyable<Parser<Factory> >::type {
|
|
1421
1468
|
}
|
1422
1469
|
} else {
|
1423
1470
|
Next();
|
1424
|
-
Expression
|
1425
|
-
ConstructorCall
|
1471
|
+
Expression* const target = ParseMemberExpression(false, CHECK);
|
1472
|
+
ConstructorCall* const con = factory_->NewConstructorCall(target);
|
1426
1473
|
if (token_ == Token::LPAREN) {
|
1427
1474
|
ParseArguments(con, CHECK);
|
1428
1475
|
}
|
@@ -1432,14 +1479,14 @@ class Parser : private Noncopyable<Parser<Factory> >::type {
|
|
1432
1479
|
switch (token_) {
|
1433
1480
|
case Token::LBRACK: {
|
1434
1481
|
Next();
|
1435
|
-
Expression* index = ParseExpression(true, CHECK);
|
1482
|
+
Expression* const index = ParseExpression(true, CHECK);
|
1436
1483
|
expr = factory_->NewIndexAccess(expr, index);
|
1437
1484
|
EXPECT(Token::RBRACK);
|
1438
1485
|
break;
|
1439
1486
|
}
|
1440
1487
|
|
1441
1488
|
case Token::PERIOD: {
|
1442
|
-
Next(
|
1489
|
+
Next<IgnoreReservedWords>(); // IDENTIFIERNAME
|
1443
1490
|
IS(Token::IDENTIFIER);
|
1444
1491
|
Identifier* const ident = ParseIdentifier(lexer_.Buffer());
|
1445
1492
|
expr = factory_->NewIdentifierAccess(expr, ident);
|
@@ -1507,7 +1554,7 @@ class Parser : private Noncopyable<Parser<Factory> >::type {
|
|
1507
1554
|
case Token::NUMBER:
|
1508
1555
|
// section 7.8.3
|
1509
1556
|
// strict mode forbids Octal Digits Literal
|
1510
|
-
if (strict_ && lexer_.NumericType() ==
|
1557
|
+
if (strict_ && lexer_.NumericType() == lexer_type::OCTAL) {
|
1511
1558
|
RAISE("octal integer literal not allowed in strict code");
|
1512
1559
|
}
|
1513
1560
|
result = factory_->NewNumberLiteral(lexer_.Numeric());
|
@@ -1515,11 +1562,11 @@ class Parser : private Noncopyable<Parser<Factory> >::type {
|
|
1515
1562
|
break;
|
1516
1563
|
|
1517
1564
|
case Token::STRING: {
|
1518
|
-
const
|
1519
|
-
if (strict_ && state ==
|
1565
|
+
const typename lexer_type::State state = lexer_.StringEscapeType();
|
1566
|
+
if (strict_ && state == lexer_type::OCTAL) {
|
1520
1567
|
RAISE("octal excape sequence not allowed in strict code");
|
1521
1568
|
}
|
1522
|
-
if (state ==
|
1569
|
+
if (state == lexer_type::NONE) {
|
1523
1570
|
result = factory_->NewDirectivable(lexer_.Buffer());
|
1524
1571
|
} else {
|
1525
1572
|
result = factory_->NewStringLiteral(lexer_.Buffer());
|
@@ -1551,7 +1598,7 @@ class Parser : private Noncopyable<Parser<Factory> >::type {
|
|
1551
1598
|
break;
|
1552
1599
|
|
1553
1600
|
default:
|
1554
|
-
|
1601
|
+
UNEXPECT(token_);
|
1555
1602
|
break;
|
1556
1603
|
}
|
1557
1604
|
return result;
|
@@ -1564,11 +1611,11 @@ class Parser : private Noncopyable<Parser<Factory> >::type {
|
|
1564
1611
|
// ArgumentList
|
1565
1612
|
// : AssignmentExpression
|
1566
1613
|
// | ArgumentList ',' AssignmentExpression
|
1567
|
-
|
1568
|
-
|
1614
|
+
template<typename Callable>
|
1615
|
+
Callable* ParseArguments(Callable* func, bool *res) {
|
1569
1616
|
Next();
|
1570
1617
|
while (token_ != Token::RPAREN) {
|
1571
|
-
expr = ParseAssignmentExpression(true, CHECK);
|
1618
|
+
Expression* const expr = ParseAssignmentExpression(true, CHECK);
|
1572
1619
|
func->AddArgument(expr);
|
1573
1620
|
if (token_ != Token::RPAREN) {
|
1574
1621
|
EXPECT(Token::COMMA);
|
@@ -1580,15 +1627,14 @@ class Parser : private Noncopyable<Parser<Factory> >::type {
|
|
1580
1627
|
|
1581
1628
|
Expression* ParseRegExpLiteral(bool contains_eq, bool *res) {
|
1582
1629
|
if (lexer_.ScanRegExpLiteral(contains_eq)) {
|
1583
|
-
RegExpLiteral* expr;
|
1584
1630
|
const std::vector<uc16> content(lexer_.Buffer());
|
1585
1631
|
if (!lexer_.ScanRegExpFlags()) {
|
1586
1632
|
RAISE("invalid regular expression flag");
|
1587
|
-
}
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1633
|
+
}
|
1634
|
+
RegExpLiteral* const expr =
|
1635
|
+
factory_->NewRegExpLiteral(content, lexer_.Buffer());
|
1636
|
+
if (!expr) {
|
1637
|
+
RAISE("invalid regular expression");
|
1592
1638
|
}
|
1593
1639
|
Next();
|
1594
1640
|
return expr;
|
@@ -1662,12 +1708,12 @@ class Parser : private Noncopyable<Parser<Factory> >::type {
|
|
1662
1708
|
Identifier* ident;
|
1663
1709
|
|
1664
1710
|
// IDENTIFIERNAME
|
1665
|
-
Next(
|
1711
|
+
Next<IgnoreReservedWordsAndIdentifyGetterOrSetter>();
|
1666
1712
|
while (token_ != Token::RBRACE) {
|
1667
1713
|
if (token_ == Token::GET || token_ == Token::SET) {
|
1668
1714
|
const bool is_get = token_ == Token::GET;
|
1669
1715
|
// this is getter or setter or usual prop
|
1670
|
-
Next(
|
1716
|
+
Next<IgnoreReservedWords>(); // IDENTIFIERNAME
|
1671
1717
|
if (token_ == Token::COLON) {
|
1672
1718
|
// property
|
1673
1719
|
ident = ParseIdentifier(
|
@@ -1720,13 +1766,17 @@ class Parser : private Noncopyable<Parser<Factory> >::type {
|
|
1720
1766
|
it->second |= type;
|
1721
1767
|
}
|
1722
1768
|
} else {
|
1723
|
-
|
1769
|
+
RAISE_RECOVERVABLE("invalid property name");
|
1724
1770
|
}
|
1725
1771
|
}
|
1726
1772
|
} else if (token_ == Token::IDENTIFIER ||
|
1727
1773
|
token_ == Token::STRING ||
|
1728
1774
|
token_ == Token::NUMBER) {
|
1729
|
-
|
1775
|
+
if (token_ == Token::NUMBER) {
|
1776
|
+
ident = ParseIdentifier(lexer_.Buffer8());
|
1777
|
+
} else {
|
1778
|
+
ident = ParseIdentifier(lexer_.Buffer());
|
1779
|
+
}
|
1730
1780
|
EXPECT(Token::COLON);
|
1731
1781
|
expr = ParseAssignmentExpression(true, CHECK);
|
1732
1782
|
object->AddDataProperty(ident, expr);
|
@@ -1745,13 +1795,13 @@ class Parser : private Noncopyable<Parser<Factory> >::type {
|
|
1745
1795
|
}
|
1746
1796
|
}
|
1747
1797
|
} else {
|
1748
|
-
|
1798
|
+
RAISE_RECOVERVABLE("invalid property name");
|
1749
1799
|
}
|
1750
1800
|
|
1751
1801
|
if (token_ != Token::RBRACE) {
|
1752
1802
|
IS(Token::COMMA);
|
1753
1803
|
// IDENTIFIERNAME
|
1754
|
-
Next(
|
1804
|
+
Next<IgnoreReservedWordsAndIdentifyGetterOrSetter>();
|
1755
1805
|
}
|
1756
1806
|
}
|
1757
1807
|
Next();
|
@@ -1797,7 +1847,8 @@ class Parser : private Noncopyable<Parser<Factory> >::type {
|
|
1797
1847
|
}
|
1798
1848
|
|
1799
1849
|
const ScopeSwitcher switcher(this, literal->scope());
|
1800
|
-
|
1850
|
+
const TargetScope scope(this);
|
1851
|
+
literal->set_start_position(lexer_.begin_position());
|
1801
1852
|
|
1802
1853
|
// '(' FormalParameterList_opt ')'
|
1803
1854
|
EXPECT(Token::LPAREN);
|
@@ -1886,8 +1937,7 @@ class Parser : private Noncopyable<Parser<Factory> >::type {
|
|
1886
1937
|
break;
|
1887
1938
|
}
|
1888
1939
|
}
|
1889
|
-
literal->set_end_position(lexer_.
|
1890
|
-
literal->SubStringSource(lexer_.source());
|
1940
|
+
literal->set_end_position(lexer_.end_position());
|
1891
1941
|
Next();
|
1892
1942
|
return literal;
|
1893
1943
|
}
|
@@ -2028,12 +2078,15 @@ class Parser : private Noncopyable<Parser<Factory> >::type {
|
|
2028
2078
|
UNEXPECT(token_);
|
2029
2079
|
}
|
2030
2080
|
|
2031
|
-
inline
|
2081
|
+
inline lexer_type& lexer() {
|
2032
2082
|
return lexer_;
|
2033
2083
|
}
|
2034
|
-
|
2035
|
-
|
2036
|
-
|
2084
|
+
template<typename LexType>
|
2085
|
+
inline Token::Type Next() {
|
2086
|
+
return token_ = lexer_.Next<LexType>(strict_);
|
2087
|
+
}
|
2088
|
+
inline Token::Type Next() {
|
2089
|
+
return token_ = lexer_.Next<IdentifyReservedWords>(strict_);
|
2037
2090
|
}
|
2038
2091
|
inline Token::Type Peek() const {
|
2039
2092
|
return token_;
|
@@ -2068,6 +2121,9 @@ class Parser : private Noncopyable<Parser<Factory> >::type {
|
|
2068
2121
|
inline void set_strict(bool strict) {
|
2069
2122
|
strict_ = strict;
|
2070
2123
|
}
|
2124
|
+
inline bool RecoverableError() const {
|
2125
|
+
return (!(error_state_ & kNotRecoverable)) && token_ == Token::EOS;
|
2126
|
+
}
|
2071
2127
|
|
2072
2128
|
protected:
|
2073
2129
|
class ScopeSwitcher : private Noncopyable<ScopeSwitcher>::type {
|
@@ -2137,10 +2193,11 @@ class Parser : private Noncopyable<Parser<Factory> >::type {
|
|
2137
2193
|
}
|
2138
2194
|
}
|
2139
2195
|
|
2140
|
-
|
2196
|
+
lexer_type lexer_;
|
2141
2197
|
Token::Type token_;
|
2142
2198
|
std::string error_;
|
2143
2199
|
bool strict_;
|
2200
|
+
int error_state_;
|
2144
2201
|
Factory* factory_;
|
2145
2202
|
Scope* scope_;
|
2146
2203
|
Target* target_;
|
data/ext/include/iv/token.h
CHANGED
@@ -83,6 +83,7 @@ class Token {
|
|
83
83
|
ASSIGN_SHL, // <<=
|
84
84
|
ASSIGN_BIT_AND, // &=
|
85
85
|
ASSIGN_BIT_OR, // |=
|
86
|
+
ASSIGN_BIT_XOR, // ^=
|
86
87
|
ASSIGN_LAST, // ASSIGN OP LAST
|
87
88
|
|
88
89
|
DELETE, // delete
|
@@ -237,6 +238,7 @@ const char* TokenContents<T>::kContents[Token::NUM_TOKENS] = {
|
|
237
238
|
"<<=",
|
238
239
|
"&=",
|
239
240
|
"|=",
|
241
|
+
"~=",
|
240
242
|
NULL, // ASSIGN OP LAST
|
241
243
|
"delete",
|
242
244
|
"typeof",
|
data/ext/iv/phonic/ast-fwd.h
CHANGED
@@ -4,8 +4,24 @@
|
|
4
4
|
#include <iv/ast.h>
|
5
5
|
namespace iv {
|
6
6
|
namespace phonic {
|
7
|
-
|
8
7
|
class AstFactory;
|
8
|
+
} // namespace iv::phonic
|
9
|
+
namespace core {
|
10
|
+
namespace ast {
|
11
|
+
template<>
|
12
|
+
class AstNodeBase<iv::phonic::AstFactory>
|
13
|
+
: public Inherit<iv::phonic::AstFactory, kAstNode> {
|
14
|
+
public:
|
15
|
+
void Location(std::size_t begin, std::size_t end) {
|
16
|
+
begin_ = begin;
|
17
|
+
end_ = end;
|
18
|
+
}
|
19
|
+
private:
|
20
|
+
std::size_t begin_;
|
21
|
+
std::size_t end_;
|
22
|
+
};
|
23
|
+
} } // namespace iv::core::ast
|
24
|
+
namespace phonic {
|
9
25
|
#define V(AST) typedef core::ast::AST<AstFactory> AST;
|
10
26
|
AST_NODE_LIST(V)
|
11
27
|
#undef V
|
data/ext/iv/phonic/creator.h
CHANGED
@@ -45,6 +45,14 @@ class Creator : public iv::core::ast::AstVisitor<AstFactory>::const_type {
|
|
45
45
|
ret_ = hash;
|
46
46
|
}
|
47
47
|
|
48
|
+
void Visit(const FunctionDeclaration* decl) {
|
49
|
+
VALUE hash = rb_hash_new();
|
50
|
+
rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("FunctionDeclaration"));
|
51
|
+
Visit(decl->function());
|
52
|
+
rb_hash_aset(hash, SYM("body"), ret_);
|
53
|
+
ret_ = hash;
|
54
|
+
}
|
55
|
+
|
48
56
|
void Visit(const VariableStatement* stmt) {
|
49
57
|
VALUE hash = rb_hash_new();
|
50
58
|
rb_hash_aset(hash, SYM("type"), rb_str_new_cstr("VariableStatement"));
|
data/ext/iv/phonic/factory.h
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
#include <iv/alloc.h>
|
7
7
|
#include <iv/ustringpiece.h>
|
8
8
|
#include "encoding.h"
|
9
|
-
#include "ast.h"
|
9
|
+
#include "ast-fwd.h"
|
10
10
|
namespace iv {
|
11
11
|
namespace phonic {
|
12
12
|
|
@@ -77,6 +77,11 @@ class AstFactory : public core::Space<2> {
|
|
77
77
|
Identifiers(Identifiers::allocator_type(this));
|
78
78
|
}
|
79
79
|
|
80
|
+
template<typename T>
|
81
|
+
T** NewPtr() {
|
82
|
+
return new (New(sizeof(T*))) T*;
|
83
|
+
}
|
84
|
+
|
80
85
|
NullLiteral* NewNullLiteral() {
|
81
86
|
return null_instance_;
|
82
87
|
}
|
@@ -109,6 +114,10 @@ class AstFactory : public core::Space<2> {
|
|
109
114
|
return new (this) FunctionStatement(func);
|
110
115
|
}
|
111
116
|
|
117
|
+
FunctionDeclaration* NewFunctionDeclaration(FunctionLiteral* func) {
|
118
|
+
return new (this) FunctionDeclaration(func);
|
119
|
+
}
|
120
|
+
|
112
121
|
Block* NewBlock() {
|
113
122
|
return new (this) Block(this);
|
114
123
|
}
|
data/ext/iv/phonic/parser.h
CHANGED
@@ -3,10 +3,11 @@
|
|
3
3
|
#include <ruby.h>
|
4
4
|
#include <iv/parser.h>
|
5
5
|
#include "factory.h"
|
6
|
+
#include "source.h"
|
6
7
|
namespace iv {
|
7
8
|
namespace phonic {
|
8
9
|
|
9
|
-
typedef core::Parser<AstFactory> Parser;
|
10
|
+
typedef core::Parser<AstFactory, UTF16Source> Parser;
|
10
11
|
|
11
12
|
} } // namespace iv::phonic
|
12
13
|
#endif // _IV_PHONIC_PARSER_H_
|
data/ext/iv/phonic/rparser.h
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
#define _IV_PHONIC_RPARSER_H_
|
3
3
|
#include <cstdlib>
|
4
4
|
#include <cstring>
|
5
|
-
#include <tr1/type_traits>
|
6
5
|
#include <ruby.h>
|
7
6
|
#include <ruby/encoding.h>
|
8
7
|
#include <ruby/intern.h>
|
@@ -27,10 +26,10 @@ class RParser {
|
|
27
26
|
0,
|
28
27
|
Qnil);
|
29
28
|
const char* str = StringValuePtr(encoded_rb_str);
|
30
|
-
std::size_t len = RSTRING_LEN(encoded_rb_str);
|
29
|
+
const std::size_t len = RSTRING_LEN(encoded_rb_str);
|
31
30
|
UTF16Source source(str, len);
|
32
|
-
Parser parser(&
|
33
|
-
FunctionLiteral* global = parser.ParseProgram();
|
31
|
+
Parser parser(&factory, &source);
|
32
|
+
const FunctionLiteral* global = parser.ParseProgram();
|
34
33
|
if (!global) {
|
35
34
|
rb_raise(cParseError, "%s", parser.error().c_str());
|
36
35
|
} else {
|
data/ext/iv/phonic/source.h
CHANGED
@@ -5,7 +5,6 @@
|
|
5
5
|
#include <string>
|
6
6
|
#include <tr1/cstdint>
|
7
7
|
#include <ruby.h>
|
8
|
-
#include <iv/source.h>
|
9
8
|
#include <iv/stringpiece.h>
|
10
9
|
#include <iv/ustring.h>
|
11
10
|
#include <iv/none.h>
|
@@ -25,7 +24,7 @@ const std::string FilenameData<T>::kFilename = "<anonymous>";
|
|
25
24
|
|
26
25
|
typedef detail::FilenameData<core::None> FilenameData;
|
27
26
|
|
28
|
-
class AsciiSource
|
27
|
+
class AsciiSource {
|
29
28
|
public:
|
30
29
|
static const int kEOS = -1;
|
31
30
|
explicit AsciiSource(const char* str)
|
@@ -52,7 +51,7 @@ class AsciiSource : public core::BasicSource {
|
|
52
51
|
std::string source_;
|
53
52
|
};
|
54
53
|
|
55
|
-
class UTF16Source
|
54
|
+
class UTF16Source {
|
56
55
|
public:
|
57
56
|
static const int kEOS = -1;
|
58
57
|
explicit UTF16Source(const char* str, std::size_t len)
|
@@ -82,7 +81,7 @@ class UTF16Source : public core::BasicSource {
|
|
82
81
|
std::size_t size_;
|
83
82
|
};
|
84
83
|
|
85
|
-
class UTF16LESource
|
84
|
+
class UTF16LESource {
|
86
85
|
public:
|
87
86
|
static const int kEOS = -1;
|
88
87
|
explicit UTF16LESource(const char* str, std::size_t len)
|
@@ -112,7 +111,7 @@ class UTF16LESource : public core::BasicSource {
|
|
112
111
|
std::size_t size_;
|
113
112
|
};
|
114
113
|
|
115
|
-
class UTF16BESource
|
114
|
+
class UTF16BESource {
|
116
115
|
public:
|
117
116
|
static const int kEOS = -1;
|
118
117
|
explicit UTF16BESource(const char* str, std::size_t len)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 5
|
9
|
+
version: 0.0.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Constellation
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-11-
|
17
|
+
date: 2010-11-28 00:00:00 +09:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -93,8 +93,8 @@ files:
|
|
93
93
|
- ext/include/iv/ast-visitor.h
|
94
94
|
- ext/include/iv/token.h
|
95
95
|
- ext/include/iv/enable_if.h
|
96
|
-
- ext/include/iv/source.h
|
97
96
|
- ext/include/iv/any.h
|
97
|
+
- ext/include/iv/keyword.h
|
98
98
|
- ext/include/iv/cmdline.h
|
99
99
|
- ext/include/iv/xorshift.h
|
100
100
|
- ext/include/iv/location.h
|
@@ -103,14 +103,13 @@ files:
|
|
103
103
|
- ext/include/iv/ustring.h
|
104
104
|
- ext/include/iv/ast-fwd.h
|
105
105
|
- ext/include/iv/utils.h
|
106
|
+
- ext/include/iv/ast-info.h
|
106
107
|
- ext/include/iv/alloc.h
|
107
108
|
- ext/include/iv/chars.h
|
108
109
|
- ext/include/iv/fixedcontainer.h
|
109
110
|
- ext/include/iv/ustringpiece.h
|
110
111
|
- ext/include/iv/ast-serializer.h
|
111
112
|
- ext/include/iv/ucdata.h
|
112
|
-
- ext/iv/phonic/rnode.h
|
113
|
-
- ext/iv/phonic/ast.h
|
114
113
|
- ext/iv/phonic/factory.h
|
115
114
|
- ext/iv/phonic/parser.h
|
116
115
|
- ext/iv/phonic/encoding.h
|
data/ext/include/iv/source.h
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
#ifndef _IV_SOURCE_H_
|
2
|
-
#define _IV_SOURCE_H_
|
3
|
-
#include <cstddef>
|
4
|
-
#include <cassert>
|
5
|
-
#include <string>
|
6
|
-
#include "ustring.h"
|
7
|
-
#include "ustringpiece.h"
|
8
|
-
|
9
|
-
namespace iv {
|
10
|
-
namespace core {
|
11
|
-
|
12
|
-
class BasicSource {
|
13
|
-
public:
|
14
|
-
static const int kEOS = -1;
|
15
|
-
virtual ~BasicSource() = 0;
|
16
|
-
|
17
|
-
virtual uc16 Get(std::size_t pos) const = 0;
|
18
|
-
virtual std::size_t size() const = 0;
|
19
|
-
virtual const std::string& filename() const = 0;
|
20
|
-
virtual UStringPiece SubString(std::size_t n,
|
21
|
-
std::size_t len = std::string::npos) const = 0;
|
22
|
-
};
|
23
|
-
|
24
|
-
inline BasicSource::~BasicSource() { }
|
25
|
-
|
26
|
-
} } // namespace iv::core
|
27
|
-
#endif // _IV_SOURCE_H_
|
data/ext/iv/phonic/ast.h
DELETED
data/ext/iv/phonic/rnode.h
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
#ifndef _IV_PHONIC_RNODE_H_
|
2
|
-
#define _IV_PHONIC_RNODE_H_
|
3
|
-
#include <cstdlib>
|
4
|
-
#include <cstring>
|
5
|
-
#include <tr1/type_traits>
|
6
|
-
#include <ruby.h>
|
7
|
-
#include <ruby/encoding.h>
|
8
|
-
#include <ruby/intern.h>
|
9
|
-
#include <iv/ast.h>
|
10
|
-
#include <iv/static_assert.h>
|
11
|
-
namespace iv {
|
12
|
-
namespace phonic {
|
13
|
-
|
14
|
-
} } // namespace iv::phonic
|
15
|
-
#endif // _IV_PHONIC_RNODE_H_
|