Browse Source

[clojure] Add a word boundary to ensure exact matches for `(comment ...)`.

Abdussalam Abdurrahman 6 years ago
parent
commit
c77f11b1b0
2 changed files with 26 additions and 2 deletions
  1. 24 0
      src/clojure/clojure.test.ts
  2. 2 2
      src/clojure/clojure.ts

+ 24 - 0
src/clojure/clojure.test.ts

@@ -792,6 +792,30 @@ testTokenization('clojure', [
 				{startIndex: 0, type: 'comment.clj'},
 			],
 		},
+		{
+			line: '(comments foo bar)',
+			tokens: [
+				{startIndex: 0, type: 'delimiter.parenthesis.clj'},
+				{startIndex: 1, type: 'identifier.clj'},
+				{startIndex: 9, type: 'white.clj'},
+				{startIndex: 10, type: 'identifier.clj'},
+				{startIndex: 13, type: 'white.clj'},
+				{startIndex: 14, type: 'identifier.clj'},
+				{startIndex: 17, type: 'delimiter.parenthesis.clj'},
+			]
+		},
+		{
+			line: '(comment6 foo bar)',
+			tokens: [
+				{startIndex: 0, type: 'delimiter.parenthesis.clj'},
+				{startIndex: 1, type: 'identifier.clj'},
+				{startIndex: 9, type: 'white.clj'},
+				{startIndex: 10, type: 'identifier.clj'},
+				{startIndex: 13, type: 'white.clj'},
+				{startIndex: 14, type: 'identifier.clj'},
+				{startIndex: 17, type: 'delimiter.parenthesis.clj'},
+			]
+		},
 		{
 			line: '(comment foo',
 			tokens: [

+ 2 - 2
src/clojure/clojure.ts

@@ -762,13 +762,13 @@ export const language = <ILanguage>{
 		whitespace: [
 			[/\s+/, 'white'],
 			[/;.*$/, 'comment'],
-			[/\(comment/, 'comment', '@comment'],
+			[/\(comment\b/, 'comment', '@comment'],
 		],
 
 		comment: [
 			[/\(/, 'comment', '@push'],
 			[/\)/, 'comment', '@pop'],
-			[/[^)]/, 'comment'],
+			[/[^()]/, 'comment'],
 		],
 
 		string: [