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.
| 84 85 86 87 | # File 'lib/yoda/parsing/source_cutter.rb', line 84 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.
| 81 82 83 | # File 'lib/yoda/parsing/source_cutter.rb', line 81 def source @source end | 
#tokens_to_append ⇒ Object (readonly)
Returns the value of attribute tokens_to_append.
| 81 82 83 | # File 'lib/yoda/parsing/source_cutter.rb', line 81 def tokens_to_append @tokens_to_append end | 
Instance Method Details
#diagnostic ⇒ Symbol?
| 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | # File 'lib/yoda/parsing/source_cutter.rb', line 108 def diagnostic begin Parsing::Parser.new.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
| 89 90 91 | # File 'lib/yoda/parsing/source_cutter.rb', line 89 def to_s @to_s ||= source + "\n" + tokens_to_append.map(&token_mapper).join("\n") end | 
#token_mapper ⇒ Object
| 93 94 95 96 97 98 99 100 101 102 103 104 105 | # File 'lib/yoda/parsing/source_cutter.rb', line 93 def token_mapper { tSEMI: ';', tLBRACE: '{', tRBRACE: '}', tLPAREN: '(', tRPAREN: ')', kEND: 'end', kNIL: 'nil', dummy_constant: 'DUMMY_CONSTANT', dummy_method: 'dummy_method', } end |