Skip to content

Commit

Permalink
extract/factor-out common code
Browse files Browse the repository at this point in the history
  • Loading branch information
hexwell committed Jan 19, 2022
1 parent ed1b851 commit ca87ed0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
8 changes: 4 additions & 4 deletions hs/BashParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ module BashParser (

import Control.Applicative (some, (<|>), many)
import Data.Maybe (catMaybes)
import Text.Parsec (Parsec, char, string, noneOf, modifyState, endOfLine,
getState, try, eof)
import Text.Parsec (char, string, noneOf, modifyState, endOfLine, getState,
try, eof)

import Utils (spaces, line, just, nothing)
import Utils (StringParser, spaces, line, just, nothing)

type Path = String
type Filename = String

data ParserState = ParserState Char Path
type Parser = Parsec String ParserState
type Parser = StringParser ParserState

ppath :: Parser String
ppath = do
Expand Down
5 changes: 4 additions & 1 deletion hs/Utils.hs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
module Utils (
StringParser,
spaces,
line,
just,
nothing
) where

import Text.Parsec (Stream, ParsecT, skipMany, char, noneOf, endOfLine,
import Text.Parsec (Parsec, Stream, ParsecT, skipMany, char, noneOf, endOfLine,
manyTill)

type StringParser u = Parsec String u

spaces :: Stream s m Char => ParsecT s u m ()
spaces = skipMany $ char ' '

Expand Down
3 changes: 2 additions & 1 deletion hs/Vflow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import BashParser (Filename, Path)
import qualified BashParser as B
import VflowParser (Block(NewFile))
import qualified VflowParser as V
import Utils (StringParser)

parse :: Parsec String s a -> s -> Filename -> ExceptT ParseError IO a
parse :: StringParser s a -> s -> Filename -> ExceptT ParseError IO a
parse parser state filename = do
content <- lift $ readFile filename

Expand Down
8 changes: 4 additions & 4 deletions hs/VflowParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import Control.Applicative ((<|>), many)
import Data.Function ((&))
import Data.Functor (void)
import Data.Maybe (catMaybes)
import Text.Parsec (Parsec, SourcePos, getState, getParserState, statePos,
string, endOfLine, noneOf, char, optionMaybe, try, eof)
import Text.Parsec (SourcePos, getState, getParserState, statePos, string,
endOfLine, noneOf, char, optionMaybe, try, eof)

import Utils (spaces, line, just, nothing)
import Utils (StringParser, spaces, line, just, nothing)

type HostLangComment = String
type Indent = Int
data ParserState = ParserState HostLangComment Indent Indent
type Parser = Parsec String ParserState
type Parser = StringParser ParserState

type Name = String
type Comment = String
Expand Down

0 comments on commit ca87ed0

Please sign in to comment.