要約
Prism::ParseResult#errors で得られる、構文解析中に発生したエラーを表すクラスです。
例外クラスではないことに注意してください。prism はエラー耐性のあるパーサであり、構文エラーがあっても例外を発生させず、見つかったエラーをこのクラスのインスタンスとして Prism::ParseResult#errors に蓄積します。
例require "prism"
error = Prism.parse("1 +\n").errors.first
p error.class # => Prism::ParseError
p error.message # => "unexpected end-of-input; expected an expression after the operator"
p error.location.start_line # => 1
[SEE_ALSO] Prism::ParseResult#errors, Prism::ParseWarning
目次
インスタンスメソッド
location -> Prism::LocationRuby 3.3 から[permalink][rdoc][edit]-
エラーが発生したソースコード上の位置を表す Prism::Location を返します。該当箇所の文字列そのものは
location.sliceで取得できます。 message -> StringRuby 3.3 から[permalink][rdoc][edit]-
エラーメッセージを返します。