logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

sql.lua (3386B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- SQL LPeg lexer.
  3. local lexer = require('lexer')
  4. local token, word_match = lexer.token, lexer.word_match
  5. local P, S = lpeg.P, lpeg.S
  6. local lex = lexer.new('sql')
  7. -- Whitespace.
  8. lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
  9. -- Keywords.
  10. lex:add_rule('keyword', token(lexer.KEYWORD, word_match({
  11. 'add', 'all', 'alter', 'analyze', 'and', 'as', 'asc', 'asensitive', 'before', 'between', 'bigint',
  12. 'binary', 'blob', 'both', 'by', 'call', 'cascade', 'case', 'change', 'char', 'character', 'check',
  13. 'collate', 'column', 'condition', 'connection', 'constraint', 'continue', 'convert', 'create',
  14. 'cross', 'current_date', 'current_time', 'current_timestamp', 'current_user', 'cursor',
  15. 'database', 'databases', 'day_hour', 'day_microsecond', 'day_minute', 'day_second', 'dec',
  16. 'decimal', 'declare', 'default', 'delayed', 'delete', 'desc', 'describe', 'deterministic',
  17. 'distinct', 'distinctrow', 'div', 'double', 'drop', 'dual', 'each', 'else', 'elseif', 'enclosed',
  18. 'escaped', 'exists', 'exit', 'explain', 'false', 'fetch', 'float', 'for', 'force', 'foreign',
  19. 'from', 'fulltext', 'goto', 'grant', 'group', 'having', 'high_priority', 'hour_microsecond',
  20. 'hour_minute', 'hour_second', 'if', 'ignore', 'in', 'index', 'infile', 'inner', 'inout',
  21. 'insensitive', 'insert', 'int', 'integer', 'interval', 'into', 'is', 'iterate', 'join', 'key',
  22. 'keys', 'kill', 'leading', 'leave', 'left', 'like', 'limit', 'lines', 'load', 'localtime',
  23. 'localtimestamp', 'lock', 'long', 'longblob', 'longtext', 'loop', 'low_priority', 'match',
  24. 'mediumblob', 'mediumint', 'mediumtext', 'middleint', 'minute_microsecond', 'minute_second',
  25. 'mod', 'modifies', 'natural', 'not', 'no_write_to_binlog', 'null', 'numeric', 'on', 'optimize',
  26. 'option', 'optionally', 'or', 'order', 'out', 'outer', 'outfile', 'precision', 'primary',
  27. 'procedure', 'purge', 'read', 'reads', 'real', 'references', 'regexp', 'rename', 'repeat',
  28. 'replace', 'require', 'restrict', 'return', 'revoke', 'right', 'rlike', 'schema', 'schemas',
  29. 'second_microsecond', 'select', 'sensitive', 'separator', 'set', 'show', 'smallint', 'soname',
  30. 'spatial', 'specific', 'sql', 'sqlexception', 'sqlstate', 'sqlwarning', 'sql_big_result',
  31. 'sql_calc_found_rows', 'sql_small_result', 'ssl', 'starting', 'straight_join', 'table',
  32. 'terminated', 'text', 'then', 'tinyblob', 'tinyint', 'tinytext', 'to', 'trailing', 'trigger',
  33. 'true', 'undo', 'union', 'unique', 'unlock', 'unsigned', 'update', 'usage', 'use', 'using',
  34. 'utc_date', 'utc_time', 'utc_timestamp', 'values', 'varbinary', 'varchar', 'varcharacter',
  35. 'varying', 'when', 'where', 'while', 'with', 'write', 'xor', 'year_month', 'zerofill'
  36. }, true)))
  37. -- Identifiers.
  38. lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word))
  39. -- Strings.
  40. local sq_str = lexer.range("'")
  41. local dq_str = lexer.range('"')
  42. local bq_str = lexer.range('`')
  43. lex:add_rule('string', token(lexer.STRING, sq_str + dq_str + bq_str))
  44. -- Comments.
  45. local line_comment = lexer.to_eol(P('--') + '#')
  46. local block_comment = lexer.range('/*', '*/')
  47. lex:add_rule('comment', token(lexer.COMMENT, line_comment + block_comment))
  48. -- Numbers.
  49. lex:add_rule('number', token(lexer.NUMBER, lexer.number))
  50. -- Operators.
  51. lex:add_rule('operator', token(lexer.OPERATOR, S(',()')))
  52. lexer.property['scintillua.comment'] = '--'
  53. return lex