lib/ddql/token.rb in ddql-1.0.0 vs lib/ddql/token.rb in ddql-1.0.1

- old
+ new

@@ -1,15 +1,14 @@ require 'forwardable' module DDQL - class Token - using StringRefinements - attr_reader :data, :type attr_accessor :location + using ::DDQL::StringRefinements + def initialize(data:, location: nil, type:) @data = data @location = location @type = type end @@ -48,10 +47,15 @@ def parse(parser, expression: nil) type.parse(parser, self, expression: expression) end + def post_process(parser:, expression:) + raise "#{type} doesn't support post-processing" unless supports_post_processing? + type.post_process(parser: parser, expression: expression) + end + def postfix? type.postfix? end def prefix? @@ -60,14 +64,22 @@ def simple_comparison? type.simple_comparison?(data) end + def supports_post_processing? + type.supports_post_processing? + end + def to_h type.as_hash(data) end def to_s "#{type.name} : #{data}" + end + + def type?(token_type) + token_type == type end end end