Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: $SyntaxHandler problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg119791] Re: $SyntaxHandler problem
  • From: Alexey Popkov <lehin.p at gmail.com>
  • Date: Wed, 22 Jun 2011 07:06:15 -0400 (EDT)
  • Reply-to: comp.soft-sys.math.mathematica at googlegroups.com

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


  • Prev by Date: Re: capacitor equation solution not working
  • Next by Date: Assigning part of indexed object
  • Previous by thread: Re: Date based calculations
  • Next by thread: Assigning part of indexed object