Skip to content

Spoofax REPL manual #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Quick Start
- Manual

- :doc:`source/langdev/manual/env/intellij/index`
- :doc:`source/langdev/manual/env/shell/index`
- :doc:`source/langdev/manual/config`

- Meta-Languages
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ recommonmark>=0.4.0
sphinx_rtd_theme>=0.1.9
pygments>=2.1.3
javasphinx>=0.9.13
git+https://github.com/metaborg/metaborg-pygments.git@master#egg=metaborg-pygments
git+https://github.com/spoofax-shell/metaborg-pygments.git@master#egg=metaborg-pygments
Copy link
Author

@Balletie Balletie Jun 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will be removed once metaborg/metaborg-pygments#3 is merged.

138 changes: 138 additions & 0 deletions source/langdev/manual/env/shell/configuration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
=============
Configuration
=============

The shell supports the configuration of any language with a DynSem
specification. The configuration consists of three parts: the
(optional) extension of the syntax, the configuration in the ESV, and
the creation of DynSem rules specific to the shell. We explain each
part of the configuration with a running example.

Extending the syntax definition
-------------------------------
Sometimes a language has a slightly different syntax inside the
context of a shell. For example, Haskell's GHCi has the ``let x =
<expression>`` syntax for defining new variables and functions. In our
example, we try to replicate the same behavior for our shell.

To extend the syntax, we use a new start symbol called ``Shell``, and
specify a grammar rule for it as shown below.

.. code-block:: sdf3
:linenos:

context-free start-symbols
// Define it as start symbol.
Prog Shell

context-free syntax
// Syntax for the Shell.
Shell.Let = <let <ID> = <Exp>> {non-assoc}

The start symbol is also specified in the ESV configuration of the
shell, which will be explained in the next section.

ESV configuration
-----------------

The ESV configuration of the shell supports setting two properties: the
evaluation method and the start symbol that is used inside of the
shell.

.. code-block:: esv
:linenos:

module Shell

shell
evaluation method : "dynsem"
shell start symbol : Shell

When the user entered an expression, the shell first tries to parse
using the start symbol as configured above. If that fails, it uses the
ordinary start symbol as a fallback.

Extending the DynSem specification
----------------------------------

To allow expressions to be evaluated in the context of previous
evaluations, one has to extend one's DynSem specification with two
kinds of shell-specific rules. The first is a rule for initializing the
execution environment for the shell, shown below. The second are the
rules for implementing shell-specific semantics.

.. note:: This section assumes basic knowledge of DynSem, and that
your language already has a DynSem specification. To learn
more about DynSem, refer to the
:ref:`DynSem documentation <dynsemdocumentation>`.

The initialization rule
~~~~~~~~~~~~~~~~~~~~~~~

The initialization rule shown below is evaluated upon the first
evaluation done after starting up the shell. It instantiates the
semantic components that form the execution environment for the shell:
an environment with an initial variable binding of :math:`x \mapsto
4`, and an empty store. The shell uses and updates the semantic
components in its successive evaluations.

.. code-block:: dynsem
:linenos:

signature

sorts
ShellInit

constructors
ShellInit : ShellInit

arrows
// Note: the ShellInit rule must have this exact signature.
ShellInit -init-> ShellInit

rules
// Initialization of shell state: an environment with "x" bound to 4,
// and an empty store.
ShellInit() -init-> ShellInit() :: Env { "x" |--> NumV(4) }, Store {}.

The rule must have the exact signature as shown above. That is, the
sort must be of the name ``ShellInit``, with an arity of
zero. Furthermore, the input of the rule must be ``ShellInit``, and
its name must be ``init``. The result value of the rule can be
anything, as it is discarded. The only part of the result of this rule
that is used by the shell are the read-write semantic components (in
this case, the environment and the store).

Shell-specific semantics
~~~~~~~~~~~~~~~~~~~~~~~~

The second kind of configuration are the rules for the shell-specific
semantics. These can be seen as entry points for the shell to the
interpreter. The rules are all named ``shell``, so that they are
distinct of the ordinary semantics. An example of such a rule is shown
below: it implements binding the result of an expression to a
variable. This rule specifies the dynamic semantics of the
shell-specific syntax that we made earlier in this section. With the
specification of this rule, the bound variable can be used in
successive evaluations done by the user of the shell.

.. code-block:: dynsem
:linenos:

signature
arrows
Expr -shell-> V

rules
// let x = 2
Let(x, e) :: E -shell-> v :: E'
where
E |- e :: Store {} --> v :: Store _;
E |- bindVar(x, v) --> E'.

Note that the environment ``E`` is passed as a *read-write* component,
instead of a *read-only* component. This is because in this case the
environment *should* be writable, since the resulting environment
after execution should be available to the shell. In line 9, the
original specification is recursively invoked.
17 changes: 17 additions & 0 deletions source/langdev/manual/env/shell/contributing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
============
Contributing
============

The source code can be found at the GitHub `repository`_. If you have
found a bug, or have problem with the shell, please create an issue at
the `issue tracker`_.

License
-------

The Spoofax Shell is released under the permissive Apache 2.0
`license`_.

.. _repository: https://github.com/metaborg/spoofax-shell
.. _issue tracker: https://github.com/metaborg/spoofax-shell/issues
.. _license: https://github.com/metaborg/spoofax-shell/blob/master/LICENSE
26 changes: 26 additions & 0 deletions source/langdev/manual/env/shell/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
=================
Shell environment
=================

The **Spoofax Shell** provides an interactive environment for
evaluating expressions in your language, much like the shells provided
by for example Haskell and Python. An interactive shell (sometimes
also called a `REPL`_) is useful for quickly experimenting with code
snippets, by allowing the code snippets to be evaluated in the context
of previous evaluations.

This part of the documentation explains how to install and configure
the shell to work for your language.

.. note:: The shell for Spoofax is still in development. As such, it
currently only supports languages that use DynSem for their dynamic
semantics specification.

.. toctree::
:maxdepth: 1

installation
configuration
contributing

.. _REPL: https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop
21 changes: 21 additions & 0 deletions source/langdev/manual/env/shell/installation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
======================
Installation and Usage
======================

There are two clients for the Spoofax Shell: one for the terminal, the
other in the form of an Eclipse plugin. Their installation and usage
is explained in this section.

Terminal client
---------------

The download location, installation and usage details of the terminal
client are available on the `release page`_. Run ``:help`` to show a
list of commands that are available.

.. _release page: https://github.com/spoofax-shell/spoofax-shell/releases/tag/v0.0.3-SNAPSHOT

Eclipse plugin
--------------

.. todo:: This has not been written yet.
1 change: 1 addition & 0 deletions source/langdev/manual/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ Language Development Manual

env/eclipse
env/intellij/index
env/shell/index
project
config
2 changes: 2 additions & 0 deletions source/langdev/meta/lang/dynsem/index.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _dynsemdocumentation:

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add this label for referring to it from the configuration page.

======
DynSem
======
Expand Down