From 5362771c14eccd80fd1a3ab6521c3a6ad9bb7838 Mon Sep 17 00:00:00 2001 From: Simon-Kor <52245124+Simon-Kor@users.noreply.github.com> Date: Tue, 17 Sep 2024 00:36:24 +0200 Subject: Corrected Math Env Parsing Since Latex has a really specify syntax for \begin{cases} ... \end{cases} The math mode in tokenizing had to be setup correctly. --- source/Syntax/Concrete.hs | 6 +++--- source/Syntax/Token.hs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'source') diff --git a/source/Syntax/Concrete.hs b/source/Syntax/Concrete.hs index 9d52995..7a89bea 100644 --- a/source/Syntax/Concrete.hs +++ b/source/Syntax/Concrete.hs @@ -373,15 +373,15 @@ grammar lexicon@Lexicon{..} = mdo -- 3 & \text{else} -- \end{cases} - functionDefineCase <- rule $ (,) <$> (_ampersand *> expr) <*> (_ampersand *> text _if *> formula) + functionDefineCase <- rule $ (,) <$> (optional _ampersand *> expr) <*> (_ampersand *> text _if *> formula) defineFunctionMathy <- rule $ DefineFunctionMathy <$> (_define *> beginMath *> varSymbol) -- Define $ f <*> (_colon *> varSymbol) -- : 'var' \to 'var' <*> (_to *> expr <* endMath <* _suchThat) -- <*> (_suchThat *> align (many1 ((_ampersand *> varSymbol <* _mapsto) <*> exprApp <*> (_ampersand *> formula)))) -- <*> (_suchThat *> align (many1 (varSymbol <* exprApp <* formula))) - <*> (beginMath *> varSymbol) <*> (paren varSymbol <* _eq <* endMath) - <*> cases (many1 functionDefineCase) + <*> (beginMath *> varSymbol) <*> (paren varSymbol <* _eq ) + <*> cases (many1 functionDefineCase) <* endMath <* optional _dot <*> proof diff --git a/source/Syntax/Token.hs b/source/Syntax/Token.hs index 52da86a..53e1e6a 100644 --- a/source/Syntax/Token.hs +++ b/source/Syntax/Token.hs @@ -189,7 +189,7 @@ toks = whitespace *> goNormal id <* eof Nothing -> pure (f []) Just t@Located{unLocated = BeginEnv "math"} -> goMath (f . (t:)) Just t@Located{unLocated = BeginEnv "align*"} -> goMath (f . (t:)) - Just t@Located{unLocated = BeginEnv "cases"} -> goMath (f . (t:)) + --Just t@Located{unLocated = BeginEnv "cases"} -> goMath (f . (t:)) Just t -> goNormal (f . (t:)) goText f = do r <- optional textToken @@ -205,7 +205,7 @@ toks = whitespace *> goNormal id <* eof Nothing -> pure (f []) Just t@Located{unLocated = EndEnv "math"} -> goNormal (f . (t:)) Just t@Located{unLocated = EndEnv "align*"} -> goNormal (f . (t:)) - Just t@Located{unLocated = EndEnv "cases"} -> goNormal (f . (t:)) + --Just t@Located{unLocated = EndEnv "cases"} -> goNormal (f . (t:)) Just t@Located{unLocated = BeginEnv "text"} -> goText (f . (t:)) Just t@Located{unLocated = BeginEnv "explanation"} -> goText (f . (t:)) Just t -> goMath (f . (t:)) @@ -282,7 +282,7 @@ alignBegin = guardM isTextMode *> lexeme do casesBegin :: Lexer (Located Token) casesBegin = guardM isTextMode *> lexeme do Char.string "\\begin{cases}" - setMathMode + --setMathMode pure (BeginEnv "cases") -- | Parses a single end math token. @@ -301,7 +301,7 @@ alignEnd = guardM isMathMode *> lexeme do casesEnd :: Lexer (Located Token) casesEnd = guardM isMathMode *> lexeme do Char.string "\\end{cases}" - setTextMode + --setTextMode pure (EndEnv "cases") -- cgit v1.2.3