hwp_script_to_latex 1.4.0 → 1.5.0
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/lib/hwp_script_to_latex/converter.rb +53 -62
- data/lib/hwp_script_to_latex/processor.rb +34 -0
- data/lib/hwp_script_to_latex/syntax.rb +1326 -0
- data/lib/hwp_script_to_latex/validator.rb +84 -0
- data/lib/hwp_script_to_latex/version.rb +1 -1
- metadata +5 -3
- data/rules.json +0 -1277
@@ -0,0 +1,84 @@
|
|
1
|
+
#
|
2
|
+
# Author: osh
|
3
|
+
# Created: 2019-05-27
|
4
|
+
# Last modified: 2019-05-27
|
5
|
+
require 'hwp_script_to_latex/syntax'
|
6
|
+
|
7
|
+
module HwpScriptToLatex
|
8
|
+
# 한글 수식스크립트를 LaTeX로 변환하기 위한 검증
|
9
|
+
class Validator
|
10
|
+
include Syntax
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@default_commands = DEFAULT_COMMANDS
|
14
|
+
end
|
15
|
+
|
16
|
+
def validate(script)
|
17
|
+
result = {
|
18
|
+
warnings: [],
|
19
|
+
errors: []
|
20
|
+
}
|
21
|
+
|
22
|
+
# Default Command
|
23
|
+
@default_commands.each do |command|
|
24
|
+
parameter_bracket_regex = %r((?i:#{rule_regex(command)})\s*(?!{|\s))
|
25
|
+
|
26
|
+
match_data = script.match(parameter_bracket_regex)
|
27
|
+
if match_data
|
28
|
+
result[:errors] << {
|
29
|
+
name: :command_parameter_need_bracket,
|
30
|
+
message: "명령어 파라미터에 중괄호가 누락되었습니다."
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Fraction Command
|
36
|
+
parameter_bracket_regex = %r(((?<!\s|})\s*(?i:over|atop))|((?i:over|atop)\s*(?!\s|{)))
|
37
|
+
match_data = script.match(parameter_bracket_regex)
|
38
|
+
if match_data
|
39
|
+
result[:errors] << {
|
40
|
+
name: :fraction_command_parameter_need_bracket,
|
41
|
+
message: "분수 명령어 파라미터에 중괄호가 누락되었습니다."
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
# Sqrt Command
|
46
|
+
parameter_bracket_regex = %r(((?i:sqrt|root)\s*([^\s{]+))|((?i:sqrt|root)\s*([^\s]+)\s*of\s*([^\s{])))
|
47
|
+
match_data = script.match(parameter_bracket_regex)
|
48
|
+
if match_data
|
49
|
+
result[:errors] << {
|
50
|
+
name: :sqrt_command_parameter_need_bracket,
|
51
|
+
message: "루트 명령어 파라미터에 중괄호가 누락되었습니다."
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
# General
|
57
|
+
open_bracket_regex = /(?<![\\])\s*{/
|
58
|
+
close_bracket_regex = /(?<![\\])\s*}/
|
59
|
+
open_bracket_count = script.scan(open_bracket_regex).length
|
60
|
+
close_bracket_count = script.scan(close_bracket_regex).length
|
61
|
+
|
62
|
+
if open_bracket_count != close_bracket_count
|
63
|
+
result[:errors] << {
|
64
|
+
name: :invalid_bracket_pair,
|
65
|
+
message: "중괄호 개수가 맞지 않습니다."
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
open_parentheses_regex = /\s*\(/
|
70
|
+
close_parentheses_regex = /\s*\)/
|
71
|
+
open_parentheses_count = script.scan(open_parentheses_regex).length
|
72
|
+
close_parentheses_count = script.scan(close_parentheses_regex).length
|
73
|
+
|
74
|
+
if open_parentheses_count != close_parentheses_count
|
75
|
+
result[:errors] << {
|
76
|
+
name: :invalid_parentheses_pair,
|
77
|
+
message: "소괄호 개수가 맞지 않습니다."
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
return result
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hwp_script_to_latex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bluesh55
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,8 +73,10 @@ files:
|
|
73
73
|
- hwp_script_to_latex.gemspec
|
74
74
|
- lib/hwp_script_to_latex.rb
|
75
75
|
- lib/hwp_script_to_latex/converter.rb
|
76
|
+
- lib/hwp_script_to_latex/processor.rb
|
77
|
+
- lib/hwp_script_to_latex/syntax.rb
|
78
|
+
- lib/hwp_script_to_latex/validator.rb
|
76
79
|
- lib/hwp_script_to_latex/version.rb
|
77
|
-
- rules.json
|
78
80
|
homepage: https://github.com/PrivateCoach/hwp_script_to_latex
|
79
81
|
licenses:
|
80
82
|
- MIT
|