要約
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
目次
インスタンスメソッド
level -> SymbolRuby 3.4 から[permalink][rdoc][edit]-
エラーの深刻度による分類を表すシンボル(例:
:syntax)を返します。 location -> Prism::LocationRuby 3.3 から[permalink][rdoc][edit]-
エラーが発生したソースコード上の位置を表す Prism::Location を返します。該当箇所の文字列そのものは
location.sliceで取得できます。 message -> StringRuby 3.3 から[permalink][rdoc][edit]-
エラーメッセージを返します。
type -> SymbolRuby 3.4 から[permalink][rdoc][edit]-
エラーの種類を表すシンボル(例:
:expect_expression_after_operator)を返します。これはエラーメッセージの変換レイヤーとの連携のために使われる内部用のシンボルであり、正式な公開 API ではありません。将来のバージョンで予告なく変わる可能性があります。