summaryrefslogtreecommitdiff
path: root/src/LambdaCube/Compiler
diff options
context:
space:
mode:
authorPéter Diviánszky <divipp@gmail.com>2016-02-12 02:37:30 +0100
committerPéter Diviánszky <divipp@gmail.com>2016-02-12 02:37:30 +0100
commite3a8062cdc2eb2ffaf41f210d8b7ee21980d185d (patch)
treed6c247cf7961c634d8cb4687c66104ea8efd66ff /src/LambdaCube/Compiler
parentfcd31ebec59279a22555f47a3b768b787966fa88 (diff)
fix arbitrary instance
Diffstat (limited to 'src/LambdaCube/Compiler')
-rw-r--r--src/LambdaCube/Compiler/Lexer.hs14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/LambdaCube/Compiler/Lexer.hs b/src/LambdaCube/Compiler/Lexer.hs
index 3421faea..9c75c675 100644
--- a/src/LambdaCube/Compiler/Lexer.hs
+++ b/src/LambdaCube/Compiler/Lexer.hs
@@ -42,21 +42,19 @@ runPT' p st = snd <$> flip evalStateT (initialPos ".....") (runParserT' p st)
42 42
43type P = ParsecT String (StateT SourcePos InnerP) 43type P = ParsecT String (StateT SourcePos InnerP)
44 44
45indentMany' p = indentMS many p 45indentMany' p = indentMS True p
46indentMany s p = reserved s >> indentMS many p 46indentMany s p = reserved s >> indentMS True p
47indentSome s p = reserved s >> indentMS some p 47indentSome s p = reserved s >> indentMS False p
48 48
49indentMS x p = option [] $ do 49indentMS null p = (if null then option [] else id) $ do
50 checkIndent 50 checkIndent
51 lvl <- indentLevel 51 lvl <- indentLevel
52 x $ do 52 (if null then many else some) $ do
53 pos <- getPosition 53 pos <- getPosition
54 guard (sourceColumn pos == lvl) 54 guard (sourceColumn pos == lvl)
55 local (second $ const (sourceLine pos, sourceColumn pos)) p 55 local (second $ const (sourceLine pos, sourceColumn pos)) p
56 56
57lexeme' sp p = do 57lexeme' sp p = checkIndent *> p <* (getPosition >>= put) <* sp
58 checkIndent
59 p <* (getPosition >>= \p -> modify (const p) >> sp)
60 58
61checkIndent = asks snd >>= \(r, c) -> getPosition >>= \pos -> when (sourceColumn pos <= c && sourceLine pos /= r) $ fail "wrong indentation" 59checkIndent = asks snd >>= \(r, c) -> getPosition >>= \pos -> when (sourceColumn pos <= c && sourceLine pos /= r) $ fail "wrong indentation"
62 60