Module: CiscoAclIntp::SpecialTokenHandler

Included in:
Scanner
Defined in:
lib/cisco_acl_intp/scanner_special_token_handler.rb

Overview

Data and Handler functions of special tokens

Constant Summary collapse

STR_REGEXP =

STRING token regexp: first letter is alphabet or digit

'[a-zA-Z\d]\S*'.freeze
STRING_ARG_TOKENS =

Tokens that takes string parameter

[
  ['remark', :leftover],
  ['description', :leftover],
  ['extended', :word],
  ['standard', :word],
  ['dynamic', :word],
  ['log-input', :word],
  ['log', :word],
  ['time-range', :word],
  ['reflect', :word],
  ['evaluate', :word],
  ['object-group', 'network', :word],
  ['object-group', 'service', :word],
  ['object-group', :word], # longest match
  ['group-object', :word]
].freeze
SYMBOL_TO_REGEXPSTR =

Conversion table of string-tokens

{
  word: ['(', STR_REGEXP, ')'].join,
  leftover: '(.*)$'
}.freeze

Instance Method Summary collapse

Instance Method Details

#convert_tokens_to_regexpstr(set) ⇒ String

Convert STRING_ARG_TOKENS to Regexp string

Parameters:

  • set (Array)

    Special tokens set

Returns:

  • (String)

    Regexp string



38
39
40
41
42
43
44
45
46
47
# File 'lib/cisco_acl_intp/scanner_special_token_handler.rb', line 38

def convert_tokens_to_regexpstr(set)
  set.map do |each|
    case each
    when String
      '(' + each + ')'
    when Symbol
      SYMBOL_TO_REGEXPSTR[each]
    end
  end
end

#gen_arg_token_listsArray

Generate regexp string list for scanner

Returns:

  • (Array)

    set of regexp and number of token



51
52
53
54
55
56
# File 'lib/cisco_acl_intp/scanner_special_token_handler.rb', line 51

def gen_arg_token_lists
  STRING_ARG_TOKENS.map do |each|
    re_str_list = convert_tokens_to_regexpstr(each)
    [re_str_list.join('\s+'), each.length]
  end
end