Class: Yoda::Parsing::SourceCutter::FixingSource
- Inherits:
-
Object
- Object
- Yoda::Parsing::SourceCutter::FixingSource
- Defined in:
- lib/yoda/parsing/source_cutter.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#tokens_to_append ⇒ Object
readonly
Returns the value of attribute tokens_to_append.
Instance Method Summary collapse
- #diagnostic ⇒ Symbol?
-
#initialize(source, tokens_to_append) ⇒ FixingSource
constructor
A new instance of FixingSource.
- #to_s ⇒ Object
- #token_mapper ⇒ Object
Constructor Details
#initialize(source, tokens_to_append) ⇒ FixingSource
Returns a new instance of FixingSource.
80 81 82 83 |
# File 'lib/yoda/parsing/source_cutter.rb', line 80 def initialize(source, tokens_to_append) @source = source @tokens_to_append = tokens_to_append end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
77 78 79 |
# File 'lib/yoda/parsing/source_cutter.rb', line 77 def source @source end |
#tokens_to_append ⇒ Object (readonly)
Returns the value of attribute tokens_to_append.
77 78 79 |
# File 'lib/yoda/parsing/source_cutter.rb', line 77 def tokens_to_append @tokens_to_append end |
Instance Method Details
#diagnostic ⇒ Symbol?
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/yoda/parsing/source_cutter.rb', line 104 def diagnostic begin ::Parser::CurrentRuby.parse(to_s) nil rescue ::Parser::SyntaxError => ex fail CannotRecoverError, "Cannot recover: #{ex.diagnostic.render}" unless ex.diagnostic.reason == :unexpected_token fail CannotRecoverError, "Cannot recover: #{ex.diagnostic.render}" unless ex.diagnostic.location.end_pos == to_s.length case ex.diagnostic.arguments[:token] when 'tSEMI' :fix_line when '$end' :fix_block else fail CannotRecoverError, "Cannot recover: #{ex.diagnostic.render}" end end end |
#to_s ⇒ Object
85 86 87 |
# File 'lib/yoda/parsing/source_cutter.rb', line 85 def to_s @to_s ||= source + "\n" + tokens_to_append.map(&token_mapper).join("\n") end |
#token_mapper ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/yoda/parsing/source_cutter.rb', line 89 def token_mapper { tSEMI: ';', tLBRACE: '{', tRBRACE: '}', tLPAREN: '(', tRPAREN: ')', kEND: 'end', kNIL: 'nil', dummy_constant: 'DUMMY_CONSTANT', dummy_method: 'dummy_method', } end |