Commit b5e28a7b authored by Nicolas Lenz's avatar Nicolas Lenz

Fix parsing of newlines

parent 9d3d60d0
......@@ -8,7 +8,7 @@ import Data.Maybe (fromJust)
import qualified Katrin.Core as Core
{-|
Algebra for Katrin AST. This corresponds (is equivalent) to the context-free grammar in ABNF of Katrin:
Algebra type (signature) for Katrin AST. This corresponds (is equivalent) to the context-free grammar in ABNF of Katrin:
@
katrin = *definition
......
......@@ -17,12 +17,13 @@ lineComment, blockComment :: Parser ()
lineComment = L.skipLineComment "//"
blockComment = L.skipBlockCommentNested "/*" "*/"
-- | Space consumer
sc :: Parser ()
sc = L.space blanks lineComment blockComment where
blanks = skipSome $ char ' '
sc = L.space (skipSome $ char ' ') lineComment blockComment
scFull :: Parser ()
scFull = L.space space1 lineComment blockComment
-- | Space consumer including newlines, for between defintions
scn :: Parser ()
scn = L.space space1 lineComment blockComment
lexeme :: Parser a -> Parser a
lexeme = L.lexeme sc
......@@ -34,15 +35,15 @@ parens :: Parser a -> Parser a
parens = between (symbol "(") (symbol ")")
literal :: Parser Int
literal = lexeme $ L.signed sc L.decimal
literal = lexeme (L.signed sc L.decimal) <?> "literal"
identifier :: Parser Text
identifier = (lexeme . try) (T.pack <$> ((:) <$> letterChar <*> many alphaNumChar))
identifier = (lexeme . try) (T.pack <$> ((:) <$> letterChar <*> many alphaNumChar)) <?> "identifier"
-- Parser
katrin :: Parser Katrin
katrin = between sc (skipMany spaceChar >> eof) (Katrin <$> definition `sepBy1` (char '\n') <?> "definition")
katrin = between scn eof (Katrin <$> definition `sepEndBy1` scn)
definition :: Parser Definition
definition = Definition <$> identifier <* symbol "=" <*> expression
......@@ -53,6 +54,6 @@ expression = Expression <$> some segment
segment :: Parser Segment
segment =
try (Lambda <$> identifier <* symbol "=>" <*> expression <?> "lambda expression")
<|> try ((Literal <$> literal) <?> "literal")
<|> try (Value <$> identifier <?> "identifier")
<|> try (Subexpression <$> parens expression <?> "subexpression")
<|> try (Literal <$> literal)
<|> try (Value <$> identifier)
<|> try (Subexpression <$> parens expression)
main = ( x => y => (succ (succ y)) ) 3 4
five = 5
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment