class SCPIregexLibrary

Introduction

SCPIregexLibrary provides access to regular expressions used across mrSCPI. Many of them are related to SCPI and IEEE 488.2-1992, and are thus useful for scripts using mrSCPI. Others are related to generic text processing as it related to SCPI results, or even mrSCPI internals. Regular expressions may be naturally anchored (available via the a member) or unanchored (available via the u member).

Use

The SCPIregexLibrary is a Singleton. The normal way to use it is as follows

aString.match?(SCPIregexLibrary.instance.a(:split_line))

Available Regexes

Public Class Methods

new() click to toggle source
# File src/mrSCPI.rb, line 139
def initialize()
  @reDatabase = [ [ :o488_NR1,     '([+-]?)([0-9]+)',                                              '^', '$',                      Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :o488_NR2,     '([+-]?)([0-9]+\.[0-9]+)',                                      '^', '$',                      Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :o488_NR3,     '([+-]?)([0-9]+\.[0-9]+)e([+-]?)([0-9]+)',                      '^', '$', Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :o488_NR123,   '([+-]?)([0-9]+|[0-9]+\.[0-9]+|[0-9]+\.[0-9]+e[+-]?[0-9]+)',    '^', '$', Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :o488_HEX,     '#h([0-9a-f]+)',                                                '^', '$', Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :o488_OCT,     '#q([0-7]+)',                                                   '^', '$', Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :o488_BIN,     '#b([01]+)',                                                    '^', '$', Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :o488_STRING,  '"((""|[^"])*)"',                                               '^', '$',                      Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :o488_NegInf,  '(-9.9e\+?37|-990{36})(\.|\.[0-9]+)?',                          '^', '$', Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :o488_PosInf,  '(\+?9.9e\+?37|\+?990{36})(\.|\.[0-9]+)?',                      '^', '$', Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :o488_NaN,     '(\+?9.91e\+?37|\+?9910{35})(\.|\.[0-9]+)?',                    '^', '$', Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :o488_FBLOCK,  '#([1-9])',                                                     '^', '',                       Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :o488_FBLOCKh, '#([1-9a-f])',                                                  '^', '',                       Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :o488_VBLOCK,  '#0',                                                           '^', '',                       Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :i488_NRf,     '([+-]?)([0-9]*\.[0-9]+|[0-9]+\.[0-9]*)\s*e\s*([+-]?)([0-9]+)', '^', '$', Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :i488_NRfNS,   '([+-]?)([0-9]*\.[0-9]+|[0-9]+\.[0-9]*)e([+-]?)([0-9]+)',       '^', '$', Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :o488_TRUE,    '(on|1)',                                                       '^', '$', Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :o488_TRUEx,   '(on|1|true|t|yes|y)',                                          '^', '$', Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :o488_FALSE,   '(off|0)',                                                      '^', '$', Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :o488_FALSEx,  '(off|0|false|f|no|n|nil|null)',                                '^', '$', Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :split_csv,    '\s*,\s*',                                                      '',  '',                       Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :split_ssv,    '\s*;\s*',                                                      '',  '',                       Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :split_space,  '\s+',                                                          '',  '',                       Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :split_line,   '\s*\R+\s*',                                                    '',  '',                       Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :mrs_url,      '(?:([a-zA-Z0-9]+):\/\/)?([^:\/]+)(?::([0-9]+)){0,1}',          '^', '$',                      Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :mrs_nickname, '(?:([^@:\/\s]*)@)?([^@:\/\s]+)',                               '^', '$',                      Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :mrs_branch,   '([^=!~]+)(=|!=|~|!~)(.+)',                                     '^', '$', Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :mrs_assign,   '([^=]+)=(.+)',                                                 '^', '$',                      Regexp::EXTENDED | Regexp::MULTILINE ],
                  [ :mrs_varexp,   '\$\{([^\}:]+)(?::([^\}]+))?\}',                                '',  '',                       Regexp::EXTENDED | Regexp::MULTILINE ],
                ]
  @reListDef  = Hash.new # REs with default anchors
  @reListNone = Hash.new # REs with no anchors (floating)

  @reDatabase.each do |reSymb, reStr, reDefAnchL, reDefAnchR, reDefFlag|
    @reListDef[reSymb]  = Regexp.new(reDefAnchL + reStr + reDefAnchR, reDefFlag)
    @reListNone[reSymb] = Regexp.new(             reStr,              reDefFlag)
  end
end

Public Instance Methods

a(aSymb) click to toggle source

Returns regexp with the default anchors. Returns nil if no regexp found.

# File src/mrSCPI.rb, line 180
def a(aSymb)
  ret = @reListDef[aSymb]
  if ret.nil? then
    PrintyPrintyBangBang.instance.logPrinter(1, "ERROR: Unknown regexp (#{aSymb.inspect})!", self, 89)
  end
  return ret
end
u(aSymb) click to toggle source

Returns a regexp with no anchors. Returns nil if no regexp found.

# File src/mrSCPI.rb, line 189
def u(aSymb)
  ret = @reListNone[aSymb]
  if ret.nil? then
    PrintyPrintyBangBang.instance.logPrinter(1, "ERROR: Unknown regexp (#{aSymb.inspect})!", self, 89)
  end
  return ret
end