iv-phonic 0.0.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/.autotest +24 -0
- data/Manifest.txt +49 -0
- data/README.rdoc +32 -0
- data/Rakefile +54 -0
- data/ext/include/iv/algorithm.h +23 -0
- data/ext/include/iv/alloc.h +200 -0
- data/ext/include/iv/any.h +71 -0
- data/ext/include/iv/ast-factory.h +277 -0
- data/ext/include/iv/ast-fwd.h +92 -0
- data/ext/include/iv/ast-serializer.h +579 -0
- data/ext/include/iv/ast-visitor.h +121 -0
- data/ext/include/iv/ast.h +1127 -0
- data/ext/include/iv/chars.h +83 -0
- data/ext/include/iv/cmdline.h +830 -0
- data/ext/include/iv/conversions.h +308 -0
- data/ext/include/iv/dtoa.h +20 -0
- data/ext/include/iv/enable_if.h +18 -0
- data/ext/include/iv/errors.h +15 -0
- data/ext/include/iv/fixedcontainer.h +42 -0
- data/ext/include/iv/functor.h +29 -0
- data/ext/include/iv/lexer.h +1281 -0
- data/ext/include/iv/location.h +23 -0
- data/ext/include/iv/mt19937.h +175 -0
- data/ext/include/iv/noncopyable.h +30 -0
- data/ext/include/iv/none.h +10 -0
- data/ext/include/iv/parser.h +2150 -0
- data/ext/include/iv/source.h +27 -0
- data/ext/include/iv/space.h +178 -0
- data/ext/include/iv/static_assert.h +30 -0
- data/ext/include/iv/stringpiece.h +385 -0
- data/ext/include/iv/token.h +311 -0
- data/ext/include/iv/ucdata.h +58 -0
- data/ext/include/iv/uchar.h +8 -0
- data/ext/include/iv/ustring.h +28 -0
- data/ext/include/iv/ustringpiece.h +9 -0
- data/ext/include/iv/utils.h +83 -0
- data/ext/include/iv/xorshift.h +74 -0
- data/ext/iv/phonic/ast-fwd.h +21 -0
- data/ext/iv/phonic/ast.h +10 -0
- data/ext/iv/phonic/creator.h +530 -0
- data/ext/iv/phonic/encoding.h +110 -0
- data/ext/iv/phonic/extconf.rb +5 -0
- data/ext/iv/phonic/factory.h +247 -0
- data/ext/iv/phonic/parser.h +12 -0
- data/ext/iv/phonic/phonic.cc +69 -0
- data/ext/iv/phonic/rnode.h +15 -0
- data/ext/iv/phonic/rparser.h +48 -0
- data/ext/iv/phonic/source.h +146 -0
- data/test/test_iv_phonic.rb +32 -0
- metadata +159 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
#ifndef _IV_LOCATION_H_
|
2
|
+
#define _IV_LOCATION_H_
|
3
|
+
#include <cstddef>
|
4
|
+
#include <tr1/type_traits>
|
5
|
+
#include "static_assert.h"
|
6
|
+
namespace iv {
|
7
|
+
namespace core {
|
8
|
+
|
9
|
+
struct Location {
|
10
|
+
std::size_t begin_position_;
|
11
|
+
std::size_t end_position_;
|
12
|
+
inline std::size_t begin_position() const {
|
13
|
+
return begin_position_;
|
14
|
+
}
|
15
|
+
inline std::size_t end_position() const {
|
16
|
+
return end_position_;
|
17
|
+
}
|
18
|
+
};
|
19
|
+
|
20
|
+
IV_STATIC_ASSERT(std::tr1::is_pod<Location>::value);
|
21
|
+
|
22
|
+
} } // namespace iv::core
|
23
|
+
#endif // _IV_LOCATION_H_
|
@@ -0,0 +1,175 @@
|
|
1
|
+
// Copyright (c) Constellation <utatane.tea@gmail.com> All rights reserved.
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
3
|
+
// found in the LICENSE file.
|
4
|
+
//
|
5
|
+
// Algorithm Lisence
|
6
|
+
// Mersenne Twister 19937
|
7
|
+
// BSD Lisence
|
8
|
+
// Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
|
9
|
+
// All rights reserved.
|
10
|
+
// http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/mt.html
|
11
|
+
|
12
|
+
#ifndef _IV_MT19937_H_
|
13
|
+
#define _IV_MT19937_H_
|
14
|
+
#include <tr1/cstdint>
|
15
|
+
#include <vector>
|
16
|
+
|
17
|
+
namespace iv {
|
18
|
+
namespace core {
|
19
|
+
|
20
|
+
class MT19937 {
|
21
|
+
public:
|
22
|
+
explicit MT19937(uint32_t s)
|
23
|
+
: mti_(N+1) {
|
24
|
+
InitGenRand(s);
|
25
|
+
}
|
26
|
+
|
27
|
+
MT19937(const uint32_t* vec, int len)
|
28
|
+
: mti_(N+1) {
|
29
|
+
InitByArray(vec, len);
|
30
|
+
}
|
31
|
+
|
32
|
+
explicit MT19937(const std::vector<uint32_t>& vec)
|
33
|
+
: mti_(N+1) {
|
34
|
+
InitByArray(vec.begin(), vec.size());
|
35
|
+
}
|
36
|
+
|
37
|
+
uint32_t GenInt32() {
|
38
|
+
uint32_t y;
|
39
|
+
if (mti_ >= N) {
|
40
|
+
int kk;
|
41
|
+
for (kk = 0; kk < N-M; ++kk) {
|
42
|
+
y = (mt_[kk] & UPPER_MASK) | (mt_[kk+1] & LOWER_MASK);
|
43
|
+
mt_[kk] = mt_[kk+M] ^ (y >> 1) ^ ((y & 0x1UL) ? MATRIX_A : 0x0UL);
|
44
|
+
}
|
45
|
+
for (; kk < N-1; ++kk) {
|
46
|
+
y = (mt_[kk] & UPPER_MASK) | (mt_[kk+1] & LOWER_MASK);
|
47
|
+
mt_[kk] = mt_[kk+(M-N)] ^ (y >> 1) ^ ((y & 0x1UL) ? MATRIX_A : 0x0UL);
|
48
|
+
}
|
49
|
+
y = (mt_[N-1] & UPPER_MASK) | (mt_[0] & LOWER_MASK);
|
50
|
+
mt_[N-1] = mt_[M-1] ^ (y >> 1) ^ ((y & 0x1UL) ? MATRIX_A : 0x0UL);
|
51
|
+
mti_ = 0;
|
52
|
+
}
|
53
|
+
|
54
|
+
y = mt_[mti_++];
|
55
|
+
|
56
|
+
y ^= (y >> 11);
|
57
|
+
y ^= (y << 7) & 0x9d2c5680UL;
|
58
|
+
y ^= (y << 15) & 0xefc60000UL;
|
59
|
+
y ^= (y >> 18);
|
60
|
+
return y;
|
61
|
+
}
|
62
|
+
|
63
|
+
uint32_t operator()() {
|
64
|
+
return GenInt32();
|
65
|
+
}
|
66
|
+
|
67
|
+
int32_t GenInt31() {
|
68
|
+
return static_cast<int32_t>(GenInt32() >> 1);
|
69
|
+
}
|
70
|
+
|
71
|
+
double GenReal1() {
|
72
|
+
return GenInt32() * (1.0 / 4294967295.0);
|
73
|
+
}
|
74
|
+
|
75
|
+
double GenReal2() {
|
76
|
+
return GenInt32() * (1.0 / 4294967296.0);
|
77
|
+
}
|
78
|
+
|
79
|
+
double GenReal3() {
|
80
|
+
return (static_cast<double>(GenInt32()) + 0.5) * (1.0 / 4294967296.0);
|
81
|
+
}
|
82
|
+
|
83
|
+
double GenReal53() {
|
84
|
+
const uint32_t a = GenInt32() >> 5;
|
85
|
+
const uint32_t b = GenInt32() >> 6;
|
86
|
+
return (a * 67108864.0 + b) * (1.0 / 9007199254740992.0);
|
87
|
+
}
|
88
|
+
|
89
|
+
private:
|
90
|
+
void InitGenRand(uint32_t s) {
|
91
|
+
mt_[0] = s & 0xffffffffUL;
|
92
|
+
for (mti_ = 1; mti_ < N; ++mti_) {
|
93
|
+
mt_[mti_] = (1812433253UL * (mt_[mti_-1] ^ (mt_[mti_-1] >> 30)) + mti_);
|
94
|
+
mt_[mti_] &= 0xffffffffUL;
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
template<typename I>
|
99
|
+
void InitByArray(const I vec, const int len) {
|
100
|
+
InitGenRand(19650218UL);
|
101
|
+
int i = 1, j = 0;
|
102
|
+
for (int k = (N > len ? N : len); k; k--) {
|
103
|
+
mt_[i] = (mt_[i] ^ ((mt_[i-1] ^ (mt_[i-1] >> 30)) * 1664525UL))
|
104
|
+
+ *(vec+j) + j; /* non linear */
|
105
|
+
mt_[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
|
106
|
+
++i;
|
107
|
+
++j;
|
108
|
+
if (i >= N) {
|
109
|
+
mt_[0] = mt_[N-1];
|
110
|
+
i = 1;
|
111
|
+
}
|
112
|
+
if (j >= len) {
|
113
|
+
j = 0;
|
114
|
+
}
|
115
|
+
}
|
116
|
+
for (int k = N-1; k; k--) {
|
117
|
+
mt_[i] = (mt_[i] ^ ((mt_[i-1] ^ (mt_[i-1] >> 30)) * 1566083941UL))
|
118
|
+
- i; // non linear
|
119
|
+
mt_[i] &= 0xffffffffUL; // for WORDSIZE > 32 machines
|
120
|
+
i++;
|
121
|
+
if (i >= N) {
|
122
|
+
mt_[0] = mt_[N-1];
|
123
|
+
i = 1;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
mt_[0] = 0x80000000UL; // MSB is 1; assuring non-zero initial array
|
127
|
+
}
|
128
|
+
|
129
|
+
static const int N = 624;
|
130
|
+
static const int M = 397;
|
131
|
+
static const uint32_t MATRIX_A = 0x9908b0dfUL; // constant vector a
|
132
|
+
static const uint32_t UPPER_MASK = 0x80000000UL; // most significant w-r bits
|
133
|
+
static const uint32_t LOWER_MASK = 0x7fffffffUL; // least significant r bits
|
134
|
+
|
135
|
+
uint32_t mt_[N];
|
136
|
+
int mti_;
|
137
|
+
};
|
138
|
+
|
139
|
+
template<typename T>
|
140
|
+
class UniformIntDistribution {
|
141
|
+
public:
|
142
|
+
UniformIntDistribution(T min, T max)
|
143
|
+
: min_(min),
|
144
|
+
max_(max) {
|
145
|
+
}
|
146
|
+
template<typename EngineType>
|
147
|
+
T operator()(EngineType& engine) { // NOLINT
|
148
|
+
return engine() % (max_ - min_ + 1) + min_;
|
149
|
+
}
|
150
|
+
private:
|
151
|
+
const T min_;
|
152
|
+
const T max_;
|
153
|
+
};
|
154
|
+
|
155
|
+
template<typename T>
|
156
|
+
class UniformRealDistribution {
|
157
|
+
public:
|
158
|
+
UniformRealDistribution(T min, T max)
|
159
|
+
: min_(min),
|
160
|
+
max_(max) {
|
161
|
+
}
|
162
|
+
template<typename EngineType>
|
163
|
+
T operator()(EngineType& engine) { // NOLINT
|
164
|
+
const uint32_t a = engine() >> 5;
|
165
|
+
const uint32_t b = engine() >> 6;
|
166
|
+
return (a * 67108864.0 + b)
|
167
|
+
* (1.0 / 9007199254740992.0) * (max_ - min_) + min_;
|
168
|
+
}
|
169
|
+
private:
|
170
|
+
const T min_;
|
171
|
+
const T max_;
|
172
|
+
};
|
173
|
+
|
174
|
+
} } // namespace iv::core
|
175
|
+
#endif // _IV_MT19937_H_
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#ifndef _IV_NONCOPYABLE_H_
|
2
|
+
#define _IV_NONCOPYABLE_H_
|
3
|
+
|
4
|
+
namespace iv {
|
5
|
+
namespace core {
|
6
|
+
|
7
|
+
// guard from ADL
|
8
|
+
// see http://ml.tietew.jp/cppll/cppll_novice/thread_articles/1652
|
9
|
+
namespace noncopyable_ {
|
10
|
+
|
11
|
+
template<typename T>
|
12
|
+
class Noncopyable {
|
13
|
+
protected:
|
14
|
+
Noncopyable() {}
|
15
|
+
~Noncopyable() {}
|
16
|
+
private:
|
17
|
+
Noncopyable(const Noncopyable&);
|
18
|
+
const T& operator=(const T&);
|
19
|
+
};
|
20
|
+
|
21
|
+
} // namespace iv::core::noncopyable_
|
22
|
+
|
23
|
+
template<typename T>
|
24
|
+
struct Noncopyable {
|
25
|
+
typedef noncopyable_::Noncopyable<T> type;
|
26
|
+
};
|
27
|
+
|
28
|
+
} } // namespace iv::core
|
29
|
+
|
30
|
+
#endif // _IV_NONCOPYABLE_H_
|