summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPéter Diviánszky <divipp@gmail.com>2016-04-17 21:24:25 +0200
committerPéter Diviánszky <divipp@gmail.com>2016-04-17 21:24:25 +0200
commit761dbf9a6dea9db82657265928bc02b8f48470b3 (patch)
tree7eecebf06506fe6e5482724a1b430b12dad4e4c4 /src
parent8690c562714a9bd4cfd75ad454a11499c15bd151 (diff)
refactoring
Diffstat (limited to 'src')
-rw-r--r--src/LambdaCube/Compiler/Lexer.hs31
-rw-r--r--src/LambdaCube/Compiler/Parser.hs4
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
410data FixityDef = Infix | InfixL | InfixR deriving (Show) 410data FixityDef = Infix | InfixL | InfixR deriving (Eq, Show)
411type Fixity = (FixityDef, Int) 411type Fixity = (FixityDef, Int)
412type FixityMap = Map.Map SName Fixity 412type 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
421calcPrec app getFixity e = compileOps [((Infix, -1000), error "calcPrec", e)] 421calcPrec 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
443parseFixity :: Parse r w Fixity 434parseFixity :: Parse r w Fixity
444parseFixity = do 435parseFixity = 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
1126type DefParser = DesugarInfo -> (Either ParseError [Stmt], [PostponedCheck]) 1126type DefParser = DesugarInfo -> (Either ParseError [Stmt], [PostponedCheck])
1127 1127
1128parseModule :: Parse () () Module 1128type HeaderParser = Parse () ()
1129
1130parseModule :: HeaderParser Module
1129parseModule = do 1131parseModule = do
1130 exts <- concat <$> many parseExtensions 1132 exts <- concat <$> many parseExtensions
1131 whiteSpace 1133 whiteSpace