Mercurial > octave
diff libinterp/parse-tree/lex.ll @ 20812:d9ca869ca124
maint: Clean-up more instances of print_usage().
* mk-opts.pl: Fix script that generates *-opt.cc files to put print_usage()
first.
* __ilu__.cc (F__ilutp__): Don't declare and initialize multiple comma
separated variables.
* __lin_interpn__.cc (F__lin_interpn__): Eliminate extra spaces in if
conditional.
* dasrt.cc (Fdasrt): Declare variables only as needed, in this case, after
input validation has succeeded.
* file-io.cc (Frewind): Declare variables after input validation succeeds.
* file-io.cc (Ftempname): Rename variable len to nargin to match rest of code.
* gammainc.cc (Fgammainc): Put nargin checking first in function.
* hex2num.cc (Fhex2num, Fnum2hex): Declare "octave_value retval;" first in
function to match rest of Octave code base.
* load-path.cc (Frmpath): Re-phrase comment.
* lu.cc (Flu): Declare variables after input validation succeeds. Use space
after ! operator.
* lu.cc (Fluupdate): Place octave_value_list declaration first in function.
Declare variables after input validation succeeds.
* matrix_type.cc (Fmatrix_type): Place octave_value declaration first in
function.
* tril.cc (do_trilu): Move nargin checking higher in function.
* utils.cc (Fdir_in_loadpath): Declare variables after input validation
succeeds.
* __glpk__.cc (F__glpk__): Rename variable nrhs to nargin to match rest of
code base.
* __magick_read__.cc (F__magick_ping__, F__magick_formats__): Add newline
to space out code for readability.
* __osmesa_print__.cc (F__osmesa_print__): Use DeMorgan's Law to simplify
nargin validation.
* audiodevinfo.cc (F__recorder_record__): Correct indentation.
* chol.cc (Fcholinsert, Fcholdelete, Fcholshift): Place octave_value_list
declaration first in function.
* dmperm.cc (Fdmperm, Fsprank): Place octave_value_list declaration first in
function.
* qr.cc (Fqrupdate, Fqrinsert, Fqrdelete, Fqrshift): Place octave_value_list
declaration first in function.
* lex.ll (Fiskeyword): Rewrite function to use modern syntax. Add BIST
tests for special words "get", "set". Add BIST tests for input validation.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 05 Dec 2015 15:59:22 -0800 |
parents | bb585db6dee2 |
children | 14cd86258b3d |
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.ll Sat Dec 05 15:10:49 2015 -0800 +++ b/libinterp/parse-tree/lex.ll Sat Dec 05 15:59:22 2015 -0800 @@ -24,7 +24,7 @@ We are using the pure parser interface and the reentrant lexer interface but the Octave parser and lexer are NOT properly reentrant because both still use many global variables. It should be -safe to create a parser object and call it while anotehr parser +safe to create a parser object and call it while another parser object is active (to parse a callback function while the main interactive parser is waiting for input, for example) if you take care to properly save and restore (typically with an unwind_protect @@ -1912,16 +1912,14 @@ { octave_value retval; - int argc = args.length () + 1; - - string_vector argv = args.make_argv ("iskeyword"); - - if (argc < 1 || argc > 2) + int nargin = args.length (); + + if (nargin > 1) print_usage (); - if (argc == 1) + if (nargin == 0) { - // Neither set and get are keywords. See the note in the + // Neither set nor get are keywords. See the note in the // is_keyword function for additional details. string_vector lst (TOTAL_KEYWORDS); @@ -1930,19 +1928,20 @@ for (int i = 0; i < TOTAL_KEYWORDS; i++) { - std::string tmp = wordlist[i].name; - - if (! (tmp == "set" || tmp == "get")) - lst[j++] = tmp; + std::string kword = wordlist[i].name; + + if (kword != "set" && kword != "get") + lst[j++] = kword; } lst.resize (j); retval = Cell (lst.sort ()); } - else if (argc == 2) + else { - retval = is_keyword (argv[1]); + std::string name = args(0).xstring_value ("iskeyword: NAME must be a string"); + retval = is_keyword (name); } return retval; @@ -1953,6 +1952,11 @@ %!assert (iskeyword ("for")) %!assert (iskeyword ("fort"), false) %!assert (iskeyword ("fft"), false) +%!assert (iskeyword ("get"), false) +%!assert (iskeyword ("set"), false) + +%!error iskeyword ("A", "B") +%!error <NAME must be a string> iskeyword (1) */