Browse Source

Improves scope names. Fixes/improves expression handling

slonon 4 năm trước cách đây
mục cha
commit
5eb9b2dc6b
1 tập tin đã thay đổi với 144 bổ sung89 xóa
  1. 144 89
      extensions/qsrc/syntaxes/QSP.tmLanguage.json

+ 144 - 89
extensions/qsrc/syntaxes/QSP.tmLanguage.json

@@ -31,10 +31,10 @@
 					"match": "(?:^|\\s?[&])\\s*((!!?)[^{'\"]*?$\\n?)",
 					"captures": {
 						"1": {
-							"name": "comment.line.exclamation.qsp"
+							"name": "comment.line.qsp"
 						},
 						"2": {
-							"name": "comment.punctuation.exclamation"
+							"name": "punctuation.definition.comment.qsp"
 						}
 					}
 				},
@@ -42,13 +42,16 @@
 					"comment": "comments with multiline chars",
 					"begin": "(?:^|\\s?[&])\\s*(!!?)",
 					"beginCaptures": {
+						"0": {
+							"name": "comment.block.qsp"
+						},
 						"1": {
-							"name": "comment.punctuation.exclamation"
+							"name": "punctuation.definition.comment.qsp"
 						}
 					},
 					"patterns": [
 						{
-							"name": "comment.block",
+							"name": "comment.block.qsp",
 							"match": "\\G",
 							"include": "#comment-block"
 						}
@@ -62,7 +65,7 @@
 					"match": "(\\s*[^{'\"]*)(?=$)",
 					"captures": {
 						"1": {
-							"name": "comment.block.text"
+							"name": "comment.block.text.qsp"
 						}
 					}
 				},
@@ -76,11 +79,12 @@
 					"match": "(\\s*[^{'\"]*)(?!$)",
 					"captures": {
 						"1": {
-							"name": "comment.block.text"
+							"name": "comment.block.text.qsp"
 						}
 					}
 				},
 				{
+					"comment": "continue parsing after the comment ends",
 					"begin": "($\\n?)",
 					"pattern": {
 						"match": "\\G",
@@ -90,12 +94,12 @@
 			]
 		},
 		"comment-block-quote": {
-			"name": "comment.block.quote",
+			"name": "comment.block.quote.qsp",
 			"begin": "('|\")",
 			"end": "(\\1)"
 		},
 		"comment-block-bracket-curly": {
-			"name": "comment.block.bracket.curly",
+			"name": "comment.block.bracket.curly.qsp",
 			"begin": "[{]",
 			"patterns": [
 				{
@@ -114,7 +118,7 @@
 					"include": "#comments"
 				},
 				{
-					"include": "#strings"
+					"include": "#pairs"
 				},
 				{
 					"include": "#qsp-control-structures"
@@ -141,15 +145,12 @@
 				},
 				{
 					"include": "#loops"
-				},
-				{
-					"include": "#qsp-line"
 				}
 			]
 		},
 		"qsp-code-block": {
 			"comment": "code blocks for this language, only possible for 'act' or 'if'",
-			"name": "meta.structure.qsp.codeblock",
+			"name": "meta.structure.codeblock.qsp",
 			"patterns": [
 				{
 					"include": "#qsp-code-block-if"
@@ -160,7 +161,7 @@
 			]
 		},
 		"qsp-code-block-if": {
-			"name": "meta.structure.qsp.codeblock.if",
+			"name": "meta.structure.codeblock.if.qsp",
 			"begin": "^\\s*(?i:(if))\\b(.*\\S.*)(:)\\s*$\\n?",
 			"beginCaptures": {
 				"1": {
@@ -178,7 +179,7 @@
 					]
 				},
 				"3": {
-					"name": "punctuation.condition.if.qsp"
+					"name": "punctuation.separator.if.qsp"
 				}
 			},
 			"patterns": [
@@ -199,7 +200,7 @@
 			}
 		},
 		"qsp-code-block-act": {
-			"name": "meta.structure.qsp.codeblock.act",
+			"name": "meta.structure.codeblock.act.qsp",
 			"begin": "^\\s*(?i:(act))\\b(.*\\S.*)(:)\\s*$\\n?",
 			"beginCaptures": {
 				"1": {
@@ -210,7 +211,6 @@
 					]
 				},
 				"2": {
-					"name": "meta.act-condition.expression.qsp",
 					"patterns": [
 						{
 							"include": "#qsp-general-structures"
@@ -218,7 +218,7 @@
 					]
 				},
 				"3": {
-					"name": "punctuation.condition.act.qsp"
+					"name": "punctuation.separator.act.qsp"
 				}
 			},
 			"patterns": [
@@ -246,24 +246,13 @@
 				}
 			]
 		},
