-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ebd926c
commit 10f4f9d
Showing
11 changed files
with
490 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist-newstyle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
* 0.1.0.0 -- 2021-11-18 | ||
** First version. Released on an unsuspecting world. | ||
|
||
* 0.1.1.0 -- 2021-11-19 | ||
** First addition to parsing capability | ||
|
||
* 0.1.3.0 -- 2021-11-21 | ||
** Interactive mode is built only table mode remaining | ||
|
||
* 0.1.4.0 -- 2021-11-22 | ||
** Table mode almost complete, bugs to be fixed by the next update | ||
|
||
* 1.0.0.0 -- 2021-11-25 | ||
** Probably final update, table mode is still ridden with bugs and interactive mode is not as pleasant as it can be though other parts seem to be doing just fine | ||
|
||
* 2.0.0.0 -- 2022-03-23 | ||
** Was not the final update, went though a major rewrite - still riddled with bugs though. | ||
* Fixed a bunch of the parsing bugs | ||
* Now added mode switching in interactive mode | ||
|
||
```text | ||
:q -- Quit | ||
:t -- Table Output | ||
:l -- Latex Output | ||
:s -- Raw Output | ||
:f -- Fold formula to max | ||
:F -- Specify number of folds to do | ||
:h -- Help page | ||
:d -- Subscript Output | ||
:i -- Print options | ||
``` | ||
* Accidentally made table mode useless |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
The MIT License (MIT) | ||
|
||
Copyright © 2021 <copyright holders> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Atom-Counter | ||
|
||
simple program for parsing formula names | ||
![Testcases](https://i.imgur.com/UL2KW17.png) | ||
|
||
** Just a small project, no longer being developed | ||
|
||
![Table Mode](https://i.imgur.com/MliTM6t.png) | ||
The basic syntax in table mode is | ||
|
||
- Any element on its own does not get affected | ||
|
||
```text | ||
Au_2 -> Au_2 | ||
|----+----------+---------| | ||
| | Reactant | Product | | ||
|----+----------+---------| | ||
| Au | 2 | 2 | | ||
|----+----------+---------| | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Main where | ||
|
||
import System.Console.GetOpt | ||
import System.Environment | ||
|
||
import Interactive | ||
import Args | ||
|
||
|
||
main :: IO () | ||
main = do | ||
args <- compilerOpts <$> getArgs | ||
args >>= (either (putStrLn =<<)putStrLn . lobby) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
module Args where | ||
|
||
import Data.Maybe | ||
import System.Console.GetOpt | ||
import Control.Lens | ||
|
||
data Options = Options | ||
{ _optInteractive :: Bool, | ||
_optHelpPage :: Bool, | ||
_optTable :: Bool, | ||
_optLatex :: Bool, | ||
_optShow :: Bool, | ||
_optToIn :: Bool, | ||
_optVersion :: Bool, | ||
_optFold :: Bool, | ||
_optFolds :: Int, | ||
_optSub :: Bool | ||
} | ||
deriving (Show) | ||
|
||
makeLenses ''Options | ||
|
||
defaultOptions = | ||
Options | ||
{ _optInteractive = False, | ||
_optHelpPage = False, | ||
_optTable = False, | ||
_optLatex = False, | ||
_optShow = False, | ||
_optToIn = False, | ||
_optVersion = False, | ||
_optFold = False, | ||
_optFolds = 0, | ||
_optSub = False | ||
} | ||
|
||
options :: [OptDescr (Options -> Options)] | ||
options = | ||
[ Option | ||
['I'] | ||
["interactive"] | ||
(NoArg (\opts -> opts {_optInteractive = True})) | ||
"Use STDIN instead of console arguments, type :q to quit", | ||
Option | ||
['i'] | ||
["input"] | ||
(NoArg (\opts -> opts {_optToIn = True})) | ||
"Send output as output recognizable by the input", | ||
Option | ||
['t', 'T'] | ||
["table"] | ||
(NoArg (\opts -> opts {_optTable = True})) | ||
"Unsubscripted Numbers gets treated as multipliers, arrays of arguments also get accepted with symbols other than parenthesis acting as delimeters", | ||
Option | ||
['l', 'L'] | ||
["latex"] | ||
(NoArg (\opts -> opts {_optLatex = True})) | ||
"Send output as a latex formula", | ||
Option | ||
['v', 'V'] | ||
["version"] | ||
(NoArg (\opts -> opts {_optVersion = True})) | ||
"Show program version", | ||
Option | ||
['s', 'S'] | ||
["show"] | ||
(NoArg (\opts -> opts {_optShow = True})) | ||
"Show output via actual value in haskell", | ||
Option | ||
['f'] | ||
["fold"] | ||
(NoArg (\opts -> opts {_optFold = True})) | ||
"Repeatedly fold formula until at lowest term", | ||
Option | ||
['F'] | ||
["folds"] | ||
( OptArg | ||
((\f opts -> opts {_optFolds = read f :: Int}) . fromMaybe "0") | ||
"NUMBER" | ||
) | ||
"Fold formula a number of times", | ||
Option | ||
['D', 'd'] | ||
["subScript"] | ||
(NoArg (\opts -> opts {_optSub = True})) | ||
"show output in subscript" | ||
] | ||
|
||
compilerOpts :: [String] -> IO (Options, [String]) | ||
compilerOpts argv = | ||
case getOpt Permute options argv of | ||
(o, n, []) -> return (foldl (flip id) defaultOptions o, n) | ||
(_, _, errs) -> ioError (userError (concat errs ++ usageInfo header options)) | ||
where | ||
header = "Usage: [OPTION...] formula..." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
module Interactive where | ||
|
||
import Args | ||
import System.Console.Haskeline | ||
|
||
import Parser | ||
import Control.Monad.IO.Class | ||
import Data.Maybe | ||
import Process | ||
import ToString | ||
--import Data.Version as V | ||
--import Paths_Atom_Counter | ||
import Data.Either | ||
import Control.Lens | ||
|
||
lobby :: (Options, [String]) -> Either (IO String) String | ||
lobby | ||
opts@( Options | ||
{ _optInteractive = isInteractive | ||
, _optTable = isTableMode | ||
, _optLatex = showLatex | ||
, _optShow = showHaskCode | ||
, _optVersion = showVersion | ||
, _optFold = maxFold | ||
, _optToIn = showIn | ||
, _optFolds = numOfFolds | ||
, _optSub = showSub | ||
}, | ||
formula | ||
) | ||
| sum (fromEnum <$> [showHaskCode, showLatex, showIn, showSub]) > 1 = Left $ return "Error: output method mixing" | ||
| isInteractive = Left $ interactive $ (fst opts) {_optInteractive = False} | ||
| isTableMode = maybe (Left $ return "UserError: Table Parse Error") (Right . orgTable . snd) $ runParser reactProdP $ concat formula | ||
-- | showVersion = Right $ "Version: " ++ V.showVersion version | ||
| showHaskCode = maybe message (Right . show) $ runParser parser $ concat formula | ||
| otherwise = maybe message (Right . concatMap (toString showFunc) . snd) $ runParser parser $ concat formula | ||
where | ||
message = Left $ return "UserError: Parse Error" | ||
showFunc | ||
| showSub = toSub | ||
| showLatex = toLatex | ||
| otherwise = toBasic | ||
|
||
parser :: Parser [Element] | ||
parser = if maxFold | ||
then flattenForm <$> formulaP | ||
else foldr (.) id (replicate numOfFolds (concatMap foldForm)) . groupForm <$> formulaP | ||
|
||
|
||
interactive :: Options -> IO String | ||
interactive opts = runInputT defaultSettings $ loop opts | ||
where | ||
loop :: Options -> InputT IO String | ||
loop opts = do | ||
minput <- getInputLine "AtomC> " | ||
case minput of | ||
Nothing -> return "Unexpected exit" | ||
Just ":q" -> return "Exited Program" | ||
Just ":t" -> loop $ opts & optTable .~ True | ||
Just ":l" -> loop $ opts & optLatex .~ True & optShow .~ False & optSub .~ False & optToIn .~ False | ||
Just ":s" -> loop $ opts & optLatex .~ False & optShow .~ True & optSub .~ False & optToIn .~ False | ||
Just ":f" -> loop $ opts & optFold .~ True | ||
Just ":F" -> do | ||
x <- runInputT defaultSettings $ getInputLine "Set fold amount:" | ||
case (maybeRead =<< x :: Maybe Int) of | ||
Nothing -> loop opts | ||
Just n -> loop $ opts & optFolds .~ n | ||
|
||
Just ":h" -> outputStrLn helpPage >> loop opts | ||
Just ":i" -> outputStrLn (show opts) >> loop opts | ||
Just ":d" -> loop $ opts & optLatex .~ False & optShow .~ False & optSub .~ True & optToIn .~ False | ||
|
||
Just (':':x) -> outputStrLn ("Unknown command: '" ++ x ++ "'") >> loop opts | ||
|
||
Just input -> do outputStrLn $ fromRight "Parse Error" $ lobby (opts, [input]) | ||
loop opts | ||
|
||
helpPage = unlines | ||
[":q -- Quit" | ||
,":t -- Table Output" | ||
,":l -- Latex Output" | ||
,":s -- Raw Output" | ||
,":f -- Fold formula to max" | ||
,":F -- Specify number of folds to do" | ||
,":h -- Help page" | ||
,":d -- Subscript Output" | ||
,":i -- Print options" | ||
] | ||
|
||
maybeRead :: Read a => String -> Maybe a | ||
maybeRead = fmap fst . listToMaybe . reads |
Oops, something went wrong.