Skip to content

Instantly share code, notes, and snippets.

@JordanMartinez
Created June 13, 2022 14:02
Show Gist options
  • Save JordanMartinez/a37247868f0f7aaf3244f8c07fc304f6 to your computer and use it in GitHub Desktop.
Save JordanMartinez/a37247868f0f7aaf3244f8c07fc304f6 to your computer and use it in GitHub Desktop.
Skip Spaces Bug
module Main where
import Prelude
import Control.Alt ((<|>))
import Data.Array as Array
import Effect.Console (log)
import Effect (Effect)
import Parsing as P
import Parsing.Combinators as PC
import Parsing.String as PS
import Parsing.String.Basic as PSB
import TryPureScript as TP
main :: Effect Unit
main = TP.render =<< TP.withConsole do
log $ show $ P.runParser content parser
content :: String
content = Array.intercalate "\n"
[ " // ignored line1"
, ""
, " "
, "// ignored line2"
, "@value"
]
parser :: P.Parser String String
parser = do
void $ PC.many $ (PSB.skipSpaces *> (singleLineComment <|> newline))
PS.string "@" *> PS.string "value"
where
singleLineComment = PS.string "//" *> untilEndOfLine
newline = void $ PS.string "\n"
untilEndOfLine = PC.many1 (PS.satisfy (\x -> x /= '\n')) *> newline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment