clausewitz-spelling 0.2.8 → 0.2.9
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/Gemfile.lock +1 -1
- data/lib/clausewitz/localisation.rb +36 -1
- data/lib/clausewitz/spelling/checker.rb +2 -0
- data/lib/clausewitz/spelling/results.rb +5 -6
- data/lib/clausewitz/spelling/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df7a1d4a0691bd8d0c5206439a475ffb7271b2114517ed0a1466272398db7f30
|
4
|
+
data.tar.gz: b2224cbea6f9e78ab1b57dc8c1b9e1e2cd0e76e8dacb192481977afff4baa7f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b26315488f9b5018c2b5289acee1c6517eb36ef362904abf8b83e15198af957c392a7144cd456a6d34103515aa7dafc8a04c129f391f9c10a65d65d19cd0cb14
|
7
|
+
data.tar.gz: 58454d39937ffbbabe81725488f304a4eefe4d7f42875bc2a7a0bda0d19e8c31ece293bee177c5c367878b3bc94afbead92bc9dc15ed969772c1a83b94bbd75b
|
data/Gemfile.lock
CHANGED
@@ -2,6 +2,17 @@ require 'yaml'
|
|
2
2
|
|
3
3
|
module Clausewitz
|
4
4
|
module Localisation
|
5
|
+
class UnparseableFileError < StandardError
|
6
|
+
attr_reader :errors
|
7
|
+
def initialize(errors)
|
8
|
+
@errors = errors
|
9
|
+
end
|
10
|
+
|
11
|
+
def message
|
12
|
+
@errors.join("\n")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
5
16
|
class LangConfig
|
6
17
|
attr_reader :name, :base, :dialects, :default_dialect
|
7
18
|
def initialize(name, base, dialects, default_dialect = nil)
|
@@ -57,6 +68,7 @@ module Clausewitz
|
|
57
68
|
}
|
58
69
|
|
59
70
|
def self.parse(text)
|
71
|
+
self.pre_validate(text)
|
60
72
|
smudged_text = text.lines.map do |line|
|
61
73
|
self.smudge_key(line)
|
62
74
|
end
|
@@ -71,6 +83,29 @@ module Clausewitz
|
|
71
83
|
contents
|
72
84
|
end
|
73
85
|
|
86
|
+
def self.pre_validate(text)
|
87
|
+
errors = []
|
88
|
+
text.lines[1..-1].each_with_index do |line, index|
|
89
|
+
lineno = index + 2
|
90
|
+
|
91
|
+
|
92
|
+
if line =~ /^\s*([\w\d.'-])+\:([0-9]+)? \"/ && line !~ /^ ([\w\d.'-])+\:([0-9]+)? \"/
|
93
|
+
errors << "Line ##{lineno} does not start with two spaces."
|
94
|
+
end
|
95
|
+
|
96
|
+
if line.count('"').odd?
|
97
|
+
errors << "Unmatched double quote on line ##{lineno}."
|
98
|
+
end
|
99
|
+
|
100
|
+
quote_pxs = (0 ... line.length).find_all { |i| line[i, 1] == '"' }
|
101
|
+
quote_pxs.shift; quote_pxs.pop;
|
102
|
+
if quote_pxs.any? { |px| line[px - 1] != '\\' }
|
103
|
+
errors << "Unescaped double quote on line ##{lineno}."
|
104
|
+
end
|
105
|
+
end
|
106
|
+
fail(UnparseableFileError, errors) unless errors.empty?
|
107
|
+
end
|
108
|
+
|
74
109
|
def self.parse_file(filepath)
|
75
110
|
contents = nil
|
76
111
|
File.open(filepath, 'r:UTF-8') do |f|
|
@@ -80,7 +115,7 @@ module Clausewitz
|
|
80
115
|
end
|
81
116
|
|
82
117
|
def self.smudge_key(line)
|
83
|
-
if line =~ / (\w
|
118
|
+
if line =~ / ([\w\d.'-])+\:([0-9]+) \"/
|
84
119
|
line.sub(/\:([0-9]+) /, '!!!\1: ')
|
85
120
|
else
|
86
121
|
line
|
@@ -63,6 +63,8 @@ module Clausewitz; module Spelling
|
|
63
63
|
|
64
64
|
begin
|
65
65
|
contents = Clausewitz::Localisation.parse_file(filepath)
|
66
|
+
rescue Clausewitz::Localisation::UnparseableFileError => e
|
67
|
+
return UnparseableFileResult.new(filepath, e.errors)
|
66
68
|
rescue => e
|
67
69
|
return UnparseableFileResult.new(filepath, e)
|
68
70
|
end
|
@@ -225,10 +225,10 @@ module Clausewitz; module Spelling
|
|
225
225
|
|
226
226
|
# Result capturing problems parsing a readable file.
|
227
227
|
class UnparseableFileResult
|
228
|
-
attr_reader :filepath, :
|
229
|
-
def initialize(filepath,
|
228
|
+
attr_reader :filepath, :errors
|
229
|
+
def initialize(filepath, errors)
|
230
230
|
@filepath = filepath
|
231
|
-
@
|
231
|
+
@errors = Array(errors)
|
232
232
|
end
|
233
233
|
|
234
234
|
def failed?
|
@@ -236,7 +236,7 @@ module Clausewitz; module Spelling
|
|
236
236
|
end
|
237
237
|
|
238
238
|
def failure_total
|
239
|
-
|
239
|
+
errors.size
|
240
240
|
end
|
241
241
|
|
242
242
|
def to_s
|
@@ -247,8 +247,7 @@ module Clausewitz; module Spelling
|
|
247
247
|
spacer = ' ' * indent
|
248
248
|
secondspacer = ' ' * (indent + 2)
|
249
249
|
"#{spacer}#{@filepath} could not be parsed\n".red +
|
250
|
-
"#{secondspacer}#{
|
251
|
-
"#{secondspacer}Make sure every entry has exactly two spaces in front of it.".red
|
250
|
+
@errors.map { |e| "#{secondspacer}#{e}".red }.join("\n")
|
252
251
|
end
|
253
252
|
end
|
254
253
|
end; end # Clausewitz::Spelling
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clausewitz-spelling
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Will Chappell
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|