Skip to content

Commit

Permalink
Improve support for comments in ReasonML lexer (#1641)
Browse files Browse the repository at this point in the history
The ReasonML lexer does not properly lex single-line comments (those
that begin with `//`) or certain types of multi-line comments. This
commit addresses those errors.

Co-authored-by: Michael Camilleri <mike@inqk.net>
  • Loading branch information
amiralies and pyrmont authored Dec 8, 2020
1 parent da7aa9a commit 19da95a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/rouge/lexers/reasonml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def self.keywords
rule %r/#{@@upper_id}(?=\s*[.])/, Name::Namespace, :dotted
rule %r/`#{@@id}/, Name::Tag
rule @@upper_id, Name::Class
rule %r/[\/][*](?![\/])/, Comment, :comment
rule %r(//.*), Comment::Single
rule %r(/\*), Comment::Multiline, :comment
rule @@id do |m|
match = m[0]
if self.class.keywords.include? match
Expand Down Expand Up @@ -55,10 +56,10 @@ def self.keywords
end

state :comment do
rule %r|[^/*)]+|, Comment
rule %r|[/][*]|, Comment, :push
rule %r|[*][/]|, Comment, :pop!
rule %r|[*/]|, Comment
rule %r([^/*]+), Comment::Multiline
rule %r(/\*), Comment::Multiline, :comment
rule %r(\*/), Comment::Multiline, :pop!
rule %r([*/]), Comment::Multiline
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/visual/samples/reasonml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
let x = 6 // This is single line comment

let c: char = 'A'; /* comment with link https://example and - = */

let respond_no_content = reqd => {
Expand Down Expand Up @@ -43,6 +45,8 @@ let ignore: 'a => unit = _ => ();
/* comment ****/
/* comment *****/

// A single line comment

let testingNotQuiteEndOfLineComments = [
"Item 1" /* Comment For First Item */,
"Item 2" /* Comment For Second Item */,
Expand Down

0 comments on commit 19da95a

Please sign in to comment.