[188-3 home > homework]
This homework involves adding a function to GNU Emacs to support regular-expression-style searching.
Define an Emacs Lisp function (num-search-forward NUM1 &optional NUM2 BASE) that searches forward in the current buffer for text that matches an integer.
With no optional arguments, the function should search for text matching the decimal integer NUM1. The text should be an optional sign (+ or -), followed by one or more decimal digits. The text of the number should not be immediately followed by a decimal digit; also, if the number lacks a sign, it should not be immediately preceded by a decimal digit. The decimal value of the number should equal NUM1. The number may have excess leading zeros, and may be negative zero.
If the optional integer argument NUM2 is present, the function should match any integer in the range NUM1 though NUM2 inclusive. If NUM2 is less than NUM1, the function should not match anything.
If the optional integer argument BASE is present, the textual representations should be in base BASE, which must be an integer in the range 2 through 16. The letters A through F stand for the digits 10 through 15 respectively, and may use either upper or lower case.
Your function should signal an error if any argument is not an integer, or if BASE is out of range, or if the search fails. If the search succeeds, it should set point to the end of the occurrence found, and return point, just as re-search-forward does by default. When invoked interactively, it should ask the user for NUM1 and search for that integer.
Use ERT to write ten good test cases for your function. At least one test case should involve the example discussed in class: (num-search-forward most-negative-fixnum most-positive-fixnum).
Submit your lab notebook log.txt as usual for homeworks.
Submit a source code file num-search.el containing your implementation of the function. An Emacs user should be able to load the file using M-x load, or to compile the file using M-x byte-compile-file.
Submit a source code file num-search-tests.el containing test cases. It should be loadable and compilable just as other Emacs source code is, and should be testable by running the shell command:
emacs -batch -l ert -l num-search -l num-search-tests -f ert-run-tests-batch-and-exit
All definitions should be commented in the usual style for Emacs Lisp. See the GNU Emacs source code for style examples.
For the second part of the homework, implement regular-expression searching for Perl-compatible regular expressions. Use libpcre to support the matching -- do not implement the matching yourself
Bind your implementation to the C-M-q; it should behave much as C-m-s (isearch-forward-regexp) does, except with Perl-compatible regular expressions rather than Emacs regular expressions. Link in libpcre by using the module-load primitive of the bleeding-edge master branch of GNU Emacs.
Optionally, if you'd rather write a paper about this than do it, write a 3- to 5-page paper describing the mechanics of how such an implementation would work. Your paper should discuss efficiency, robustness, and security implications, as well as the technical software software construction details.