Просмотр исходного кода

fixes/improves single line parsing

slonon 4 лет назад
Родитель
Сommit
477a6000dd
1 измененных файлов с 122 добавлено и 118 удалено
  1. 122 118
      qsrc/syntaxes/QSP.tmLanguage.json

+ 122 - 118
qsrc/syntaxes/QSP.tmLanguage.json

@@ -120,10 +120,10 @@
 					"include": "#qsp-control-structures"
 				},
 				{
-					"include": "#qsp-expression"
+					"include": "#if-branches"
 				},
 				{
-					"include": "#if-branches"
+					"include": "#qsp-expression"
 				},
 				{
 					"include": "#preprocessor"
@@ -141,18 +141,9 @@
 				},
 				{
 					"include": "#loops"
-				}
-			]
-		},
-		"qsp-expression": {
-			"comment": "basically 'act' or 'if' expressions",
-			"name": "meta.structure.qsp.expression",
-			"patterns": [
-				{
-					"include": "#qsp-expression-if"
 				},
 				{
-					"include": "#qsp-expression-act"
+					"include": "#qsp-line"
 				}
 			]
 		},
@@ -255,36 +246,117 @@
 				}
 			]
 		},
-		"qsp-expression-if": {
-			"comment": "parse single line if",
-			"name": "meta.line.if.qsp",
-			"begin": "\\s*\\b(?i:(if))\\b",
-			"beginCaptures": {
+		"qsp-line": {
+			"comment": "a line containing expesstions",
+			"name": "meta.structure.line.qsp",
+			"match": "(^\\s*(?i:if|act).*(?![:]\\s*)$\\n?)",
+			"captures": {
 				"1": {
 					"patterns": [
 						{
-							"include": "#keywords-if"
+							"include": "#qsp-expression"
 						}
 					]
 				}
-			},
-			"end": "([:])\\s*(?!$\\n?|&)",
-			"endCaptures": {				
-				"1": {
-					"name":"punctuation.condition.if"
+			}
+		},
+		"qsp-expression": {
+			"comment": "basically 'act' or 'if' expressions",
+			"name": "meta.structure.qsp.expression",
+			"patterns": [
+				{
+					"include": "#qsp-expression-if"
+				},
+				{
+					"include": "#qsp-expression-act"
+				},
+				{
+					"include": "#expression"
 				}
-			},
-			"patterns": [			
+			]
+		},
+		"qsp-expression-if": {
+			"patterns": [
 				{
-					"comment": "parse 'ifelse'/'else' constructs continuing the expression",
-					"include": "#if-condition"
+					"begin": "(?:^|[:]|&)\\s*\\b(?i:(if))\\b",
+					"beginCaptures": {
+						"1": {
+							"patterns": [
+								{
+									"include": "#keywords-if"
+								}
+							]
+						}
+					},
+					"end": "(?=([:]))",
+					"endCaptures": {
+						"1": {
+							"name": "punctuation.expression.if.qsp"
+						}
+					},
+					"patterns": [
+						{
+							"include": "#if-condition"
+						}
+					]
+				},
+				{
+					"begin": "(?:[:])\\s*(.?\\S+.*)\\b(?i:(elseif))\\b",
+					"beginCaptures": {
+						"1":{
+							"patterns": [{"include": "#expression"}]
+						},
+						"2": {
+							"patterns": [
+								{
+									"include": "#keywords-if"
+								}
+							]
+						}
+					},
+					"end": "(?=([:]))",
+					"endCaptures": {
+						"1": {
+							"name": "punctuation.expression.if.qsp"
+						}
+					},
+					"patterns": [
+						{
+							"include": "#if-condition"
+						}
+					]
+				},
+				{
+					"name":"meta.structure.line.else.qsp",
+					"begin": "(?:([:]))\\s*(.?\\S+.*)\\b(?i:(else))\\b",
+					"beginCaptures": {
+						"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*(?i:(act))\\b",
+			"begin": "(?:^|[:]|&)\\s*\\b(?i:(act))\\b",
 			"beginCaptures": {
 				"1": {
 					"patterns": [
@@ -294,16 +366,15 @@
 					]
 				}
 			},
-			"end": "([:])\\s*(?!$\\n?|&)",
-			"endCaptures": {				
+			"end": "(?=([:]))",
+			"endCaptures": {
 				"1": {
-					"name":"punctuation.condition.act"
+					"name": "punctuation.expression.act.qsp"
 				}
 			},
 			"patterns": [
 				{
-					"name":"meta.condition.act",
-					"include": "#qsp-general-structures"
+					"include": "#if-condition"
 				}
 			]
 		},
@@ -376,19 +447,6 @@
 				}
 			]
 		},
-		"compare": {
-			"patterns": [				
-				{
-					"comment": "QSP accepts this, but it complicates text search and is bad practice",
-					"name": "invalid.keyword.operator.compare.qsp",
-					"match": "(=(<|>))"
-				},
-				{
-					"name": "keyword.operator.compare.qsp",
-					"match": "((<|>)?=|!|<>|<|>)"
-				}
-			]			
-		},
 		"if-branches": {
 			"comment": "'elseif' or 'else' whithin a 'if'-block",
 			"patterns": [
@@ -405,7 +463,7 @@
 			"match": "\\s*(?i:(elseif))\\b\\s*(.?\\S.*?)(:)\\s*$\\n?",
 			"captures": {
 				"0": {
-					"name": "meta.elseif-condition.line.qsp"
+					"name": "meta.structure.qsp.codeblock.if.elseif"
 				},
 				"1": {
 					"patterns": [
@@ -431,7 +489,7 @@
 			"match": "^\\s*(?i:(else))\\s*$\\n?",
 			"captures": {
 				"0": {
-					"name": "meta.elseif-condition.line.qsp"
+					"name": "meta.structure.qsp.codeblock.if.else"
 				},
 				"1": {
 					"patterns": [
@@ -448,84 +506,30 @@
 					"include": "#compare"
 				},
 				{
-					"include": "#qsp-general-structures"
+					"include": "#strings"
+				},
+				{
+					"include": "#single-words"
 				}
 			]
 		},
-		"ifLine": {
+		"expression": {
 			"patterns": [
 				{
-					"match": "(.+?)\\s*\\b(?i:(elseif))\\b\\s*(.?\\S.*?)(:)\\s*(.?\\S.*\\s*$\\n?)",
-					"name": "meta.elseif.line.qsp",
-					"captures": {
-						"0": {
-							"name": "meta.elseif-condition.line.qsp"
-						},
-						"1": {
-							"patterns": [
-								{
-									"include": "$self"
-								}
-							]
-						},
-						"2": {
-							"patterns": [
-								{
-									"include": "#keywords-if"
-								}
-							]
-						},
-						"3": {
-							"patterns": [
-								{
-									"include": "#if-condition"
-								}
-							]
-						},
-						"4": {
-							"name": "punctuation.condition.if.qsp"
-						},
-						"5": {
-							"patterns": [
-								{
-									"include": "#ifLine"
-								}
-							]
-						}
-					}
-				},
+					"include": "#if-condition"
+				}
+			]
+		},
+		"compare": {
+			"patterns": [
 				{
-					"match": "(.+?)\\s*\\b(?i:(else))\\b\\s*(.?\\S.*\\s*$\\n?)",
-					"name": "meta.else.line.qsp",
-					"captures": {
-						"0": {
-							"name": "meta.else-condition.line.qsp"
-						},
-						"1": {
-							"patterns": [
-								{
-									"include": "$self"
-								}
-							]
-						},
-						"2": {
-							"patterns": [
-								{
-									"include": "#keywords-if"
-								}
-							]
-						},
-						"3": {
-							"patterns": [
-								{
-									"include": "$self"
-								}
-							]
-						}
-					}
+					"comment": "QSP accepts this, but it complicates text search and is bad practice",
+					"name": "invalid.keyword.operator.compare.qsp",
+					"match": "(=(<|>))"
 				},
 				{
-					"include": "$self"
+					"name": "keyword.operator.compare.qsp",
+					"match": "((<|>)?=|!|<>|<|>)"
 				}
 			]
 		},