Skip to content

Instantly share code, notes, and snippets.

@takahisa
Created August 3, 2014 12:44
Show Gist options
  • Save takahisa/2f3fc4ff961900c568e9 to your computer and use it in GitHub Desktop.
Save takahisa/2f3fc4ff961900c568e9 to your computer and use it in GitHub Desktop.
comment
var any = Chars.Any();
var newline = Combinator.Choice(Chars.Sequence("\u000d\u000a"),
Chars.Sequence("\u000d"),
Chars.Sequence("\u000a"))
.Ignore();
var lineCommentBegin = Chars.Sequence("//");
var lineComment = lineCommentBegin
.Right(Flows.Until(any, eof.Or(newline)))
.Ignore();
Parser<Char, Unit> blockCommentImpl = null;
var blockCommentBegin = Chars.Sequence("/*");
var blockCommentEnd = Chars.Sequence("*/");
var blockComment = Combinator.Lazy(() => blockCommentImpl);
var blockCommentRest = blockCommentBegin.Not().Right(blockCommentEnd.Not()).Right(any.Ignore())
.Or(blockComment);
var comment = lineComment.Or(blockComment);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment