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


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

Re: $SyntaxHandler problem

Started byAlexey Popkov <lehin.p@gmail.com>
First post2011-06-22 11:08 +0000
Last post2011-06-22 11:08 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

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

#3242 — Re: $SyntaxHandler problem

FromAlexey Popkov <lehin.p@gmail.com>
Date2011-06-22 11:08 +0000
SubjectRe: $SyntaxHandler problem
Message-ID<itsieg$8h6$1@smc.vnet.net>
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

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web