Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment Parser #48

Merged
merged 4 commits into from
Jan 21, 2015
Merged

Comment Parser #48

merged 4 commits into from
Jan 21, 2015

Conversation

IanWold
Copy link
Contributor

@IanWold IanWold commented Jan 20, 2015

I wanted to share my solution to the problem discussed in this issue regarding comment parsing. I created this CommentParser class, which provides the user with a few comment parsers which will work with whichever headers they require. I removed the EndOfLineComment parser in Parse.Primitives.cs (as this CommentParser class achieves the same goal), and updated AssemblerTests to use the CommentParser class instead of that EndOfLineComment parser. I also modified the Xml Example to parse and ignore comments using CommentParser, so as to demonstrate the use of the class.

Added CommentParser class to construct custom single and multi-line
comment parsers.

* Updated AssemblerTests.cs to use new CommentParser class.
* Removed EndOfLineComment in Parse.Primitives.cs
Creates an interface for CommentParser.
Adds comments to XmlExample to demonstrate CommentParser class.
@gordonwatts
Copy link

This is pretty cool. For single line comments I note that a number of languages have multiple characters (I've dealt with some that have # and "//" for example). Could that be made an array?

The other approach is to have a set of primitives that take the comment as an argument... so, for example,

Parser<string> SingleLineComment (string startOfComment) {...

or similar.

@mikehadlow
Copy link
Collaborator

Many thanks for this.

mikehadlow added a commit that referenced this pull request Jan 21, 2015
@mikehadlow mikehadlow merged commit 0a84be6 into sprache:master Jan 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants