summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* New function: regex-source.Kaz Kylheku2016-09-253-0/+23
| | | | | | | | | * regex.c (regex_source): New function. (regex_init): regex-source intrinsic registered. * regex.h (regex_source): Declared. * txr.1: Documented.
* Bugfix in regex printing: & operator.Kaz Kylheku2016-09-251-1/+1
| | | | | * regex.c (print_rec): Fix checking arg1 for consp but accessing arg2.
* awk macro: support paragraph mode.Kaz Kylheku2016-09-252-9/+57
| | | | | | | | | | | * share/txr/stdlib/awk.tl (sys:awk-state loop): If the rs variable is nil, provide a record reader which reads paragraphs, like under Awk's paragraph mode when RS is blank. This does not support the requirement that newline is always a field separator, regardless of the value of FS. * txr.1: Documented paragraph mode.
* awk macro: loop uses closure to read records.Kaz Kylheku2016-09-251-23/+27
| | | | | | | | | | | | | * share/txr/stdlib/awk.tl (sys:awk-state loop): Refactor code so that record-processing loop obtains a lambda which is called to extract a record. If rs and krs did not change, then the same lambda is obtained from a variable which caches it. The get-rec-reader local function thus encapsulates the whole record delimiting strategy as well as changes to the variables. With this structure, it will be relatively easy to add support for Awk's paragraph mode, which is notably missing in the implementation.
* awk macro: handle dynamic changes in rs variable.Kaz Kylheku2016-09-252-20/+40
| | | | | | | | * awk.tl (sys:awk-state loop): The loop now notices when rs or krs changes and switches to a new record-adapter or to the raw stream as necessary. * txr.1: Notes added about changes to rs and krs.
* New strlist list input stream type.Kaz Kylheku2016-09-243-0/+150
| | | | | | | | | | | | | | | | | | * stream.c (struct strlist_in): New struct type. (strlist_in_stream_mark, strlist_in_get_line, strlist_in_get_char, strlist_in_unget_char, strlist_in_get_prop, strlist_in_get_error_str): New static functions. (strlist_in_ops): New static struct. (make_strlist_input_stream): New function. (stream_init): Register make-strlist-input-stream intrinsic. * stream.h (make_strlist_input_stream): Declared. * txr.1: Documented make-strlist-input-stream. Call fill_stream_ops on new strlist_in_ops struct to fill in common default stream operations.
* doc: add to fconv documentation.Kaz Kylheku2016-09-241-0/+14
| | | | | * txr.1: Documenting effect of fconv on rec, and its return value.
* doc: take advantage of orec in awk example.Kaz Kylheku2016-09-241-0/+7
| | | | | * txr.1: POSIX-derived example 1 can be made to conform to the original with orec.
* awk macro: add orec variable.Kaz Kylheku2016-09-242-3/+32
| | | | | | | | | | * share/txr/stdlib/awk.tl (sys:awk-state): New slot, orig-rec. (sys:awk-state loop): Initialize orig-rec after reading each record. (sys:awk-let): Provide orec symbol macro. * txr.1: Document orec variable.
* doc: add awk macro examples.Kaz Kylheku2016-09-241-0/+213
| | | | | * txr.1: Adding 19 examples, converted from POSIX standard's Awk eamples.
* awk macro: use range test logic for clause conditions.Kaz Kylheku2016-09-242-5/+16
| | | | | | | | | | | * share/txr/stdlib/awk.tl (sys:range-test): Function renamed to sys:awk-test, since it's not just for ranges. (sys:awk-let): Uses of sys:range-test follow rename. sys:awk-test introduced into expansion of cond parts of cond-action clauses. * txr.1: Documented new behavior (conditions can produce a function or regex, which is implicitly invoked on rec).
* doc: use .coSS only for headings with identifiers.Kaz Kylheku2016-09-241-2/+2
| | | | * txr.1: Change .coSS to .SS* in two places.
* awk macro: exit if no cond-action clauses.Kaz Kylheku2016-09-241-12/+14
| | | | | | | | * share/txr/stdlib/awk.tl: If there are no cond-action clauses in the macro, do not generate the main record processing lambda, or the begin-file and end-file lambdas, and do not generate the call to the awk state object's loop method.
* awk macro: fconv conversions iz, xz, oz, bz and rz.Kaz Kylheku2016-09-242-1/+27
| | | | | | | * share/txr/stdlib/conv.tl (sys:conv-let): New flets iz, oz, xz, bz and rz. * txr.1: Documented under fconv.
* New functions: tofloatz and tointz.Kaz Kylheku2016-09-244-0/+63
| | | | | | | | | | * arith.c (tofloatz, tointz): New functions. * arith.h (tofloatz, tointz): Declared. * eval.c (eval_init): Register tofloatz and tointz intrinsics. * txr.1: Documented new functions.
* Bugfix: -Dvar=val not seen in some Lisp code.Kaz Kylheku2016-09-232-3/+12
| | | | | | | | | | | | | | | | | | | TXR Lisp files run from the command line do not see -Dvar=val bindings, whereas -p expressions do. The REPL sees the bindings, but not code loaded from it using (load "file.tl") because they are lexical. Let's keep these bindings as local lexicals for -p and -e forms, but install them as global lexicals for the other situations. * parser.c (repl): Get rid of the local repl_env made from the bindings that are passed in. Instead, before starting the REPL, loop through the bindings and install them as global lexicals with reg_varl. * txr.c (txr_main): Before processing a Lisp file, install the bindings as global lexicals with reg_varl.
* Bugfix: out-of-range negative indices into lists.Kaz Kylheku2016-09-232-6/+41
| | | | | | | | | | | | | | | | | | We have a problem not handling negative list indices which index beyond the beginning of the list. Such accesses are just storing and retrieving the first element! * lib.c (listref): If a negative index is still negative after the length of the list is added to it, then return nil. Do not return car(list)! (listref_l): Similary, do not return car_l(list) if the index is less than zero, so that an error occurs for an out-of-range negative index. * txr.1: Update the documentation for ref to describe these indexing constraints, and also to include hashes.
* awk macro: support regexes better in ranges.Kaz Kylheku2016-09-232-5/+43
| | | | | | | | | | | | | | | | | | | * share/txr/stdlib/awk.tl (sys:awk-compile-time): New slot, rng-rec-temp. Specifies the name of a temporary variable which is scoped over the evaluation of ranges, and which caches a reference to the current record string. (sys:range-test): New function. (awk:let): Rename the original rng macrolet to sys:rng, and introduce rng as a wrapper around it which inserts the logic for calling the regex or function that might emerge from the evaluation of from-expr or to-expr. (awk): If ranges are present in the syntax, then bind the temporary variable which caches the record around the evaluations of the ranges. * txr.1: Document new special behavior of rng w.r.t functions and regexes. Add admonition against modifying rec and some other awk variables from range expressions.
* Switch regex type from sys:regex to regex.Kaz Kylheku2016-09-232-1/+6
| | | | | | | | | | | | | | | | | The sys:regex internal symbol was historically used when derivative-based regexes had a S-exp representation headed by that symbol. It had to be a private symbol. Now the regex symbol is only used as the COBJ class type for regexes; it makes no sense for it to be in the sys package. We want user code to be able to refer to this type using a public symbol. * lib.c (obj_init): Intern the regex symbol stored in regex_s in user_package. * txr.1: Include regex in the type graph in the Object Type section, and in the type list under the typeof function.
* eval: error message change.Kaz Kylheku2016-09-231-1/+1
| | | | | | | * eval.c (do_eval): The no such function or operator message is replaced with one which makes it clear that this means that the first element of the form doesn't name an operator or function.
* New regex functions: m^$, m^, m$, and others.Kaz Kylheku2016-09-233-0/+372
| | | | | | | | | | | | | | | | | | | * regex.c (do_match_full, do_match_full_offs, do_match_left, do_match_left_offs, do_match_right, do_match_right_offs): New static functions. (regex_match_full_fun, regex_match_right_fun, regex_match_full, regex_match_left, regex_match_right, regex_range_full, regex_range_left, regex_range_right): New functions. (regex_init): Register f^$, f^, f$, m^$, m^, m$, r^$, r^ and r$ intrinsics. * regex.h (regex_match_full_fun, regex_match_right_fun, regex_match_full, regex_match_left, regex_match_right, regex_range_full, regex_range_left, regex_range_right): Declared. * txr.1: Documented new functions.
* doc: add regex intro paragraph.Kaz Kylheku2016-09-231-0/+13
| | | | | * txr.1: New paragraph added under the Regular Expressions Library minor section.
* Semantics change in match-regex-right.Kaz Kylheku2016-09-222-22/+90
| | | | | | | | | | | | | | | | | | | | | | | | | | The way the end-position argument works in match-regex-right and match-regst-right is poorly considered. It basically enforces a constraint that there is a match which ends at that position and does not go beyond. This patch changes it work right: the functions test that the regex matches up to that position, as if the string ended there. * regex.c (match_regex_right_old): New static function, identical to the previous match_regex_right. Since we won't ever be using this inside TXR from any other module, we don't make it external. (match_regex_right): Rewritten to new semantics. (match_regst_right_old): New static function; provides the semantics of the old match_regst_right based on match_regex_right_old. (regex_init): Register match-regex-right and match-regst-right intrinsics to the match_regex_right_old and match_regst_right_old functions if compatibility <= 150 is requested. Otherwise they go to the rewritten new functions. * txr.1: Documentation updated, and compat notes added.
* Fix match-regex not conforming to documentation.Kaz Kylheku2016-09-223-3/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The documentation says that match-regex returns the length. Actually, it returns the position after the last character matched. This makes a difference when the match doesn't begin at character zero. The actual behavior is that of the match_regex C function which has behaved that way since the dawn of TXR, and internals depend on it behaving that way. So the internal function is being retained, and a new function is being registered as the match-regex intrinsic. The choice of binding for match-regex is subject to the compatibility option. The behavior of match-regst is also being fixed since its return value is incorrect due to this issue. Since its return value makes no sense at all (does not represent the matched text), it is not subject to the compatibility option; it is just fixed to conform with the documentation. * regex.c (match_regex_len): New function. (match_regst): Keep using match_regex, but use its return value properly. This simplifies the range extraction code, which is why match_regex works that way in the first place. (regex_init): Register match-regex to match_regex_len, unless compatibility <= 150 is requested; then register to match_regex. * regex.h (match_regex_len): Declared. * txr.1: Compatibility notes added.
* Going back to unmodified 2-Clause BSD License.Kaz Kylheku2016-09-229-75/+67
| | | | | | | | | | | | | | | | | | | | | | | | | * LICENSE: Reverted to Two-Clause BSD license. The copyright of the Linenoise library are included, because it uses exactly the same license. A note is added about MPI being in the public domain. * LICENSE-CYG: Revised text to clarify the situation that Cygnal is only bundled with a particular Windows build of TXR. * METALICENSE: Revised text. All references to modifications to the BSD license are removed. Gives pointers to the MPI and linenoise license files. Notes that linenoise is under the Two-Clause BSD also. Makes a note about Cygnal and points to LICENSE-CYG. * inst.nsi: Remove the text which tells the user that use of the program requires agreement with the license; refer only to redistribution. The "Agree" buttons are renamed "Acknowledge". * mpi/make-logtab, mpi/mpi.c, mpi/mpi.h, mpi/mplogic.c, mpi/mplogic.h: Remove copyright notices and "all rights reserved", since the author had placed this into the public domain, as made explicit in the README file.
* doc: fix regex function not mentioned in heading.Kaz Kylheku2016-09-221-1/+1
| | | | | * txr.1: search-regst added to heading of section which describes it.
* Regexes now callable as functions.Kaz Kylheku2016-09-222-6/+110
| | | | | | | | * lib.c (generic_funcall): Add case for regexes. Handle arguments in such a way that the string is always rightmost, with a view to convenient partial application. * txr.1: Documented in multiple places.
* Support functional argument in regsub.Kaz Kylheku2016-09-222-27/+59
| | | | | | | | | * regex.c (regsub): Allow the second argument to be a function, which is called with str as an argument, and returns a range which indicates what part of the string is to be replaced, or else nil. * txr.1: Documented functional argument of regsub.
* Support negative positions in regex matching funs.Kaz Kylheku2016-09-212-2/+29
| | | | | | | | | * regex.c (match_regex, match_regex_right): Detect a negative start or end position, respectively, and add the string length to it. If it is still negative, bail with nil. * txr.1: Documented.
* Move regex intrinsic registrations to regex.c.Kaz Kylheku2016-09-212-14/+14
| | | | | | | | * eval.c (eval_init): Remove all regex-related function registrations from here. * regex.c (regex_init): Move regex-related function registrations here.
* Use rlet in a few place macros for better code.Kaz Kylheku2016-09-211-3/+3
| | | | | | * share/txr/stdlib/place.tl (pset, push, pushnew): Use rlet for binding the assigned or pushed value to a temporary, so the temporary can disappear if the value is a constant.
* Fix broken sys:rslot place.Kaz Kylheku2016-09-211-4/+4
| | | | | | | | | | | | This is used in the awk macro. Breaking test case is an update modification of f, like (push 3 f); a broken call to sys:rslotset is generated with a too few arguments. * share/txr/stdlib/struct.tl (defplace sys:rslot): Fix name clash between gensym and parameter. Add the meth-slot-sym parameter into the sys:rslotset call where it is missing as a required parameter.
* doc: about assignment to nonexistent awk fields.Kaz Kylheku2016-09-211-0/+10
| | | | | * txr.1: Adding remark that assignment to nonexistent fields isn't permitted, unlike in Awk.
* doc: revised descrs of awk vars fs, ft an kfs.Kaz Kylheku2016-09-211-121/+65
| | | | | | | | * txr.1: fs and ft are described in one simplified section. The default behavior when they are both nil is described simply as token extraction, which is how it is now implemented. Some verbiage is reduced in the krs description.
* awk macro: streamline field splitting.Kaz Kylheku2016-09-211-13/+7
| | | | | | | | | * share/txr/awk.tl (sys:awk-state rec-to-f): Check for empty record only in the fs case; it's not necessary when tokenizing with ft. Check (not self.kfs) first, since it's the common case. Handle default case (no fs or ft) using tok-str using the regex #/[^ \t\n]+/, which requires no trim-str and no empty record check.
* New library feature: imperative list building.Kaz Kylheku2016-09-203-0/+403
| | | | | | | | | | | * lisplib.c (build_set_entries, build_instantiate): New static functions. (dlt_register): Register dynamic loading of build.tl via the two new functions. * share/txr/stdlib/build.tl: New file. * txr.1: Documented everything.
* Version 150.txr-150Kaz Kylheku2016-09-186-354/+396
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* New awk operator: fconv.Kaz Kylheku2016-09-183-1/+201
| | | | | | | | | * share/txr/stdlib/awk.tl (sys:awk-let): Add new symbol macro, fconv. * share/txr/stdlib/conv.tl: New file. * txr.1: Documented fconv.
* doc: typo in section on setuid operation.Kaz Kylheku2016-09-171-1/+1
| | | | * txr.1: "require user id" -> "required user id".
* doc: mention USERPROFILE.Kaz Kylheku2016-09-171-7/+14
| | | | | | | * txr.1: Document that on Windows, the home directory is determined from USERPROFILE for finding the ~/.txr_history file as well placing the temporary file for the edit-in-editor interactive feature.
* linenoise: use USERPROFILE for home dir on Cygnal.Kaz Kylheku2016-09-171-1/+18
| | | | | | | * linenoise/linenoise.c (get_home): New static function. (edit_in_editor): Call get_home instead of getenv("HOME").
* New awk variable: krs.Kaz Kylheku2016-09-172-7/+30
| | | | | | | | | | | * share/txr/stdlib/awk.tl (sys:awk-state): New slot, krs. (sys:awk-state loop): Use record-adapter if krs is true, even if the default fs is in effect. Pass value of krs to record-adapter function. (sys:awk-let): Provide krs "awk variable" symbol macro. * txr.1: Documented krs. Clarified semantics of rs being those of both separation and termination.
* Tests for tok-str.Kaz Kylheku2016-09-172-0/+73
| | | | * tests/015/split.tl: New cases added.
* Adding tests for split-str.Kaz Kylheku2016-09-173-0/+127
| | | | | | | | * Makefile (TXR_DBG_OPTS): Disable for tst/tests/015. * tests/common.tl (mtest): New macro. * tests/015/split.tl: New file.
* Bugfix in tok-str: empty-match regexes.Kaz Kylheku2016-09-161-10/+7
| | | | | | | | | | | | | | * lib.c (tok_str): Only continue the loop if the new position isn't past the end of the string. This fixes the problem of recognizing an empty token past the last character in the string. Also, advance new_pos by one if there is a zero length match. Then don't advance pos by one later in that case. This fixes the bug that we collect empty separator pieces *and* empty tokens, and also prevents empty matches before the first character of the string. Logic in tok_str is now very similar to that in split_str_keep.
* New awk variables: ft and kfs.Kaz Kylheku2016-09-162-14/+164
| | | | | | | | | | * share/txr/stdlib/awk.tl (sys:awk-state): New slots, ft and kfs. (sys:awk-state rec-to-f): Implement ft and kfs semantics. (sys:awk-let): Provide ft and kfs as "awk variable" via symbol macros. * txr.1: Documented ft and kfs.
* doc: fs variable.Kaz Kylheku2016-09-161-5/+17
| | | | | * txr.1: Improve some wording in the description of the awk fs variable.
* Bugfix in split-str: empty-match regexes.Kaz Kylheku2016-09-162-6/+12
| | | | | | | | | | | * lib.c (split_str_keep): In the regex case, changing to an infinite loop. The do/while is no longer needed because the if statement includes a test of the position having reached the end of the string. This is done before it is incremented by len, so we avoid wrongly keeping a separator. * txr.1: Clarified that an empty regex match behaves like an sep which is an empty string,
* split-str gains ability to keep separating pieces.Kaz Kylheku2016-09-164-3/+29
| | | | | | | | | | | | | | | * eval.c (eval_init): Register split-str to split_str_keep, with optional argument. * lib.c (split_str_keep): New function, formed from split_str, with third argument. (split_str): Reduced to wrapper around split_str_keep. Thus we don't have to update umpteen existing calls with an extra nil parameter. * lib.h (split_str_keep): Declared. * txr.1: Documented new optional argument of split-str.
* regex: optimize double complement.Kaz Kylheku2016-09-161-40/+46
| | | | * regex.c (reg_optimize): Implement ~~R -> R reduction.