Class: GitlabZOQL::Parser
- Inherits:
-
Racc::Parser
- Object
- Racc::Parser
- GitlabZOQL::Parser
- Defined in:
- lib/gitlab-zoql/parser/parser.rex.rb,
lib/gitlab-zoql/parser/parser.racc.rb
Overview
-*- fill-column: 30; -*-
Defined Under Namespace
Modules: Statement Classes: ScanError
Constant Summary collapse
- Racc_arg =
[ racc_action_table, racc_action_check, racc_action_default, racc_action_pointer, racc_goto_table, racc_goto_check, racc_goto_default, racc_goto_pointer, racc_nt_base, racc_reduce_table, racc_token_table, racc_shift_n, racc_reduce_n, racc_use_result_var ]
- Racc_token_to_s_table =
[ "$end", "error", "SELECT", "FROM", "WHERE", "identifier", "OR", "AND", "not_equals_operator", "NULL", "equals_operator", "less_than_operator", "greater_than_operator", "less_than_or_equals_operator", "greater_than_or_equals_operator", "plus_sign", "minus_sign", "asterisk", "solidus", "sign", "general_value_specification", "comma", "quote", "character_string_literal", "DATETIME", "datetime_string", "unsigned_integer", "period", "$start", "direct_sql_statement", "direct_sql_data_statement", "direct_select_statement_multiple_rows", "query_expression", "query_specification", "select_list", "table_expression", "select_sublist", "column_name", "column_name_list", "value_expression", "from_clause", "where_clause", "table_reference", "table_name", "search_condition", "boolean_term", "boolean_factor", "predicate", "null_predicate", "comparison_predicate", "numeric_value_expression", "general_literal", "term", "factor", "value_expression_primary", "unsigned_value_specification", "unsigned_literal", "unsigned_numeric_literal", "datetime_literal", "exact_numeric_literal" ]
- Racc_debug_parser =
false
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#lineno ⇒ Object
readonly
Returns the value of attribute lineno.
-
#state ⇒ Object
Returns the value of attribute state.
Instance Method Summary collapse
- #_next_token ⇒ Object
- #_reduce_none(val, _values, result) ⇒ Object
- #action ⇒ Object
- #load_file(filename) ⇒ Object
- #next_token ⇒ Object
- #scan_file(filename) ⇒ Object
- #scan_setup(str) ⇒ Object
- #scan_str(str) ⇒ Object (also: #scan)
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
16 17 18 |
# File 'lib/gitlab-zoql/parser/parser.rex.rb', line 16 def filename @filename end |
#lineno ⇒ Object (readonly)
Returns the value of attribute lineno.
15 16 17 |
# File 'lib/gitlab-zoql/parser/parser.rex.rb', line 15 def lineno @lineno end |
#state ⇒ Object
Returns the value of attribute state.
17 18 19 |
# File 'lib/gitlab-zoql/parser/parser.rex.rb', line 17 def state @state end |
Instance Method Details
#_next_token ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/gitlab-zoql/parser/parser.rex.rb', line 56 def _next_token text = @ss.peek(1) @lineno += 1 if text == "\n" token = case @state when nil case when (text = @ss.scan(/\'/i)) action { @state = :STRS; [:quote, text] } when (text = @ss.scan(/[0-9]+/i)) action { [:unsigned_integer, text.to_i] } when (text = @ss.scan(/\s+/i)) ; when (text = @ss.scan(/AND\b/i)) action { [:AND, text] } when (text = @ss.scan(/COUNT\b/i)) action { [:COUNT, text] } when (text = @ss.scan(/ELSE\b/i)) action { [:ELSE, text] } when (text = @ss.scan(/FROM\b/i)) action { [:FROM, text] } when (text = @ss.scan(/NULL\b/i)) action { [:NULL, text] } when (text = @ss.scan(/OR\b/i)) action { [:OR, text] } when (text = @ss.scan(/SELECT\b/i)) action { [:SELECT, text] } when (text = @ss.scan(/WHERE\b/i)) action { [:WHERE, text] } when (text = @ss.scan(/!=/i)) action { [:not_equals_operator, text] } when (text = @ss.scan(/=/i)) action { [:equals_operator, text] } when (text = @ss.scan(/<=/i)) action { [:less_than_or_equals_operator, text] } when (text = @ss.scan(/</i)) action { [:less_than_operator, text] } when (text = @ss.scan(/>=/i)) action { [:greater_than_or_equals_operator, text] } when (text = @ss.scan(/>/i)) action { [:greater_than_operator, text] } when (text = @ss.scan(/,/i)) action { [:comma, text] } when (text = @ss.scan(/\w+/i)) action { [:identifier, text] } when (text = @ss.scan(/----/i)) ; when (text = @ss.scan(/require/i)) ; else text = @ss.string[@ss.pos .. -1] raise ScanError, "can not match: '" + text + "'" end # if when :STRS case when (text = @ss.scan(/[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+\+[0-9]+:[0-9]+/i)) action { [:datetime_string, DateTime.parse(text)] } when (text = @ss.scan(/(?:[^\\']|\\.|'')+/i)) action { [:character_string_literal, text] } when (text = @ss.scan(/\'/i)) action { @state = nil; [:quote, text] } else text = @ss.string[@ss.pos .. -1] raise ScanError, "can not match: '" + text + "'" end # if else raise ScanError, "undefined state: '" + state.to_s + "'" end # case state token end |
#_reduce_none(val, _values, result) ⇒ Object
599 600 601 |
# File 'lib/gitlab-zoql/parser/parser.racc.rb', line 599 def _reduce_none(val, _values, result) val[0] end |
#action ⇒ Object
25 26 27 |
# File 'lib/gitlab-zoql/parser/parser.rex.rb', line 25 def action yield end |
#load_file(filename) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/gitlab-zoql/parser/parser.rex.rb', line 35 def load_file( filename ) @filename = filename File.open(filename, "r") do |f| scan_setup(f.read) end end |
#next_token ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/gitlab-zoql/parser/parser.rex.rb', line 48 def next_token return if @ss.eos? # skips empty actions until token = _next_token or @ss.eos?; end token end |
#scan_file(filename) ⇒ Object
42 43 44 45 |
# File 'lib/gitlab-zoql/parser/parser.rex.rb', line 42 def scan_file( filename ) load_file(filename) do_parse end |
#scan_setup(str) ⇒ Object
19 20 21 22 23 |
# File 'lib/gitlab-zoql/parser/parser.rex.rb', line 19 def scan_setup(str) @ss = StringScanner.new(str) @lineno = 1 @state = nil end |
#scan_str(str) ⇒ Object Also known as: scan
29 30 31 32 |
# File 'lib/gitlab-zoql/parser/parser.rex.rb', line 29 def scan_str(str) scan_setup(str) do_parse end |