Class: RDL::Type::Parser
- Defined in:
- lib/rdl/types/lexer.rex.rb,
lib/rdl/types/parser.tab.rb
Defined Under Namespace
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", "COMMA", "RARROW", "OR", "HASH_TYPE", "HASH_QUERY", "CONST_BEGIN", "RASSOC", "FIXNUM", "FLOAT", "COLON", "DOT", "DOTS", "ID", "SYMBOL", "SPECIAL_ID", "STRING", "PREDICATE", "LPAREN", "RPAREN", "LBRACE", "RBRACE", "LBRACKET", "RBRACKET", "QUERY", "BANG", "STARSTAR", "STAR", "LESS", "GREATER", "EOF", "$start", "entry", "method_type", "bare_type", "query_type", "type_expr", "arg_list", "block", "method_sig_list", "nonempty_arg_list", "named_arg_list", "arg", "base_arg", "named_arg", "base_arg_query_only", "union_type", "type_expr_comma_list", "hash_expr", "hash_expr_comma_list", "single_type" ]
- 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.
15 16 17 |
# File 'lib/rdl/types/lexer.rex.rb', line 15 def filename @filename end |
#lineno ⇒ Object (readonly)
Returns the value of attribute lineno.
14 15 16 |
# File 'lib/rdl/types/lexer.rex.rb', line 14 def lineno @lineno end |
#state ⇒ Object
Returns the value of attribute state.
16 17 18 |
# File 'lib/rdl/types/lexer.rex.rb', line 16 def state @state end |
Instance Method Details
#_next_token ⇒ Object
55 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 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/rdl/types/lexer.rex.rb', line 55 def _next_token text = @ss.peek(1) @lineno += 1 if text == "\n" token = case @state when nil case when (text = @ss.scan(/\s/)) ; when (text = @ss.scan(/or/)) action { [:OR, text] } when (text = @ss.scan(/->/)) action { [:RARROW, text] } when (text = @ss.scan(/=>/)) action { [:RASSOC, text] } when (text = @ss.scan(/\(/)) action { [:LPAREN, text] } when (text = @ss.scan(/\)/)) action { [:RPAREN, text] } when (text = @ss.scan(/\{\{(?:(?!}}).)+\}\}/)) action { [:PREDICATE, text[2..-3]] } when (text = @ss.scan(/\{/)) action { [:LBRACE, text] } when (text = @ss.scan(/\}/)) action { [:RBRACE, text] } when (text = @ss.scan(/\[/)) action { [:LBRACKET, text] } when (text = @ss.scan(/\]/)) action { [:RBRACKET, text] } when (text = @ss.scan(/</)) action { [:LESS, text] } when (text = @ss.scan(/>/)) action { [:GREATER, text] } when (text = @ss.scan(/,/)) action { [:COMMA, text] } when (text = @ss.scan(/\?/)) action { [:QUERY, text] } when (text = @ss.scan(/\!/)) action { [:BANG, text] } when (text = @ss.scan(/\*\*/)) action { [:STARSTAR, text] } when (text = @ss.scan(/\*/)) action { [:STAR, text] } when (text = @ss.scan(/\#T/)) action { [:HASH_TYPE, text] } when (text = @ss.scan(/\#Q/)) action { [:HASH_QUERY, text] } when (text = @ss.scan(/\$\{/)) action { [:CONST_BEGIN, text] } when (text = @ss.scan(/\.\.\./)) action { [:DOTS, text] } when (text = @ss.scan(/\./)) action { [:DOT, text] } when (text = @ss.scan(/-?\d\.\d+/)) action { [:FLOAT, text] } # Must go before FIXNUM when (text = @ss.scan(/-?(\d)+/)) action { [:FIXNUM, text] } when (text = @ss.scan(/(\w|\:\:)+/)) action { [:ID, text] } when (text = @ss.scan(/:\w+/)) action { [:SYMBOL, text[1..-1]] } when (text = @ss.scan(/\:/)) action { [:COLON, text] } # Must come after SYMBOL when (text = @ss.scan(/%\w+/)) action { [:SPECIAL_ID, text] } when (text = @ss.scan(/'[^']*'/)) action { [:STRING, text.gsub("'", "")] } when (text = @ss.scan(/"[^"]*"/)) action { [:STRING, text.gsub('"', "")] } 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
805 806 807 |
# File 'lib/rdl/types/parser.tab.rb', line 805 def _reduce_none(val, _values, result) val[0] end |
#action ⇒ Object
24 25 26 |
# File 'lib/rdl/types/lexer.rex.rb', line 24 def action yield end |
#load_file(filename) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/rdl/types/lexer.rex.rb', line 34 def load_file( filename ) @filename = filename open(filename, "r") do |f| scan_setup(f.read) end end |
#next_token ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/rdl/types/lexer.rex.rb', line 47 def next_token return if @ss.eos? # skips empty actions until token = _next_token or @ss.eos?; end token end |
#scan_file(filename) ⇒ Object
41 42 43 44 |
# File 'lib/rdl/types/lexer.rex.rb', line 41 def scan_file( filename ) load_file(filename) do_parse end |
#scan_setup(str) ⇒ Object
18 19 20 21 22 |
# File 'lib/rdl/types/lexer.rex.rb', line 18 def scan_setup(str) @ss = StringScanner.new(str) @lineno = 1 @state = nil end |
#scan_str(str) ⇒ Object Also known as: scan
28 29 30 31 |
# File 'lib/rdl/types/lexer.rex.rb', line 28 def scan_str(str) scan_setup(str) do_parse end |