Skip to content

Commit

Permalink
Merge pull request #1129 from layus/fix-comments
Browse files Browse the repository at this point in the history
Fix comments parsing
  • Loading branch information
edolstra committed Nov 14, 2016
2 parents dd77f7d + a5e761d commit b8d9616
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/libexpr/lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ or { return OR_KW; }

[ \t\r\n]+ /* eat up whitespace */
\#[^\r\n]* /* single-line comments */
\/\*([^*]|\*[^\/])*\*\/ /* long comments */
\/\*([^*]|\*+[^*/])*\*+\/ /* long comments */

. return yytext[0];

Expand Down
1 change: 1 addition & 0 deletions tests/lang/eval-okay-comments.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"abcdefghijklmnopqrstuvwxyz"
59 changes: 59 additions & 0 deletions tests/lang/eval-okay-comments.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# A simple comment
"a"+ # And another
## A double comment
"b"+ ## And another
# Nested # comments #
"c"+ # and # some # other #
# An empty line, following here:

"d"+ # and a comment not starting the line !

"e"+
/* multiline comments */
"f" +
/* multiline
comments,
on
multiple
lines
*/
"g" +
# Small, tricky comments
/**/ "h"+ /*/*/ "i"+ /***/ "j"+ /* /*/ "k"+ /*/* /*/ "l"+
# Comments with an even number of ending '*' used to fail:
"m"+
/* */ /* **/ /* ***/ /* ****/ "n"+
/* */ /** */ /*** */ /**** */ "o"+
/** **/ /*** ***/ /**** ****/ "p"+
/* * ** *** **** ***** */ "q"+
# Random comments
/* ***** ////// * / * / /* */ "r"+
# Mixed comments
/* # */
"s"+
# /* #
"t"+
# /* # */
"u"+
# /*********/
"v"+
## */*
"w"+
/*
* Multiline, decorated comments
* # This ain't a nest'd comm'nt
*/
"x"+
''${/** with **/"y"
# real
/* comments
inside ! # */
# (and empty lines)
}''+ /* And a multiline comment,
on the same line,
after some spaces
*/ # followed by a one-line comment
"z"
/* EOF */

0 comments on commit b8d9616

Please sign in to comment.