eturem 0.3.1 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,56 @@
1
+ # coding: utf-8
2
+
3
+ module Eturem
4
+ module ArgumentErrorExt
5
+ include ExceptionExt
6
+
7
+ def eturem_message()
8
+ given = nil
9
+ if @eturem_message.include?("wrong number of arguments")
10
+ if @eturem_message.match(/\(given (?<given>\d+), expected (?<expected>[^)]+)\)/)
11
+ given = Regexp.last_match(:given).to_i
12
+ expected = Regexp.last_match(:expected)
13
+ elsif @eturem_message.match(/\((?<given>\d+) for (?<expected>[^)]+)\)/)
14
+ given = Regexp.last_match(:given).to_i
15
+ expected = Regexp.last_match(:expected)
16
+ end
17
+ end
18
+
19
+ if given
20
+ eturem_wrong_number_of_arguments(given, expected)
21
+ elsif @eturem_message.match(/too big/)
22
+ eturem_argument_too_big
23
+ else
24
+ eturem_other_argument_error
25
+ end
26
+ super
27
+ end
28
+
29
+ def eturem_wrong_number_of_arguments(given, expected)
30
+ @eturem_message_ja = "引数の数が正しくありません。「#{@eturem_method}」は本来"
31
+ case expected
32
+ when "0"
33
+ @eturem_message_ja += "引数が不要です"
34
+ when /^(\d+)\.\.(\d+)$/
35
+ @eturem_message_ja += " #{$1}~#{$2} 個の引数を取ります"
36
+ when /^(\d+)\+$/
37
+ @eturem_message_ja += " #{$1} 個以上の引数を取ります"
38
+ else
39
+ @eturem_message_ja += " #{expected} 個の引数を取ります"
40
+ end
41
+ if given == 0
42
+ @eturem_message_ja += "が、引数が1つも渡されていません。"
43
+ else
44
+ @eturem_message_ja += "が、#{given} 個の引数が渡されています。"
45
+ end
46
+ end
47
+
48
+ def eturem_argument_too_big()
49
+ @eturem_message_ja = "「#{@eturem_method}」への引数が大きすぎます。"
50
+ end
51
+
52
+ def eturem_other_argument_error()
53
+ @eturem_message_ja = "「#{@eturem_method}」への引数が正しくありません。"
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,13 @@
1
+ module Eturem
2
+ module DXRubyErrorExt
3
+ include ExceptionExt
4
+
5
+ def eturem_message()
6
+ case @eturem_message
7
+ when /^Load error - (.+)/
8
+ @eturem_message_ja = %<ファイル "#{$1}" の読み込みに失敗しました。ファイル名を確認してください。>
9
+ end
10
+ super
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+
3
+ module Eturem
4
+ module Errno_ENOENTExt
5
+ include ExceptionExt
6
+
7
+ def eturem_message()
8
+ @eturem_message_ja = "ファイルアクセスに失敗しました。"
9
+ if @eturem_message.match(/-\s*(?<filename>.+)\s*$/)
10
+ filename = Regexp.last_match(:filename).encode("utf-8")
11
+ @eturem_message_ja += %<ファイル "#{filename}" がありません。>
12
+ else
13
+ @eturem_message_ja += "ファイルがありません。"
14
+ end
15
+ @eturem_message_ja += "ファイル名を確認してください。"
16
+ super
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ # coding: utf-8
2
+
3
+ module Eturem
4
+ module InterruptExt
5
+ include ExceptionExt
6
+
7
+ def eturem_message()
8
+ @eturem_message_ja = "プログラムが途中で強制終了されました。"
9
+ super
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ # coding: utf-8
2
+
3
+ module Eturem
4
+ module LoadErrorExt
5
+ include ExceptionExt
6
+
7
+ def eturem_message()
8
+ @eturem_message_ja =
9
+ %<ファイル/ライブラリ "#{self.path.encode("utf-8")}" が見つかりません。> +
10
+ %<ファイル/ライブラリ名を確認してください。>
11
+ super
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,220 @@
1
+ require "eturem/base"
2
+ Dir[File.expand_path("..", __FILE__) + "/*.rb"].each do |path|
3
+ require path unless path == File.expand_path(__FILE__)
4
+ end
5
+
6
+ module Eturem
7
+ def self._extend_exception(exception)
8
+ ext = case exception
9
+ when NoMemoryError then NoMemoryErrorExt
10
+ when LoadError then LoadErrorExt
11
+ # when NotImplementedError then NotImplementedErrorExt
12
+ when SyntaxError then SyntaxErrorExt
13
+ # when ScriptError then ScriptErrorExt
14
+ # when SecurityError then SecurityErrorExt
15
+ when Interrupt then InterruptExt
16
+ # when SignalException then SignalExceptionExt
17
+ when UncaughtThrowError then UncaughtThrowErrorExt
18
+ when ArgumentError then ArgumentErrorExt
19
+ # when Encoding::CompatibilityError then Encoding_CompatibilityErrorExt
20
+ # when Encoding::ConverterNotFoundError then Encoding_ConverterNotFoundErrorExt
21
+ # when Encoding::InvalidByteSequenceError then Encoding_InvalidByteSequenceErrorExt
22
+ # when Encoding::UndefinedConversionError then Encoding_UndefinedConversionErrorExt
23
+ # when EncodingError then EncodingErrorExt
24
+ # when FiberError then FiberErrorExt
25
+ # when EOFError then EOFErrorExt
26
+ # when IOError then IOErrorExt
27
+ # when KeyError then KeyErrorExt
28
+ # when ClosedQueueError then ClosedQueueErrorExt
29
+ # when StopIteration then StopIterationExt
30
+ # when IndexError then IndexErrorExt
31
+ # when LocalJumpError then LocalJumpErrorExt
32
+ # when Math::DomainError then Math_DomainErrorExt
33
+ # when NoMethodError then NoMethodErrorExt
34
+ when NameError then NameErrorExt
35
+ # when FloatDomainError then FloatDomainErrorExt
36
+ # when RangeError then RangeErrorExt
37
+ # when RegexpError then RegexpErrorExt
38
+ # when RuntimeError then RuntimeErrorExt
39
+ # when Errno::E2BIG then Errno_E2BIGExt
40
+ # when Errno::EACCES then Errno_EACCESExt
41
+ # when Errno::EADDRINUSE then Errno_EADDRINUSEExt
42
+ # when Errno::EADDRNOTAVAIL then Errno_EADDRNOTAVAILExt
43
+ # when Errno::EADV then Errno_EADVExt
44
+ # when Errno::EAFNOSUPPORT then Errno_EAFNOSUPPORTExt
45
+ # when Errno::EAGAIN then Errno_EAGAINExt
46
+ # when Errno::EALREADY then Errno_EALREADYExt
47
+ # when Errno::EAUTH then Errno_EAUTHExt
48
+ # when Errno::EBADE then Errno_EBADEExt
49
+ # when Errno::EBADF then Errno_EBADFExt
50
+ # when Errno::EBADFD then Errno_EBADFDExt
51
+ # when Errno::EBADMSG then Errno_EBADMSGExt
52
+ # when Errno::EBADR then Errno_EBADRExt
53
+ # when Errno::EBADRPC then Errno_EBADRPCExt
54
+ # when Errno::EBADRQC then Errno_EBADRQCExt
55
+ # when Errno::EBADSLT then Errno_EBADSLTExt
56
+ # when Errno::EBFONT then Errno_EBFONTExt
57
+ # when Errno::EBUSY then Errno_EBUSYExt
58
+ # when Errno::ECANCELED then Errno_ECANCELEDExt
59
+ # when Errno::ECAPMODE then Errno_ECAPMODEExt
60
+ # when Errno::ECHILD then Errno_ECHILDExt
61
+ # when Errno::ECHRNG then Errno_ECHRNGExt
62
+ # when Errno::ECOMM then Errno_ECOMMExt
63
+ # when Errno::ECONNABORTED then Errno_ECONNABORTEDExt
64
+ # when Errno::ECONNREFUSED then Errno_ECONNREFUSEDExt
65
+ # when Errno::ECONNRESET then Errno_ECONNRESETExt
66
+ # when Errno::EDEADLK then Errno_EDEADLKExt
67
+ # when Errno::EDEADLOCK then Errno_EDEADLOCKExt
68
+ # when Errno::EDESTADDRREQ then Errno_EDESTADDRREQExt
69
+ # when Errno::EDOM then Errno_EDOMExt
70
+ # when Errno::EDOOFUS then Errno_EDOOFUSExt
71
+ # when Errno::EDOTDOT then Errno_EDOTDOTExt
72
+ # when Errno::EDQUOT then Errno_EDQUOTExt
73
+ # when Errno::EEXIST then Errno_EEXISTExt
74
+ # when Errno::EFAULT then Errno_EFAULTExt
75
+ # when Errno::EFBIG then Errno_EFBIGExt
76
+ # when Errno::EFTYPE then Errno_EFTYPEExt
77
+ # when Errno::EHOSTDOWN then Errno_EHOSTDOWNExt
78
+ # when Errno::EHOSTUNREACH then Errno_EHOSTUNREACHExt
79
+ # when Errno::EHWPOISON then Errno_EHWPOISONExt
80
+ # when Errno::EIDRM then Errno_EIDRMExt
81
+ # when Errno::EILSEQ then Errno_EILSEQExt
82
+ # when Errno::EINPROGRESS then Errno_EINPROGRESSExt
83
+ # when Errno::EINTR then Errno_EINTRExt
84
+ # when Errno::EINVAL then Errno_EINVALExt
85
+ # when Errno::EIO then Errno_EIOExt
86
+ # when Errno::EIPSEC then Errno_EIPSECExt
87
+ # when Errno::EISCONN then Errno_EISCONNExt
88
+ # when Errno::EISDIR then Errno_EISDIRExt
89
+ # when Errno::EISNAM then Errno_EISNAMExt
90
+ # when Errno::EKEYEXPIRED then Errno_EKEYEXPIREDExt
91
+ # when Errno::EKEYREJECTED then Errno_EKEYREJECTEDExt
92
+ # when Errno::EKEYREVOKED then Errno_EKEYREVOKEDExt
93
+ # when Errno::EL2HLT then Errno_EL2HLTExt
94
+ # when Errno::EL2NSYNC then Errno_EL2NSYNCExt
95
+ # when Errno::EL3HLT then Errno_EL3HLTExt
96
+ # when Errno::EL3RST then Errno_EL3RSTExt
97
+ # when Errno::ELIBACC then Errno_ELIBACCExt
98
+ # when Errno::ELIBBAD then Errno_ELIBBADExt
99
+ # when Errno::ELIBEXEC then Errno_ELIBEXECExt
100
+ # when Errno::ELIBMAX then Errno_ELIBMAXExt
101
+ # when Errno::ELIBSCN then Errno_ELIBSCNExt
102
+ # when Errno::ELNRNG then Errno_ELNRNGExt
103
+ # when Errno::ELOOP then Errno_ELOOPExt
104
+ # when Errno::EMEDIUMTYPE then Errno_EMEDIUMTYPEExt
105
+ # when Errno::EMFILE then Errno_EMFILEExt
106
+ # when Errno::EMLINK then Errno_EMLINKExt
107
+ # when Errno::EMSGSIZE then Errno_EMSGSIZEExt
108
+ # when Errno::EMULTIHOP then Errno_EMULTIHOPExt
109
+ # when Errno::ENAMETOOLONG then Errno_ENAMETOOLONGExt
110
+ # when Errno::ENAVAIL then Errno_ENAVAILExt
111
+ # when Errno::ENEEDAUTH then Errno_ENEEDAUTHExt
112
+ # when Errno::ENETDOWN then Errno_ENETDOWNExt
113
+ # when Errno::ENETRESET then Errno_ENETRESETExt
114
+ # when Errno::ENETUNREACH then Errno_ENETUNREACHExt
115
+ # when Errno::ENFILE then Errno_ENFILEExt
116
+ # when Errno::ENOANO then Errno_ENOANOExt
117
+ # when Errno::ENOATTR then Errno_ENOATTRExt
118
+ # when Errno::ENOBUFS then Errno_ENOBUFSExt
119
+ # when Errno::ENOCSI then Errno_ENOCSIExt
120
+ # when Errno::ENODATA then Errno_ENODATAExt
121
+ # when Errno::ENODEV then Errno_ENODEVExt
122
+ when Errno::ENOENT then Errno_ENOENTExt
123
+ # when Errno::ENOEXEC then Errno_ENOEXECExt
124
+ # when Errno::ENOKEY then Errno_ENOKEYExt
125
+ # when Errno::ENOLCK then Errno_ENOLCKExt
126
+ # when Errno::ENOLINK then Errno_ENOLINKExt
127
+ # when Errno::ENOMEDIUM then Errno_ENOMEDIUMExt
128
+ # when Errno::ENOMEM then Errno_ENOMEMExt
129
+ # when Errno::ENOMSG then Errno_ENOMSGExt
130
+ # when Errno::ENONET then Errno_ENONETExt
131
+ # when Errno::ENOPKG then Errno_ENOPKGExt
132
+ # when Errno::ENOPROTOOPT then Errno_ENOPROTOOPTExt
133
+ # when Errno::ENOSPC then Errno_ENOSPCExt
134
+ # when Errno::ENOSR then Errno_ENOSRExt
135
+ # when Errno::ENOSTR then Errno_ENOSTRExt
136
+ # when Errno::ENOSYS then Errno_ENOSYSExt
137
+ # when Errno::ENOTBLK then Errno_ENOTBLKExt
138
+ # when Errno::ENOTCAPABLE then Errno_ENOTCAPABLEExt
139
+ # when Errno::ENOTCONN then Errno_ENOTCONNExt
140
+ # when Errno::ENOTDIR then Errno_ENOTDIRExt
141
+ # when Errno::ENOTEMPTY then Errno_ENOTEMPTYExt
142
+ # when Errno::ENOTNAM then Errno_ENOTNAMExt
143
+ # when Errno::ENOTRECOVERABLE then Errno_ENOTRECOVERABLEExt
144
+ # when Errno::ENOTSOCK then Errno_ENOTSOCKExt
145
+ # when Errno::ENOTSUP then Errno_ENOTSUPExt
146
+ # when Errno::ENOTTY then Errno_ENOTTYExt
147
+ # when Errno::ENOTUNIQ then Errno_ENOTUNIQExt
148
+ # when Errno::ENXIO then Errno_ENXIOExt
149
+ # when Errno::EOPNOTSUPP then Errno_EOPNOTSUPPExt
150
+ # when Errno::EOVERFLOW then Errno_EOVERFLOWExt
151
+ # when Errno::EOWNERDEAD then Errno_EOWNERDEADExt
152
+ # when Errno::EPERM then Errno_EPERMExt
153
+ # when Errno::EPFNOSUPPORT then Errno_EPFNOSUPPORTExt
154
+ # when Errno::EPIPE then Errno_EPIPEExt
155
+ # when Errno::EPROCLIM then Errno_EPROCLIMExt
156
+ # when Errno::EPROCUNAVAIL then Errno_EPROCUNAVAILExt
157
+ # when Errno::EPROGMISMATCH then Errno_EPROGMISMATCHExt
158
+ # when Errno::EPROGUNAVAIL then Errno_EPROGUNAVAILExt
159
+ # when Errno::EPROTO then Errno_EPROTOExt
160
+ # when Errno::EPROTONOSUPPORT then Errno_EPROTONOSUPPORTExt
161
+ # when Errno::EPROTOTYPE then Errno_EPROTOTYPEExt
162
+ # when Errno::ERANGE then Errno_ERANGEExt
163
+ # when Errno::EREMCHG then Errno_EREMCHGExt
164
+ # when Errno::EREMOTE then Errno_EREMOTEExt
165
+ # when Errno::EREMOTEIO then Errno_EREMOTEIOExt
166
+ # when Errno::ERESTART then Errno_ERESTARTExt
167
+ # when Errno::ERFKILL then Errno_ERFKILLExt
168
+ # when Errno::EROFS then Errno_EROFSExt
169
+ # when Errno::ERPCMISMATCH then Errno_ERPCMISMATCHExt
170
+ # when Errno::ESHUTDOWN then Errno_ESHUTDOWNExt
171
+ # when Errno::ESOCKTNOSUPPORT then Errno_ESOCKTNOSUPPORTExt
172
+ # when Errno::ESPIPE then Errno_ESPIPEExt
173
+ # when Errno::ESRCH then Errno_ESRCHExt
174
+ # when Errno::ESRMNT then Errno_ESRMNTExt
175
+ # when Errno::ESTALE then Errno_ESTALEExt
176
+ # when Errno::ESTRPIPE then Errno_ESTRPIPEExt
177
+ # when Errno::ETIME then Errno_ETIMEExt
178
+ # when Errno::ETIMEDOUT then Errno_ETIMEDOUTExt
179
+ # when Errno::ETOOMANYREFS then Errno_ETOOMANYREFSExt
180
+ # when Errno::ETXTBSY then Errno_ETXTBSYExt
181
+ # when Errno::EUCLEAN then Errno_EUCLEANExt
182
+ # when Errno::EUNATCH then Errno_EUNATCHExt
183
+ # when Errno::EUSERS then Errno_EUSERSExt
184
+ # when Errno::EWOULDBLOCK then Errno_EWOULDBLOCKExt
185
+ # when Errno::EXDEV then Errno_EXDEVExt
186
+ # when Errno::EXFULL then Errno_EXFULLExt
187
+ # when Errno::EXXX then Errno_EXXXExt
188
+ # when Errno::NOERROR then Errno_NOERRORExt
189
+ # when SystemCallError then SystemCallErrorExt
190
+ # when ThreadError then ThreadErrorExt
191
+ when TypeError then TypeErrorExt
192
+ when ZeroDivisionError then ZeroDivisionErrorExt
193
+ # when StandardError then StandardErrorExt
194
+ when SystemStackError then SystemStackErrorExt
195
+ end
196
+ return ext if ext
197
+ ext = case exception.class.to_s
198
+ # when "FrozenError" then FrozenErrorExt
199
+ when "DXRuby::DXRubyError" then DXRubyErrorExt
200
+ end
201
+ return ext
202
+ end
203
+
204
+ module ExceptionExt
205
+ def eturem_location_to_s(location)
206
+ %<"#{location.path}" #{location.lineno}行目: '#{location.label}'>
207
+ end
208
+
209
+ def eturem_traceback(order = :bottom)
210
+ order == :top ? "" : "\e[1mTraceback\e[0m(エラー発生までの流れを直前のものほど下に表示しています。):\n"
211
+ end
212
+
213
+ def eturem_message()
214
+ "\e[1;31m【エラー】\e[0m" +
215
+ (@eturem_path == "(eval)" ? "eval 中の" : %<ファイル"#{@eturem_path}">) +
216
+ " #{@eturem_lineno}行目:\e[1m(\e[4m#{self.class}\e[0;1m)\n" +
217
+ "#{@eturem_message_ja || @eturem_message}"
218
+ end
219
+ end
220
+ end
@@ -0,0 +1,50 @@
1
+ module Eturem
2
+ module NameErrorExt
3
+ include ExceptionExt
4
+
5
+ def eturem_message()
6
+ if self.name.to_s.encode("utf-8").include?(" ")
7
+ eturem_multibyte_space
8
+ elsif self.name.to_s.encode("utf-8").match(/[”’`(){}#]/)
9
+ eturem_multibyte_char
10
+ elsif self.receiver == nil
11
+ eturem_receiver_is_nil
12
+ else
13
+ eturem_basic_name_error
14
+ end
15
+ super
16
+ end
17
+
18
+ def eturem_multibyte_space
19
+ @eturem_script_lines = Eturem::Base.read_script(@eturem_path)
20
+ Eturem::Base.highlight(@eturem_script_lines[@eturem_lineno], / +/, "\e[1;4;31m")
21
+ @eturem_message_ja = "スクリプト中に全角空白が混じっています。"
22
+ end
23
+
24
+ def eturem_multibyte_char
25
+ @eturem_script_lines = Eturem::Base.read_script(@eturem_path)
26
+ if @eturem_script_lines[@eturem_lineno]
27
+ @eturem_script_lines[@eturem_lineno].gsub!(/[”’`()#]+/){ "\e[1;4;31m#{$&}\e[0m" }
28
+ end
29
+ @eturem_message_ja = "スクリプト中に全角記号が混じっています。"
30
+ end
31
+
32
+ def eturem_receiver_is_nil
33
+ @eturem_message_ja =
34
+ "nil に対して #{self.name.to_s.encode("utf-8")} というメソッドを呼び出そうとしています。\n" +
35
+ "変数の値/メソッドの返値が予期せず nil になっている可能性があります。"
36
+ end
37
+
38
+ def eturem_basic_name_error
39
+ @eturem_message_ja =
40
+ (self.is_a?(NoMethodError) ? "メソッド" : "変数/メソッド") +
41
+ "「\e[1;4;31m#{self.name.to_s.encode("utf-8")}\e[0m」は存在しません。"
42
+ unless @eturem_corrections.empty?
43
+ did_you_mean = @eturem_corrections.map{ |d|
44
+ "\e[1;33m#{d.to_s.encode("utf-8")}\e[0m"
45
+ }.join(" / ")
46
+ @eturem_message_ja += "「#{did_you_mean}」の入力ミスではありませんか?"
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,12 @@
1
+ # coding: utf-8
2
+
3
+ module Eturem
4
+ module NoMemoryErrorExt
5
+ include ExceptionExt
6
+
7
+ def eturem_message()
8
+ @eturem_message_ja = "メモリを確保できませんでした。あまりにも大量のデータを作成していませんか?"
9
+ super
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,88 @@
1
+ module Eturem
2
+ module SyntaxErrorExt
3
+ include ExceptionExt
4
+
5
+ def eturem_message()
6
+ if @eturem_message.match(/unexpected (?<unexpected>(?:','|[^,])+)/)
7
+ eturem_unexpected(eturem_transform_keyword(Regexp.last_match(:unexpected)))
8
+ elsif @eturem_message.match(/Invalid (?<invalid>(?:break|next|retry|redo|yield))/)
9
+ eturem_invalid(Regexp.last_match(:invalid))
10
+ elsif @eturem_message.include?("unterminated string meets end of file")
11
+ eturem_unterminated_string
12
+ elsif @eturem_message.include?("unterminated regexp meets end of file")
13
+ eturem_unterminated_regexp
14
+ end
15
+ super
16
+ end
17
+
18
+ def eturem_unexpected(unexpected)
19
+ expecting = ["ファイルの末尾"]
20
+ if @eturem_message.match(/[,\s]expecting (?<expecting>.+)/)
21
+ expecting = Regexp.last_match(:expecting).split(" or ").map do |exp|
22
+ eturem_transform_keyword(exp)
23
+ end
24
+ end
25
+ Eturem::Base.highlight(@eturem_script_lines[@eturem_lineno], unexpected, "\e[1;4;31m")
26
+
27
+ keywords = %w[if unless case while until for begin def class module do].select do |keyword|
28
+ @eturem_script_lines.join.include?(keyword)
29
+ end
30
+ keywords = "「#{keywords.join(" / ")}」"
31
+ keywords = "ifなど" if keywords == "「」"
32
+ if unexpected == "ファイルの末尾"
33
+ @eturem_message_ja =
34
+ "(ただし、実際のエラーの原因はおそらく#{@eturem_lineno}行目より前にあります。)\n"
35
+ if expecting.join == "ファイルの末尾"
36
+ @eturem_message_ja += "構文エラーです。何か足りないものがあるようです。"
37
+ else
38
+ @eturem_message_ja += "構文エラーです。 #{expecting.join(" または ")} が足りない可能性があります。"
39
+ end
40
+ if expecting.include?("end")
41
+ @eturem_message_ja += "#{keywords}に対応する「end」があるか確認してください。"
42
+ end
43
+ elsif expecting.join == "ファイルの末尾"
44
+ @eturem_message_ja =
45
+ "構文エラーです。予期せぬ #{unexpected} があります。以下のような可能性があります。\n" +
46
+ "・その直前に何らかのエラーの原因がある。\n" +
47
+ "・#{unexpected} が余分に書かれている、またはタイプミスで予期せず書いてしまった。"
48
+ if unexpected == "end"
49
+ @eturem_message_ja += "\n・#{keywords}と「end」の対応が合っていない。"
50
+ end
51
+ elsif !expecting.empty?
52
+ @eturem_message_ja =
53
+ "構文エラーです。 #{expecting.join(" または ")} が来るべき場所に、" +
54
+ "#{unexpected} が来てしまいました。"
55
+ end
56
+ end
57
+
58
+ def eturem_invalid(invalid)
59
+ Eturem::Base.highlight(@eturem_script_lines[@eturem_lineno], invalid, "\e[1;4;31m")
60
+ @eturem_message_ja = "#{invalid} が不適切な場所にあります。"
61
+ end
62
+
63
+ def eturem_unterminated_string()
64
+ @eturem_message_ja = "文字列が閉じられていません。「\"」や「'」を確認してください。"
65
+ end
66
+
67
+ def eturem_unterminated_regexp()
68
+ @eturem_message_ja = "正規表現が閉じられていません。「/」を確認してください。"
69
+ end
70
+
71
+ def eturem_transform_keyword(keyword)
72
+ case keyword
73
+ when "end-of-input", "$end"
74
+ "ファイルの末尾"
75
+ when /^(?:keyword|modifier)_/
76
+ Regexp.last_match.post_match
77
+ when "'\\n'"
78
+ "改行"
79
+ when "backslash"
80
+ "\\"
81
+ when /^[`']([^']+)'$/
82
+ $1
83
+ else
84
+ keyword
85
+ end
86
+ end
87
+ end
88
+ end