mirror of
https://github.com/The1Penguin/org-to-mafiauniverse.git
synced 2024-11-22 02:08:13 +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
|
* Spec
|
||||||
|
|
||||||
| org | forum |
|
| org | forum | Notes |
|
||||||
|-----+-----------------|
|
|-----+-----------------+---------------------------|
|
||||||
| * | [TITLE][/TITLE] |
|
| * | [TITLE][/TITLE] | |
|
||||||
| ** | [SIZE=4][/SIZE] |
|
| ** | [SIZE=4][/SIZE] | |
|
||||||
| *** | [SIZE=2][/SIZE] |
|
| *** | [SIZE=2][/SIZE] | |
|
||||||
| | |
|
| - | [*] | Needs a [LIST] around all |
|
||||||
| | |
|
| | | |
|
||||||
| | |
|
| | | |
|
||||||
| | |
|
| | | |
|
||||||
| | |
|
| | | |
|
||||||
| | |
|
| | | |
|
||||||
|
| | | |
|
||||||
|
34
app/Main.hs
34
app/Main.hs
@ -1,20 +1,28 @@
|
|||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
import Control.Applicative
|
import Control.Applicative hiding (some)
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import Data.Functor
|
import Data.Functor
|
||||||
|
import Data.Void
|
||||||
import System.Environment
|
import System.Environment
|
||||||
import System.Exit
|
import System.Exit
|
||||||
import Text.Megaparsec hiding (parse, satisfy)
|
import Text.Megaparsec hiding (satisfy)
|
||||||
import Text.ParserCombinators.ReadP
|
import Text.Megaparsec.Char
|
||||||
|
import Text.ParserCombinators.ReadP hiding (string)
|
||||||
|
|
||||||
parse :: ReadP String -> String -> String
|
type Parser = Parsec Void String
|
||||||
parse rules = fst . last . readP_to_S rules
|
|
||||||
|
|
||||||
parseFile :: String -> 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
|
fileParser = undefined
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
@ -25,13 +33,17 @@ parseCli [] = return usage
|
|||||||
parseCli [x] =
|
parseCli [x] =
|
||||||
if head x /= '-'
|
if head x /= '-'
|
||||||
then parseFile <$> readFile x
|
then parseFile <$> readFile x
|
||||||
else return $ useArgs $ parse argParse x
|
else case parse argParse "" x of
|
||||||
parseCli [x, _] = return $ useArgs $ parse argParse x
|
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"
|
parseCli _ = fail "Too many arugemnts"
|
||||||
|
|
||||||
argParse :: ReadP String
|
argParse :: Parser String
|
||||||
argParse =
|
argParse =
|
||||||
string "-" >> many1 (satisfy (/= ' '))
|
string "-" >> some alphaNumChar
|
||||||
|
|
||||||
useArgs :: String -> String
|
useArgs :: String -> String
|
||||||
useArgs [] = ""
|
useArgs [] = ""
|
||||||
|
Loading…
Reference in New Issue
Block a user