Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add error clarifiers

  • Loading branch information...
commit e4706020b337d2856f503169f56611271d64dbd3 1 parent 7af9098
@feuerbach feuerbach authored
Showing with 9 additions and 6 deletions.
  1. +4 −4 Parse.hs
  2. +5 −2 Parsec.hs
View
8 Parse.hs
@@ -88,7 +88,7 @@ word terminators acceptEmpty = do
-- this parser needs to be used everywhere where newline is needed, except
-- 'lineConts'
-- todo: more efficient string concatenation
-newline = do
+newline = "newline" `definedAs` do
char '\n'
-- check if we need to parse any here-docs
mapM_ readHereDoc . reverse =<< pendingHereDocs
@@ -147,7 +147,7 @@ opFirstLetters = '\n' : (nub . map head) operatorList
--- Comments ---
comment :: Parser ()
-comment = do
+comment = "comment" `definedAs` do
char '#'
many $ satisfy (/= '\n')
return ()
@@ -370,11 +370,11 @@ simpleCommand = ifNotReserved $ do
reservedWords = ["!", "{", "}", "case", "do", "done", "elif", "else", "esac",
"fi", "for", "if", "in", "then", "until", "while"]
-reservedWord = try $ do
+reservedWord = ("reserved word" `definedAs`) . try $ do
[Bare x] <- token_word
guard $ x `elem` reservedWords
return $ x
-theReservedWord w = (<?> "reserved word \"" ++ w ++ "\"") $ try $ do
+theReservedWord w = (("reserved word \"" ++ w ++ "\"") `definedAs`) $ try $ do
w' <- reservedWord
guard $ w == w'
return w
View
7 Parsec.hs
@@ -32,6 +32,9 @@ type HereDocHandle = (String, Int, HereDocQuoted)
data HereDocQuoted = HereDocQuoted | HereDocNotQuoted
deriving (Show,Read,Eq)
+definedAs :: String -> Parser a -> Parser a
+definedAs = flip (<?>)
+
-- put here-docs delimiter into the queue
-- returns unique number by which the contents of here-doc may be accessed later
enqueueHereDoc :: String -> HereDocQuoted -> Parser Int
@@ -50,7 +53,7 @@ pendingHereDocs = hereDocHandles <$> getState
type Parser = ParsecT Stream SS (Reader RS)
lineConts :: Parser ()
-lineConts = do
+lineConts = "line continuation" `definedAs` do
many $ try $ Base.string "\\\n"
return ()
@@ -92,7 +95,7 @@ char x = try $ do
-- if skipLineContinuation is True, line continuation will be skipped before and
-- inside the string
string :: String -> Parser String
-string s = try $ do
+string s = (s `definedAs`) . try $ do
sequence $ map char s
return s
Please sign in to comment.
Something went wrong with that request. Please try again.