Sha256: c6789451b8800ae5a005372c947c2db3edc03ec3a8d54e95661b3ab3dc28b298

Contents?: true

Size: 395 Bytes

Versions: 3

Compression:

Stored size: 395 Bytes

Contents

# frozen_string_literal: true

#
module TokenUtil
  # /**
  #  * Returns value of 'n' if rule token ends with '[n]'. where 'n' is the
  #  * variable group index.
  #  *
  #  * @param string token to check for subscript.
  #  */
  def self.extract_subscript(token: '')
    return -1 if token.is_a? Array

    subscript = token[/\[(\d+)\]$/, 1]
    subscript.nil? ? -1 : subscript.to_i
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rast-1.0.0 lib/rast/rules/token_util.rb
rast-0.19.1 lib/rast/rules/token_util.rb
rast-0.19.0 lib/rast/rules/token_util.rb