Sha256: 1c41590b77832a463df77d223647bf7e0c67a16ec69acf463739bdc3990041d3

Contents?: true

Size: 870 Bytes

Versions: 4

Compression:

Stored size: 870 Bytes

Contents

# frozen_string_literal: true

module Gherkin
  class TokenFormatterBuilder
    def initialize
      reset
    end

    def reset
      @tokens = []
    end

    def build(token)
      tokens << token
    end

    def start_rule(_rule_type); end

    def end_rule(_rule_type); end

    def get_result
      tokens.map { |token| "#{format_token(token)}\n" }.join
    end

    private

    def tokens
      @tokens ||= []
    end

    def format_token(token)
      return 'EOF' if token.eof?

      sprintf(
        "(%s:%s)%s:%s/%s/%s",
        token.location[:line],
        token.location[:column],
        token.matched_type,
        token.matched_keyword ? sprintf("(%s)%s", token.matched_keyword_type, token.matched_keyword) : "",
        token.matched_text,
        Array(token.matched_items).map { |i| "#{i.column}:#{i.text}" }.join(',')
      )
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cucumber-gherkin-30.0.4 lib/gherkin/token_formatter_builder.rb
cucumber-gherkin-30.0.3 lib/gherkin/token_formatter_builder.rb
cucumber-gherkin-30.0.2 lib/gherkin/token_formatter_builder.rb
cucumber-gherkin-30.0.1 lib/gherkin/token_formatter_builder.rb