Download A Proxima-based Haskell IDE

Transcript
3.2 A Closer Look
Implementation and Instantiation
Proxima is implemented in Haskell and uses the GTK+ and Gtk2Hs libraries for the graphical user
interface. To instantiate an editor, the basic document type of Proxima has to be extended and Proxima
must be provided with a number of sheets that define the mappings between some of the data levels.
For the presentation process (top-to-bottom) these mappings are an
• evaluation sheet, to compute derived values, and a
• presentation sheet, to define how to present the document
For the interpretation process (bottom-to-top), the mappings are defined in a
• scanning sheet, which contains regular expressions that describe the allowed set of tokens, a
• parsing sheet, to interpret the presentation level (inverse of presentation sheet), and a
• reduction sheet, to map edit operations on derived values onto edit operations on the document
(inverse of evaluation sheet)
UUAG [SB04], an attribute grammar system developed at Utrecht University, is used for the presentation sheet. The UUAG compiler reads files containing a higher-order attribute grammar, in
which semantic functions are described through Haskell expressions, and out of this description catamorphisms (‘folds’) and data type definitions are generated. The presentations are written in the
presentation language Xprez [SJ01].
The scanning sheet is (part of) an Alex1 lexical syntax specification. Parsable tokens have to be
defined; structural tokens are dealt with by the generic part of Proxima.
A parser combinator library from Utrecht University is used for the parsing sheet, with which
parsable tokens can be parsed and structural tokens can be ‘recognised’.
The rest of the sheets are Haskell files.
3.2
A Closer Look
Further in this thesis, we take a look at a couple of issues regarding the Proxima architecture or
implementation. In this section, we look at some background information to understand those issues.
Whitespace
As mentioned under Extra State in the previous section, most whitespace (spaces, line breaks) in a
source code editor has no meaning on the document level and is not represented. Nevertheless, it
has to be presented when rendering the document. In Proxima this is implemented using a whitespace
map: a (set of) mapping(s) from the tokens to the number of line breaks and spaces that follow the
token, called layout. The focus (cursor) of the document is stored here as well. For example, the code
fragment
1
x
2
3
y
4
5
6
=
*
7
8
9
(1
3
10 11 12 13 14
+
y)
may be represented on the document level by
Declaration
(Identifier "x") -- function name
[ Identifier "y" ] -- patterns
(Times
-- the expression
(Parenthesised
(Plus (Int 1) (Var "y"))
)
(Int 3)
)
1 Alex:
Declaration
Identifier
"x"
List
Identifier
Times
[]
Parenthesised
Int
Plus
3
"y"
Int
Var
1
"y"
A lexical analyser generator for Haskell
15