Parsing and Printing of and with Triples: Amperspiegel source code
This page corresponds to the RAMICS'17 paper, containing the source-code corresponding to the paper.
Paper abstract. We introduce the tool Amperspiegel, which uses triple graphs for parsing, printing and manipulating data.
The tool was originally developed to aid in the development of Ampersand.
We show how to conveniently encode parsers, graph manipulation-rules, and printers using several relations.
Accordingly, parsers, rules and printers are all encoded as graphs themselves.
This allows us to parse, manipulate and print these parsers, rules and printers within the system.
A parser for a context free grammar is graph-encoded with only four relations.
The graph manipulation-rules turn out to be especially helpful when parsing.
The printers strongly correspond to the parsers, being described using only five relations.
The combination of parsers, rules and printers allows us to extract Ampersand source code from Archimate XML documents.
Source files
Download the sources of the necessary parts of Amperspiegel, together with the files necessary to parse Archimate documents.
The current license is a highly restrictive review-only license.
Should the paper be accepted, a (less restrictive) research-only license will be offered.
The purpose of these licenses is to prevent distribution of the sources.
Another (arguably better!) version of Amperspiegel is offered as open-source (GLP3) on github/sjcjoosten/amperspiegel, which is intended for distribution.
If you intend to use this software for any purposes other than reviewing (or research), then that is probably the version you want to use.
Installation
The software is tested with GHC-8.0.1. Newer versions are likely to work too.
Installation works via haskellstack.
If you are working on Unix, you can install it via curl -sSL https://get.haskellstack.org/ | sh.
To install amperspiegel, simply type (from the unpacked sources directory):
stack install
Check the output of the command: it will warn you if the installation directory is not in your path (if so, put it there). You should be able to use:
amperspiegel -h
Reproducing claims in the paper
We distinguish claims made in relation to amperspiegel from those made in relation to the application.
For the claims in relation to amperspiegel, go to the directory Base to reproduce these claims:
- The number of lines, excluding the initial graphs, is less than one thousand: cloc *.hs --by-file (note that BaseState.hs contains the initial graphs)
- We can make changes to the CFG parser. The command that achieves this is: amperspiegel -Parse cfg.ASL parser cfg.
If you wish to use the changes in cfg.ASL by default in Amperspiegel, use amperspiegel -Parse cfg.ASL parser cfg -collect state -showTS state and paste the result into BaseState.hs.
Note that the syntax in which the CFG parser is written was not introduced in the paper.
- We can make a parser that can parse itself (minus the rules).
The required rules are in rules.cfg and not in the initial state of Amperspiegel.
We load them, and then parse the simple parse that can parse itself.
amperspiegel -Parse rules.cfg cfg rules -Parse basic.cfg cfg cfg2
To see that this is a parser that can parse itself, run the command:
amperspiegel -Parse rules.cfg cfg rules -Parse basic.cfg cfg cfg2 -parse basic.cfg cfg2 cfg2 -apply rules cfg2 cfg2 -show cfg2 -parse basic.cfg cfg2 cfg2 -apply rules cfg2 cfg2 -show cfg2
Note that the output of both occurences of show is identical.
After the fist parse, the relations UnquotedString and QuotedString are still present, so amperspiegel -Parse rules.cfg cfg rules -Parse basic.cfg cfg cfg2 -show cfg2 yields a different result (but describes the same parser).
For the claims in the application section of the paper, go to the directory Archimate to reproduce these claims:
- Matching an opening tag with an invalid closing tag produces a warning: amperspiegel -Parse xml.cfg cfg xml -Parse SyntaxError.xml xml
- Obtain the triples from parsing a small bit of XML code: amperspiegel -Parse xml.cfg cfg xml -Parse archiBasic.cfg cfg archi -Parse Example.xml xml -apply archi -show
- Print the small bit of Archimate code as Ampersand code: amperspiegel -Parse xml.cfg cfg xml -Parse archi.cfg cfg archi -Parse Example.xml xml -apply archi -print archi
- Parsing ~600 lines of XML, transforming and printing it takes about 7 seconds and produces 209 lines of Ampersand code: time amperspiegel -Parse xml.cfg cfg xml -Parse archi.cfg cfg archi -Parse Archisurance.xml xml -apply archi -print archi.
(We experienced that the GHC version has a big impact on the runtime; these experiments were conducted with GHC 8.1.20161028 on a Mid 2015 MacBook Pro with 2,5GHz i7).
This page was made by Sebastiaan J. C. Joosten