module Rbscmlex
Constants
- RELEASE
- Token
a structure to store properties of a token of Scheme program.
- VERSION
Public Class Methods
Converts a Hash object to a string of JSON notation.
# File lib/rbscmlex/token.rb, line 113 def hash2json(hash) JSON.generate(hash) end
Converts a Hash object, which has type and literal as its key, to a new token object. The value associated to type of the Hash must be valid token type. Otherwise, raises UnknownTokenTypeError
.
# File lib/rbscmlex/token.rb, line 75 def hash2token(hash) if hash.key?(:type) and hash.key?(:literal) type = hash[:type].intern raise UnknownTokenTypeError, ("got=%s" % type) unless token_type?(type) literal = hash[:literal] new_token(type, literal) else raise InvalidHashError, ("got=%s" % hash) end end
Converts a JSON notation to a new Hash object.
# File lib/rbscmlex/token.rb, line 120 def json2hash(json) JSON.parse(json) end
Converts a JSON notation, which hash type and literal, to a new token object. The value associated to type of the JSON must be valid token type. Otherwise, raises UnknownTokenTypeError
.
# File lib/rbscmlex/token.rb, line 90 def json2token(json) h = JSON.parse(json, symbolize_names: true) begin hash2token(h) rescue InvalidHashError => _ raise InvalidJsonError, ("got=%s" % json) end end
# File lib/rbscmlex.rb, line 9 def self.lexer(source) Lexer.new(source) end
Returns a new Hash object with type and literal as its keys.
# File lib/rbscmlex/token.rb, line 67 def make_hash(type, literal) {type: type, literal: literal} end
Instantiates a new token object form type and literal.
# File lib/rbscmlex/token.rb, line 55 def new_token(type, literal = nil) Token.new(type, literal) end
Converts a Token
object to a Hash object.
# File lib/rbscmlex/token.rb, line 101 def token2hash(token) token.to_h end
Converts a Token
object to a string of JSON notation.
# File lib/rbscmlex/token.rb, line 107 def token2json(token) token.to_json end
Returns true when the argument is valid token type.
# File lib/rbscmlex/token.rb, line 61 def token_type?(type) TOKEN_TYPES.include?(type) end