git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Better error messages for bad indentation (#2368)
commit61019d0816b261261a9da6e8e76367e51a59f58b authorPhil Freeman <paf31@cantab.net> dateTue 11 Oct 2016, 15:52 (10 years ago) parentcfacd20
1 file changed+8−5
src/Language/PureScript/Parser/Common.hs+8−5
src/Language/PureScript/Parser/Common.hs+8−5
@@ -107,23 +107,26 @@ mark p = do
107107-- |
108108-- Check that the current identation level matches a predicate
109109--
110−checkIndentation :: (P.Column -> P.Column -> Bool) -> P.Parsec s ParseState ()
111−checkIndentation rel = do
110+checkIndentation
111+ :: (P.Column -> String)
112+ -> (P.Column -> P.Column -> Bool)
113+ -> P.Parsec s ParseState ()
114+checkIndentation mkMsg rel = do
112115 col <- P.sourceColumn <$> P.getPosition
113116 current <- indentationLevel <$> P.getState
114− guard (col `rel` current)
117+ guard (col `rel` current) P.<?> mkMsg current
115118
116119-- |
117120-- Check that the current indentation level is past the current mark
118121--
119122indented :: P.Parsec s ParseState ()
120−indented = checkIndentation (>) P.<?> "indentation"
123+indented = checkIndentation (("indentation past column " ++) . show) (>)
121124
122125-- |
123126-- Check that the current indentation level is at the same indentation as the current mark
124127--
125128same :: P.Parsec s ParseState ()
126−same = checkIndentation (==) P.<?> "no indentation"
129+same = checkIndentation (("indentation at column " ++) . show) (==)
127130
128131-- |
129132-- Read the comments from the the next token, without consuming it