Skip to content

Commit

Permalink
Main function realized
Browse files Browse the repository at this point in the history
  • Loading branch information
Lev135 committed Mar 9, 2022
1 parent c67466c commit e377ddb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion LaTeX-generator.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ category: Math
extra-source-files: README.md


executable LaTeX-generator
executable texgen
-- .hs or .lhs file containing the Main module.
main-is: Main.hs

Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
Для тестового запуска трансляции выполните:
Для запуска скомпилированного файла выполните:
```
cabal new-update
cabal new-run texgen -- examples/nibergall.ttex examples/nibergall.tex
```

Для запуска трансляции из интерпретатора выполните:
```
cabal new-update
cabal new-repl
Expand Down
20 changes: 7 additions & 13 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Main where
import Generator
import Data.Text(Text, pack, unpack)
import Text.Megaparsec (parse, errorBundlePretty, MonadParsec (eof), mkPos, Pos)
import System.Environment (getArgs)

parsePart :: Parser a -> Text -> Either String a
parsePart p s = case parse p "" s of
Expand All @@ -26,16 +27,9 @@ processFile inpFile outpFile = do
Left e -> putStrLn e
Right (defs, r) -> writeFile outpFile (unpack $ texDoc defs r)


printErr :: Show a => Either String a -> IO ()
printErr (Left e) = putStrLn e
printErr (Right v) = print v

test :: Show a => (Definitions -> Pos -> Parser a) -> Int -> Text -> IO ()
test p n str= do
inp <- pack <$> readFile "tests/defs2.ttex"
case parseAll pDefinitionBlock inp of
Left e -> putStrLn e
Right des -> printErr $ parseAll (p (processDefs des) (mkPos n)) str

main = putStrLn "Hello, world!"
main :: IO ()
main = do
args <- getArgs
case args of
[inpF, outpF] -> processFile inpF outpF
_ -> putStrLn "Incorrect number of arguments. Usage: texgen <inpFile> <outpFile>"

0 comments on commit e377ddb

Please sign in to comment.