Class: CodeLexer::Abstractor

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

Instance Method Summary collapse

Constructor Details

#initialize(identifiers_dictionary = [], strings_dictionary = [], numbers_dictionary = []) ⇒ Abstractor

Returns a new instance of Abstractor.



5
6
7
8
9
10
11
12
# File 'lib/code-lexer/abstractor.rb', line 5

def initialize(identifiers_dictionary = [], strings_dictionary = [], numbers_dictionary = [])
    @dictionary = {}
    @dictionary[:identifiers] = ['NOOP'] + identifiers_dictionary
    @dictionary[:strings] = strings_dictionary
    @dictionary[:numbers] = numbers_dictionary
    
    @abstractor_pieces = []
end

Instance Method Details

#abstract!(tokens) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/code-lexer/abstractor.rb', line 85

def abstract!(tokens)
    @abstractor_pieces.each do |abstractor_piece|
        tokens = abstractor_piece.abstract(tokens)
    end
    
    return self
end

#abstract_commentsObject



55
56
57
58
# File 'lib/code-lexer/abstractor.rb', line 55

def abstract_comments
    @abstractor_pieces << CommentAbstractor.new(self)
    return self
end

#abstract_everythingObject



14
15
16
17
18
19
20
21
22
# File 'lib/code-lexer/abstractor.rb', line 14

def abstract_everything
    self.abstract_identifiers
    self.abstract_numbers
    self.abstract_comments
    self.abstract_strings
    self.abstract_spaces
    
    return self
end

#abstract_identifiersObject



45
46
47
48
# File 'lib/code-lexer/abstractor.rb', line 45

def abstract_identifiers
    @abstractor_pieces << IdentifierAbstractor.new(self)
    return self
end

#abstract_numbersObject



50
51
52
53
# File 'lib/code-lexer/abstractor.rb', line 50

def abstract_numbers
    @abstractor_pieces << NumberAbstractor.new(self)
    return self
end

#abstract_spacesObject



65
66
67
68
# File 'lib/code-lexer/abstractor.rb', line 65

def abstract_spaces
    @abstractor_pieces << SpaceAbstractor.new(self)
    return self
end

#abstract_stringsObject



60
61
62
63
# File 'lib/code-lexer/abstractor.rb', line 60

def abstract_strings
    @abstractor_pieces << StringAbstractor.new(self)
    return self
end

#deabstract!(tokens) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/code-lexer/abstractor.rb', line 93

def deabstract!(tokens)
    @abstractor_pieces.each do |abstractor_piece|
        tokens = abstractor_piece.deabstract(tokens)
    end
    
    return self
end

#dictionariesObject



41
42
43
# File 'lib/code-lexer/abstractor.rb', line 41

def dictionaries
    @dictionary
end

#dictionaryObject



24
25
26
27
# File 'lib/code-lexer/abstractor.rb', line 24

def dictionary
    warn "[DEPRECATION] The method CodeLexer::Abstractor#dictionary is deprecated; used CodeLexer::Abstractor#identifiers_dictionary instead"
    self.identifiers_dictionary
end

#identifiers_dictionaryObject



29
30
31
# File 'lib/code-lexer/abstractor.rb', line 29

def identifiers_dictionary
    @dictionary[:identifiers]
end

#numbers_dictionaryObject



37
38
39
# File 'lib/code-lexer/abstractor.rb', line 37

def numbers_dictionary
    @dictionary[:numbers]
end

#remove_commentsObject



80
81
82
83
# File 'lib/code-lexer/abstractor.rb', line 80

def remove_comments
    @abstractor_pieces << CommentRemover.new(self)
    return self
end

#remove_newlinesObject



75
76
77
78
# File 'lib/code-lexer/abstractor.rb', line 75

def remove_newlines
    @abstractor_pieces << NewlineRemover.new(self)
    return self
end

#remove_spacesObject



70
71
72
73
# File 'lib/code-lexer/abstractor.rb', line 70

def remove_spaces
    @abstractor_pieces << SpaceRemover.new(self)
    return self
end

#strings_dictionaryObject



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

def strings_dictionary
    @dictionary[:strings]
end