Browse Source

Added support for Perl quote-like operators to fix #1101

Matthew D. Miller 6 năm trước cách đây
mục cha
commit
40fdb5d594
1 tập tin đã thay đổi với 71 bổ sung1 xóa
  1. 71 1
      src/perl/perl.ts

+ 71 - 1
src/perl/perl.ts

@@ -469,12 +469,13 @@ export const language = <ILanguage>{
 			{ include: '@whitespace' },
 
 			[
-				/[a-zA-Z\-_][\w\-_]+/,
+				/[a-zA-Z\-_][\w\-_]*/,
 				{
 					cases: {
 						'@keywords': 'keyword',
 						'@builtinFunctions': 'type.identifier',
 						'@builtinFileHandlers': 'variable.predefined',
+						'@quoteLikeOps': { token: '@rematch', next: 'quotedConstructs' },
 						'@default': '',
 					},
 				},
@@ -547,6 +548,75 @@ export const language = <ILanguage>{
 			[/./, 'string'],
 		],
 
+		// Quoted constructs
+		// Percent strings in Ruby are similar to quote-like operators in Perl.
+		// This is adapted from pstrings in ../ruby/ruby.ts.
+		quotedConstructs: [
+			[/(q|qw|tr|y)\s*\(/, { token: 'string.delim', switchTo: '@qstring.(.)' }],
+			[/(q|qw|tr|y)\s*\[/, { token: 'string.delim', switchTo: '@qstring.[.]' }],
+			[/(q|qw|tr|y)\s*\{/, { token: 'string.delim', switchTo: '@qstring.{.}' }],
+			[/(q|qw|tr|y)\s*</, { token: 'string.delim', switchTo: '@qstring.<.>' }],
+			[/(q|qw|tr|y)#/, { token: 'string.delim', switchTo: '@qstring.#.#' }],
+			[/(q|qw|tr|y)\s*([^A-Za-z0-9#\s])/, { token: 'string.delim', switchTo: '@qstring.$2.$2' }],
+			[/(q|qw|tr|y)\s+(\w)/, { token: 'string.delim', switchTo: '@qstring.$2.$2' }],
+
+			[/(qr|m|s)\s*\(/, { token: 'regexp.delim', switchTo: '@qregexp.(.)' }],
+			[/(qr|m|s)\s*\[/, { token: 'regexp.delim', switchTo: '@qregexp.[.]' }],
+			[/(qr|m|s)\s*\{/, { token: 'regexp.delim', switchTo: '@qregexp.{.}' }],
+			[/(qr|m|s)\s*</, { token: 'regexp.delim', switchTo: '@qregexp.<.>' }],
+			[/(qr|m|s)#/, { token: 'regexp.delim', switchTo: '@qregexp.#.#' }],
+			[/(qr|m|s)\s*([^A-Za-z0-9_#\s])/, { token: 'regexp.delim', switchTo: '@qregexp.$2.$2' }],
+			[/(qr|m|s)\s+(\w)/, { token: 'regexp.delim', switchTo: '@qregexp.$2.$2' }],
+
+			[/(qq|qx)\s*\(/, { token: 'string.delim', switchTo: '@qqstring.(.)' }],
+			[/(qq|qx)\s*\[/, { token: 'string.delim', switchTo: '@qqstring.[.]' }],
+			[/(qq|qx)\s*\{/, { token: 'string.delim', switchTo: '@qqstring.{.}' }],
+			[/(qq|qx)\s*</, { token: 'string.delim', switchTo: '@qqstring.<.>' }],
+			[/(qq|qx)#/, { token: 'string.delim', switchTo: '@qqstring.#.#' }],
+			[/(qq|qx)\s*([^A-Za-z0-9#\s])/, { token: 'string.delim', switchTo: '@qqstring.$2.$2' }],
+			[/(qq|qx)\s+(\w)/, { token: 'string.delim', switchTo: '@qqstring.$2.$2' }],
+		],
+
+		// Non-expanded quoted string
+		// qstring<open>.<close>
+		//  open = open delimiter
+		//  close = close delimiter
+		qstring: [
+			[/\\./, 'string.escape'],
+			[/./, {
+				cases: {
+					'$#==$S3': { token: 'string.delim', next: '@pop' },
+					'$#==$S2': { token: 'string.delim', next: '@push' }, // nested delimiters
+					'@default': 'string'
+				}
+			}],
+		],
+
+    // Quoted regexp
+		// qregexp.<open>.<close>
+		//  open = open delimiter
+		//  close = close delimiter
+		qregexp: [
+			{ include: '@variables' },
+			[/\\./, 'regexp.escape'],
+			[/./, {
+				cases: {
+					'$#==$S3': { token: 'regexp.delim', next: '@pop' },
+					'$#==$S2': { token: 'regexp.delim', next: '@push' }, // nested delimiters
+					'@default': 'regexp'
+				}
+			}],
+		],
+		
+		// Expanded quoted string
+		// qqstring.<open>.<close>
+		//  open = open delimiter
+		//  close = close delimiter
+		qqstring: [
+			{ include: '@variables' },
+			{ include: '@qstring' },
+		],
+
 		heredoc: [
 			[
 				/<<\s*['"`]?([\w\-]+)['"`]?/,