diff options
author | Péter Diviánszky <divipp@gmail.com> | 2016-04-17 21:24:25 +0200 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2016-04-17 21:24:25 +0200 |
commit | 761dbf9a6dea9db82657265928bc02b8f48470b3 (patch) | |
tree | 7eecebf06506fe6e5482724a1b430b12dad4e4c4 /src | |
parent | 8690c562714a9bd4cfd75ad454a11499c15bd151 (diff) |
refactoring
Diffstat (limited to 'src')
-rw-r--r-- | src/LambdaCube/Compiler/Lexer.hs | 31 | ||||
-rw-r--r-- | src/LambdaCube/Compiler/Parser.hs | 4 |
2 files changed, 14 insertions, 21 deletions
diff --git a/src/LambdaCube/Compiler/Lexer.hs b/src/LambdaCube/Compiler/Lexer.hs index 19c4b903..b44dca20 100644 --- a/src/LambdaCube/Compiler/Lexer.hs +++ b/src/LambdaCube/Compiler/Lexer.hs | |||
@@ -407,7 +407,7 @@ theReservedNames = Set.fromList $ | |||
407 | 407 | ||
408 | -------------------------------------------------------------------------------- fixity handling | 408 | -------------------------------------------------------------------------------- fixity handling |
409 | 409 | ||
410 | data FixityDef = Infix | InfixL | InfixR deriving (Show) | 410 | data FixityDef = Infix | InfixL | InfixR deriving (Eq, Show) |
411 | type Fixity = (FixityDef, Int) | 411 | type Fixity = (FixityDef, Int) |
412 | type FixityMap = Map.Map SName Fixity | 412 | type FixityMap = Map.Map SName Fixity |
413 | 413 | ||
@@ -418,27 +418,18 @@ calcPrec | |||
418 | -> e | 418 | -> e |
419 | -> [(f, e)] | 419 | -> [(f, e)] |
420 | -> m e | 420 | -> m e |
421 | calcPrec app getFixity e = compileOps [((Infix, -1000), error "calcPrec", e)] | 421 | calcPrec app getFixity = compileOps [] |
422 | where | 422 | where |
423 | compileOps [(_, _, e)] [] = return e | 423 | compileOps [] e [] = return e |
424 | compileOps acc [] = compileOps (shrink acc) [] | 424 | compileOps acc@ ~(((dir', i'), op', e'): acc') e es@ ~((op, e''): es') |
425 | compileOps acc@((p, g, e1): ee) es_@((op, e'): es) = do | 425 | | c == LT || c == EQ && dir == dir' && dir == InfixL = compileOps acc' (app op' e' e) es |
426 | b <- compareFixity (pr, op) (p, g) | 426 | | c == GT || c == EQ && dir == dir' && dir == InfixR = compileOps ((pr, op, e): acc) e'' es' |
427 | case b of | 427 | | otherwise = throwError $ "fixity error:" ++ show (op, op') |
428 | GT -> compileOps ((pr, op, e'): acc) es | ||
429 | LT -> compileOps (shrink acc) es_ | ||
430 | where | 428 | where |
431 | pr = getFixity op | 429 | pr@(dir, i) = getFixity op |
432 | 430 | c | null es = LT | |
433 | shrink ((_, op, e): (pr, op', e'): es) = (pr, op', app op e' e): es | 431 | | null acc = GT |
434 | 432 | | otherwise = compare i i' | |
435 | compareFixity ((dir, i), op) ((dir', i'), op') | ||
436 | | i > i' = return GT | ||
437 | | i < i' = return LT | ||
438 | | otherwise = case (dir, dir') of | ||
439 | (InfixL, InfixL) -> return LT | ||
440 | (InfixR, InfixR) -> return GT | ||
441 | _ -> throwError $ "fixity error:" ++ show (op, op') | ||
442 | 433 | ||
443 | parseFixity :: Parse r w Fixity | 434 | parseFixity :: Parse r w Fixity |
444 | parseFixity = do | 435 | parseFixity = do |
diff --git a/src/LambdaCube/Compiler/Parser.hs b/src/LambdaCube/Compiler/Parser.hs index ca9570b4..00ef3e49 100644 --- a/src/LambdaCube/Compiler/Parser.hs +++ b/src/LambdaCube/Compiler/Parser.hs | |||
@@ -1125,7 +1125,9 @@ data Module | |||
1125 | 1125 | ||
1126 | type DefParser = DesugarInfo -> (Either ParseError [Stmt], [PostponedCheck]) | 1126 | type DefParser = DesugarInfo -> (Either ParseError [Stmt], [PostponedCheck]) |
1127 | 1127 | ||
1128 | parseModule :: Parse () () Module | 1128 | type HeaderParser = Parse () () |
1129 | |||
1130 | parseModule :: HeaderParser Module | ||
1129 | parseModule = do | 1131 | parseModule = do |
1130 | exts <- concat <$> many parseExtensions | 1132 | exts <- concat <$> many parseExtensions |
1131 | whiteSpace | 1133 | whiteSpace |