API refactor

This commit is contained in:
Pagwin 2025-12-27 19:49:26 -05:00
parent cb0cfebae3
commit 478fec0000
No known key found for this signature in database
GPG key ID: 81137023740CA260
2 changed files with 23 additions and 4 deletions

View file

@ -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
- https://github.com/wereHamster/haskell-css-syntax
- JS
- Doing our own tokenizer lol
- [ ] setup fingerprinting in file names for css and js
- [ ] process source code blocks to syntax highlight them
- tree sitter https://hackage.haskell.org/package/tree-sitter

View file

@ -3,6 +3,8 @@
module Utilities.Javascript
( minify,
toTokens,
displayToken,
)
where
@ -10,13 +12,29 @@ import Control.Applicative (Alternative (many), optional, (<|>))
import Data.Data (Proxy (Proxy))
import Data.Maybe (maybeToList)
import Data.String (IsString (fromString))
import Data.Void (Void)
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 Utilities.Parsing
minify :: String -> String
minify = id
minify :: (Characters s) => [Token s] -> [Token s]
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
-- s is either Text or String