From 19da95a03beec37a9fa8a4d4a3a3b8b1a3ed8d0e Mon Sep 17 00:00:00 2001 From: Amirali Esmaeili Date: Tue, 8 Dec 2020 23:07:32 +0330 Subject: [PATCH] Improve support for comments in ReasonML lexer (#1641) 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 --- lib/rouge/lexers/reasonml.rb | 11 ++++++----- spec/visual/samples/reasonml | 4 ++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/rouge/lexers/reasonml.rb b/lib/rouge/lexers/reasonml.rb index 9bdd543e75..07c9f6c4e1 100644 --- a/lib/rouge/lexers/reasonml.rb +++ b/lib/rouge/lexers/reasonml.rb @@ -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 @@ -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 diff --git a/spec/visual/samples/reasonml b/spec/visual/samples/reasonml index cb5ff947f1..c246beb9b2 100644 --- a/spec/visual/samples/reasonml +++ b/spec/visual/samples/reasonml @@ -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 => { @@ -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 */,