Class: CodeLexer::LexedContent

Inherits:
Object
  • Object
show all
Defined in:
lib/code-lexer/lexer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tokens) ⇒ LexedContent

Returns a new instance of LexedContent.



33
34
35
# File 'lib/code-lexer/lexer.rb', line 33

def initialize(tokens)
    @tokens = tokens
end

Instance Attribute Details

#tokensObject (readonly)

Returns the value of attribute tokens.



31
32
33
# File 'lib/code-lexer/lexer.rb', line 31

def tokens
  @tokens
end

Instance Method Details

#token_linesObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/code-lexer/lexer.rb', line 37

def token_lines
    result = []
    current_line = []
    @tokens.each do |t|
        if t.type == :newline
            result << current_line
            current_line = []
        else
            current_line << t
        end
    end
    
    result << current_line
    result.delete_if { |line| line.empty? }
    
    return result
end

#token_stream(abstractor = nil) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/code-lexer/lexer.rb', line 55

def token_stream(abstractor = nil)
    abstractor.abstract!(@tokens) if abstractor
    
    result = []
    @tokens.each do |token|
        result << token.abstracted_value
    end
    
    return result.join(" ")
end