Module | RubyToken |
In: |
parsers/parse_rb.rb
|
Definitions of all tokens involved in the lexical analysis
# File parsers/parse_rb.rb, line 270 270: def RubyToken.def_token(token_n, super_token = Token, reading = nil, *opts) 271: token_n = token_n.id2name unless token_n.kind_of?(String) 272: if RubyToken.const_defined?(token_n) 273: fail AlreadyDefinedToken, token_n 274: end 275: 276: token_c = Class.new super_token 277: RubyToken.const_set token_n, token_c 278: # token_c.inspect 279: 280: if reading 281: if TkReading2Token[reading] 282: fail TkReading2TokenDuplicateError, token_n, reading 283: end 284: if opts.empty? 285: TkReading2Token[reading] = [token_c] 286: else 287: TkReading2Token[reading] = [token_c].concat(opts) 288: end 289: end 290: TkSymbol2Token[token_n.intern] = token_c 291: 292: if token_c <= TkOp 293: token_c.class_eval %{ 294: def self.op_name; "#{reading}"; end 295: } 296: end 297: end
# File parsers/parse_rb.rb, line 112 112: def Token(token, value = nil) 113: tk = nil 114: case token 115: when String, Symbol 116: source = token.kind_of?(String) ? TkReading2Token : TkSymbol2Token 117: if (tk = source[token]).nil? 118: fail TkReading2TokenNoKey, token 119: end 120: tk = Token(tk[0], value) 121: else 122: tk = if (token.ancestors & [TkId, TkVal, TkOPASGN, TkUnknownChar]).empty? 123: token.new(@prev_line_no, @prev_char_no) 124: else 125: token.new(@prev_line_no, @prev_char_no, value) 126: end 127: end 128: tk 129: end