@@ -0,0 +1,46 @@
1+{- | This module aims to make it easier to create dev tools for Elm.
2+
3+ It provides the ability to:
4+
5+ * Detect problems in a program
6+ * Figure out types of particular expressions
7+ * Canonicalize variables
8+ * Convert expressions to JS and HTML
9+
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+-}
15+module Language.Elm.DevTools where
16+
17+data Program
18+
19+-- | Parse an Elm program into an AST.
20+parse :: String -> Either [Problem] Program
21+
22+-- | Get the type of a region of the program. Lets you look
23+-- up the type of particular values and expressions.
24+typeOf :: Program -> Region -> Either [Problem] String
25+
26+-- | Canonicalize a variable. So in a normal module `map` would be canonicalized
27+-- to `List.map`.
28+canonicalize :: Program -> Region -> [String]
29+
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.
32+data Problem = Problem { message :: String, region :: Region }
33+
34+type Row = Int
35+type Column = Int
36+
37+-- | Represents a region, spanning two points in the source code.
38+data Region = Region { start :: (Row,Column), end :: (Row,Column) }
39+
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.
45+region :: (Row,Column) -> Region
46+region pos = Region pos pos