Skip to content

Commit

Permalink
[ #376 ] C/Ocaml: do not include CR in line-comment regex
Browse files Browse the repository at this point in the history
However, I am not sure that changes anything, at least not on LF or
CR/LF systems.
  • Loading branch information
andreasabel committed Aug 26, 2021
1 parent d71ff33 commit 1ee2889
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions source/src/BNFC/Backend/C/CFtoFlexC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ lexChars yylval charToken =
-- delimiters.
--
-- >>> lexComments ([("{-","-}")],["--"])
-- <INITIAL>"--"[^\n]* /* skip */; /* BNFC: comment "--" */
-- <INITIAL>"--"[^\n\r]* /* skip */; /* BNFC: comment "--" */
-- <INITIAL>"{-" BEGIN COMMENT; /* BNFC: block comment "{-" "-}" */
-- <COMMENT>"-}" BEGIN INITIAL;
-- <COMMENT>. /* skip */;
Expand All @@ -305,13 +305,13 @@ commentStates = map ("COMMENT" ++) $ "" : map show [1..]
-- comment.
--
-- >>> lexSingleComment "--"
-- <INITIAL>"--"[^\n]* /* skip */; /* BNFC: comment "--" */
-- <INITIAL>"--"[^\n\r]* /* skip */; /* BNFC: comment "--" */
--
-- >>> lexSingleComment "\""
-- <INITIAL>"\""[^\n]* /* skip */; /* BNFC: comment "\"" */
-- <INITIAL>"\""[^\n\r]* /* skip */; /* BNFC: comment "\"" */
lexSingleComment :: String -> Doc
lexSingleComment c =
"<INITIAL>" <> cstring c <> "[^\\n]*"
"<INITIAL>" <> cstring c <> "[^\\n\\r]*"
<+> "/* skip */;"
<+> unless (containsCCommentMarker c) ("/* BNFC: comment" <+> cstring c <+> "*/")

Expand Down
6 changes: 3 additions & 3 deletions source/src/BNFC/Backend/OCaml/CFtoOCamlLex.hs
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ mkRule entrypoint (r:rs) = vcat

-- | Create regex for single line comments
-- >>> mkRegexSingleLineComment "--"
-- "--" (_ # '\n')*
-- "--" [^ '\n' '\r']*
-- >>> mkRegexSingleLineComment "\""
-- "\"" (_ # '\n')*
-- "\"" [^ '\n' '\r']*
mkRegexSingleLineComment :: String -> Doc
mkRegexSingleLineComment s = cstring s <+> "(_ # '\\n')*"
mkRegexSingleLineComment s = cstring s <+> "[^ '\\n' '\\r']*"

-- | Create regex for multiline comments.
-- >>> mkRegexMultilineComment "<!--" "-->"
Expand Down

0 comments on commit 1ee2889

Please sign in to comment.