mirror of
https://github.com/The1Penguin/org-to-mafiauniverse.git
synced 2024-11-21 17:58:12 +00:00
Cli parser using new parsing technique
This commit is contained in:
parent
6306edab84
commit
39f5aa8770
23
README.org
23
README.org
@ -6,14 +6,15 @@ The name is pronounced like autumn.
|
||||
|
||||
* Spec
|
||||
|
||||
| org | forum |
|
||||
|-----+-----------------|
|
||||
| * | [TITLE][/TITLE] |
|
||||
| ** | [SIZE=4][/SIZE] |
|
||||
| *** | [SIZE=2][/SIZE] |
|
||||
| | |
|
||||
| | |
|
||||
| | |
|
||||
| | |
|
||||
| | |
|
||||
| | |
|
||||
| org | forum | Notes |
|
||||
|-----+-----------------+---------------------------|
|
||||
| * | [TITLE][/TITLE] | |
|
||||
| ** | [SIZE=4][/SIZE] | |
|
||||
| *** | [SIZE=2][/SIZE] | |
|
||||
| - | [*] | Needs a [LIST] around all |
|
||||
| | | |
|
||||
| | | |
|
||||
| | | |
|
||||
| | | |
|
||||
| | | |
|
||||
| | | |
|
||||
|
34
app/Main.hs
34
app/Main.hs
@ -1,20 +1,28 @@
|
||||
module Main where
|
||||
|
||||
import Control.Applicative
|
||||
import Control.Applicative hiding (some)
|
||||
import Control.Monad
|
||||
import Data.Functor
|
||||
import Data.Void
|
||||
import System.Environment
|
||||
import System.Exit
|
||||
import Text.Megaparsec hiding (parse, satisfy)
|
||||
import Text.ParserCombinators.ReadP
|
||||
import Text.Megaparsec hiding (satisfy)
|
||||
import Text.Megaparsec.Char
|
||||
import Text.ParserCombinators.ReadP hiding (string)
|
||||
|
||||
parse :: ReadP String -> String -> String
|
||||
parse rules = fst . last . readP_to_S rules
|
||||
type Parser = Parsec Void String
|
||||
|
||||
parseFile :: String -> String
|
||||
parseFile = unlines . map (parse fileParser) . lines
|
||||
parseFile =
|
||||
unlines
|
||||
. map
|
||||
( \x -> case parse fileParser "" x of
|
||||
Left bundle -> error ("Error parsing text" ++ errorBundlePretty bundle)
|
||||
Right text -> text
|
||||
)
|
||||
. lines
|
||||
|
||||
fileParser :: ReadP String
|
||||
fileParser :: Parser String
|
||||
fileParser = undefined
|
||||
|
||||
main :: IO ()
|
||||
@ -25,13 +33,17 @@ parseCli [] = return usage
|
||||
parseCli [x] =
|
||||
if head x /= '-'
|
||||
then parseFile <$> readFile x
|
||||
else return $ useArgs $ parse argParse x
|
||||
parseCli [x, _] = return $ useArgs $ parse argParse x
|
||||
else case parse argParse "" x of
|
||||
Left bundle -> fail $ "Failed parsing args" ++ errorBundlePretty bundle
|
||||
Right text -> return $ useArgs text
|
||||
parseCli [x, _] = case parse argParse "" x of
|
||||
Left bundle -> fail $ "Failed parsing args" ++ errorBundlePretty bundle
|
||||
Right text -> return $ useArgs text
|
||||
parseCli _ = fail "Too many arugemnts"
|
||||
|
||||
argParse :: ReadP String
|
||||
argParse :: Parser String
|
||||
argParse =
|
||||
string "-" >> many1 (satisfy (/= ' '))
|
||||
string "-" >> some alphaNumChar
|
||||
|
||||
useArgs :: String -> String
|
||||
useArgs [] = ""
|
||||
|
Loading…
Reference in New Issue
Block a user