Class: Syntax::SQLite

Inherits:
Tokenizer show all
Defined in:
lib/syntax/lang/sqlite.rb

Constant Summary collapse

SQLite_PREDEFINED_FUNCTIONS =
Set.new %w{abs avg coalesce count glob
hex ifnull last_insert_rowid length like load_extension lower 
ltrim max min sum nullif
quote random randomblob replace round
rtrim soundex sqlite_version substr total
trim typeof upper zeroblob
date time datetime julianday
strftime over}
SQLite_KEYWORDS =
Set.new %w{abort add after all alter analyze
asc attach autoincrement before by cascade change character
check commit conflict constraint create cross  collate
current_date current_time current_timestamp database default
deferrable deferred delete desc detach distinct drop each
escape except exclusive explain fail for foreign from
full group having if ignore immediate
index initially inner insert instead intersect into is
join key left limit modify natural of offset on or order
outer plan pragma primary query raise references reindex
rename replace restrict right rollback row select set
table temp temporary to transaction trigger union
unique update using vacuum values view virtual
where partition}
SQLite_DATATYPES =
Set.new %w{null none text numeric integer
text blob int varchar char real float
double}
SQLite_OPERATORS =
Set.new %w{not escape isnull notnull between and
in exists case when then else begin end cast as
like glob regexp < >  || * / % + - << >>
& | <= >= = == != <>
match}

Instance Attribute Summary

Attributes inherited from Tokenizer

#chunk, #group

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Tokenizer

#finish, #option, #set, #setup, #start, #teardown, #tokenize

Class Method Details

.add_function(name) ⇒ Object



7
8
9
# File 'lib/syntax/lang/sqlite.rb', line 7

def self.add_function(name)
  SQLite_PREDEFINED_FUNCTIONS << name
end

Instance Method Details

#stepObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/syntax/lang/sqlite.rb', line 45

def step
  case
  when scan(/\s+/)
    start_group :normal, matched
  when scan(%r{ "(?: \\. | \\" | [^"\n])*" }x)
    start_group :string, matched
  when scan(%r{ '(?: \\. | \\' | [^'\n])*' }x )
    start_group :string, matched
  when (scan(/[a-z_][a-z_\d]+/i) or scan(/[<>\|\*%&!=]+/))
    m = matched.downcase
    if SQLite_PREDEFINED_FUNCTIONS.include?( m )
      start_group :function, matched
    elsif SQLite_KEYWORDS.include?( m )
      start_group :keyword, matched
    elsif SQLite_DATATYPES.include?( m )
      start_group :datatype, matched
    elsif SQLite_OPERATORS.include?( m )
      start_group :operator, matched
    else
      start_group :ident, matched
    end
  when scan(/--.*$/)
    start_group :comment, matched
  else
    start_group :other, scan(/./x)
  end
end