diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-02-12 02:37:30 +0100 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-02-12 02:37:30 +0100 |
commit | e3a8062cdc2eb2ffaf41f210d8b7ee21980d185d (patch) | |
tree | d6c247cf7961c634d8cb4687c66104ea8efd66ff /src/LambdaCube/Compiler | |
parent | fcd31ebec59279a22555f47a3b768b787966fa88 (diff) |
fix arbitrary instance
Diffstat (limited to 'src/LambdaCube/Compiler')
-rw-r--r-- | src/LambdaCube/Compiler/Lexer.hs | 14 |
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 | ||
43 | type P = ParsecT String (StateT SourcePos InnerP) | 43 | type P = ParsecT String (StateT SourcePos InnerP) |
44 | 44 | ||
45 | indentMany' p = indentMS many p | 45 | indentMany' p = indentMS True p |
46 | indentMany s p = reserved s >> indentMS many p | 46 | indentMany s p = reserved s >> indentMS True p |
47 | indentSome s p = reserved s >> indentMS some p | 47 | indentSome s p = reserved s >> indentMS False p |
48 | 48 | ||
49 | indentMS x p = option [] $ do | 49 | indentMS 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 | ||
57 | lexeme' sp p = do | 57 | lexeme' sp p = checkIndent *> p <* (getPosition >>= put) <* sp |
58 | checkIndent | ||
59 | p <* (getPosition >>= \p -> modify (const p) >> sp) | ||
60 | 58 | ||
61 | checkIndent = asks snd >>= \(r, c) -> getPosition >>= \pos -> when (sourceColumn pos <= c && sourceLine pos /= r) $ fail "wrong indentation" | 59 | checkIndent = asks snd >>= \(r, c) -> getPosition >>= \pos -> when (sourceColumn pos <= c && sourceLine pos /= r) $ fail "wrong indentation" |
62 | 60 | ||