jkf 0.4.3 → 0.5.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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +16 -0
- data/.rubocop.yml +46 -990
- data/.rubocop_todo.yml +1 -5
- data/CHANGELOG.md +63 -0
- data/Gemfile +11 -9
- data/Guardfile +3 -3
- data/README.en.md +28 -15
- data/README.md +9 -5
- data/Rakefile +7 -2
- data/bench.rb +12 -0
- data/bin/console +4 -4
- data/jkf.gemspec +14 -12
- data/lib/jkf/converter/base.rb +12 -10
- data/lib/jkf/converter/csa.rb +141 -150
- data/lib/jkf/converter/ki2.rb +93 -91
- data/lib/jkf/converter/kif.rb +105 -99
- data/lib/jkf/converter/kifuable.rb +160 -160
- data/lib/jkf/converter.rb +6 -8
- data/lib/jkf/parser/base.rb +81 -95
- data/lib/jkf/parser/csa.rb +652 -667
- data/lib/jkf/parser/ki2.rb +332 -338
- data/lib/jkf/parser/kif.rb +468 -485
- data/lib/jkf/parser/kifuable.rb +500 -518
- data/lib/jkf/parser.rb +5 -7
- data/lib/jkf/version.rb +1 -2
- data/lib/jkf.rb +6 -6
- data/manifest.scm +143 -0
- data/po/all.pot +176 -0
- data/po/en.po +199 -0
- data/po4a.cfg +11 -0
- metadata +13 -7
- data/.codeclimate.yml +0 -28
- data/.travis.yml +0 -9
data/lib/jkf/parser/base.rb
CHANGED
@@ -1,118 +1,104 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
fail(type: "end", description: "end of input") if failed? && @current_pos < input.size
|
26
|
-
raise ParseError
|
1
|
+
require 'strscan'
|
2
|
+
|
3
|
+
module Jkf
|
4
|
+
module Parser
|
5
|
+
# Base of Parser
|
6
|
+
class Base
|
7
|
+
# start parse
|
8
|
+
#
|
9
|
+
# @param [String] input
|
10
|
+
#
|
11
|
+
# @return [Hash] JKF
|
12
|
+
def parse(input)
|
13
|
+
@scanner = StringScanner.new(input.dup)
|
14
|
+
@reported_pos = 0
|
15
|
+
@max_fail_pos = 0
|
16
|
+
|
17
|
+
@result = parse_root
|
18
|
+
|
19
|
+
if success? && @scanner.eos?
|
20
|
+
@result
|
21
|
+
else
|
22
|
+
record_failure(type: 'end', description: 'end of input') if failed? && @scanner.pos < input.size
|
23
|
+
raise ParseError
|
24
|
+
end
|
27
25
|
end
|
28
|
-
end
|
29
26
|
|
30
|
-
|
27
|
+
protected
|
31
28
|
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
def success?
|
30
|
+
@result != :failed
|
31
|
+
end
|
35
32
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
ret = :failed
|
46
|
-
fail(type: "class", value: reg.inspect, description: reg.inspect) if @silent_fails == 0
|
33
|
+
def failed?; !success?; end
|
34
|
+
|
35
|
+
def match_regexp(reg)
|
36
|
+
matched = @scanner.scan(reg)
|
37
|
+
unless matched
|
38
|
+
record_failure(type: 'class', value: reg.inspect, description: reg.inspect)
|
39
|
+
return :failed
|
40
|
+
end
|
41
|
+
matched
|
47
42
|
end
|
48
|
-
ret
|
49
|
-
end
|
50
43
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
ret = :failed
|
59
|
-
fail(type: "literal", value: str, description: "\"#{str}\"") if @slient_fails == 0
|
44
|
+
def match_str(str)
|
45
|
+
matched = @scanner.scan(str)
|
46
|
+
unless matched
|
47
|
+
record_failure(type: 'literal', value: str, description: str.inspect)
|
48
|
+
return :failed
|
49
|
+
end
|
50
|
+
matched
|
60
51
|
end
|
61
|
-
ret
|
62
|
-
end
|
63
52
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
53
|
+
# match space
|
54
|
+
def match_space
|
55
|
+
match_str(' ')
|
56
|
+
end
|
68
57
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
matched = match_space
|
73
|
-
while matched != :failed
|
74
|
-
stack << matched
|
58
|
+
# match space one or more
|
59
|
+
def match_spaces
|
60
|
+
stack = []
|
75
61
|
matched = match_space
|
62
|
+
while matched != :failed
|
63
|
+
stack << matched
|
64
|
+
matched = match_space
|
65
|
+
end
|
66
|
+
stack
|
76
67
|
end
|
77
|
-
stack
|
78
|
-
end
|
79
68
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
69
|
+
# match digit
|
70
|
+
def match_digit
|
71
|
+
match_regexp(/\d/)
|
72
|
+
end
|
84
73
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
matched = match_digit
|
89
|
-
while matched != :failed
|
90
|
-
stack << matched
|
74
|
+
# match digits
|
75
|
+
def match_digits
|
76
|
+
stack = []
|
91
77
|
matched = match_digit
|
78
|
+
while matched != :failed
|
79
|
+
stack << matched
|
80
|
+
matched = match_digit
|
81
|
+
end
|
82
|
+
stack
|
92
83
|
end
|
93
|
-
stack
|
94
|
-
end
|
95
84
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
85
|
+
# match digit one ore more
|
86
|
+
def match_digits!
|
87
|
+
matched = match_digits
|
88
|
+
if matched.empty?
|
89
|
+
:failed
|
90
|
+
else
|
91
|
+
matched
|
92
|
+
end
|
103
93
|
end
|
104
|
-
end
|
105
94
|
|
106
|
-
|
107
|
-
|
108
|
-
return if @current_pos < @max_fail_pos
|
95
|
+
def record_failure(expected)
|
96
|
+
return if @scanner.pos < @max_fail_pos
|
109
97
|
|
110
|
-
|
111
|
-
@max_fail_pos = @current_pos
|
112
|
-
@max_fail_expected = []
|
113
|
-
end
|
98
|
+
return unless @scanner.pos > @max_fail_pos
|
114
99
|
|
115
|
-
|
100
|
+
@max_fail_pos = @scanner.pos
|
101
|
+
end
|
116
102
|
end
|
117
103
|
end
|
118
104
|
end
|