Skip to content

Commit a692140

Browse files
blawlor-8westrupertlssmith
authored andcommitted
fixes elm#29
fixes elm#9 Implementation of deadEndsToString.
1 parent 02839df commit a692140

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

src/Parser.elm

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ type Problem
154154
| BadRepeat
155155

156156

157+
158+
159+
157160
{-| Turn all the `DeadEnd` data into a string that is easier for people to
158161
read.
159162
@@ -168,7 +171,67 @@ _thinks_ is happening can be really helpful!
168171
-}
169172
deadEndsToString : List DeadEnd -> String
170173
deadEndsToString deadEnds =
171-
"TODO deadEndsToString"
174+
String.join "\n" (List.map deadEndToString deadEnds)
175+
176+
177+
deadEndToString : DeadEnd -> String
178+
deadEndToString deadEnd =
179+
problemToString deadEnd.problem
180+
++ " at "
181+
++ deadEndToRowColString deadEnd
182+
183+
problemToString : Problem -> String
184+
problemToString prob =
185+
case prob of
186+
Expecting s ->
187+
"Expecting " ++ s
188+
189+
ExpectingInt ->
190+
"Expecting Int"
191+
192+
ExpectingHex ->
193+
"Expecting Hex"
194+
195+
ExpectingOctal ->
196+
"Expecting Octal"
197+
198+
ExpectingBinary ->
199+
"Expecting Binary"
200+
201+
ExpectingFloat ->
202+
"Expecting Float"
203+
204+
ExpectingNumber ->
205+
"Expecting Number"
206+
207+
ExpectingVariable ->
208+
"Expecting Variable"
209+
210+
ExpectingSymbol s ->
211+
"Expecting Symbol " ++ s
212+
213+
ExpectingKeyword s ->
214+
"Expecting Keyword " ++ s
215+
216+
ExpectingEnd ->
217+
"Expecting End"
218+
219+
UnexpectedChar ->
220+
"Unexpected Char"
221+
222+
Problem s ->
223+
"Problem: " ++ s
224+
225+
BadRepeat ->
226+
"Bad Repeat"
227+
228+
229+
230+
231+
deadEndToRowColString : DeadEnd -> String
232+
deadEndToRowColString deadEnd =
233+
"row " ++ String.fromInt deadEnd.row ++ ", " ++ "col " ++ String.fromInt deadEnd.col
234+
172235

173236

174237

@@ -1256,3 +1319,5 @@ toAdvancedNestable nestable =
12561319
case nestable of
12571320
NotNestable -> A.NotNestable
12581321
Nestable -> A.Nestable
1322+
1323+

0 commit comments

Comments
 (0)