asciimath 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +14 -0
- data/Rakefile +5 -0
- data/lib/asciimath/parser.rb +19 -3
- data/lib/asciimath/version.rb +1 -1
- data/{test → spec}/parser_spec.rb +8 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa1c3652a0a8ee204467385b78c06902d31c473d
|
4
|
+
data.tar.gz: 5c5f71402ee68f2b5f4fbbcca771b2f0f7b1107b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0c849c8dbcafb79620ae2b1358629e4644f6372f324b0e56a74beabc4509b395512dd3a64deb9916dc864bda42a16a013253db3a75818268a3193a82da6fa82
|
7
|
+
data.tar.gz: fbd88a8fa50bd2042976f9fe9b2529af73f4d8dac108197d316aa1e2b9666694ec283ce218f5af1862fe619b9cd79a692f3d05a6ef381e104d60c0258aa9f22a
|
data/.travis.yml
ADDED
data/Rakefile
CHANGED
data/lib/asciimath/parser.rb
CHANGED
@@ -53,7 +53,6 @@ module AsciiMath
|
|
53
53
|
#
|
54
54
|
class Tokenizer
|
55
55
|
WHITESPACE = /^\s+/
|
56
|
-
NUMBER_START = /[-0-9]/
|
57
56
|
NUMBER = /-?[0-9]+(?:\.[0-9]+)?/
|
58
57
|
TEXT = /"[^"]+"/
|
59
58
|
|
@@ -87,7 +86,7 @@ module AsciiMath
|
|
87
86
|
case @string.peek(1)
|
88
87
|
when '"'
|
89
88
|
read_text
|
90
|
-
when
|
89
|
+
when '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
|
91
90
|
read_number() || read_symbol
|
92
91
|
else
|
93
92
|
read_symbol()
|
@@ -125,6 +124,17 @@ module AsciiMath
|
|
125
124
|
end
|
126
125
|
end
|
127
126
|
|
127
|
+
if String.method_defined?(:bytesize)
|
128
|
+
def bytesize(s)
|
129
|
+
s.bytesize
|
130
|
+
end
|
131
|
+
else
|
132
|
+
def bytesize(s)
|
133
|
+
s.length
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
|
128
138
|
# Private: Reads a symbol token from the input string. This method first creates
|
129
139
|
# a String from the input String starting from the current position with a length
|
130
140
|
# that matches that of the longest key in the symbol table. It then looks up that
|
@@ -143,7 +153,7 @@ module AsciiMath
|
|
143
153
|
until s.length == 1 || @symbols.include?(s)
|
144
154
|
s.chop!
|
145
155
|
end
|
146
|
-
@string.pos = position + s
|
156
|
+
@string.pos = position + bytesize(s)
|
147
157
|
@symbols[s] || {:value => s, :type => :identifier}
|
148
158
|
end
|
149
159
|
end
|
@@ -162,6 +172,12 @@ module AsciiMath
|
|
162
172
|
s
|
163
173
|
end
|
164
174
|
end
|
175
|
+
|
176
|
+
if String.respond_to?(:byte_size)
|
177
|
+
def byte_size(s)
|
178
|
+
s.byte_size
|
179
|
+
end
|
180
|
+
end
|
165
181
|
end
|
166
182
|
|
167
183
|
class Parser
|
data/lib/asciimath/version.rb
CHANGED
@@ -42,8 +42,16 @@ TEST_CASES = {
|
|
42
42
|
'<math><mrow><mo>(</mo><mtable><mtr><mtd><msub><mi>a</mi><mn>11</mn></msub></mtd><mtd><mo>⋯</mo></mtd><mtd><msub><mi>a</mi><mrow><mn>1</mn><mi>n</mi></mrow></msub></mtd></mtr><mtr><mtd><mo>⋮</mo></mtd><mtd><mo>⋱</mo></mtd><mtd><mo>⋮</mo></mtd></mtr><mtr><mtd><msub><mi>a</mi><mrow><mi>m</mi><mn>1</mn></mrow></msub></mtd><mtd><mo>⋯</mo></mtd><mtd><msub><mi>a</mi><mrow><mi>m</mi><mi>n</mi></mrow></msub></mtd></mtr></mtable><mo>)</mo></mrow></math>',
|
43
43
|
'sum_(k=1)^n k = 1+2+ cdots +n=(n(n+1))/2' =>
|
44
44
|
'<math><munderover><mo>∑</mo><mrow><mi>k</mi><mo>=</mo><mn>1</mn></mrow><mi>n</mi></munderover><mi>k</mi><mo>=</mo><mn>1</mn><mo>+</mo><mn>2</mn><mo>+</mo><mo>⋯</mo><mo>+</mo><mi>n</mi><mo>=</mo><mfrac><mrow><mi>n</mi><mrow><mo>(</mo><mi>n</mi><mo>+</mo><mn>1</mn><mo>)</mo></mrow></mrow><mn>2</mn></mfrac></math>',
|
45
|
+
'"Скорость"=("Расстояние")/("Время")' =>
|
46
|
+
'<math><mtext>Скорость</mtext><mo>=</mo><mfrac><mtext>Расстояние</mtext><mtext>Время</mtext></mfrac></math>'
|
45
47
|
}
|
46
48
|
|
49
|
+
version = RUBY_VERSION.split('.').map { |s| s.to_i }
|
50
|
+
|
51
|
+
if version[0] > 1 || version[1] > 8
|
52
|
+
TEST_CASES['Скорость=(Расстояние)/(Время)'] = '<math><mi>С</mi><mi>к</mi><mi>о</mi><mi>р</mi><mi>о</mi><mi>с</mi><mi>т</mi><mi>ь</mi><mo>=</mo><mfrac><mrow><mi>Р</mi><mi>а</mi><mi>с</mi><mi>с</mi><mi>т</mi><mi>о</mi><mi>я</mi><mi>н</mi><mi>и</mi><mi>е</mi></mrow><mrow><mi>В</mi><mi>р</mi><mi>е</mi><mi>м</mi><mi>я</mi></mrow></mfrac></math>'
|
53
|
+
end
|
54
|
+
|
47
55
|
module AsciiMathHelper
|
48
56
|
def expect_mathml(asciimath, mathml)
|
49
57
|
expect(AsciiMath.parse(asciimath).to_mathml).to eq(mathml)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asciimath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pepijn Van Eeckhoudt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -61,6 +61,7 @@ extensions: []
|
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
63
|
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
64
65
|
- Gemfile
|
65
66
|
- LICENSE.txt
|
66
67
|
- README.md
|
@@ -72,7 +73,7 @@ files:
|
|
72
73
|
- lib/asciimath/mathml.rb
|
73
74
|
- lib/asciimath/parser.rb
|
74
75
|
- lib/asciimath/version.rb
|
75
|
-
-
|
76
|
+
- spec/parser_spec.rb
|
76
77
|
homepage: ''
|
77
78
|
licenses:
|
78
79
|
- MIT
|
@@ -98,5 +99,5 @@ signing_key:
|
|
98
99
|
specification_version: 4
|
99
100
|
summary: AsciiMath parser and converter
|
100
101
|
test_files:
|
101
|
-
-
|
102
|
+
- spec/parser_spec.rb
|
102
103
|
has_rdoc:
|