Module: TokenUtil

Defined in:
lib/rast/rules/token_util.rb

Class Method Summary collapse

Class Method Details

.extract_subscript(token: '') ⇒ Object

/**

* Returns value of 'n' if rule token ends with '[n]'. where 'n' is the
* variable group index.
*
* @param string token to check for subscript.
*/


11
12
13
14
15
16
# File 'lib/rast/rules/token_util.rb', line 11

def self.extract_subscript(token: '')
  return -1 if token.is_a? Array

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