on 63243ca help sign in
elk/compiler/Language/Elm/DevTools.hs
46 lines 1.8 kB history raw
1{- | This module aims to make it easier to create dev tools for Elm.
3 It provides the ability to:
5 * Detect problems in a program
6 * Figure out types of particular expressions
7 * Canonicalize variables
8 * Convert expressions to JS and HTML
10 This module gives limeted access to the structure of an Elm Program.
11 Giving full access would expose many internal details that are likely to
12 change as Elm progresses. These details have been hidden to avoid breaking
13 changes.
14-}
15module Language.Elm.DevTools where
17data Program
19-- | Parse an Elm program into an AST.
20parse :: String -> Either [Problem] Program
22-- | Get the type of a region of the program. Lets you look
23-- up the type of particular values and expressions.
24typeOf :: Program -> Region -> Either [Problem] String
26-- | Canonicalize a variable. So in a normal module `map` would be canonicalized
27-- to `List.map`.
28canonicalize :: Program -> Region -> [String]
30-- | Any problem that may come up while parsing or typing a program.
31-- All problems come with a region that is causing the problem.
32data Problem = Problem { message :: String, region :: Region }
34type Row = Int
35type Column = Int
37-- | Represents a region, spanning two points in the source code.
38data Region = Region { start :: (Row,Column), end :: (Row,Column) }
40-- | Takes a specific point in the source code, such as the cursor position.
41-- It then determines the region that best represents that point. When the
42-- cursor is within a variable, it chooses the variable. When the cursor is
43-- on parentheses, it selects the region within the parentheses. When the
44-- cursor is on keywords like let, it chooses the whole let-expression.
45region :: (Row,Column) -> Region
46region pos = Region pos pos