summaryrefslogtreecommitdiff
path: root/test/lisp/emacs-lisp/rx-tests.el
Commit message (Collapse)AuthorAge
* ; Add 2023 to copyright years.Eli Zaretskii2023-01-01
|
* Fix pcase rx patterns using rx-let bindings (bug#59814)Mattias Engdegård2022-12-11
| | | | | | | | Reported by Daniel Pittman. * lisp/emacs-lisp/rx.el (rx): Move binding of rx--local-definitions... (rx--to-expr): ...here. * test/lisp/emacs-lisp/rx-tests.el (rx-let-pcase): New test.
* ; Add 2022 to copyright years.Eli Zaretskii2022-01-01
|
* ; Minor stylistic checkdoc fixes in test/**/*.elStefan Kangas2021-09-26
|
* Fix pcase 'rx' patterns with a single named submatch (bug#48477)Mattias Engdegård2021-05-18
| | | | | | | | | | | | | | | pcase 'rx' patterns with a single named submatch, like (rx (let x "a")) would always succeed because of an over-optimistic transformation. Patterns with 0 or more than 1 named submatches were not affected. Reported by Philipp Stephani. * lisp/emacs-lisp/rx.el (rx--pcase-macroexpander): Special case for a single named submatch. * test/lisp/emacs-lisp/rx-tests.el (rx-pcase): Add tests.
* Fix pcase 'rx' pattern match-data bugMattias Engdegård2021-02-28
| | | | | | | | | | | | | | | | | | | | | | | | | | | The pcase 'rx' pattern would in some cases allow the match data to be clobbered before it is read. For example: (pcase "PQR" ((and (rx (let a nonl)) (rx ?z)) (list 'one a)) ((rx (let b ?Q)) (list 'two b))) The above returned (two "P") instead of the correct (two "Q"). This occurred because the calls to string-match and match-string were presented as separate patterns to pcase, which would interleave them with other patterns. As a remedy, combine string matching and match-data extraction into a single pcase pattern. This introduces a slight inefficiency for two or more submatches as they are grouped into a list structure which then has to be destructured. Found by Stefan Monnier. See discussion at https://lists.gnu.org/archive/html/emacs-devel/2021-02/msg02010.html * lisp/emacs-lisp/rx.el (rx--reduce-right): New helper. (rx [pcase macro]): Combine string-match and match-string calls into a single pcase pattern. * test/lisp/emacs-lisp/rx-tests.el (rx-pcase): Add test cases.
* Fix pcase rx pattern bugsMattias Engdegård2021-02-26
| | | | | | | | | | | | | | | Two unrelated bugs: A missing type check caused an error in rx patterns for non-string match targets, and rx patterns did not work at all in pcase-let or pcase-let*. Second bug reported by Basil Contovounesios and Ag Ibragimov; fixes proposed by Stefan Monnier. Discussion and explanation in thread at https://lists.gnu.org/archive/html/emacs-devel/2021-02/msg01924.html * lisp/emacs-lisp/rx.el (rx): Add (pred stringp) to avoid type errors, and replace the `pred` clause for the actual match with something that works with pcase-let(*) without being optimised away. * test/lisp/emacs-lisp/rx-tests.el (rx-pcase): Add test cases.
* Fix regexp mistakesMattias Engdegård2021-02-19
| | | | | | | | | | * lisp/progmodes/cperl-mode.el (cperl--package-regexp): Avoid double repetition; cperl--ws-or-comment-regexp is already repeated with 1+. * test/lisp/textmodes/dns-mode-tests.el (dns-mode-tests-dns-mode-soa-increment-serial): Escape literal '$'. * test/lisp/emacs-lisp/rx-tests.el (rx-regexp): Modify test to not trigger a linting warning while retaining its testing power.
* Fix rx `regexp` form with deprecated syntaxMattias Engdegård2021-02-18
| | | | | | | | | | | | The argument of the rx `regexp` form is assumed to evaluate to a valid regexp, but certain kinds of deprecated but still accepted usage were not handled correctly, such as unescaped literal (special) characters: (rx "a" (regexp "*")) => "a*" which is wrong. Handle these cases; there is no extra trouble. * lisp/emacs-lisp/rx.el (rx--translate-regexp): Force bracketing of single special characters. * test/lisp/emacs-lisp/rx-tests.el (rx-regexp): Add test case.
* Update copyright year to 2021Paul Eggert2021-01-01
| | | | Run "TZ=UTC0 admin/update-copyright".
* Better warning suppression in rx-testsMattias Engdegård2020-11-09
| | | | | | * test/lisp/emacs-lisp/rx-tests.el (rx-compat): Use with-no-warnings instead of with-suppressed-warnings which complains when running the test interactively.
* Fix pcase rx form snag with '?' and '??' (bug#44532)Mattias Engdegård2020-11-09
| | | | | | | | This is a regression from Emacs 26. Reported by Phillip Stephani. * lisp/emacs-lisp/rx.el (rx--pcase-transform): Process ? and ?? correctly. * test/lisp/emacs-lisp/rx-tests.el (rx-pcase): Add test case.
* Suppress obsoletion warning in test of obsolete rx functionMattias Engdegård2020-10-06
| | | | | * test/lisp/emacs-lisp/rx-tests.el (rx-compat): Add byte-compilation warning suppression.
* * test/lisp/emacs-lisp/rx-tests.el: Improve test coverage.Mattias Engdegård2020-08-29
|
* Suppress relint diagnostics in rx-tests.elMattias Engdegård2020-04-05
| | | | | * test/lisp/emacs-lisp/rx-tests.el (rx-char-any, rx-any): Suppress relint complaints; these regexps are intentionally bad.
* Fix rx error with ? and ??Mattias Engdegård2020-03-05
| | | | | | | | | The ? and ?? rx operators are special in that they can be written as characters (space and '?' respectively). This confused the definition look-up mechanism in rare cases. * lisp/emacs-lisp/rx.el (rx--expand-def): Don't look up non-symbols. * test/lisp/emacs-lisp/rx-tests.el (rx-charset-or): Test.
* rx: Improve 'or' compositionality (bug#37659)Mattias Engdegård2020-03-01
| | | | | | | | | | | | | | | | | Perform 'regexp-opt' on nested 'or' forms, and after expansion of user-defined and 'eval' forms. Characters are now turned into strings for wider 'regexp-opt' scope. This preserves the longest-match semantics for string in 'or' forms over composition. * doc/lispref/searching.texi (Rx Constructs): Document. * lisp/emacs-lisp/rx.el (rx--normalise-or-arg) (rx--all-string-or-args): New. (rx--translate-or): Normalise arguments first, and check for strings in subforms. (rx--expand-eval): Extracted from rx--translate-eval. (rx--translate-eval): Call rx--expand-eval. * test/lisp/emacs-lisp/rx-tests.el (rx-or, rx-def-in-or): Add tests. * etc/NEWS: Announce.
* Fix rx charset generationMattias Engdegård2020-02-29
| | | | | | * lisp/emacs-lisp/rx.el (rx--charset-p): Don't overquote. (rx--generate-alt): Generate '.' for negated newline. * test/lisp/emacs-lisp/rx-tests.el (rx-any, rx-charset-or): Test.
* rx: Use longest match for all-string 'or' forms (bug#37659)Mattias Engdegård2020-02-12
| | | | | | | | | | | | | | | | | Revert to the Emacs 26 semantics that always gave the longest match for rx 'or' forms with only string arguments. This guarantee was never well documented, but it is useful and people likely have come to rely on it. For example, prior to this change, (rx (or ">" ">=")) matched ">" even if the text contained ">=". * lisp/emacs-lisp/rx.el (rx--translate-or): Don't tell regexp-opt to preserve the matching order. * doc/lispref/searching.texi (Rx Constructs): Document the longest-match guarantee for all-string 'or' forms. * test/lisp/emacs-lisp/rx-tests.el (rx-or): Update test.
* Update copyright year to 2020Paul Eggert2020-01-01
| | | | Run "TZ=UTC0 admin/update-copyright $(git ls-files)".
* Allow characters and single-char strings in rx charsetsMattias Engdegård2019-12-13
| | | | | | | | | | | | | | | | The `not' and `intersection' forms, and `or' inside these forms, now accept characters and single-character strings as arguments. Previously, they had to be wrapped in `any' forms. This does not add expressive power but is a convenience and is easily understood. * doc/lispref/searching.texi (Rx Constructs): Amend the documentation. * etc/NEWS: Announce the change. * lisp/emacs-lisp/rx.el (rx--charset-p, rx--translate-not) (rx--charset-intervals, rx): Accept characters and 1-char strings in more places. * test/lisp/emacs-lisp/rx-tests.el (rx-not, rx-charset-or) (rx-def-in-charset-or, rx-intersection): Test the change.
* Use `or' instead of `union' for charset union in rxMattias Engdegård2019-12-12
| | | | | | | | | | | | | | Design change suggested by Stefan Monnier. * doc/lispref/searching.texi (Rx Constructs): * etc/NEWS: Document. * lisp/emacs-lisp/rx.el (rx--translate-or): Detect charset arguments. (rx--charset-p): New. (rx--translate-not, rx--charset-intervals, rx--translate-union): Change from `union' to `or'. (rx--translate-form, rx--builtin-forms, rx): Remove `union'. * test/lisp/emacs-lisp/rx-tests.el (rx-union, rx-def-in-union) (rx-intersection): Rename tests and change `union' to `or' and `|'.
* Add `union' and `intersection' to rx (bug#37849)Mattias Engdegård2019-12-10
| | | | | | | | | | | | | | | | | | | | | | These character set operations, together with `not' for set complement, improve the compositionality of rx, and reduce duplication in complicated cases. Named character classes are not permitted in set operations. * lisp/emacs-lisp/rx.el (rx--translate-any): Split into multiple functions. (rx--foldl, rx--parse-any, rx--generate-alt, rx--intervals-to-alt) (rx--complement-intervals, rx--intersect-intervals) (rx--union-intervals, rx--charset-intervals, rx--charset-union) (rx--charset-all, rx--charset-intersection, rx--translate-union) (rx--translate-intersection): New. (rx--translate-not, rx--translate-form, rx--builtin-forms, rx): Add `union' and `intersection'. * test/lisp/emacs-lisp/rx-tests.el (rx-union ,rx-def-in-union) (rx-intersection, rx-def-in-intersection): New tests. * doc/lispref/searching.texi (Rx Constructs): * etc/NEWS: Document `union' and `intersection'.
* Spelling fixesPaul Eggert2019-12-09
|
* Avoid duplicated character classes in rxMattias Engdegård2019-12-03
| | | | | | | | For example, (any digit digit) should produce "[[:digit:]]", not "[[:digit:][:digit:]]". * lisp/emacs-lisp/rx.el (rx--translate-any): Deduplicate character classes. * test/lisp/emacs-lisp/rx-tests.el (rx-any): Add test case.
* Expand rx definitions inside (not ...)Mattias Engdegård2019-10-27
| | | | | | | | | * lisp/emacs-lisp/rx.el (rx--translate-not): * test/lisp/emacs-lisp/rx-tests.el (rx-not, rx-def-in-not): * doc/lispref/searching.texi (Rx Constructs, Extending Rx): Allow user-defined rx constructs to be expanded inside (not ...) forms, for better composability (bug#37849).
* Use [^z-a] for matching any character (anychar/anything) in rxMattias Engdegård2019-10-18
| | | | | | | | | | * lisp/emacs-lisp/rx.el (rx--translate-symbol): * test/lisp/emacs-lisp/rx-tests.el (rx-any, rx-atoms): Use [^z-a] instead of ".\\|\n" for anychar. The new expression is faster (about 2×) and does not allocate regexp stack space. For example, (0+ anychar) now matches strings of any size (bug#37659).
* Add `unmatchable' as alias for (or) in rx (bug#37659)Mattias Engdegård2019-10-18
| | | | | | | | | * lisp/emacs-lisp/rx.el (rx--translate-symbol, rx--builtin-symbols, rx): * test/lisp/emacs-lisp/rx-tests.el (rx-atoms): * doc/lispref/searching.texi (Rx Constructs): * etc/NEWS: Add `unmatchable', more descriptive than (or), and corresponding to the variable `regexp-unmatchable'.
* Add `anychar' as alias to `anything' in rx (bug#37659)Mattias Engdegård2019-10-18
| | | | | | | | | * lisp/emacs-lisp/rx.el (rx--translate-symbol, rx--builtin-symbols, rx): * test/lisp/emacs-lisp/rx-tests.el (rx-atoms): * doc/lispref/searching.texi (Rx Constructs): * etc/NEWS: Add `anychar', an alias for `anything'. Since `anychar' is more descriptive (and slightly shorter), treat it as the preferred name.
* Add `rx-submatch-n' for compatibility (bug#37517)Mattias Engdegård2019-09-29
| | | | | | | | It was an internal symbol in the old `rx' implementation, used in old versions of the `flycheck' package. * lisp/emacs-lisp/rx.el (rx-submatch-n): Alias of `rx-to-string'. * test/lisp/emacs-lisp/rx-tests.el (rx-compat): Test it.
* Add rx extension mechanismMattias Engdegård2019-09-25
| | | | | | | | | | | | | | | | | | Add a built-in set of extension macros: `rx-define', `rx-let' and `rx-let-eval'. * lisp/emacs-lisp/rx.el (rx-constituents, rx-to-string): Doc updates. (rx--builtin-symbols, rx--builtin-names, rx--local-definitions) (rx--lookup-def, rx--substitute, rx--expand-template) (rx--make-binding, rx--make-named-binding, rx--extend-local-defs) (rx-let-eval, rx-let, rx-define): New. (rx--translate-symbol, rx--translate-form): Use extensions if any. (rx): Use local definitions. * test/lisp/emacs-lisp/rx-tests.el (rx-let, rx-define) (rx-to-string-define, rx-let-define, rx-let-eval): New. * etc/NEWS (Changes in Specialized Modes and Packages): * doc/lispref/searching.texi (Rx Notation, Rx Functions, Extending Rx): Add node about rx extensions.
* New rx implementationMattias Engdegård2019-09-25
| | | | | | | | | | | | * lisp/emacs-lisp/rx.el: * test/lisp/emacs-lisp/rx-tests.el: * doc/lispref/searching.texi (Rx Constructs): Rewrite rx for correctness, clarity, and performance. The new implementation retains full compatibility and has more comprehensive tests. * lisp/emacs-lisp/re-builder.el (reb-rx-font-lock-keywords): Adapt to changes in internal variables in rx.el.
* Fix (rx-to-string (and (literal STR) (regexp STR)) regressionNoam Postavsky2019-06-26
| | | | | | * lisp/emacs-lisp/rx.el (rx-regexp, rx-literal): Check the cadr of the form for stringness, not the form itself. * test/lisp/emacs-lisp/rx-tests.el (rx-to-string-lisp-forms): New test.
* Support (rx (and (regexp EXPR) (literal EXPR))) (Bug#36237)Noam Postavsky2019-06-25
| | | | | | | | | | | | | | | | | * lisp/emacs-lisp/rx.el (rx-regexp): Allow non-string forms. (rx-constituents): Add literal constituent, which is like a plain STRING form, but allows arbitrary lisp expressions. (rx-literal): New function. (rx-compile-to-lisp): New variable. (rx--subforms): New helper function for handling subforms, including non-constant case. (rx-group-if, rx-and, rx-or, rx-=, rx->=, rx-repeat, rx-submatch) (rx-submatch-n, rx-kleene, rx-atomic-p): Use it to handle non-constant subforms. (rx): Document new form, wrap non-constant forms with concat call. * test/lisp/emacs-lisp/rx-tests.el (rx-tests--match): New macro. (rx-nonstring-expr, rx-nonstring-expr-non-greedy): New tests. * etc/NEWS: Announce changes.
* Allow zero-argument rx `or' and `seq' formsMattias Engdegård2019-05-20
| | | | | | | | | | | Make the rx `or' and `seq' forms accept zero arguments to produce a never-matching regexp and an empty string, respectively. * lisp/emacs-lisp/rx.el: Require cl-extra. (rx-constituents, rx-or): Permit zero args. (rx): Amend doc string for `or' and `seq'. * test/lisp/emacs-lisp/rx-tests.el (rx-or, rx-seq): Test the change. * etc/NEWS (Changes in Specialized Modes and Packages): Mention the change.
* Revert "Allow zero-argument rx `or' and `seq' forms"Mattias Engdegård2019-05-20
| | | | | This reverts commit b552fc05c231ca6800330a318d3a74ddd0f5a13c. It caused a bootstrapping failure which I have yet to resolve - sorry.
* Allow zero-argument rx `or' and `seq' formsMattias Engdegård2019-05-20
| | | | | | | | | | Make the rx `or' and `seq' forms accept zero arguments to produce a never-matching regexp and an empty string, respectively. * lisp/emacs-lisp/rx.el (rx-constituents, rx-or): Permit zero args. (rx): Amend doc string for `or' and `seq'. * test/lisp/emacs-lisp/rx-tests.el (rx-or, rx-seq): Test the change. * etc/NEWS (Changes in Specialized Modes and Packages): Mention the change.
* Disallow reversed char ranges in `rx'Mattias Engdegård2019-03-19
| | | | | | | | | | (any "a-Z0-9") generated "[0-9]", and (any (?9 . ?0)) generated "[9-0]". Reversed ranges are either mistakes or abuse. Neither should be allowed. etc/NEWS: Explain the change. lisp/emacs-lisp/rx.el (rx): Document. (rx-check-any-string, rx-check-any): Add error checks for reversed ranges. test/lisp/emacs-lisp/rx-tests.el (rx-char-any-range-bad): New test.
* Fix some ineffective backslashes in string literalsMattias Engdegård2019-03-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Deal with lone backslashes that have no effect in string literals, but indicate that something is amiss. * lisp/auth-source-pass.el (auth-source-pass-entries): * lisp/textmodes/artist.el (artist-figlet-get-font-list-windows): * lisp/org/ob-abc.el (org-babel-expand-body:abc, org-babel-execute:abc): * lisp/org/ob-forth.el (org-babel-forth-session-execute): * lisp/vc/vc-git.el (vc-git--program-version): Add backslash in regexp for correctness. * lisp/gnus/nnmail.el (nnmail-split-abbrev-alist): Replace `\||' with `\\|' to follow the obvious regexp intent. * lisp/org/org-list.el (org-plain-list-ordered-item-terminator): Add backslash in doc comment so that it appears as intended. * lisp/progmodes/cc-engine.el (c-forward-decl-or-cast-1, c-end-of-decl-1): * lisp/progmodes/f90.el (f90-font-lock-keywords-2): * lisp/progmodes/etags.el (etags-tags-completion-table): * lisp/progmodes/ruby-mode.el (ruby-syntax-propertize): * test/lisp/emacs-lisp/cl-print-tests.el (cl-print-tests-1): Remove superfluous backslashes from regexp. * test/lisp/emacs-lisp/rx-tests.el (rx-char-any): Remove superfluous backslash from doc comment.
* rx: fix `or' ordering by adding argument to regexp-optMattias Engdegård2019-03-02
| | | | | | | | | | | | | | | | | The rx `or' form may reorder its arguments in an unpredictable way, contrary to user expectation, since it sometimes uses `regexp-opt'. Add a NOREORDER option to `regexp-opt' for preventing it from producing a reordered regexp (Bug#34641). * doc/lispref/searching.texi (Regular Expression Functions): * etc/NEWS (Lisp Changes in Emacs 27.1): Describe the new regexp-opt NOREORDER argument. * lisp/emacs-lisp/regexp-opt.el (regexp-opt): Add NOREORDER. Make no attempt at regexp improvement if the set of strings contains a prefix of another string. (regexp-opt--contains-prefix): New. * lisp/emacs-lisp/rx.el (rx-or): Call regexp-opt with NOREORDER. * test/lisp/emacs-lisp/rx-tests.el: Test rx `or' form match order.
* Prevent over-eager rx character range condensationMattias Engdegård2019-02-16
| | | | | | | | | | | | | `rx' incorrectly considers character ranges between ASCII and raw bytes to cover all codes in-between, which includes all non-ASCII Unicode chars. This causes (any "\000-\377" ?Å) to be simplified to (any "\000-\377"), which is not at all the same thing: [\000-\377] really means [\000-\177\200-\377] (Bug#34492). * lisp/emacs-lisp/rx.el (rx-any-condense-range): Split ranges going from ASCII to raw bytes. * test/lisp/emacs-lisp/rx-tests.el (rx-char-any-raw-byte): Add test case. * etc/NEWS: Mention the overall change (Bug#33205).
* Make the rx operators \? and \?? behave correctlyMattias Engdegård2019-02-01
| | | | | | * lisp/emacs-lisp/rx.el (rx-kleene): Treat \? and \?? like ? and ?? (Bug#34100). * test/lisp/emacs-lisp/rx-tests.el: Add tests for all repetition operators.
* Merge from origin/emacs-26Paul Eggert2018-12-31
|\ | | | | | | | | | | 2fcf2df Fix copyright years by hand 26bed8b Update copyright year to 2019 2814292 Fix value of default frame height. (Bug#33921)
| * Update copyright year to 2019Paul Eggert2019-01-01
| | | | | | | | Run 'TZ=UTC0 admin/update-copyright $(git ls-files)'.
* | Handle raw bytes, and LF in ranges, in rx `any' argument stringsMattias Engdegård2018-12-29
|/ | | | | | * lisp/emacs-lisp/rx.el (rx-check-any-string): Rewrite to handle raw bytes in unibyte strings and accept LF as range endpoints (Bug#33205). * test/lisp/emacs-lisp/rx-tests.el: Add tests for the above.
* Update copyright year to 2018Paul Eggert2018-01-01
| | | | Run admin/update-copyright.
* Prefer HTTPS to FTP and HTTP in documentationPaul Eggert2017-09-13
| | | | | | | | | | | | | Most of this change is to boilerplate commentary such as license URLs. This change was prompted by ftp://ftp.gnu.org's going-away party, planned for November. Change these FTP URLs to https://ftp.gnu.org instead. Make similar changes for URLs to other organizations moving away from FTP. Also, change HTTP to HTTPS for URLs to gnu.org and fsf.org when this works, as this will further help defend against man-in-the-middle attacks (for this part I omitted the MS-DOS and MS-Windows sources and the test tarballs to keep the workload down). HTTPS is not fully working to lists.gnu.org so I left those URLs alone for now.
* Add 'rx' pattern for pcase.Philipp Stephani2017-07-23
| | | | | * lisp/emacs-lisp/rx.el (rx): New pcase macro. * test/lisp/emacs-lisp/rx-tests.el (rx-pcase): Add unit test.
* Update copyright year to 2017 in masterPaul Eggert2017-01-01
| | | | | | Run admin/update-copyright in the master branch. This fixes files that were not already fixed in the emacs-25 branch before it was merged here.
* Fix rx-any with range with ?\] and ?-Noam Postavsky2016-12-18
* lisp/emacs-lisp/rx.el: Make sure not to produce a circular list (Bug#25123). * test/lisp/emacs-lisp/rx-tests.el (rx-char-any): New test.