-
Notifications
You must be signed in to change notification settings - Fork 22
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
Balletie
wants to merge
7
commits into
metaborg:master
Choose a base branch
from
spoofax-shell-2016:repl-docs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b883cc1
Initial skeleton of Spoofax REPL documentation
Balletie 8e6c290
Add documentation and manual for configuring the REPL
Balletie 1c06d8b
Add short installation and contributing info
Balletie 4a76f07
Rename contact.rst to contributing.rst
Balletie de82a19
Use "shell" consistently, instead of both "shell" and "REPL"
Balletie eb08172
Also rename folder from repl to shell
Balletie 9aa1c41
Include document in main ToC at front page.
Balletie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,6 @@ Language Development Manual | |
|
||
env/eclipse | ||
env/intellij/index | ||
env/shell/index | ||
project | ||
config |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.. _dynsemdocumentation: | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
====== | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.