Class: LanguageParser::SQLLanguageScanner
- Inherits:
-
LanguageScanner
- Object
- LanguageScanner
- LanguageParser::SQLLanguageScanner
- Defined in:
- lib/cgialib/lp/SQLLanguageScanner.rb
Overview
class : SQLLanguageScanner
This is the SQLLanguageScanner which is an object specialized to read the important language elements of an SQL file.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#fieldClass ⇒ Object
The class to use to build Field objects.
-
#tableClass ⇒ Object
The class to use to build Table objects.
-
#tables ⇒ Object
readonly
The array of tables.
Instance Method Summary collapse
-
#initialize ⇒ SQLLanguageScanner
constructor
initialize().
-
#parse(tokens) ⇒ Object
parse( tokens ).
-
#to_s ⇒ Object
to_s().
Constructor Details
#initialize ⇒ SQLLanguageScanner
initialize()
Constructs the SQL language scanner class
114 115 116 117 118 119 120 121 |
# File 'lib/cgialib/lp/SQLLanguageScanner.rb', line 114 def initialize() @tables = [] @table_hash = {} @tableClass = SQLTable @fieldClass = SQLField end |
Instance Attribute Details
#fieldClass ⇒ Object
The class to use to build Field objects
125 126 127 |
# File 'lib/cgialib/lp/SQLLanguageScanner.rb', line 125 def fieldClass @fieldClass end |
#tableClass ⇒ Object
The class to use to build Table objects
124 125 126 |
# File 'lib/cgialib/lp/SQLLanguageScanner.rb', line 124 def tableClass @tableClass end |
#tables ⇒ Object (readonly)
The array of tables
123 124 125 |
# File 'lib/cgialib/lp/SQLLanguageScanner.rb', line 123 def tables @tables end |
Instance Method Details
#parse(tokens) ⇒ Object
parse( tokens )
tokens - An array of tokens built by a Tokenizer
This method reads the stream of tokens built by a Tokenizer and fills the @prototypes array with the prototypes that are found.
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/cgialib/lp/SQLLanguageScanner.rb', line 160 def parse( tokens ) # This is the code fragment leading up to the interior # of the function codefrag = TokenStream.new() has_create = false building_table = false # Look through each token comment = "" tokens.each_index { |index| tok = tokens[ index ] if tok.to_s =~ /^create$/i comment = tokens.get_comments( index ) has_create = true elsif tok.to_s =~ /^table$/i && has_create building_table = true has_create = false elsif tok.to_s == ";" && building_table parse_table( codefrag, comment ) codefrag = TokenStream.new() building_table = false has_create = false comment = "" elsif has_create && tok.is_a?( CodeToken ) has_create = false elsif building_table codefrag.push( tok ) end } end |
#to_s ⇒ Object
to_s()
Pretty printer for this object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/cgialib/lp/SQLLanguageScanner.rb', line 131 def to_s() text = "" tables.each { |table| text += "#{table.name}:\n" table.fields.each { |field| text += " #{field}\n" } text += "Comment:\n#{table.comment.strip}\n" text += "\n" } text end |