Skip to content

Commit d47e94a

Browse files
committed
Patch comment parsing
1 parent edbaa22 commit d47e94a

File tree

4 files changed

+737
-3
lines changed

4 files changed

+737
-3
lines changed

waspc/src/Wasp/Psl/Parser/Common.hs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ import Text.Parsec
2020
( alphaNum,
2121
char,
2222
letter,
23+
notFollowedBy,
24+
string,
2325
(<|>),
2426
)
25-
import Text.Parsec.Language (emptyDef)
2627
import Text.Parsec.String (Parser)
27-
import qualified Text.Parsec.Token as T
28+
import Wasp.Psl.Parser.Common.Language (emptyDef)
29+
import qualified Wasp.Psl.Parser.Common.Token as T
2830

2931
type SourceCode = String
3032

@@ -71,8 +73,11 @@ lexer :: T.TokenParser ()
7173
lexer =
7274
T.makeTokenParser
7375
emptyDef
74-
{ T.commentLine = "//",
76+
{ T.commentLine = commentSymbol,
7577
T.caseSensitive = True,
7678
T.identStart = letter,
7779
T.identLetter = alphaNum <|> char '_'
7880
}
81+
where
82+
commentSymbol :: Parser ()
83+
commentSymbol = string "//" >> notFollowedBy (char '/')
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
-- This module is a copy-paste of the `empyDef` from `Text.Parsec.Language` module, with the
2+
-- following changes:
3+
-- 1. Made `commentLine` a `Parser` instead of a `String`.
4+
-- This way, we can accept arbitrary parsers for line comments, which is useful for our use case, as
5+
-- just adding `//` as a line comment would make the parser ignore documentation comments `///`.
6+
-- Original at
7+
-- https://hackage.haskell.org/package/parsec-3.1.14.0/docs/src/Text.Parsec.Language.html#emptyDef
8+
-- -------------------------------------------------------------------------------------------------
9+
10+
-- |
11+
-- Module : Text.Parsec.Language
12+
-- Copyright : (c) Daan Leijen 1999-2001, (c) Paolo Martini 2007
13+
-- License : BSD-style (see the LICENSE file)
14+
--
15+
-- Maintainer : derek.a.elkins@gmail.com
16+
-- Stability : provisional
17+
-- Portability : non-portable (uses non-portable module Text.Parsec.Token)
18+
--
19+
-- A helper module that defines some language definitions that can be used
20+
-- to instantiate a token parser (see "Text.Parsec.Token").
21+
module Wasp.Psl.Parser.Common.Language
22+
( emptyDef,
23+
)
24+
where
25+
26+
import Control.Monad (void)
27+
import Text.Parsec
28+
import Wasp.Psl.Parser.Common.Token
29+
30+
-----------------------------------------------------------
31+
-- minimal language definition
32+
--------------------------------------------------------
33+
34+
-- | This is the most minimal token definition. It is recommended to use
35+
-- this definition as the basis for other definitions. @emptyDef@ has
36+
-- no reserved names or operators, is case sensitive and doesn't accept
37+
-- comments, identifiers or operators.
38+
emptyDef :: LanguageDef st
39+
emptyDef =
40+
LanguageDef
41+
{ commentLine = void $ string "//",
42+
nestedComments = True,
43+
identStart = letter <|> char '_',
44+
identLetter = alphaNum <|> oneOf "_'",
45+
opStart = opLetter emptyDef,
46+
opLetter = oneOf ":!#$%&*+./<=>?@\\^|-~",
47+
reservedOpNames = [],
48+
reservedNames = [],
49+
caseSensitive = True
50+
}

0 commit comments

Comments
 (0)