Skip to content

Commit

Permalink
Merge pull request #89 from wisn/improve-comment
Browse files Browse the repository at this point in the history
Improve parser for block-comment
  • Loading branch information
gdotdesign authored Sep 5, 2018
2 parents e207159 + a7b20c9 commit 9b646ed
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
9 changes: 9 additions & 0 deletions spec/parsers/comment_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "../spec_helper"

describe "Block Comment" do
subject comment

expect_ok "/*\n Block Comment\n */"
expect_ok "/*!\n * Block Comment\n */"
expect_ok "/* Block comment with EOF"
end
10 changes: 10 additions & 0 deletions src/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ module Mint
@position += 1
end

def eof? : Bool
@position == input.size
end

# Helpers for raising errors
# ----------------------------------------------------------------------------

Expand Down Expand Up @@ -130,6 +134,12 @@ module Mint
raise error unless keyword(word)
end

def keyword_ahead(word) : Bool
result = input[position, word.size]

result == word
end

def keyword(word) : Bool
result = input[position, word.size]
if result == word
Expand Down
4 changes: 2 additions & 2 deletions src/parsers/comment.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module Mint
skip unless keyword "/*"

value =
gather { consume_while(char != '*' || char == '\0') }.to_s
gather { consume_while((!(keyword_ahead "*/") || char == '\0') && !eof?) }.to_s

keyword! "*/", SyntaxError
keyword "*/"
whitespace

Ast::Comment.new(
Expand Down

0 comments on commit 9b646ed

Please sign in to comment.