-		"qsp-line": {
-			"comment": "a line containing expesstions",
-			"name": "meta.structure.line.qsp",
-			"match": "(^\\s*(?i:if|act).*(?![:]\\s*)$\\n?)",
-			"captures": {
-				"1": {
-					"patterns": [
-						{
-							"include": "#qsp-expression"
-						}
-					]
-				}
-			}
-		},
 		"qsp-expression": {
 			"comment": "basically 'act' or 'if' expressions",
-			"name": "meta.structure.qsp.expression",
+			"name": "meta.structure.expression.qsp",
 			"patterns": [
+				{
+					"include": "#pairs"
+				},
 				{
 					"include": "#qsp-expression-if"
 				},
@@ -271,14 +260,14 @@
 					"include": "#qsp-expression-act"
 				},
 				{
-					"include": "#expression"
+					"include": "#single-words"
 				}
 			]
 		},
 		"qsp-expression-if": {
 			"patterns": [
 				{
-					"begin": "(?:^|[:]|&)\\s*\\b(?i:(if))\\b",
+					"begin": "\\s*\\b(?i:(if))\\b",
 					"beginCaptures": {
 						"1": {
 							"patterns": [
@@ -288,25 +277,22 @@
 							]
 						}
 					},
-					"end": "(?=([:]))",
+					"end": "([:])",
 					"endCaptures": {
 						"1": {
-							"name": "punctuation.expression.if.qsp"
+							"name": "punctuation.separator.if.qsp"
 						}
 					},
 					"patterns": [
 						{
-							"include": "#if-condition"
+							"include": "#qsp-expression"
 						}
 					]
 				},
 				{
-					"begin": "(?:[:])\\s*(.?\\S+.*)\\b(?i:(elseif))\\b",
+					"begin": "\\s*\\b(?i:(elseif))\\b",
 					"beginCaptures": {
-						"1":{
-							"patterns": [{"include": "#expression"}]
-						},
-						"2": {
+						"1": {
 							"patterns": [
 								{
 									"include": "#keywords-if"
@@ -317,46 +303,32 @@
 					"end": "(?=([:]))",
 					"endCaptures": {
 						"1": {
-							"name": "punctuation.expression.if.qsp"
+							"name": "punctuation.separator.if.qsp"
 						}
 					},
 					"patterns": [
 						{
-							"include": "#if-condition"
+							"include": "#qsp-expression"
 						}
 					]
 				},
 				{
-					"name":"meta.structure.line.else.qsp",
-					"begin": "(?:([:]))\\s*(.?\\S+.*)\\b(?i:(else))\\b",
-					"beginCaptures": {
+					"match": "\\s*\b(?i:(else))\\b",
+					"captures": {
 						"1": {
-							"name": "punctuation.expression.qsp"
-						},
-						"2":{
-							"patterns": [{"include": "#expression"}]
-						},
-						"3": {
 							"patterns": [
 								{
 									"include": "#keywords-if"
 								}
 							]
 						}
-					},
-					"end": "(?=[&]|$\\n?)",
-					"patterns": [
-						{
-							"include": "#expression"
-						}
-					]
+					}
 				}
 			]
 		},
 		"qsp-expression-act": {
 			"comment": "parse single line act",
-			"name": "meta.line.act.qsp",
-			"begin": "(?:^|[:]|&)\\s*\\b(?i:(act))\\b",
+			"begin": "\\s*\\b(?i:(act))\\b",
 			"beginCaptures": {
 				"1": {
 					"patterns": [
@@ -366,30 +338,27 @@
 					]
 				}
 			},
-			"end": "(?=([:]))",
+			"end": "([:])",
 			"endCaptures": {
 				"1": {
-					"name": "punctuation.expression.act.qsp"
+					"name": "punctuation.separator.act.qsp"
 				}
 			},
 			"patterns": [
 				{
-					"include": "#if-condition"
+					"include": "#qsp-expression"
 				}
 			]
 		},
 		"loops": {
 			"comment": "loop parsing",
-			"name": "meta.loop.qsp",
+			"name": "meta.structure.line.loop.qsp",
 			"patterns": [
 				{
 					"match": "^\\s*(:)\\s?(.+?)\\s*$\\n?",
 					"captures": {
-						"0": {
-							"name": "meta.loop-start.qsp"
-						},
 						"1": {
-							"name": "punctuation.loop.qsp"
+							"name": "punctuation.separator.loop.qsp"
 						},
 						"2": {
 							"name": "keyword.other.user.loop.qsp"
@@ -399,11 +368,10 @@
 				{
 					"match": "\\b(?i:(jump))\\s?(['][a-zA-Z_][a-zA-Z0-9_]*?['])",
 					"captures": {
-						"0": {
-							"name": "meta.loop-jump.qsp"
-						},
 						"1": {
-							"name": "keyword.control.jump.qsp"
+							"patterns": [
+								{"include": "#keywords-loop"}
+							]
 						},
 						"2": {
 							"name": "keyword.other.user.loop.end.qsp"
@@ -412,35 +380,114 @@
 				}
 			]
 		},
+		"pairs":{
+			"patterns": [
+				{"include": "#strings"},
+				{
+					"begin": "(\\[)",
+					"beginCaptures": {
+						"1":{"name":"punctuation.brackets.square.open.qsp"}
+					},
+					"end": "(\\])",
+					"endCaptures": {
+						"1":{"name":"punctuation.brackets.square.close.qsp"}
+					},
+					"patterns": [
+						{"include": "#qsp-general-structures"}
+					]
+				},
+				{
+					"begin": "([{])",
+					"beginCaptures": {
+						"1":{"name":"punctuation.brackets.curly.open.qsp"}
+					},
+					"end": "([}])",
+					"endCaptures": {
+						"1":{"name":"punctuation.brackets.curly.close.qsp"}
+					},
+					"patterns": [
+						{"include": "#qsp-general-structures"}
+					]
+				},
+				{
+					"begin": "([(])",
+					"beginCaptures": {
+						"1":{"name":"punctuation.brackets.round.open.qsp"}
+					},
+					"end": "([)])",
+					"endCaptures": {
+						"1":{"name":"punctuation.brackets.round.close.qsp"}
+					},
+					"patterns": [
+						{"include": "#qsp-general-structures"}
+					]
+				}
+			]
+		},
 		"strings": {
 			"comment": "parse string and their inlines",
 			"patterns": [
 				{
-					"name": "string.quoted.double.qsp",
-					"begin": "\"",
-					"end": "\"",
+					"begin": "(\")",
+					"beginCaptures": {
+						"0":{"name":"string.quoted.double.qsp"},
+						"1":{"name":"punctuation.definition.string.begin.qsp"}
+					},
+					"end": "(\")",
+					"endCaptures": {
+						"0":{"name":"string.quoted.double.qsp"},
+						"1":{"name":"punctuation.definition.string.end.qsp"}
+					},
 					"patterns": [
 						{
 							"include": "#stringInterpolated"
+						},
+						{
+							"match": ".",
+							"name": "string.quoted.double.qsp"
 						}
 					]
 				},
 				{
-					"name": "string.quoted.single.qsp",
-					"begin": "'",
-					"end": "'",
+					"begin": "(')",
+					"beginCaptures": {
+						"0":{"name":"string.quoted.single.qsp"},
+						"1":{"name":"punctuation.definition.string.begin.qsp"}
+					},
+					"end": "(')",
+					"endCaptures": {
+						"0":{"name":"string.quoted.single.qsp"},
+						"1":{"name":"punctuation.definition.string.end.qsp"}
+					},
 					"patterns": [
 						{
 							"include": "#stringInterpolated"
+						},
+						{
+							"comment": "//TODO: html parsing, default doesn't work due to inline code: 'include': 'text.html.basic'"
+						},
+						{
+							"match": ".",
+							"name": "string.quoted.single.qsp"
 						}
 					]
 				}
 			]
 		},
 		"stringInterpolated": {
-			"name": "string.interpolated.qsp",
-			"begin": "<<",
-			"end": ">>",
+			"name":"meta.interpolation.qsp",
+			"begin": "(<<)",
+			"beginCaptures": {
+				"1":{
+					"name":"punctuation.definition.stringinterpolation.qsp"
+				}
+			},
+			"end": "(>>)",
+			"endCaptures": {
+				"1":{
+					"name":"punctuation.definition.stringinterpolation.qsp"
+				}
+			},
 			"patterns": [
 				{
 					"include": "#qsp-general-structures"
@@ -463,7 +510,7 @@
 			"match": "\\s*(?i:(elseif))\\b\\s*(.?\\S.*?)(:)\\s*$\\n?",
 			"captures": {
 				"0": {
-					"name": "meta.structure.qsp.codeblock.if.elseif"
+					"name": "meta.structure.qsp.codeblock.if.elseif.qsp"
 				},
 				"1": {
 					"patterns": [
@@ -489,7 +536,7 @@
 			"match": "^\\s*(?i:(else))\\s*$\\n?",
 			"captures": {
 				"0": {
-					"name": "meta.structure.qsp.codeblock.if.else"
+					"name": "meta.structure.qsp.codeblock.if.else.qsp"
 				},
 				"1": {
 					"patterns": [
@@ -503,10 +550,10 @@
 		"if-condition": {
 			"patterns": [
 				{
-					"include": "#compare"
+					"include": "#pairs"
 				},
 				{
-					"include": "#strings"
+					"include": "#compare"
 				},
 				{
 					"include": "#single-words"
@@ -614,6 +661,14 @@
 				}
 			]
 		},
+		"keywords-loop": {
+			"patterns": [
+				{
+					"name": "keyword.control.loop.qsp",
+					"match": "\\b(?i:(jump))\\b"
+				}
+			]
+		},
 		"entities": {
 			"patterns": [
 				{
@@ -687,7 +742,7 @@
 			]
 		},
 		"errors": {
-			"name": "invalid",
+			"name": "invalid.keyword.control.qsp",
 			"patterns": [
 				{
 					"name": "invalid.keyword.control.end.qsp",