mirror of
https://github.com/gren-lang/compiler.git
synced 2024-09-11 08:45:42 +03:00
Add comments to the whitespace parser type signature
This commit is contained in:
parent
89677a5ccb
commit
eff5b1c6b1
@ -1,7 +1,8 @@
|
||||
{-# OPTIONS_GHC -Wall #-}
|
||||
|
||||
module AST.Source
|
||||
( Expr,
|
||||
( Comment (..),
|
||||
Expr,
|
||||
Expr_ (..),
|
||||
VarType (..),
|
||||
Def (..),
|
||||
@ -38,6 +39,15 @@ import qualified Gren.String as ES
|
||||
import qualified Parse.Primitives as P
|
||||
import qualified Reporting.Annotation as A
|
||||
|
||||
-- COMMENTS
|
||||
|
||||
data Comment
|
||||
= BlockComment [ES.String]
|
||||
| LineComment ES.String
|
||||
| CommentTrickOpener
|
||||
| CommentTrickCloser
|
||||
| CommentTrickBlock ES.String
|
||||
|
||||
-- EXPRESSIONS
|
||||
|
||||
type Expr = A.Located Expr_
|
||||
|
@ -153,11 +153,12 @@ addComment maybeComment (A.At _ name) comments =
|
||||
|
||||
-- FRESH LINES
|
||||
|
||||
freshLine :: (Row -> Col -> E.Module) -> Parser E.Module ()
|
||||
freshLine :: (Row -> Col -> E.Module) -> Parser E.Module [Src.Comment]
|
||||
freshLine toFreshLineError =
|
||||
do
|
||||
Space.chomp E.ModuleSpace
|
||||
comments <- Space.chomp E.ModuleSpace
|
||||
Space.checkFreshLine toFreshLineError
|
||||
return comments
|
||||
|
||||
-- CHOMP DECLARATIONS
|
||||
|
||||
@ -186,7 +187,7 @@ chompInfixes infixes =
|
||||
chompModuleDocCommentSpace :: Parser E.Module (Either A.Region Src.DocComment)
|
||||
chompModuleDocCommentSpace =
|
||||
do
|
||||
(A.At region ()) <- addLocation (freshLine E.FreshLine)
|
||||
(A.At region comments) <- addLocation (freshLine E.FreshLine)
|
||||
oneOfWithFallback
|
||||
[ do
|
||||
docComment <- Space.docComment E.ImportStart E.ModuleSpace
|
||||
@ -329,7 +330,7 @@ chompSubscription =
|
||||
spaces_em
|
||||
addLocation (Var.upper E.Effect)
|
||||
|
||||
spaces_em :: Parser E.Module ()
|
||||
spaces_em :: Parser E.Module [Src.Comment]
|
||||
spaces_em =
|
||||
Space.chompAndCheckIndent E.ModuleSpace E.Effect
|
||||
|
||||
|
@ -33,14 +33,14 @@ type Parser x a =
|
||||
|
||||
-- CHOMP
|
||||
|
||||
chomp :: (E.Space -> Row -> Col -> x) -> P.Parser x ()
|
||||
chomp :: (E.Space -> Row -> Col -> x) -> P.Parser x [Src.Comment]
|
||||
chomp toError =
|
||||
P.Parser $ \(P.State src pos end indent row col) cok _ cerr _ ->
|
||||
let (# status, newPos, newRow, newCol #) = eatSpaces pos end row col
|
||||
in case status of
|
||||
Good ->
|
||||
let !newState = P.State src newPos end indent newRow newCol
|
||||
in cok () newState
|
||||
in cok [] {-TODO-} newState
|
||||
HasTab -> cerr newRow newCol (toError E.HasTab)
|
||||
EndlessMultiComment -> cerr newRow newCol (toError E.EndlessMultiComment)
|
||||
|
||||
@ -69,7 +69,7 @@ checkFreshLine toError =
|
||||
|
||||
-- CHOMP AND CHECK
|
||||
|
||||
chompAndCheckIndent :: (E.Space -> Row -> Col -> x) -> (Row -> Col -> x) -> P.Parser x ()
|
||||
chompAndCheckIndent :: (E.Space -> Row -> Col -> x) -> (Row -> Col -> x) -> P.Parser x [Src.Comment]
|
||||
chompAndCheckIndent toSpaceError toIndentError =
|
||||
P.Parser $ \(P.State src pos end indent row col) cok _ cerr _ ->
|
||||
let (# status, newPos, newRow, newCol #) = eatSpaces pos end row col
|
||||
@ -78,7 +78,7 @@ chompAndCheckIndent toSpaceError toIndentError =
|
||||
if newCol > indent && newCol > 1
|
||||
then
|
||||
let !newState = P.State src newPos end indent newRow newCol
|
||||
in cok () newState
|
||||
in cok [] {-TODO-} newState
|
||||
else cerr row col toIndentError
|
||||
HasTab -> cerr newRow newCol (toSpaceError E.HasTab)
|
||||
EndlessMultiComment -> cerr newRow newCol (toSpaceError E.EndlessMultiComment)
|
||||
|
@ -36,6 +36,9 @@ Flag dev {
|
||||
Common gren-common
|
||||
if flag(dev)
|
||||
ghc-options: -O0 -Wall -Werror
|
||||
|
||||
-- temporary while implementing gren format
|
||||
ghc-options: -Wno-error=unused-do-bind -Wno-error=unused-matches
|
||||
else
|
||||
ghc-options: -O2 -threaded "-with-rtsopts=-N"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user