Class: ErrorToCommunicate::Heuristic::SyntaxError
- Inherits:
-
ErrorToCommunicate::Heuristic
- Object
- ErrorToCommunicate::Heuristic
- ErrorToCommunicate::Heuristic::SyntaxError
- Defined in:
- lib/error_to_communicate/heuristic/syntax_error.rb
Instance Attribute Summary collapse
-
#expected ⇒ Object
Returns the value of attribute expected.
-
#invalid_loc ⇒ Object
Returns the value of attribute invalid_loc.
-
#reported_file ⇒ Object
Returns the value of attribute reported_file.
-
#reported_line ⇒ Object
Returns the value of attribute reported_line.
-
#unexpected ⇒ Object
Returns the value of attribute unexpected.
Attributes inherited from ErrorToCommunicate::Heuristic
Class Method Summary collapse
- .for?(einfo) ⇒ Boolean
-
.parse_message(message) ⇒ Object
“/Users/josh/code/what-we-ve-got-here-is-an-error-to-communicate/proving_grounds/simple_syntax_error.rb:2: syntax error, unexpected end-of-input, expecting keyword_end”.
Instance Method Summary collapse
-
#initialize ⇒ SyntaxError
constructor
A new instance of SyntaxError.
- #semantic_explanation ⇒ Object
- #semantic_info ⇒ Object
Methods inherited from ErrorToCommunicate::Heuristic
#backtrace, #classname, #explanation, #message, #semantic_backtrace, #semantic_summary
Constructor Details
#initialize ⇒ SyntaxError
Returns a new instance of SyntaxError.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/error_to_communicate/heuristic/syntax_error.rb', line 13 def initialize(*) super self.reported_file , self.reported_line , self.unexpected , self.expected = self.class.() self.invalid_loc = ExceptionInfo::Location.new \ path: reported_file, linenum: reported_line, label: "unexpected #{unexpected}, expected: #{expected}", pred: backtrace[0], binding: nil end |
Instance Attribute Details
#expected ⇒ Object
Returns the value of attribute expected.
11 12 13 |
# File 'lib/error_to_communicate/heuristic/syntax_error.rb', line 11 def expected @expected end |
#invalid_loc ⇒ Object
Returns the value of attribute invalid_loc.
11 12 13 |
# File 'lib/error_to_communicate/heuristic/syntax_error.rb', line 11 def invalid_loc @invalid_loc end |
#reported_file ⇒ Object
Returns the value of attribute reported_file.
11 12 13 |
# File 'lib/error_to_communicate/heuristic/syntax_error.rb', line 11 def reported_file @reported_file end |
#reported_line ⇒ Object
Returns the value of attribute reported_line.
11 12 13 |
# File 'lib/error_to_communicate/heuristic/syntax_error.rb', line 11 def reported_line @reported_line end |
#unexpected ⇒ Object
Returns the value of attribute unexpected.
11 12 13 |
# File 'lib/error_to_communicate/heuristic/syntax_error.rb', line 11 def unexpected @unexpected end |
Class Method Details
.for?(einfo) ⇒ Boolean
6 7 8 |
# File 'lib/error_to_communicate/heuristic/syntax_error.rb', line 6 def self.for?(einfo) einfo.classname == 'SyntaxError' && (einfo.) end |
.parse_message(message) ⇒ Object
“/Users/josh/code/what-we-ve-got-here-is-an-error-to-communicate/proving_grounds/simple_syntax_error.rb:2: syntax error, unexpected end-of-input, expecting keyword_end”
49 50 51 52 53 |
# File 'lib/error_to_communicate/heuristic/syntax_error.rb', line 49 def self.() return if !~ /^(.*?):(\d+):.*?unexpected (.*?), expecting (.*)$/ file, line, unexpected, expected = $1, $2.to_i, $3, $4 [file, line, unexpected, expected] end |
Instance Method Details
#semantic_explanation ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/error_to_communicate/heuristic/syntax_error.rb', line 38 def semantic_explanation [ :message, [ [:context, 'Unexpected '], [:details, unexpected], [:context, ', expected'], [:details, expected], ] ] end |
#semantic_info ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/error_to_communicate/heuristic/syntax_error.rb', line 27 def semantic_info [:heuristic, [:code, { location: invalid_loc, context: -5..5, message: "unexpected #{unexpected}, expected #{expected}", emphasis: :code, }] ] end |