Variable: cperl--ws+-rx
cperl--ws+-rx is a variable defined in cperl-mode.el.gz.
Value
(1+
(or (sequence (or space "\n"))
(sequence "#" (0+ (not (in "\n"))) "\n")))
Documentation
Regular expression for a sequence of whitespace and comments in Perl.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/cperl-mode.el.gz
;;; Perl Grammar Components
;;
;; The following regular expressions are building blocks for a
;; minimalistic Perl grammar, to be used instead of individual (and
;; not always consistent) literal regular expressions.
;; This is necessary to compile this file under Emacs 26.1
;; (there's no rx-define which would help)
(eval-and-compile
(defconst cperl--basic-identifier-rx
;; The rx expression in the following line is a workaround for
;; bug#70948 under Emacs 29
'(regex "[_[:alpha:]][_[:word:]]*")
;; The rx expression in the following line is equivalent but
;; inefficient under Emacs 29.3
;; '(sequence (or alpha "_") (* (or word "_")))
"A regular expression for the name of a \"basic\" Perl variable.
Neither namespace separators nor sigils are included. As is,
this regular expression applies to labels,subroutine calls where
the ampersand sigil is not required, and names of attributes.")
(defconst cperl--label-rx
`(sequence symbol-start
,cperl--basic-identifier-rx
(0+ space)
":")
"A regular expression for a Perl label.
By convention, labels are uppercase alphabetics, but this isn't
enforced.")
(defconst cperl--false-label-rx
'(sequence (or (in "sym") "tr") (0+ space) ":")
"A regular expression which is similar to a label, but might as
well be a quote-like operator with a colon as delimiter.")
(defconst cperl--normal-identifier-rx
`(or (sequence (1+ (sequence
(opt ,cperl--basic-identifier-rx)
"::"))
(opt ,cperl--basic-identifier-rx))
,cperl--basic-identifier-rx)
"A regular expression for a Perl variable name with optional namespace.
Examples are `foo`, `Some::Module::VERSION`, and `::` (yes, that
is a legal variable name).")
(defconst cperl--special-identifier-rx
'(or
(1+ digit) ; $0, $1, $2, ...
(sequence "^" (any "A-Z" "]^_?\\")) ; $^V
(sequence "{" (0+ space) ; ${^MATCH}
"^" (any "A-Z" "]^_?\\")
(0+ (any "A-Z" "_" digit))
(0+ space) "}")
(in "!\"$%&'()+,-./:;<=>?@\\]^_`|~")) ; $., $|, $", ... but not $^ or ${
"The list of Perl \"punctuation\" variables, as listed in perlvar.")
(defconst cperl--basic-scalar-rx
`(sequence "$" ,cperl--basic-identifier-rx)
"Regular expression for a scalar (without package).
This regexp intentionally does not support spaces (nor newlines
and comments) between the sigil and the identifier, for
educational reasons. So \"$foo\" will be matched, but \"$ foo\"
or \"${ foo }\" will not.")
(defconst cperl--basic-array-rx
`(sequence "@" ,cperl--basic-identifier-rx)
"Regular expression for an array variable (without package).
This regexp intentionally does not support spaces (nor newlines
and comments) between the sigil and the identifier, for
educational reasons. So \"@foo\" will be matched, but \"@ foo\"
or \"@{ foo }\" will not.")
(defconst cperl--basic-hash-rx
`(sequence "%" ,cperl--basic-identifier-rx)
"Regular expression for a hash variable (without package).
This regexp intentionally does not support spaces (nor newlines
and comments) between the sigil and the identifier, for
educational reasons. So \"%foo\" will be matched, but \"% foo\"
or \"%{ foo }\" will not.")
(defconst cperl--ws-rx
'(sequence (or space "\n"))
"Regular expression for a single whitespace in Perl.")
(defconst cperl--eol-comment-rx
'(sequence "#" (0+ (not (in "\n"))) "\n")
"Regular expression for a single end-of-line comment in Perl")
(defconst cperl--ws-or-comment-rx
`(or ,cperl--ws-rx
,cperl--eol-comment-rx)
"A regular expression for either whitespace or comment")
(defconst cperl--ws*-rx
`(0+ ,cperl--ws-or-comment-rx)
"Regular expression for optional whitespaces or comments in Perl")
(defconst cperl--ws+-rx
`(1+ ,cperl--ws-or-comment-rx)
"Regular expression for a sequence of whitespace and comments in Perl.")
(defconst cperl--basic-variable-rx
`(sequence (in "$@%") ,cperl--basic-identifier-rx)
"Regular expression for a Perl variable (scalar, array or hash).
This regexp intentionally does not support spaces (nor newlines
and comments) between the sigil and the identifier, for
educational reasons. So \"$foo\" will be matched, but \"$ foo\"
or \"${ foo }\" will not.")
(defconst cperl--variable-list-rx
`(sequence "("
(optional (sequence
,cperl--ws*-rx
,cperl--basic-variable-rx
(0+ (sequence
,cperl--ws*-rx
","
,cperl--ws*-rx
,cperl--basic-variable-rx))
,cperl--ws*-rx)))
"Regular expression for a list of Perl variables for declarations.")
;; This is left as a string regexp. There are many version schemes in
;; the wild, so people might want to fiddle with this variable.
(defconst cperl--version-regexp
(rx-to-string
`(or
(sequence (optional "v")
(>= 2 (sequence (1+ digit) "."))
(1+ digit)
(optional (sequence "_" (1+ word))))
(sequence (1+ digit)
(optional (sequence "." (1+ digit)))
(optional (sequence "_" (1+ word))))))
"A sequence for recommended version number schemes in Perl.")
(defconst cperl--single-attribute-rx
`(sequence ,cperl--basic-identifier-rx
(optional (sequence "("
(0+ (or (sequence "\\" not-newline)
(not (any "()\\"))
(sequence "("
(zero-or-more
(not
(any "()\\")))
")")))
")")))
"A regular expression for a single attribute, without leading colon.
It may have parameters in parens, one level of parens within the
parameter's value is supported. This regexp does not have
capture groups.")
(defconst cperl--attribute-list-rx
`(sequence ":"
(optional
,cperl--ws*-rx
,cperl--single-attribute-rx
(0+ (sequence
(or (sequence ,cperl--ws*-rx
":"
,cperl--ws*-rx)
,cperl--ws+-rx)
,cperl--single-attribute-rx))
(optional ":")))
"A regular expression for an attribute list.
Attribute lists may only occur in certain declarations. A colon
is required before the first attribute but optional between
subsequent attributes. This regexp does not have capture groups.")
(defconst cperl--prototype-rx
`(sequence "("
(0+ (any "$@%&*;\\[]"))
")")
"A regular expression for a subroutine prototype. Not as strict
as the actual prototype syntax, but good enough to distinguish
prototypes from signatures.")
(defconst cperl--signature-rx
`(sequence "("
(optional
(sequence
(0+ (sequence ,cperl--ws*-rx
(or ,cperl--basic-scalar-rx "$")
,cperl--ws*-rx
","))
,cperl--ws*-rx
(or ,cperl--basic-scalar-rx
,cperl--basic-array-rx
,cperl--basic-hash-rx
"$" "%" "@")))
(optional (sequence ,cperl--ws*-rx) "," )
,cperl--ws*-rx
")")
"A rx sequence subroutine signature without initializers.
These are a bit more restricted than \"my\" declaration lists
because they allow only one slurpy variable, and only in the last
place.")
(defconst cperl--sloppy-signature-rx
`(sequence "("
,cperl--ws*-rx
(or ,cperl--basic-scalar-rx
,cperl--basic-array-rx
,cperl--basic-hash-rx)
,cperl--ws*-rx
(or "," "=" "||=" "//=" ")"))
"A rx sequence for the begin of a signature with initializers.
Initializers can contain almost all Perl constructs and thus can
not be covered by regular expressions. This sequence captures
enough to distinguish a signature from a prototype.")
(defconst cperl--package-rx
`(sequence (group (or "package" "class"))
,cperl--ws+-rx
(group ,cperl--normal-identifier-rx)
(optional (sequence ,cperl--ws+-rx
(group (regexp ,cperl--version-regexp)))))
"A regular expression for package|class NAME VERSION in Perl.
Contains three groups for the initial keyword \"package\" or
\"class\", for the package name and for the version.")
(defconst cperl--package-for-imenu-rx
`(sequence symbol-start
(group-n 1 "package")
,cperl--ws+-rx
(group-n 2 ,cperl--normal-identifier-rx)
(optional (sequence ,cperl--ws+-rx
(regexp ,cperl--version-regexp)))
,cperl--ws*-rx
(group-n 3 (or ";" "{")))
"A regular expression to collect package names for `imenu'.
Catches \"package NAME;\", \"package NAME VERSION;\", \"package
NAME BLOCK\" and \"package NAME VERSION BLOCK.\" Contains three
groups: One for the keyword \"package\", one for the package
name, and one for the discovery of a following BLOCK.")
;; This gets a regexp of its own because classes allow attributes
;; (e.g. ":isa(Parent)") while packages don't. We skip over it, but
;; like for "package" we capture the following ";" or "{".
(defconst cperl--class-for-imenu-rx
`(sequence (or space line-start)
(group-n 1 "class")
,cperl--ws+-rx
(group-n 2 ,cperl--normal-identifier-rx)
(optional (sequence ,cperl--ws+-rx
(regexp ,cperl--version-regexp)))
(optional (sequence ,cperl--ws*-rx
,cperl--attribute-list-rx))
,cperl--ws*-rx
(group-n 3 (or ";" "{")))
"A regular expression to collect package names for `imenu'.
Catches \"class NAME;\", \"class NAME VERSION;\", \"class NAME
BLOCK\" and \"class NAME VERSION BLOCK\" and allows for
attributes like \":isa(Parent)\". Contains three groups: One for
the keyword \"package\", one for the package name, and one for
the discovery of a following BLOCK.")
(defconst cperl--sub-name-for-imenu-rx
`(sequence symbol-start
(optional (sequence (group-n 3 (or "my" "state" "our"))
,cperl--ws+-rx))
(group-n 1 (or "method" "sub"))
,cperl--ws+-rx
(group-n 2 ,cperl--normal-identifier-rx))
"A regular expression to detect a subroutine or method start.
Contains three groups: One to distinguish lexical from \"normal\"
subroutines, for the keyword \"sub\" or \"method\", and one for
the subroutine name.")
(defconst cperl--sub-name-generated-rx
`(sequence symbol-start
(optional (group-n 3 unmatchable))
;; autogenerated methods are not lexicals, so enforce the
;; third capture group to be nil
(group-n 1 "field")
,cperl--ws+-rx
,cperl--basic-variable-rx
,cperl--ws+-rx
(group-n 2 ,cperl--attribute-list-rx))
"A regular expression to capture autogenerated reader methods.
The name of the method is either the field name without its sigil, or
given in parentheses after the \":reader\" or \":writer\" keyword. More
than one attribute can be present: The match will be parsed in an extra
step.")
(defconst cperl--block-declaration-rx
`(sequence
(or "class" "method" "package" "sub")
(1+ ,cperl--ws-or-comment-rx)
,cperl--normal-identifier-rx)
"A regular expression to find a declaration for a named block.
Used for indentation. These declarations introduce a block which
does not need a semicolon to terminate the statement.")
(defconst cperl--field-declaration-rx
`(sequence
"field"
(1+ ,cperl--ws-or-comment-rx)
,cperl--basic-variable-rx
(optional (sequence ,cperl--ws+-rx ,cperl--attribute-list-rx))
)
"A regular expression to find a declaration for a field.
Fields can have attributes for fontification, and even for imenu because
for example \":reader\" implicitly declares a method.")
(defconst cperl--pod-heading-rx
`(sequence line-start
(group-n 1 "=head")
(group-n 3 (in "1-4"))
(1+ (in " \t"))
(group-n 2 (1+ (not (in "\n")))))
"A regular expression to detect a POD heading.
Contains two groups: One for the heading level, and one for the
heading text.")
(defconst cperl--imenu-entries-rx
`(or ,cperl--package-for-imenu-rx
,cperl--class-for-imenu-rx
,cperl--sub-name-for-imenu-rx
,cperl--sub-name-generated-rx
,cperl--pod-heading-rx)
"A regular expression to collect stuff that goes into the `imenu' index.
Covers packages and classes, subroutines and methods, and POD headings.")
;; end of eval-and-compiled stuff
)