Sha256: 1ae7d6cdfa67b4d92bfac03134e453bdcfe5aad4dc52cb9c315d92ce94c7251f

Contents?: true

Size: 784 Bytes

Versions: 1

Compression:

Stored size: 784 Bytes

Contents

module Gherkin
  class TokenFormatterBuilder
    def initialize
      reset
    end

    def reset
      @tokens_text = ''
    end

    def build(token)
      @tokens_text << "#{format_token(token)}\n"
    end

    def start_rule(_rule_type); end

    def end_rule(_rule_type); end

    def get_result
      @tokens_text
    end

    private

    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

1 entries across 1 versions & 1 rubygems

Version Path
cucumber-gherkin-30.0.0 lib/gherkin/token_formatter_builder.rb