summaryrefslogtreecommitdiffstats
path: root/parser.y
Commit message (Collapse)AuthorAgeFilesLines
* Bugfix: rlcp function was incorrect for new way of storingKaz Kylheku2012-02-281-0/+6
| | | | | | | | | line number info. * parser.h (rlset): Declared. (rlcp): Use rlset. * parser.y (rlset): New function.
* Fixing long-time (pre-GIT) bug. The object (nil) was stupidly used toKaz Kylheku2012-02-261-28/+38
| | | | | | | | | | | | | | | | | | | | | represent empty optional output clauses, distinguishing them from missing clauses. This creates an ambiguity, so that an @(output) block which puts out a single empty line is treated as empty. Present but empty clauses are now represented by t. * match.c (do_output_line): Check for t and bail. (do_output): Check for t instead of (nil) and bail. * parser.y (o_elems_opt2): Nonterminal deleted. (out_clauses_opt): Empty case generates nil. (req_parts_opt): o_elems_opt2 replaced by o_elems_opt. (repeat_rep_helper): Function now keeps track of which clauses were specified. For those that were specified, but empty, it substitutes t. * tests/008/empty-clauses.expected: New file. * tests/008/empty-clauses.txr: New file.
* Bug #35625Kaz Kylheku2012-02-261-9/+27
| | | | | | | | | | | | | | | | | | | | | | * 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.y (clause): "Doh" moment. We don't need the specialKaz Kylheku2012-02-251-9/+1
| | | | | | | | transformation of the load syntax because the parent location is already associated with the syntax. * match.c (v_load): Pull out source location info from the form itself.
* * 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-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* Allow braced output variables to actually be arbitrary substitutions.Kaz Kylheku2012-02-181-5/+4
| | | | | | | | | | | | | | * eval.c (subst_vars): Treat the variable as an arbitrary expression rather than just a symbol. * match.c (subst_vars): Likewise. * parser.y (o_var): Further simplification. The first item in an output var is an expr and not an IDENT. * txr.1: Updated. * txr.vim: Likewise.
* * parser.y (o_var): Remove productions from grammar by using exprs_opt.Kaz Kylheku2012-02-181-10/+6
|
* * eval.c (subst_vars): Handle lone symbols (not wrappedKaz Kylheku2012-02-131-0/+2
| | | | | | | | | | | | 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-0/+2
| | | | | | | | | | | | | | | | | 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.
* * eval.c (rest_s, op_s): New variables.Kaz Kylheku2012-02-031-8/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | (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.
* * eval.c (lookup_sym_lisp1): New function.Kaz Kylheku2012-02-011-2/+2
| | | | | | | | | | | | | | | (do_eval, do_eval_args): New static functions. (eval, eval_args): Become wrappers for do_eval and do_eval_args, respectively. (eval_lisp1, eval_args_lisp1): New static functions. (dwim_loc, op_dwim): Use eval_lisp1 and eval_args_lisp1 instead of eval and eval_args. * parser.y (meta_expr): Bugfix: expand the whole dwim expression, rather than its arguments, which are not an expression. * txr.1: Updated with notes that dwim really does Lisp-1 style evaluation.
* * eval.c (eval_init): New functions registered.Kaz Kylheku2012-01-251-1/+4
| | | | | | | | | | | | | | | | | | * 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-2/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (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 (v_gather): Implemented until/last clause.Kaz Kylheku2012-01-061-2/+21
| | | | | | | * parser.y (gather_parts, additional_gather_parts): New nonterminals. (gather_clause): Syntax refactored for until/last clause. * txr.1: Updated.
* * match.c (counter_k): New keyword symbol variable.Kaz Kylheku2011-12-301-9/+11
| | | | | | | | | | | | | | | | | | | | (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-3/+32
| | | | | | | | | | | | | | | | | | | | | | * 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.
* * parser.y (repeat_rep_helper): Bugfix. Circular listsKaz Kylheku2011-12-291-1/+1
| | | | | | were being created here when clauses of the same kind appear multiple times. The problem is that append2 no longer copies the second list, which the code was relying on it to do.
* * parser.y (quasi_item): Switch from var to o_var. This fixesKaz Kylheku2011-12-281-1/+1
| | | | | cases like `@a@(foo)@b` where foo was being translated to (foo) rather than (sys:expr foo).
* Bug #35139Kaz Kylheku2011-12-211-3/+3
| | | | | | | Better fix. * parser.y (YYEOF): If YYEOF is not defined, define it as zero. (yybadtoken): Undo previous changes: do not test for zero.
* Bug #35139Kaz Kylheku2011-12-211-3/+3
| | | | | * parser.y (yybadtoken): The current token (yychar) is 0 on byacc rather than YYEOF or YYEMPTY, so we have to handle that.
* * eval.c (eval_init): not added as synonym for null.Kaz Kylheku2011-12-151-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | * lib.c (copy_list): Use list_collect_append rather than list_collect_terminate. (append2, appendv): Simplified using new list_collect_append. (nappend2): Simplified using new list_collect_nconc. * lib.h (list_collect): Added check for accidental usage of list_collect after list_append, since PTAIL has different semantics. (list_collect_nconc, list_collect_append): Semantics fixed so that append collecting works more like the Common Lisp append function, allowing trailing atoms or a lone atom. The meaning of PTAIL is changed, however. Now PTAIL actually tracks the head of the most recently appended segment. Each append operation has to first traverse the previously added piece to get to the end. (list_collect_terminate): Macro removed. * match.c (v_gather): Removed useless use of list_collect_terminate. * parser.y: Some headers added that are needed by list_collect. * txr.1: Documented append, list, atom, null, not, consp, make-lazy-cons, lcons-fun, listp, proper-listp, length-list, mapcar, mappend, and apply.
* Bignum support, here we go!Kaz Kylheku2011-12-091-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* * eval.c (op_unwind_protect): Fixed uninitialized variableKaz Kylheku2011-12-061-8/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | warning. (eval_init): New functions registered: typeof and vector functions, as well as length_list. * lib.c (length): Function renamed to length_list, because it is list specific. (length_vec, size_vec, vector_list): New functions. (length): New function, generic over lists, vectors and strings. * lib.h (length_list, length_vec, size_vec, vector_list): Declared. * match.c (h_var, h_fun, robust_length, v_deffilter, v_fun): Use length_list instead of length. * parser.l: Introduced # token. * parser.y (vector): New nonterminal. (expr): vector is a kind of expr. (chrlist): Bugfix: single-character syntax was not working; for instance #\x to denote the charcter x. (lit_char_helper): Use length_list instead of length. * stream.c (string_in_get_line): Bugfix: this was using the wrong length function: length was being applied to a string. The genericity of length makes that correct now, but changing to length_str anyway. * txr.1: Blank sections created for functions. Vector syntax documented.
* * parser.y (force_regular_quotes): Function removed.Kaz Kylheku2011-12-041-30/+8
| | | | | | | | (list): Prior commit reversed. * txr.1: Prior commit reversed. * RELNOTES: No semantics clarification in quasiquote; bugfixes only.
* * eval.c (op_qquote_error, op_unquote_error): New static functions.Kaz Kylheku2011-12-041-8/+30
| | | | | | | | | | | | | (expand_qquote): Bugfix: missing case added to handle directly quoted quasiquote. (eval_init): Error-catching pseudo-operators registered in op_table. * parser.y (force_regular_quotes): New function. (list): Quotes within unquotes and splices are regular. * txr.1: Clarified new rules. Removed description of ,'form and ,*'form special syntax.
* * parser.y (list): unquote and splice actions look inside theKaz Kylheku2011-12-021-2/+8
| | | | | | | | | | argument form. If an unquote or splice are applied to a quoted form, its quote becomes a regular quote. This behavior is necessary to make ,',form work in nested quotes, otherwise the ' is a quasiquote which captures the comma in ,form, reducing ,',form to ,form. * txr.1: Documented this special behavior.
* * lib.h (or2): Restore macro version of or2, because we needKaz Kylheku2011-11-301-0/+2
| | | | | | | | | | | | | | | | | | | | the sequencing! Making it an inline function broke the tests. But we can't have multiple evaluation either, so it's going to use a temporary lexical variable. (uses_or2): Macro which declares the lexical variable needed by or2. * debug.c (debug): add uses_or2. * eval.c (eval_intrinsic, op_modplace): Likewise. * lib.c (lazy_str, lazy_str_force_upto, lazy_str_get_trailing_list): Likewise. * match.c (h_parallel, v_freeform, v_parallel, v_output): Likewise. * parser.y (unquotes_occur): Likewise. * stream.c (format): Likewise.
* Removing useless hash table.Kaz Kylheku2011-11-301-1/+0
| | | | | | | | | | | | * parser.h (ln_to_forms_hash): Declaration removed. * parser.l (ln_to_forms_hash): Variable removed. (parse_init): Initialization and protection of ln_to_forms_hash removed. * parser.y (rl): Update of ln_to_forms_hash removed. * txr.1:
* Support assignment to (car ...) and (cdr ...).Kaz Kylheku2011-11-291-8/+3
| | | | | | | | | | | | | | * eval.c (car_s, cdr_s): New symbol variables. (op_modplace): Cases for car and cdr added. (expand_place): Likewise. Calls abort should the cases fall through rather than returning 42. (expand): Bugfix: for and for* case not propagating source location info. Bugfix: expansion for do added. (eval_init): car_s and cdr_s initialized and used in place of previous intern calls. * parser.y (elem): Removed wrong logic for expanding the do form. It was expanding only the first argument.
* Added evaluation support for quote and quasiquote with unquotes.Kaz Kylheku2011-11-281-6/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | New functions list, append and eval. Code walking framework for expanding quasiquotes. quotes right now. * eval.c (let_s, lambda_s, call_s, cond_s, if_s, and_s, or_s defvar_s, defun_s, list_s, append_s): New symbol variables. (eval_intrinsic, op_quote, expand_forms, expand_cond_pairs, expand_place, expand_qquote): New static functions. (expand): New external function. (eval_init): Initialize new symbol variables. Use newly defined symbol variables to register functions. Also, new functions: quote, append, list and eval. * eval.h (expand): Declared. * lib.c (appendv): New function. (obj_init): quote and splice operator symbols moved into system package. (obj_print, obj_pprint): Support for printing quotes and splices. * lib.h (appendv): Declared. * match.c (do_s): New symbol variable. (syms_init): New variable initialized. (dir_tales_init): New variable used instead of intern. * match.h (do_s): Declared. * parser.y (elem): @(do) form recognized and its argument passed through the new expander. (o_elem, quasi_item): Pass list through expander. (list): Use choose_quote to decide whether to put regular quote or quasiquote on quoted list. (meta_expr): Fixed abstract syntax so the expression is a single argument of the sys:expr, rather than multiple arguments. (unquotes_occur, choose_quote): New static function.
* * parser.y (expr): Set source location info on elements.Kaz Kylheku2011-11-261-7/+12
| | | | (strlit): Set location info.
* * match.c (subst_vars): Handle expr_s, so thatKaz Kylheku2011-11-261-1/+2
| | | | | | | | | | | Lisp expressions can be interpolated into quasiliterals. (extract_vars): Avoid recursing into expressions marked with expr_s. (do_output_line): Handle expr_s so that Lisp expressions can be interpolated into output. * parser.y (o_elem, quasi_items): Handle list expressions, annotated with expr_s.
* * parser.y (texts, elem): Fixed incorrect use of rl ratherKaz Kylheku2011-11-241-4/+4
| | | | | | than rlcp. Added forgotten rlcp on result of optimize_text. * RELNOTES: Updated.
* Optimization: if all the elements of (text ...) areKaz Kylheku2011-11-231-1/+10
| | | | | | | | strings, then replace the (text ...) by the catenation of those strings. * parser.y (optimize_text): New function. (elem): Use optimize_text.
* Semantics change. If a variable is followed by a mixtureKaz Kylheku2011-11-231-4/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | of text and regular expressions, that whole mixture is considered to follow the variable and used for matching. The earlier semantics change whereby a single unescaped space denotes the regular expression / +/ broke the simple case @a word. It caused the @a to be followed not by the text " word" but by just the regular expression element. With this change @a word means that a is followed by the regex / +/ and "word". * match.c (text_s): New symbol variable. (h_text): New function. (syms_init): Initialize new symbol variable. (dir_tables_init): Hook h_text into horizontal directives table. * match.h (text_s): Declared. * parser.y (text, texts): New nonterminals. (elem): TEXT, SPACE and regex are now handled under texts grammar production. All texts are run together and produce an item which looks like (text items ...). * txr.1, RELNOTES: Updated. * txr.c (remove_hash_bang_line): Updated to find #! buried in (text ...) syntax.
* * parser.y (char_from_name): const on wchar_t *.Kaz Kylheku2011-11-201-2/+2
|
* Bug #34630Kaz Kylheku2011-11-201-2/+4
| | | | | * parser.y (repeat_clause, rep_elem): Allow empty body. (yybadtoken): Handle unexpected newline with different message.
* * parser.y (yybadtoken): Use ~a to print bad character rather than #\Kaz Kylheku2011-11-191-1/+1
| | | | notation.
* * parser.y: Regression IDENT, '{' and '}'Kaz Kylheku2011-11-181-2/+1
| | | | | | must be on the same precedence level and right associative. Without this consective braced variables don't work, etc.
* Task #11598.Kaz Kylheku2011-11-171-5/+10
| | | | | | | | | | | | | * match.c (resolve_k): New keyword symbol variable. (h_parallel, v_parallel): Implement :resolve keyword in @(some) directive. (syms_init): New symbol variable initialized. * parser.l: Allow (some) to have argument material. * parser.y (some_clause, elem): SOME syntax adjusted. * txr.1: Documented new :resolve keyword in @(some).
* Adding quote and unquote read syntax to list forms, resemblingKaz Kylheku2011-11-171-2/+5
| | | | | | | | | | | | | | | | Lisp. The difference is that splice is spelled ,* because @ already means something, and that there is only one quote operator. None of this does anything; it is only syntax. * lib.c (quote_s, qquote_s, unquote_s, splice_s): New variables. (obj_init): New variables initialized. * lib.h (quote_s, qquote_s, unquote_s, splice_s): Declared. * parser.l: Added recognition rules. * parser.y (SPLICE): New symbolic token. (list): Added new syntax for quote and splicing.
* * parser.y: Bugfix: precedence of { } must be low, close to that ofKaz Kylheku2011-11-171-1/+2
| | | | IDENT, otherwise @{var}@(foo) doesn't parse.
* Allow directives after variable to be a kind of negative match.Kaz Kylheku2011-11-161-4/+5
| | | | | | | | | | | | | | | * match.c (search_form): bugfix: return correct match extent. * parser.y: Adjusting associativity and precedence of directives, IDENT, and grouping tokens once again. This is so that a var followed by a directive will turn into one elem, rather than the var being reduced to an elem first. * txr.1: Revised documentation to mroe clearly define the concept of a negative match, broken into subsections. Some sections belonging to syntax were moved to an appropriate location. Subsections added to description of form syntax. Explanation of directive-driven syntax.
* Variable matches can span over function calls.Kaz Kylheku2011-11-161-2/+2
| | | | | | | | | | | | Function calls following variables have searching semantics. * match.c (ml_specline_pos, search_form): New static functions. (h_var): Handle functions and regexes in a common way. * parser.y: Adjusted precedence of IDENT and ( so that @var@(func) are parsed into a single var element. * txr.1: Documented.
* * match.c (h_var): when manipulating specline, propagate theKaz Kylheku2011-11-151-23/+28
| | | | | | | | | | | | | | | | | source locatio info. (v_skip): Don't use specline for trace messages, because it may be nil. Use the skip spec. * parser.h (rl): Declared. (rlcp): New inline function. * parser.y (rl): Static declaration removed. Function becomes extern. (clause): Propagate location info from clause to clause list backbone. (collect_clause, COLL): Bugfix: car/cdr mixup in location info. (elem): Use rlcp function to abbreviate code. (o_elems_opt, o_elems_opt2, o_elem): Set location info.
* Changing read syntax for character literals, because we are going toKaz Kylheku2011-11-151-24/+58
| | | | | | | | | | | | | | | | | | | | | | | | | | | | need the single quote in the Lisp way for suppressing evaluation, eventually. I'm going with a Scheme-compatible syntax for character literals. It has a richer repertoire of standard character names than Common Lisp, and has a x convention for coding characters in hex. * lib.c (obj_print): Print characters in a Scheme-like way. * parser.h (end_of_char): New function declared. * parser.l (grammar): Implement rules for #\ syntax, with involving new HASH_BACKSLASH token. (end_of_regex): Enhancement: added check that end_of_regex is called in correct state, like the one in end_of_char. (end_of_char): New function. * parser.y (repeat_rep_helper, o_elems_transform, define_transform, lit_char_helper): Functions changed to static. (rl): Function moved down, past the grammar section. (HASH_BACKSLASH): New terminal symbol. (chrlit): Grammar redesigned. (char_from_name): New function. * txr.1: Character syntax documented.
* * parser.y: Correctly record line number info for regex.Kaz Kylheku2011-11-121-1/+1
|
* Eliminate line numbers from the abstract syntaxKaz Kylheku2011-11-121-24/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | tree representation of the TXR query. * match.c (debuglf, sem_error, file_err, eval_form): Line number argument replaced with the form to which the situation pertains. Location information is pulled from the hash table entry associated with the form. (dest_set, dest_bind, eval_form, vars_to_bindings): Context argument renamed since it isn't a line number. (struct match_line_ctx): spec_lineno member removed. (ml_all, ml_bindings_specline): lineno parameter removed. (LOG_MISMATCH, LOG_MATCH, h_var, h_skip, h_coll, h_parallel, match_line): Pass elem to debuglf instead of line number. as context. (h_trailer, h_eol): define elem for LOG_MISMATCH and LOG_MATCH macros. (h_fun): Pass elem variable to debuglf instead of line number. Body stored as a simple cons cell once again (no line number). (do_output_line): Line number parameter removed. Pass specline to sem_error instead of line number. (do_output): Adjusted for one less parameter in do_output_line. (mf_from_ml): Pass one less parameter to ml_all. Conversion of specline to spec is just a wrapping into a nested list, with no line number. (spec_bind): Linenumber variable parameter removed from macro. Definition simplified. (v_skip): Pass specline to debuglf instead of spec_linenum, which is no longer computed. (v_trailer): Use new definition of specline. Pass first_spec to sem_error instead of spec_linenum. Computation of ff_specline no longer has to skip line number. (v_freeform, v_block, v_accept_fail, v_next, v_parallel, v_gather, v_collect, v_merge, v_bind, hv_trampoline, v_cat, v_output, v_try, v_defex, v_throw, v_deffilter, v_filter, match_funcall): Use new definition of specline. Pass first_spec to sem_error instead of spec_linenum. (v_forget_local): Specline computed differently since there is no linenumber to skip. (h_define): Back to implified representation of function with no extra cell for line number. (v_define, v_fun): Pass first_spec to sem_error instead of spec_linenum. Back to implified representation of function with no extra cell for line number. (match_files): first_spec_item computed differently. Pass first_spec to sem_error instead of spec_linenum. * parser.h (source_loc): Declared. * parser.l (source_loc): New function. * parser.y:x (grammar): Removed line numbers from abstract sytnax tree. A few more places needed the annotation of forms with location info, and a couple of cases of the need to propagate the info was
* Infrastructure for storing line number informationKaz Kylheku2011-11-121-51/+96
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | outside of the code, in hash tables. * filter.c (make_trie, trie_add): Update to three-argument make_hash. * hash.c (struct hash): New members, hash_fun, assoc_fun acons_new_l_fun. (ll_hash): Renamed to equal_hash. (eql_hash): New static function. (cobj_hash_op): Follows ll_hash rename. (hash_grow): Use new function indirection to call hashing function. (make_hash): New argument to specify type of hashing. Initialize new members of struct hash. (gethash_l, gethash, remhash): Use function indirection for hashing and chain search and update. (pushhash): New function. * hash.h (make_hash): Declaration updated with new parameter. (pushhash): Declared. * lib.c (eql_f): New global variable. (eql, assq, aconsq_new, aconsq_new_l): New functions. (make_package): Updated to new three-argument make_hash. (obj_init): gc-protect and initialize new variable eql_f. * lib.h (eql, assq, aconsq_new, aconsq_new_l): Declared. * match.c (dir_tables_init): Updated to there-argument make_hash. * parser.h (form_to_ln_hash, ln_to_forms_hash): Global variables declared. * parser.l (form_to_ln_hash, ln_to_forms_hash): New global variables. (grammar): Set yylval.lineno for tokens that are classified to that type in parser.y. (parse_init): Initialize and gc-protect new global variables. * parser.y (rl): New static helper function. (%union): New member, lineno. (ALL, SOME, NONE, MAYBE, CASES, CHOOSE, GATHER, AND, OR, END, COLLECT, UNTIL, COLL, OUTPUT, REPEAT, REP, SINGLE, FIRST, LAST, EMPTY, DEFINE, TRY, CATCH, FINALLY, ERRTOK, '('): Reclassified as lineno type. In the grammar, these keywords can thus provide a stable line number from the lexer. (grammar): Numerous rules updated to add constructs to the line number hash tables via the rl helper. * dep.mk: Updated. * Makefile (depend): Use the installed, stable txr in the system path to update dependencies rather than locally built ./txr, to prevent the problem that txr is broken because out out-of-date dependencies, and thus cannot regenerate dependencies.