git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Better error messages for bad indentation (#2368)
61019d0Phil Freeman
src/Language/PureScript/Parser/Common.hs+8−5
@@ -107,23 +107,26 @@ mark p = do
107-- |
107-- |
108-- Check that the current identation level matches a predicate
108-- Check that the current identation level matches a predicate
109--
109--
110+checkIndentation
111+ :: (P.Column -> String)
112+ -> (P.Column -> P.Column -> Bool)
110−checkIndentation :: (P.Column -> P.Column -> Bool) -> P.Parsec s ParseState ()
113+ -> P.Parsec s ParseState ()
111−checkIndentation rel = do
114+checkIndentation mkMsg rel = do
112 col <- P.sourceColumn <$> P.getPosition
115 col <- P.sourceColumn <$> P.getPosition
113 current <- indentationLevel <$> P.getState
116 current <- indentationLevel <$> P.getState
114− guard (col `rel` current)
117+ guard (col `rel` current) P.<?> mkMsg current
115
118
116-- |
119-- |
117-- Check that the current indentation level is past the current mark
120-- Check that the current indentation level is past the current mark
118--
121--
119indented :: P.Parsec s ParseState ()
122indented :: P.Parsec s ParseState ()
120−indented = checkIndentation (>) P.<?> "indentation"
123+indented = checkIndentation (("indentation past column " ++) . show) (>)
121
124
122-- |
125-- |
123-- Check that the current indentation level is at the same indentation as the current mark
126-- Check that the current indentation level is at the same indentation as the current mark
124--
127--
125same :: P.Parsec s ParseState ()
128same :: P.Parsec s ParseState ()
126−same = checkIndentation (==) P.<?> "no indentation"
129+same = checkIndentation (("indentation at column " ++) . show) (==)
127
130
128-- |
131-- |
129-- Read the comments from the the next token, without consuming it
132-- Read the comments from the the next token, without consuming it