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¶ ↑
-
For instrument response strings as defined in IEEE 488.2-1992 (anchor: both sides)
:o488_NR1
-
Strict response NR1 integer. Ref: 8.7.2.2 of IEEE 488.2-1992 p96. Submatches: sign, value
:o488_NR2
-
Strict response NR2 float. Ref: 8.7.3.2 of IEEE 488.2-1992 p97. Submatches: sign, value
:o488_NR3
-
Strict response NR2 float. Ref: 8.7.4.2 of IEEE 488.2-1992 p98. Submatches: man sgn, man value, exp sgn, exp value
:o488_NR123
-
Matches any of
:o488_NR1
,:o488_NR2
,:o488_NR3
. Submatches: man sgn
:o488_HEX
-
Strict response HEX integer. Ref: 8.7.5.2 of IEEE 488.2-1992 p99. Submatches: digits
:o488_OCT
-
Strict response OCT integer. Ref: 8.7.6.2 of IEEE 488.2-1992 p100. Submatches: digits
:o488_BIN
-
Strict response BIN integer. Ref: 8.7.7.2 of IEEE 488.2-1992 p101. Submatches: digits
:o488_STRING
-
Strict response string. Ref: 8.7.8.2 of IEEE 488.2-1992 p102. Submatches: chars
:o488_NegInf
-
Negative infinity in NR1, NR2, or NR3 format
:o488_PosInf
-
Positive infinity in NR1, NR2, or NR3 format
:o488_NaN
-
NaN NR1, NR2, or NR3 format
-
For instrument response binary block headers as defined in IEEE 488.2-1992 (anchor: front)
:o488_FBLOCK
-
Fixed sized data block first 2 chars. Ref: 8.7.9.2 of IEEE 488.2-1992 p103. Submatches: digits
:o488_FBLOCKh
-
Like
:o488_FBLOCK
, but supports HEX second char. Submatches: Digit
:o488_VBLOCK
-
Variable sized data block header. Ref: 8.7.9.2 of IEEE 488.2-1992 p103.
-
For instrument program or response strings as used in practice (anchor: both sides)
:x488_TRUE
-
Matches conventional SCPI
ON
or1
messages
:x488_TRUEx
-
Like
:o488_TRUE
, but addsT
,TRUE
,Y
, &YES
:x488_FALSE
-
Matches conventional SCPI
OFF
or0
messages
:x488_FALSEx
-
Like
:o488_FALSE
, but addsF
,FALSE
,N
,NO
,NIL
, &NULL
-
For program input strings sent to an instrument as defined in IEEE 488.2-1992 (anchor: both sides)
:i488_NRf
-
Strict input NRf float. Ref: 7.7.2.2 of IEEE 488.2-1992 p 73. Submatches: man sgn, man value, exp sgn, exp value
:i488_NRfNS
-
Like
:i488_NRf
, but no whitespace allowed. Submatches: man sgn, man value, exp sgn, exp value
-
For splitting strings (anchor: NONE)
:split_csv
-
Split on commas surrounded by optional white space
:split_ssv
-
Split on semicolons surrounded by optional white space
:split_space
-
Split on blocks of whitespace (horizontal or vertical)
:split_line
-
Split on blocks of vertical whitespace
-
Handy regexes for mrSCPI internals (anchor: NONE)
:mrs_url
-
Match mrSCPI URL. Submatches: protocol, ip address, port number
:mrs_nickname
-
Match mrSCPI nickname. Submatches: network, name
:mrs_branch
-
Match mrSCPI script branching statements (
:skip_if
,:next_if
). Submatches: LHS, operator, RHS
:mrs_assign
-
Match mrSCPI script assignment statements (
:eval
,:var
). Submatches: LHS, RHS
:mrs_varexp
-
Match mrSCPI script variable expantion expressions. Submatches: variable name, default value
Public Class Methods
# 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
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
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