summaryrefslogtreecommitdiffstats
path: root/parser.l
Commit message (Collapse)AuthorAgeFilesLines
* * parser.l: Allowing ^ to be a quote character, and adjusting definitionKaz Kylheku2014-03-031-10/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | of identifiers to rule this out from being the first character of a symbol which has no prefix. Recognize the ^ character as a token in the NESTED state. * lib.c (obj_print, obj_pprint): Render sys:qquote as ^. * parser.y (choose_quote): Function removed. (n_expr): Recognize '^' as quasiquote. Removed all the "smart quote" hacks that try to make quote behave as quote or quasiquote, or try to cancel out unquotes and quotes. * tests/009/json.txr: Fixed to ^ quasiquote. * tests/010/reghash.txr: Likewise. * tests/011/macros-2.txr: Likewise. * tests/011/mandel.txr: Likewise. * tests/011/special-1.txr: Likewise. * txr.1: Updated docs. * genvim.txr: Revamped definitions for txr_ident and txl_ident so that unqualified identifiers cannot start with # or ^, but ones with @ or : in front can start with these characters. * txr.vim: Regenerated.
* * parser.l: Regression: valid floating-point literals taggedKaz Kylheku2014-02-271-9/+9
| | | | | as having trailing junk. The fix is to put the junk-matching rule after the valid rules.
* * parser.l (regex_parse, lisp_parse): Better formattingKaz Kylheku2014-02-261-2/+2
| | | | for the context string that serves in place of a filename.
* * parser.l: Support octal and binary numbers.Kaz Kylheku2014-02-241-0/+44
| | | | | | * txr.1: Documented. * genvim.txr, txr.vim: Updated.
* * parser.l: Disallow syntax like 1.0a, flagging it asKaz Kylheku2014-02-121-0/+14
| | | | | | | | an invalid floating-point token. The problem is that 1a is allowed, for compatibility with other Lisp dialects (it is a symbol) whereas 1.0a was scanning as 1.0 followed by a, which is inconsistent. Some Lisp dialects embedded dots in symbols, and allow 1.0a as a symbol token. We don't.
* * hash.c (hash_mark, hash_grow, make_similar_hash,Kaz Kylheku2014-02-011-1/+1
| | | | | | | | | | | | | | | copy_hash, gethash_l, gethash, gethash_f, gethash_n, hash_count, hash_next, hash_eql, hash_equal): Use num_fast instead of num. (make_hash): An attempt to make a weak-keys hash that has equal-based keys is nonsensical; it is now diagnosed with an exception. Use num_fast instead of num. (hash_process_weak): Call breakpt whenever the weak object(s) due to which entries are being deleted match the value in break_obj. Use num_fast instead of num. * parser.l (parse_init): Bugfix: the forms_to_ln_hash was equal-based, which makes no sense.
* Lexing and parsing improvements, leaving things less hacky than before,Kaz Kylheku2014-01-271-20/+13
| | | | | | | | | | | | | | | | | | | | | | | albeit hacky. * parser.l (BSYM, NSYM): Regex definitions gone. (BT0, BT1, BT2, NT0, NT1, NT2): New regex definitions. (BTREG, BTKEY, NTREG, NTKEY): Rewritten, so that they cannot match a lone @ character as a symbol name. (grammar): Rules for returning METAPAR, METABKT and METAQUO are gone. Instead, we just recognize a @ in the NESTED and BRACED states and return it as a token. * parser.y (METAPAR, METABKT, METAQUO): Token types removed. (meta_expr): Nonterminal symbol removed. ('@'): New token type. (list): Quotes and splices handling removed from this rule. The new token '@' is handled here, on the other hand, because there are places that reference the list rule that need to support @ expressions. (n_expr): Reference to meta_expr removed. Quote, unquote and splice added here. (yybadtoken): Removed references to METAPAR, METABKT and METAQUO.
* Sigh; more lexical-syntactic hacks. This adds handlingKaz Kylheku2014-01-261-6/+17
| | | | | | | | | | for the @' combination, as in @(bind a @'(foo ,bar)) * parser.l: Handle the new METAQUO token. * parser.y (METAQUO): New token. (meta_expr): New "METAQUO expr" case. Added missing METABKT error handling case.
* * configure: Detect platforms which don't reveal declarationsKaz Kylheku2014-01-101-4/+0
| | | | | | | | | | | | | | in C headers which are extensions to standard C, like popen or fileno, in response to standard feature selection macros like -D_POSIX_SOURCE. MinGW and Cygwin are offenders. These platforms hide the declarations when gcc is in -ansi mode, by testing for __STRICT_ANSI__. Turns out, however, that -U__STRICT_ANSI__ on the gcc command line strips this away, causing the declarations to be revealed. * lib.c, parser.l, stream.c, utf8.c: Removed the declarations which compensated for the above problem. Yippee! Fuck you, stupid Cygwin troglodytes, and the MinGW horse you rode in on. http://cygwin.com/ml/cygwin/2011-10/msg00131.html
* * eval.c (eval_init): Renaming lisp-parse to read; lisp-parseKaz Kylheku2014-01-101-2/+4
| | | | | | | | is retained as an obsolescent synonym. All arguments become optional. * parser.l (lisp_parse): Handle nil source. * txr.1: Updated.
* Long overdue MinGW port maintenance.Kaz Kylheku2014-01-091-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Makefile: Use new EXE variable from config.mk. * configure (exe, have_windows_h): New variables. Handle situations with .exe suffix; on MiGW, the rm command doesn't work on executables if the .exe suffix is not given. New tests for localtime_r and gmtime_r. * lib.c: Supply declarations which are missing on MinGW because we use gcc -ansi, because MinGW doesn't follow established conventions like -D_POSIX_SOURCE. Supply definitions for gmtime_r, localtime_r, setenv and unsetenv. * parser.l: Supply declarations which are missing on MinGW. * signal.h (async_sig_enabled): Declare differently based on HAVE_POSIX_SIGS. Misspelled typedef fixed in the code for !HAVE_POSIX_SIGS that has hitherto not been compiled. (sig_mask): Wrap declaration in #ifdef HAVE_POSIX_SIGS because it relies on sigset_t. * stream.c: Supply declarations which are missing on MinGW. Include <windows.h> if we have it. (sleep): Define for Windows. (statf): Handle missing st_blksize and st_blocks members in struct stat. (stream_init): Handle numerous missing S_* macros. * utf8.c: Supply declarations which are missing on MinGW.
* The lisp-parse function can now be called multiple timesKaz Kylheku2014-01-071-9/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | on the same stream to extract multiple objects; the requirement that the stream must hold exactly one complete Lisp object with no following material is now lifted. * parser.l (YY_INPUT): Modified the macro so that it reads no more than one character. Though this probably makes the lexer less efficient, it gives us the important property that the lexer does not scan ahead into the input stream, hogging data into its buffer which is then destroyed. This is essential if the lisp-parse function is to support multiple calls to pull objects one by one out of a stream. * parser.y (spec): Use YYACCEPT in the SECRET_ESCAPE_E clause for pulling a single expression out of the token stream. YYACCEPT is a trick for not invoking the $accept : spec . $end production which is implicitly built into the grammar, and which causes a token of lookahead to occur. This allows us to read a full expression without stealing any further token: but only if the grammar is structured right. (exprs): This phrase structure now handles the DOTDOT syntax. There is no such thing as an expr DOTDOT expr expression any more; it is in the list syntax (and not supported in the dot position). (expr): Remove DOTDOT syntax. * txr.1: Updated description of .. syntax, and relaxed the description of lisp-parse since it now allows multiple calls to extract multiple objects.
* * lib.c (intern): fix the previous diagnostic bug once more with moreKaz Kylheku2013-12-161-11/+7
| | | | | | | | | | feeling. * parser.l (grammar): Recognize package prefixes in symbol tokens. Got rid of special rule for handling lone colon. * parser.y (sym_helper): Catch undefined package as a parsing error rather allowing intern function to throw exception.
* Changing the tokenizer to get rid of IDENT, KEYWORD and METAVARKaz Kylheku2013-12-151-14/+5
| | | | | | | | | | | | | | | | | | | | | token categories, replaced by a single one called SYMTOK. Package prefixes are now recognized and processed in tokens. * lib.c (delete_package): Fix problem in no-such-package error case: it would always report nil as the name. (intern): Fix nonsensical error message: in the no-such-package case it would report that the symbol exists already. * parser.l (grammar): Occurences of KEYWORD, METAVAR, and IDENT scrubbed. All rules reporting any of these now return SYMTOK. The main one of these is greatly simplified. * parser.y (sym_helper): New function. (char_from_name): const qualifier inside param's type declaration. (grammar): IDENT, KEYWORD and METAVAR tokens are gone. New token SYMTOK. Grammar refactored around SYMTOK and using the new sym_helper function. (char_from_name): Updated.
* Support for parsing Lisp expression out of strings and streams.Kaz Kylheku2013-12-141-1/+31
| | | | | | | | | | | | | | | | | | | | | | New catenated streams make the Yacc hack possible. * eval.c (eval_init): Register lisp_parse as intrinsic. * parser.h (lisp_parse): Declared. * parser.l: New lexical hack to produce SECRET_ESCAPE_E token. (regex_parse): Move declaration before statements. (lisp_parse): New function. * parser.y (SECRET_ESCAPE_E): New token type. (spec): New production rule for single expression. * stream.c (cat_stream_print, cat_get_line, cat_get_char, cat_get_byte, cat_get_prop): New static functions. (cat_stream_ops): New static function. (make_catenated_stream): New function. * stream.h (make_catenated_stream): Declared.
* First cut at signal handling support.Kaz Kylheku2013-12-121-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Makefile (OBJS-y): Include signal.o if have_posix_sigs is "y". * configure (have_posix_sigs): New variable, set by detecting POSIX signal stuff. * dep.mk: Regenerated. * arith.c, debug.c, eval.c, filter.c, hash.c, match.c, parser.y, parser.l, rand.c, regex.c, syslog.c, txr.c, utf8.c: Include new signal.h header, now required by unwind, and the <signal.h> system header. * eval.c (exit_wrap): New function. (eval_init): New functions registered as intrinsics: exit_wrap, set_sig_handler, get_sig_handler, sig_check. * gc.c (release): Unused functions removed. * gc.h (release): Declaration removed. * lib.c (init): Call sig_init. * stream.c (set_putc, se_getc, se_fflush): New static functions. (stdio_put_char_callback, stdio_get_char_callback, stdio_put_byte, stdio_flush, stdio_get_byte): Use new functions to enable signals when blocked on I/O. (tail_strategy): Allow signals across sleep. (pipev_close): Allow signals across waitpid. (se_pclose): New static function. (pipe_close): Use new function to enable signals across pclose. * unwind.c (uw_unwind_to_exit_point): use extended_longjmp instead of longjmp. * unwind.h (struct uw_block, struct uw_catch): jb member changes from jmp_buf to extended_jmp_buf. (uw_block_begin, uw_simple_catch_begin, uw_catch_begin): Use extended_setjmp instead of setjmp. * signal.c: New file. * signal.h: New file.
* Bumping copyrights to 2014 and expressing them as year ranges.Kaz Kylheku2013-12-101-1/+1
| | | | Fixing some errors in copyright comments.
* * parser.l (end_of_regex): Fix start condition stack underflowKaz Kylheku2013-12-061-3/+5
| | | | during regex_parse.
* * parser.l (regex_parse): Match the simplified grammar nowKaz Kylheku2013-12-061-3/+5
| | | | | expected in the parser, with no slashes around the regex. Change prefix for diagnostic message.
* * eval.c (eval_init): Registered regex_parse as newKaz Kylheku2013-12-051-0/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | intrinsic function and std_null as new variable. * parser.h (yylex_destroy): Existing function declared. * parser.l (regex_parse): New function. New lexical syntax added which returns SECRET_ESCAPE_R. * parser.y (SECRET_ESCAPE_R): New token. (spec): Added syntactic variant which lets us smuggle a regex into the parser easily. * stream.c:x (std_null): New global variable. (null_stream_print): New static function. (null_ops): New static structure. (make_null_stream): New function. (stream_init): Protect and initialize std_null. * stream.h (std_null, make_null_stream): Declared. * txr.1: New features documented: regex-parse, *stdnull*. * txr.c (txr_main): Call yylex_destroy after parsing the program now that I know about this function; this can free up some memory.
* * Changelog: missing entries reconstructed.Kaz Kylheku2013-11-271-1/+3
| | | | | | | | | | | | | * Makefile (conftest.clean): Use @ to suppress output. * configure (have_unistd): New variable. Set true by every successful test that compiles something that contains #include <unistd.h>. HAVE_UNISTD_H is conditionally generated in config.h based on this variable. Minor cleanup. * parser.l: Inclusion of <unistd.h> wrapped in #if/#endif. * stream.c: Conditional inclusion of <unistd.h> based on new HAVE_UNISTD_H symbol.
* * configure: Added check to detect POSIX sleep function.Kaz Kylheku2013-11-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (eval_init): Register new open_tail function as intrinsic. * match.c (complex_snarf, complex_stream): Update calls to make_stdio_stream and make_pipe_stream to take fewer arguments. (match_files): Support a stream object as a data source specification in place of a string. * parser.l (parse_reset): Update call to make_stdio_stream to take fewer arguments. * stream.c: Inclusion of <unistd.h> made properly conditional. (struct stdio_handle): pid member defined as pid_t only if we have fork functionality, otherwise defined as int. (tail_get_line, tail_get_char, tail_get_byte): New static functions. (tail_ops): New static structure. (make_stdio_stream_common): New static structure. (make_stdio_stream, make_pipe_stream): These functions lose the input and output parameters, which ended up never used. Reimplemented in terms of new common function. (make_tail_stream): New function. (make_pipevp_stream): Reimplemented in terms of new common function. (open_file, open_command): Simplified by removal of useless local variables and their computation, which used to be extra arguments to make_stdio_stream and make_pipe_stream. (open_tail): New function. (stream_init): Calls to make_stdio_stream updated. * stream.h (make_stdio_stream, make_pipe_stream): Declarations updated. (make_tail_stream, open_tail): Declared. * txr.c (txr_main): Calls to make_stdio_stream updated.
* * parser.l: Diagnose unrecognized escape sequences in stringKaz Kylheku2013-07-131-1/+9
| | | | | | literals and quasiliterals and after @\. Support "\ " (backslash space) escape in string literals and quasiliterals.
* * parser.l: Implemented hexadecimal integer constants.Kaz Kylheku2012-09-161-2/+25
| | | | | | | These will be very useful since bit operations are about to be implemented. * txr.1: Documented.
* First cut at implementing \s, \d, \w, \S, \D and \W regex tokens.Kaz Kylheku2012-04-191-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * lib.c (init): Call regex_init. * parser.l: return new REGTOKEN kind. * parser.y (REGTOKEN): New token type. (REGTERM): Translate REGTERM to keyword. (regclass): Restructured to handle inherited nodes as lists. (regclassterm): Produce $$ as list. Add handling for REGTOKEN occurring inside character class by expanding it. This might not be the best approach. (yybadtoken): Handle REGTOKEN in switch. * regex.c (struct any_char_set, struct small_char_set, struct displaced_char_set, struct large_char_set, struct xlarge_char_set): New bitfield member, stat. (char_set_create): New parameter for indicating static char set. (char_set_destroy): Do not free a static char set. (char_set_compile): Pass zero to new parameter of char_set_create. (spaces): New static array. (space_cs, digit_cs, word_cs, cspace_cs, cdigit_cs, cword_cs): New static pointers to char_set_t. (init_special_char_sets, nfa_compile_given_set): New static function. (nfa_compile_regex, dv_compile_regex): Handle new character set token keywords. (space_k, digit_k, word_char_k, cspace_k, cdigit_k, cword_char_k, regex_space_chars): New variables. (regex_init): New function. * regex.h (space_k, digit_k, word_char_k, cspace_k, cdigit_k, cword_char_k, regex_space_chars, regex_init): Declared.
* * parser.l: Bugfix: was not allowing e-notation floatsKaz Kylheku2012-03-221-1/+1
| | | | | | | | | | | | | | | | with no decimal point like 1E1. * stream.c: (vformat): Keep track of whether or not precision was given in precision_p local variable. When printing #<bad-float> pass a precision of 0 to vformat_str, not precision, since precision does not apply. In ~f and ~e, if the precision was not given, default it to 3. Restructured float printing in ~a and ~s. It now just uses sprintf's %g with a precision. If user does not specify precision, it defaults to DBL_DIG to print the number with reasonable accuracy. A .0 is added if it sprintf produces an integer, and the conversion is ~s rather than ~a.
* * arith.c (neg): Floating-point support.Kaz Kylheku2012-03-211-2/+12
| | | | | | | | | | | | | * parser.l: FLO and FLODOT cases had to be reordered because the lex trailing context counts as part of the match length, causing 3.0 to be matched as three characters with 0 as the trailing context. The cases are split up to eliminate a flex warning. * stream.c (vformat): Support bignum in floating point conversion. Bugfixes: floating point conversion was accessing obj->fl.n instead of using n. Changed some if/else ladders to switches.
* Regression fix: 1..3 scans incorrectly into 1. .3 tokens.Kaz Kylheku2012-03-201-3/+8
| | | | | | | | | | | * parser.l (SGN, EXP, DIG): New regex definitions. (FLO): Do not recognize numbers of the form 123. Decimal point must be followed either by exponent, or digits (which may then be followed by an exponent). (FLODOT): New token type, recognizes 123. (grammar): Recognize FLODOT as a floating point number, only if it not trailed by another dot, and recognize FLO unconditionally.
* * parser.l (FLO): Adjusted syntax of floating point numbersKaz Kylheku2012-03-201-1/+1
| | | | to allow leading or trailing decimal.
* * configure (uintptr): New variable. Indicates whether unsignedKaz Kylheku2012-03-191-2/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | version of intptr_t is available and should be generated in config.h as uintptr_t. * eval.c (eval_init): New intrinsic functions floatp, integerp, flo-str. * gc.c (finalize): Handle FLNUM case. Rearranged cases so that all trivially returning cases are together. (mark): Handle FLNUM case. * hash.c (hash_double): New function. (equal_hash): Handle FLNUM via hash_double. (eql_hash): Likewise. * lib.c: <math.h> is included. (float_s): New symbol variable. (code2type, equal): Handle FLNUM case in switch. (integerp): New function; does the same thing as integerp before. (numberp): Returns t for floats. (flo, floatp, flo_str): New functions. (obj_init): Initialize new float_s variable. (obj_print, obj_pprint): Handle FLNUM case in switch. Printing does not work yet; needs work in stream.c. * lib.h (enum type): New enumeration FLNUM. (struct flonum): New struct type. (union obj): New member, fl. (float_s, flo, floatp, integerp, flo_str): Declared. * parser.l (FLO): New token pattern definition. Scans to a NUMBER token. Corrected uses of yylval.num to yylval.val. * parser.y (%union): Removed num member from yystype.
* Implementing #H((...) ...) read/print syntax for hash tables.Kaz Kylheku2012-03-141-0/+5
| | | | | | | | | | | | | | | | * hash.c (print_key_val, hash_print_op): New static functions. (hash_ops): hash_print_op wired in in place of cobj_print_op. * parser.l (HASH_H): New token recognized. * parser.y (HASH_H): New terminal symbol. (hash): New nonterminal symbol. (expr): Acquires hash as a constituent. (hash_from_notation): New static function. * txr.1: Hash syntax described. * txr.vim: Updated.
* Change: @(block) requires @(end) from now on.Kaz Kylheku2012-03-131-0/+6
| | | | | | | | | | | | | | | | | | | Blocks no longer extend to the end of the surrounding scope. * match.c (v_block): Rewrite for new syntax. * parser.l (BLOCK): New token type handled. * parser.y (BLOCK): New token. (block_clause): New nonterminal grammar symbol. (clause): Collateral fix: replaced a bunch of list(X, nao) forms with cons(X, nil). Introduced block_clause as a constituent of clause. * txr.1: Revamped documentation of block, and wrote about using blocks for reducing nested skips and reducing backtracking in general.
* * parser.l (ID_END): Bugfix: ID_END was defined incorrectlyKaz Kylheku2012-03-131-1/+1
| | | | | | for the current way in which an identifier token is recognized. As a result @(collect-ing) was being interpreted as @(collect -ing). It should be the complement of NSCHR.
* Bug #35625Kaz Kylheku2012-02-261-464/+490
| | | | | | | | | | | | | | | | | | | | | | * parser.l (BSCHR, BSYM, BTOK): New lexical definitions. (BRACED): New state. (grammar): Refactored so that braced variables are now handled in the BRACED state, allowing for lexical differences between braced variables and Lisp. This allows us to have the /regex/ syntax in braces, but /regex/ is just a symbol in the Lisp. The new #/ token is recognized and returned as HASH_SLASH. All rules reformatted to a more easily maintainble convention. * parser.y (HASH_SLASH): New token. (modifiers, lisp_regex): New nonterminals. (var): Grammar changed to use modifiers nonterminal instead of exprs. (var_op): Rule moved closer to var. (expr): Produces lisp_regex rather than regex. (yybadtoken): Handle HASH_SLASH in the switch statement. Bugfix: HASH_BACKSLASH was not handled. * txr.1: Documented #/regex/ syntax.
* * parser.l (num_esc): Skip octal indicator 'o' if present.Kaz Kylheku2012-02-251-1/+3
| | | | | | | This is needed for character constants. (CHRLIT): Fix broken hex constants, being treated as octal. * txr.1: Document octal character constants.
* * parser.l (source_loc_str): Missing function re-written.Kaz Kylheku2012-02-251-2/+14
| | | | | | | | (Accidentally originally written in lex.yy.c file!) (parse_reset): If file can't be opened, try adding .txr suffix to it. * txr.1: Suffix-handling behavior documented.
* * debug.c (debug): Use new way of getting line number.Kaz Kylheku2012-02-241-1/+1
| | | | | | | | | | | | | | * eval.c (eval_error): Use source_loc_str to get source location. * match.c (debuglf, sem_err, file_err): Likewise. * parser.h (source_loc_str): Declared. * parser.l (parse_init): form_to_ln_hash must be equal based now. * parser.y (rl): Store new form of read-time source location info. * txr.1: Documented load.
* First cut at @(load) directive. Incomplete: debug location infoKaz Kylheku2012-02-241-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | needs to record file name, not only line number; absolute paths not handled, etc. * match.c (load_s): New symbol variable. (v_load): New static function. (syms_init): load_s initialized. (dir_tables_init): Load directive registered. * match.h (load_s): Declared. * parser.h (parse_reset): New function declared. * parser.l (spec_file_str): Global variable moved from txr.c. (parse_reset): New function. * parser.y (clause): Special handling for @(load ...) directive. parent file path inserted into the syntax at parse time, so when the load directive executes, it can load the file from the same directory as the parent file. * txr.c (spec_file_str): Global variable moved to parser.l.
* Introducing optional arguments.Kaz Kylheku2012-02-211-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * debug.c (help, show_bindings): put_string arguments reversed. * eval.c (bind_args): Support colon notation in interpreted function lambda lists for optional arguments. Improved error checking. (apply): Allow optional arguments to be left out. (dwim_loc): Reversed arguments to replace_str, replace_vec, replace_list. (eval_init): Numerous intrinsics now have arguments that are optional. New function rand introduced which reverses arguments relative to random. New intrinsic function hash introduced for alternative construction of hashes. * gc.c (sweep): Reversed arguments to put_char. * hash.c (weak_keys_k, weak_vals_k, equal_based_k): New keyword symbol variables. (hashv): New function. (hash_init): Intern new symbols. * hash.h (weak_keys_k, weak_vals_k, equal_based_k, hashv): Declared. * lib.c (colon_k): New keyword symbol variable. (replace_list, replace_str, replace_vec): Arguments rearranged. (tree_find): testfun becomes optional argument. (int_str): base becomes optional argument. (func_f0, func_f1, func_f2, func_f3, func_f4, func_n0, func_n1, func_n2, func_n3, func_n4, func_f0v, func_f1v, func_f2v, func_f3v, func_f4v, func_n0v, func_n1v, func_n2v, func_n3v, func_n4v, func_interp): Initialize optargs to zero. (func_n0o, func_n1o, func_n2o, func_n3o, func_n4o): New functions. (cobj_print_op): Reversed arguments to put_string. (find): testfun and keyfun become optional arguments. (replace): Parameters rearranged and arguments rearranged in calls to replace_list, replace_str and replace_vec. (obj_init): colon_k initialized. (obj_print, obj_pprint): Arguments reversed, and stream defaults to std_output. Arguments reversed in calls to put_char and put_string. (dump): Arguments reversed in call to put_char. * lib.h (struct func): sizes of minparam, fixparam bitfields adjusted. New bitfield optargs. New unnamed bitfield added so the previous ones add up to 16 bits. (colon_k): Declared. (func_n0o, func_n1o, func_n2o, func_n3o, func_n4o): Declared. (replace_list, replace_str, replace_vec, replace): Declarations updated. * match.c (debuglf, dump_shell_string, dump_byte_string, dump_var, do_output_line, extract): Reversed arguments to put_char and
* * eval.c (subst_vars): Handle lone symbols (not wrappedKaz Kylheku2012-02-131-1/+1
| | | | | | | | | | | | in sys::var form) as variables. This allows interpretation of metanums in quasiliterals, because these are replaced by variables in the op expander. * parser.l: Recognize METANUM in QSILIT state. * parser.y (quasi_item): METANUM parsed in quasiliteral. * txr.vim: Metanums highlighted properly.
* * lib.c (obj_print): Print control characters in string andKaz Kylheku2012-02-121-1/+1
| | | | | | | | | | | | | | | | | character literals as hex escapes, followed by semicolon if necessary. Don't use iswprint function since it is locale-specific and concludes that non-ASCII characters are unprintable. Changed print syntax for lazy strings. (obj_pprint): Changed print syntax for lazy strings. * parser.l: Bugfix in hex/octal character constant. num_esc(yytext) was called rather than num_esc(yytext+1). * parser.y (chrlit): Bugfix: missing case for hex and octal constants which are given by a LITCHAR token. * stream.c (vformat): Bugfix: strings were being printed as if using ~a even under ~s.
* * parser.l: Allow semicolon terminator on hex and octalKaz Kylheku2012-02-051-2/+2
| | | | | | | | | escapes in a regex. Removed o escape character from octal constants in strings and quasiliterals: no such thing is documented. Octal constants can be semicolon-terminated like hex ones. * txr.1: Documented semicolons after octal constants in string literals and after hex and octal constants in regexes.
* * eval.c (rest_s, op_s): New variables.Kaz Kylheku2012-02-031-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | (do_eval_args): Allow calls specified by improper lists like (x y . z) where the z expression must evaluate to a list that turns into addition arguments to be applied. (transform_op, expand_op): New static functions. (expand): Call expand_op. (eval_init): Initialize rest_s and op_s. Use rest_s to register rest function. * lib.c (gensym): New function based on gensymv. (gensymv): Now calls gensym. * lib.h (gensym): Declared. * parser.l: Parse @ followed by digits as a new kind of token, METANUM. * parser.y (METANUM): New token. (meta_expr, exprs): Missing rlcp's added. (expr): METANUM variant introduced. (yybadtoken): Handle METANUM. * txr.1: Documented one-symbol argument list of lambda. Documented op. Closed some unbalanced parentheses. * txr.vim: Highlight op.
* * parser.l: Support hex and octal escapes in string and quasiliterals,Kaz Kylheku2012-01-271-0/+5
| | | | | | | as the documentation says. Also support an optional trailing ; delimiter in hex escapes. * txr.1: Documented.
* * eval.c (eval_init): New functions registered.Kaz Kylheku2012-01-251-0/+5
| | | | | | | | | | | | | | | | | | * lib.c (sub_list, replace_list, vectorp): New functions. (sub_vec): Allow negative indices from end of array. (replace_vec): New function. * lib.h (sub_list, replace_list, vectorp, replace_vec): Declared. * parser.l (DOTDOT): Scan .. as new token. * parser.y (DOTDOT): New token. (expr): New syntax with DOTDOT. (yybadtoken): Handle DOTDOT. * txr.vim: Added new functions. Also missing append* and dwim. * txr.1: Updated.
* * eval.c (dwim_s): New symbol variable.Kaz Kylheku2012-01-251-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (dwim_loc, op_dwim): New static functions. (op_modplace): Support assignment to dwim forms with the help of dwim_loc. (expand_place): Handle dwim places. (eval_init): Initialize dwim_s. Register dwim operator in op_table. * eval.h (dwim_s): Declared. * lib.c (chr_str, chr_str_set): Allow negative indices to index backwards from end of string. (vecref, vecref_l): Allow negative indices to index from rear of array. (obj_print, obj_pprint): Render (dwim ...) forms as [...]. * parser.l: Peoduce new METABKT token type for @[, and '[', ']' tokens. * parser.y (METABKT): New token. %type declaration for '['. (list): Support square-bracket style of list, translated into dwim form. (meta_expr): Support @[...] variant. (yybadtoken): Handle METABKT in switch. * txr.1: Documented [...] syntax and dwim operator. * txr.vim: Updated.
* * match.c (counter_k): New keyword symbol variable.Kaz Kylheku2011-12-301-4/+4
| | | | | | | | | | | | | | | | | | | | (do_output_line): Process new :counter argument of rep. (do_output): Ditto, for repeat. (syms_init): Intern new keyword symbol. * match.h (counter_k): Declared. * parser.l (REPEAT, REP): Lexical syntax changed to allow arguments. * parser.y (repeat_rep_helper): Takes extra argument, representing the repeat/rep args. This is inserted into the second position of the output list. (repeat_clause, rep_elem): Extract repeat/rep arguments and pass to repeat_rep_helper. (yybadtoken): Do not put quotes around the word "number". * txr.1: Updated.
* New functionality: mod and modlast directives in repeat and rep.Kaz Kylheku2011-12-291-0/+12
| | | | | | | | | | | | | | | | | | | | | | * eval.c (eval_init): Use new symbol variable mod_s instead of calling intern. * match.c (mod_s, modlast_s): Symbol variables defined. (do_output_line): mod and modlast directives implemented under rep. (do_output): likewise under repeat. (syms_init): Initialize new symbol variables. * match.h (mod_s, modlast_s): Declared. * parser.l (MOD, MODLAST): Parse new token types. * parser.y (MOD, MODLAST): New tokens. (repeat_parts_opt, rep_parts_opt): New syntax. (repeat_rep_helper): Handle mod and modlast syntax. * txr.1: Updated. * txr.vim: Updated.
* @# comments are becoming obsolescent. @# commentsKaz Kylheku2011-12-141-4/+7
| | | | | | | | | | | can now be used. Within nested forms, Lisp-compatible ; comments are suported. * parser.l: Support @# and ; comments. * txr.1: Documentation updated. * txr.vim: Updated.
* Bignum support, here we go!Kaz Kylheku2011-12-091-23/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Bignums, based on Michael Fromberger's MPI library, are integrated into the input syntax, stream output, equality testing, the garbage collector, and hashing. The plus operation handles transitions between fixnums and bignums. Other operations are still fixnum only. * Makefile (CFLAGS): Add mpi directory to include file search. (OBJS): Include new arith.o module and all of MPI_OBJS. (MPI_OBJS, MPI_OBJS_BASE): New variables. * configure (mpi_version, have_quilt, have_patch): New variables. Script detects whether patch and quilt are available. Unpacks mpi library, applies patches. Detects 128 bit integer type. Records more information in config.h about the sizes of types. * dep.mk: Updated. * depend.txr: Make work with paths that have directory components. * eval.c (eval_init): Rename of nump to fixnump. * gc.c (finalize, mark_obj): Handle BGNUM case. * hash.c: (hash_c_str): Changed to return unsigned long instead of long. (equal_hash): Handle BGNUM case. (eql_hash): Handle bignums with equal-hash, but other objects as eq. * lib.c (num_s): Variable renamed to fixnum_s. (bignum_s): New symbol variable. (code2type): Follow rename of num_s. Handle BGNUM case. (typeof): Follow rename of num_s. (eql): Handle bignums using equal, and other types using eq. (equal): Handle BGNUM case. (chk_calloc): New function. (c_num): Wording change in error message: is not a fixnum. (nump): Renamed to fixnump. (bignump): New function. (plus): Function removed, reimplemented in arith.c. (int_str): Handle integers which are too large for wcstol using bignum conversion. Base 0 is no longer passed to wcstol but converted to 10 because the special semantics for 0 would be inconsistent for bignums. (obj_init): Follow rename of num_s. Initialize bignum_s.