Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Dev to main #25

Merged
merged 45 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c34c4ad
Add tests
guillaumeAbel Dec 12, 2023
7e1f543
add begin of functions in env
TTENSHII Dec 13, 2023
8969dea
add working simple functions
TTENSHII Dec 13, 2023
1b0f4be
add more complex tests
TTENSHII Dec 13, 2023
d9a6ed1
add working function variables
TTENSHII Dec 13, 2023
b94ec51
add work in progress
TTENSHII Dec 13, 2023
92a755d
fix tests
TTENSHII Dec 13, 2023
0c0bed3
add lambda support
TTENSHII Dec 13, 2023
21b5d99
Add option for koaky
Saverio976 Dec 15, 2023
98b0f1c
Fixw norm
Saverio976 Dec 15, 2023
9d3970f
Fix norm
Saverio976 Dec 15, 2023
6d8f8be
Merge pull request #20 from X-R-G-B/19-option-help
guillaumeAbel Dec 15, 2023
d437d1b
Clean code
TTENSHII Dec 16, 2023
55c4555
Add evaluateSymbol to compute list as define
TTENSHII Dec 16, 2023
51b61b4
Fix warnings
TTENSHII Dec 16, 2023
df44831
Fix newenv in handleSimpleList
TTENSHII Dec 16, 2023
ccee1af
Fix one test
TTENSHII Dec 16, 2023
adb738d
add more tests
TTENSHII Dec 16, 2023
8b7267f
Change result type
TTENSHII Dec 16, 2023
260ddaf
Add other func declaration possibility
TTENSHII Dec 16, 2023
17f4f02
add more tests
TTENSHII Dec 16, 2023
8a0bb8c
Add eof
TTENSHII Dec 16, 2023
ba17645
Add support of if
TTENSHII Dec 16, 2023
6d13756
add more conditions
TTENSHII Dec 17, 2023
55fc259
Update src/Types.hs
TTENSHII Dec 17, 2023
e80648e
Add test
guillaumeAbel Dec 17, 2023
37faf1d
Merge branch 'dev' into computeFunctions
TTENSHII Dec 17, 2023
77a35e4
adapt checkParsing to new Result type
TTENSHII Dec 17, 2023
3203f83
Split code, failing test
guillaumeAbel Dec 17, 2023
9a64ce1
fix some norm error
TTENSHII Dec 17, 2023
71d04cc
Add multiple line handler
guillaumeAbel Dec 17, 2023
5ed924b
add Epitech Header
TTENSHII Dec 17, 2023
4daa61a
Fix norm
guillaumeAbel Dec 17, 2023
0d30b98
fix too long line
TTENSHII Dec 17, 2023
99c2a7a
fix norm in computeAst
TTENSHII Dec 17, 2023
442eb03
fix division by zero
TTENSHII Dec 17, 2023
82fb2d8
enhance defines
TTENSHII Dec 17, 2023
5af97aa
add define case "already defined"
TTENSHII Dec 17, 2023
e8066fc
fix norm
TTENSHII Dec 17, 2023
77608d7
Merge pull request #24 from X-R-G-B/handleMultipleLine
TTENSHII Dec 17, 2023
1ab3f4c
Merge branch 'dev' into computeFunctions
TTENSHII Dec 17, 2023
ef4edff
remove useless coma
TTENSHII Dec 17, 2023
16d4ed6
fix norm
TTENSHII Dec 17, 2023
155a7a9
Merge pull request #21 from X-R-G-B/computeFunctions
Saverio976 Dec 17, 2023
4827087
Change version
Saverio976 Dec 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions app/Args.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{-
-- EPITECH PROJECT, 2023
-- Koaky
-- File description:
-- args
-}


module Args
(
Action(..),
Args(..),
RunOpt(..),
parseArgs,
printHelp
) where

data Action = ShowHelp | ShowVersion | Run
data RunOpt = RunStdin | RunFile

data Args = Args {
action :: Action,
runOpt :: RunOpt,
filePath :: String
}

parseArgs' :: [String] -> Args -> Either Args String
parseArgs' [] args =
Left args
parseArgs' ("--help":xs) args =
parseArgs' xs (args {action = ShowHelp})
parseArgs' ("-h":xs) args =
parseArgs' xs (args {action = ShowHelp})
parseArgs' ("--version":xs) args =
parseArgs' xs (args {action = ShowVersion})
parseArgs' ("-v":xs) args =
parseArgs' xs (args {action = ShowVersion})
parseArgs' ("-f":f:xs) args =
parseArgs' xs (args {action = Run, runOpt = RunFile, filePath = f})
parseArgs' ["-f"] _ =
Right "No file specified"
parseArgs' ("-":xs) args =
parseArgs' xs (args {action = Run, runOpt = RunStdin})
parseArgs' (x:_) _ =
Right ("Unknown option: " ++ x)

parseArgs :: [String] -> Either Args String
parseArgs args =
parseArgs' args (Args {action = Run, runOpt = RunStdin, filePath = ""})

printHelp :: IO ()
printHelp = putStr help
where
line1 = "Usage: koaky [OPTION]\n\nInterpret Lisp\n"
line2a = "With no options, koaky reads from standard input.\n\n"
line3 = "Options:\n"
line4 = "\t-h, --help\n\t\tDisplay this help and exit\n"
line5 = "\t-v, --version\n\t\tOutput version information and exit\n"
line6 = "\t-f FILE, --file FILE\n\t\tRead FILE and Interpret it\n"
line7 = "\t-\n\t\tRead from standard input and Interpret it\n"
help = line1 ++ line2a ++ line3 ++ line4 ++ line5 ++ line6 ++ line7
42 changes: 12 additions & 30 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,17 @@
-- Main
-}

