Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #3242

Re: $SyntaxHandler problem

From Alexey Popkov <lehin.p@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: $SyntaxHandler problem
Date 2011-06-22 11:08 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <itsieg$8h6$1@smc.vnet.net> (permalink)

Show all headers | View raw


16 Oct 2010=C2 =D0=B3. 22:22:09 UTC+5 Andrea wrote:
> I'm exploring functions in the tutorial/TheMainLoop section of
> Mathematica help but $SyntaxHandler doesn't seem to work.
> I copied and executed the following code from pag. 694 of "The
> Mathematica book" fourth edition:
>
> >>$SyntaxHandler = (Print[StringForm["Error at char `1` in `2`", #2, #1]]; $Failed) &
>
> then I wrote
>
> >> 3 + /
>
> obtaining
>
> >>Syntax::tsntxi: "3+/" is incomplete; more input is needed.
> >>Syntax::sntxi: Incomplete expression; more input is needed.
>
> but not my customized error string.
>
> Does anyone understand why?
> Thanks,
> Andrea

It does not work because the input cell must have the "RawInputForm" style.  Such a cell may be created by creating ordinary empty input cell and then converting it to the "RawInputForm" cell by the appropriate command in the = "Cell" -> "Convert To" menu.

Here is much more informative variant of this function:

$SyntaxHandler =
  Function[{str, pos},
   Print["Input string: ", ToString[str, InputForm], "\n",
    "Position of syntax error: ", pos, "\n",
    StringInsert[ToString[str, InputForm],
     ToString[Style["\[DownArrowBar]", Red, Background -> Yellow],
      StandardForm], pos + 2]]; $Failed];

See also this answer:

http://stackoverflow.com/questions/6433671/how-to-find-syntax-error/6436231#6436231

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: $SyntaxHandler problem Alexey Popkov <lehin.p@gmail.com> - 2011-06-22 11:08 +0000

csiph-web