This is the Robert Jacobson's Python implementation of the FoxySheep parser and lexer for Mathematica. It has been stripped down and reorganized a bit.

Examples
--------

When installed, the command-line translator is called `foxy-sheep`
which can convert `Mathematica InputForm
<https://reference.wolfram.com/language/ref/InputForm.html>`_ to
`Mathematica FullForm
<https://reference.wolfram.com/language/ref/FullForm.html>`_ without
having Mathematica installed: To run the code interactively:

::

   $ foxy-sheep
   Enter a Mathematica expression. Enter either an empty line, Ctrl-C, or Ctrl-D to exit.
   in:= 1+2
   Plus[1,2]
   in:=D[4 x^2]
   D[Times[4,Power[x,2]]]
   in:=
   $


To call from Python:

.. code:: python

   from FoxySheep import FullForm_from_string
   print(FullForm_from_string("x^2-3x+4"))
   # Prints: Plus[Power[x,2],Times[-1,3,x],4]


To see a demo run ``python demo.py`` in this directory.

Regenerating the lexer/parser
-----------------------------

To change the grammar you'll need the ANTLR Parser Generator
(``antlr4``), version 4.7.x installed.

To (re)generate the lexer/parser you need to

::

   $ make


The resulting files are placed in ``FoxySheep/generated``.

Files generated by ANTLR4 are assumed to be in a subdirectory called ``generated`` containing an empty ``__init__.py`` file. See the Makefile for details.

FoxySheepLexer Must Subclass Lexer
++++++++++++++++++++++++++++++++++

In order for the generated antlr4 lexer to work we need to patch the generated Python lexer ``FoxySheep.lexer.py``; The patch file ``FoxySheep.lexer.py.patch`` does this.
The Makefile target for ``FoxySheepParser.py`` contains the ``patch`` command.

If patching is not done you'll get an ``AttributeError`` exception in the lexer you try to run it such as through ``foxy-sheep``.

::

   AttributeError: 'FoxySheepLexer' object has no attribute 'checkAdditiveOp'


See Also
--------

`FoxySheep <https://github.com/rljacobson/FoxySheep>`_