import Computing.ComputeAST
import Parsing.Parser
import Types
import System.IO

printErrors :: (Env) -> IO ()
printErrors (Env defines_ []) =
printErrors (Env defines_ ["Unable to compute"])
printErrors (Env defines_ errors_) =
mapM_ putStrLn errors_ >> handleInput (Env defines_ [])

checkComputing :: (Env, Maybe Result) -> IO ()
checkComputing (env, Nothing) = printErrors env
checkComputing (env, Just result) = putStrLn (show result) >> handleInput env

checkParsing :: Maybe (Tree, String) -> Env -> IO ()
checkParsing Nothing _ = return ()
checkParsing (Just (tree, _)) env = checkComputing (computeAST env tree)

checkInput :: String -> Env -> IO ()
checkInput ":q" _ = return ()
checkInput input env = checkParsing (runParser (parseTree) input) env

checkEOF :: Env -> Bool -> IO ()
checkEOF _ True = return ()
checkEOF env False = getLine >>= (\x -> checkInput x env)

handleInput :: Env -> IO ()
handleInput env = isEOF >>= (\x -> checkEOF env x)
import System.Environment (getArgs)
import Args
import Run
import Version

dispatchAction :: Either Args String -> IO ()
dispatchAction (Right error_) = putStrLn error_
dispatchAction (Left (Args ShowHelp _ _)) = printHelp
dispatchAction (Left (Args ShowVersion _ _)) = printVersion
dispatchAction (Left (Args Run RunFile f)) = runFile f
dispatchAction (Left (Args Run RunStdin _)) = runStdin

main :: IO ()
main = handleInput (Env [] [])
main = getArgs >>= (dispatchAction . parseArgs)
65 changes: 65 additions & 0 deletions app/Run.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{-
-- EPITECH PROJECT, 2023
-- Koaky
-- File description:
-- run
-}

module Run
(
runStdin,
runFile
) where

import Computing.ComputeAST
import Parsing.Parser
import Types
import System.IO

data HHHandle = HHHandle Handle Bool

printErrors :: HHHandle -> Env -> IO ()
printErrors hand (Env defines_ [] funcs_) =
printErrors hand (Env defines_ ["Unable to compute"] funcs_)
printErrors hand (Env defines_ errors_ funcs_) =
mapM_ putStrLn errors_ >> handleInput hand (Env defines_ [] funcs_) []

checkComputing :: HHHandle -> (Env, Result) -> IO ()
checkComputing hand (env, Right _) = printErrors hand env
checkComputing hand (env, Left Nothing) = handleInput hand env []
checkComputing hand (env, Left (Just result)) =
print result >> handleInput hand env []

checkParsing :: HHHandle -> String -> Maybe (Tree, String) -> Env -> IO ()
checkParsing hand str Nothing env = handleInput hand env str
checkParsing hand _ (Just (tree, _)) env =
checkComputing hand (computeAST env tree)

checkInput :: HHHandle -> String -> Env -> IO ()
checkInput _ ":q" _ = return ()
checkInput hand input env =
checkParsing hand input (runParser (parseTree) input) env

checkEOF :: HHHandle -> Env -> String -> Bool -> IO ()
checkEOF _ _ _ True = return ()
checkEOF (HHHandle ff shouldClosee) env prevStr False = hGetLine ff >>=
(\x -> checkInput (HHHandle ff shouldClosee) (prevStr ++ x) env)

handleInput :: HHHandle -> Env -> String -> IO ()
handleInput (HHHandle ff shouldClosee) env prevStr =
hIsEOF ff >>= (\x -> checkEOF (HHHandle ff shouldClosee) env prevStr x)

runStdin :: IO ()
runStdin = runFileHandle stdin False

runFile :: String -> IO ()
runFile filePath = openFile filePath ReadMode >>= \x -> runFileHandle x True

onEnd :: HHHandle -> IO ()
onEnd (HHHandle ff True) = hClose ff
onEnd _ = return ()

runFileHandle :: Handle -> Bool -> IO ()
runFileHandle ff shouldClosee =
handleInput (HHHandle ff shouldClosee) (Env [] [] []) [] >>
onEnd (HHHandle ff shouldClosee)
15 changes: 15 additions & 0 deletions app/Version.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{-
-- EPITECH PROJECT, 2023
-- koaky
-- File description:
-- version
-}

module Version
( printVersion
) where

import KoakyLibVersion

printVersion :: IO ()
printVersion = putStrLn koakyLibVersion
13 changes: 10 additions & 3 deletions koaky.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.35.2.
-- This file has been generated from package.yaml by hpack version 0.36.0.
--
-- see: https://github.com/sol/hpack

Expand All @@ -27,11 +27,15 @@ library
exposed-modules:
AST
Computing.ComputeAST
Computing.ComputeDeepLists
Computing.ComputeLists
Computing.Defines
Computing.Errors
Computing.Functions
Computing.ListContainList
Computing.Operators.Assert
Computing.Operators.Calculate
Computing.Operators.EvaluateSymbol
Computing.ReplaceFunctionParams
KoakyLibVersion
Parsing.Parser
Types
other-modules:
Expand All @@ -46,6 +50,9 @@ library
executable koaky-exe
main-is: Main.hs
other-modules:
Args
Run
Version
Paths_koaky
hs-source-dirs:
app
Expand Down
Loading
Loading