Module: Omnium::Common
- Included in:
- Interpreter::Core, Lexer::Core, Lexer::TokenHelper, Parser::Core
- Defined in:
- lib/omnium/common.rb
Constant Summary collapse
- VALUE_BASED_TOKENS =
[ { type: :plus, value: '+' }, { type: :minus, value: '-' }, { type: :multiply, value: '*' }, { type: :divide, value: '/' }, { type: :left_parenthesis, value: '(' }, { type: :right_parenthesis, value: ')' }, { type: :semicolon, value: ';' }, { type: :dot, value: '.' }, { type: :assignment, value: ':=' }, { type: :colon, value: ':' }, { type: :comma, value: ',' } ].freeze
- PARAMETERISED_TOKENS =
[ { type: :identifier }, { type: :integer }, # int { type: :real } # float ].freeze
- NIL_VALUE_TOKENS =
[ { type: :eof, value: nil } ].freeze
- TOKENS =
{} .merge(value_based: VALUE_BASED_TOKENS) .merge(parameterised: PARAMETERISED_TOKENS) .merge(nil_value: NIL_VALUE_TOKENS)
- RESERVED_KEYWORDS =
{ program: 'program', var: 'var', int: 'int', # integer float: 'float', # real begin: 'begin', end: 'end' }.freeze
Class Method Summary collapse
- .define_token_predicate_method(type, value = nil) ⇒ Object
- .define_token_type_method(type) ⇒ Object
- .token_entity ⇒ Object
Class Method Details
.define_token_predicate_method(type, value = nil) ⇒ Object
53 54 55 56 57 |
# File 'lib/omnium/common.rb', line 53 def define_token_predicate_method(type, value = nil) define_method("#{type}?") do token_entity == type || (!value.nil? && token_entity == value) end end |
.define_token_type_method(type) ⇒ Object
59 60 61 |
# File 'lib/omnium/common.rb', line 59 def define_token_type_method(type) define_method("#{type}_token") { type } end |
.token_entity ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/omnium/common.rb', line 43 def token_entity if instance_variable_defined?(:@character) @character # Lexer#character elsif instance_variable_defined?(:@token) @token&.type # Parser::Core#token elsif instance_variable_defined?(:@type) @type # Interpreter#type end end |