Skip to content

Patch Parsec's comment parsing #2985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions waspc/src/Wasp/Psl/Parser/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ import Text.Parsec
( alphaNum,
char,
letter,
notFollowedBy,
string,
(<|>),
)
import Text.Parsec.Language (emptyDef)
import Text.Parsec.String (Parser)
import qualified Text.Parsec.Token as T
import Wasp.Psl.Parser.Common.Language (emptyDef)
import qualified Wasp.Psl.Parser.Common.Token as T

type SourceCode = String

Expand Down Expand Up @@ -71,8 +73,11 @@ lexer :: T.TokenParser ()
lexer =
T.makeTokenParser
emptyDef
{ T.commentLine = "//",
{ T.commentLine = commentSymbol,
T.caseSensitive = True,
T.identStart = letter,
T.identLetter = alphaNum <|> char '_'
}
where
commentSymbol :: Parser ()
commentSymbol = string "//" >> notFollowedBy (char '/')
50 changes: 50 additions & 0 deletions waspc/src/Wasp/Psl/Parser/Common/Language.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-- This module is a copy-paste of the `empyDef` from `Text.Parsec.Language` module, with the
-- following changes:
-- 1. Made `commentLine` a `Parser` instead of a `String`.
-- This way, we can accept arbitrary parsers for line comments, which is useful for our use case, as
-- just adding `//` as a line comment would make the parser ignore documentation comments `///`.
-- Original at
-- https://hackage.haskell.org/package/parsec-3.1.14.0/docs/src/Text.Parsec.Language.html#emptyDef
-- -------------------------------------------------------------------------------------------------

-- |
-- Module : Text.Parsec.Language
-- Copyright : (c) Daan Leijen 1999-2001, (c) Paolo Martini 2007
-- License : BSD-style (see the LICENSE file)
--
-- Maintainer : derek.a.elkins@gmail.com
-- Stability : provisional
-- Portability : non-portable (uses non-portable module Text.Parsec.Token)
--
-- A helper module that defines some language definitions that can be used
-- to instantiate a token parser (see "Text.Parsec.Token").
module Wasp.Psl.Parser.Common.Language
( emptyDef,
)
where

import Control.Monad (void)
import Text.Parsec
import Wasp.Psl.Parser.Common.Token

-----------------------------------------------------------
-- minimal language definition
--------------------------------------------------------

-- | This is the most minimal token definition. It is recommended to use
-- this definition as the basis for other definitions. @emptyDef@ has
-- no reserved names or operators, is case sensitive and doesn't accept
-- comments, identifiers or operators.
emptyDef :: LanguageDef st
emptyDef =
LanguageDef
{ commentLine = void $ string "//",
nestedComments = True,
identStart = letter <|> char '_',
identLetter = alphaNum <|> oneOf "_'",
opStart = opLetter emptyDef,
opLetter = oneOf ":!#$%&*+./<=>?@\\^|-~",
reservedOpNames = [],
reservedNames = [],
caseSensitive = True
}
Loading
Loading