Library lpeg-utility
Utility functions for LPeg.
Copyright © Same as Nmap--See https://nmap.org/book/man-legal.html
Source: https://svn.nmap.org/nmap/nselib/lpeg-utility.lua
Functions
- anywhere (patt)
Returns a pattern which matches the input pattern anywhere on a subject string.
- atwordboundary (patt)
Returns a pattern which only matches at a word boundary (beginning).
- caseless (literal)
Returns a pattern which matches the literal string caselessly.
- debug (grammar, printer)
Adds hooks to a grammar to print debugging information
- escaped_quote (quot, esc)
Returns a pattern which captures the contents of a quoted string.
- get_response (fp, probe)
Turn the service fingerprint reply to a probe into a binary blob
- localize (grammar)
Adds the current locale from lpeg.locale() to the grammar and returns the final pattern.
- parse_fp (fp)
Get the service fingerprint reply to a probe into a binary blob
- split (str, sep)
Splits the input string on the input separator.
Functions
- anywhere (patt)
-
Returns a pattern which matches the input pattern anywhere on a subject string.
Parameters
- patt
- Input pattern.
Return value:
An LPeg pattern. - atwordboundary (patt)
-
Returns a pattern which only matches at a word boundary (beginning).
Essentially the same as '\b' in a PCRE pattern.
Parameters
- patt
- A pattern.
Return value:
A new LPeg pattern. - caseless (literal)
-
Returns a pattern which matches the literal string caselessly.
Parameters
- literal
- A literal string to match case-insensitively.
Return value:
An LPeg pattern. - debug (grammar, printer)
-
Adds hooks to a grammar to print debugging information
Debugging LPeg grammars can be difficult. Calling this function on your grammmar will cause it to print ENTER and LEAVE statements for each rule, as well as position and subject after each successful rule match.
For convenience, the modified grammar is returned; a copy is not made though, and the original grammar is modified as well.
Parameters
- grammar
- The LPeg grammar to modify
- printer
- A printf-style formatting printer function to use. Default: stdnse.debug1
Return value:
The modified grammar. - escaped_quote (quot, esc)
-
Returns a pattern which captures the contents of a quoted string.
This can handle embedded escaped quotes, and captures the unescaped string.
Parameters
- quot
- The quote character to use. Default: '"'
- esc
- The escape character to use. Cannot be the same as quot. Default: "\"
- get_response (fp, probe)
-
Turn the service fingerprint reply to a probe into a binary blob
Parameters
- fp
- the
port.version.service_fp
provided by the NSE API. - probe
- the probe name to match, e.g. GetRequest, TLSSessionReq, etc.
Return value:
the raw probe response received to that probe, or nil if there was no response. - localize (grammar)
-
Adds the current locale from lpeg.locale() to the grammar and returns the final pattern.
Parameters
- grammar
- Input grammar.
Return value:
An LPeg pattern. - parse_fp (fp)
-
Get the service fingerprint reply to a probe into a binary blob
Parameters
- fp
- the
port.version.service_fp
provided by the NSE API.
- split (str, sep)
-
Splits the input string on the input separator.
Parameters
- str
- Input string to split.
- sep
- Input string/pattern to separate on.
Return value:
All splits.