API refactor
This commit is contained in:
parent
cb0cfebae3
commit
478fec0000
2 changed files with 23 additions and 4 deletions
3
TODO.md
3
TODO.md
|
|
@ -1,7 +1,8 @@
|
||||||
- [ ] minify js and css when copying over instead of just copying (May just end up using Tree sitter for parsing due to lack of js packages)
|
- [ ] minify js and css when copying over instead of just copying
|
||||||
- CSS
|
- CSS
|
||||||
- https://github.com/wereHamster/haskell-css-syntax
|
- https://github.com/wereHamster/haskell-css-syntax
|
||||||
- JS
|
- JS
|
||||||
|
- Doing our own tokenizer lol
|
||||||
- [ ] setup fingerprinting in file names for css and js
|
- [ ] setup fingerprinting in file names for css and js
|
||||||
- [ ] process source code blocks to syntax highlight them
|
- [ ] process source code blocks to syntax highlight them
|
||||||
- tree sitter https://hackage.haskell.org/package/tree-sitter
|
- tree sitter https://hackage.haskell.org/package/tree-sitter
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
module Utilities.Javascript
|
module Utilities.Javascript
|
||||||
( minify,
|
( minify,
|
||||||
|
toTokens,
|
||||||
|
displayToken,
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
|
|
@ -10,13 +12,29 @@ import Control.Applicative (Alternative (many), optional, (<|>))
|
||||||
import Data.Data (Proxy (Proxy))
|
import Data.Data (Proxy (Proxy))
|
||||||
import Data.Maybe (maybeToList)
|
import Data.Maybe (maybeToList)
|
||||||
import Data.String (IsString (fromString))
|
import Data.String (IsString (fromString))
|
||||||
|
import Data.Void (Void)
|
||||||
import Logger
|
import Logger
|
||||||
import Text.Megaparsec (MonadParsec (notFollowedBy, try), Stream (tokensToChunk), anySingle, choice)
|
import Text.Megaparsec (MonadParsec (notFollowedBy, try), ParseErrorBundle, Stream (tokensToChunk), anySingle, choice, parse)
|
||||||
import Text.Megaparsec.Char (hspace, newline, string)
|
import Text.Megaparsec.Char (hspace, newline, string)
|
||||||
import Utilities.Parsing
|
import Utilities.Parsing
|
||||||
|
|
||||||
minify :: String -> String
|
minify :: (Characters s) => [Token s] -> [Token s]
|
||||||
minify = id
|
minify = reduce_identifiers . remove_redundants
|
||||||
|
where
|
||||||
|
-- need to figure out how to add State into this
|
||||||
|
reduce_identifiers = map $ \token -> case token of
|
||||||
|
Identifier name -> Identifier name
|
||||||
|
v -> v
|
||||||
|
-- this could also use state so I can remove redundant newlines
|
||||||
|
remove_redundants = filter $ \token -> case token of
|
||||||
|
WhiteSpace -> False
|
||||||
|
_ -> True
|
||||||
|
|
||||||
|
toTokens :: (Characters s) => s -> Either (ParseErrorBundle s Void) [Token s]
|
||||||
|
toTokens = parse tokens ""
|
||||||
|
|
||||||
|
displayToken :: (ToText s) => Token s -> s
|
||||||
|
displayToken _ = error "TODO"
|
||||||
|
|
||||||
-- yeah I guess I'm making a javascript tokenizer
|
-- yeah I guess I'm making a javascript tokenizer
|
||||||
-- s is either Text or String
|
-- s is either Text or String
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue