From e2058496ef7f8ec1637190646c221a0a8b217e4f Mon Sep 17 00:00:00 2001 From: geequlim Date: Sun, 26 Feb 2017 18:50:01 +0800 Subject: [PATCH] Ignore syntax checking with comments Fix for expression checking with [] and {} Fix bug with out of range checking from #7 Better syntax checking with code blocks close #4 --- src/gdscript/diagnostic.ts | 17 ++++++++++------- src/gdscript/symbolparser.ts | 1 + 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/gdscript/diagnostic.ts b/src/gdscript/diagnostic.ts index 75b37b3..30a0601 100644 --- a/src/gdscript/diagnostic.ts +++ b/src/gdscript/diagnostic.ts @@ -77,14 +77,15 @@ class GDScriptDiagnosticSeverity { private validateExpression(doc: vscode.TextDocument) { let diagnostics = []; - const text = doc.getText().replace(new RegExp(/#.*$/, "gm"), ""); //excludes comments from being checked for syntax + const text = doc.getText(); const lines = text.split(/\r?\n/); lines.map((line:string, i: number) =>{ let matchstart = /[^\s]+.*/.exec(line); let curLineStartAt = 0; if(matchstart) curLineStartAt = matchstart.index; - + // ignore comments + if(line.match(/^\s*#.*/) || line.match(/^#.*/)) return // normalize line content line = "\t" + line + "\t"; @@ -98,18 +99,20 @@ class GDScriptDiagnosticSeverity { diagnostics.push(new vscode.Diagnostic(range, "':' expected at end of the line.", DiagnosticSeverity.Error)); else if(line.match(/(if|elif|while|func|class)\s*\:/)) diagnostics.push(new vscode.Diagnostic(range, "Indentifier expected before ':'", DiagnosticSeverity.Error)); - else if(line.match(/[^\w]for[^\w]/) && !line.match(/\s+for\s\w+\s+in\s+\w+/)) + else if(line.match(/[^\w]for[^\w]/) && !line.match(/\s+for\s\w+\s+in\s+[\w+]|\{.*?\}|\[.*?\]/)) diagnostics.push(new vscode.Diagnostic(range, "Invalid for expression", DiagnosticSeverity.Error)); else if(line.match(/(if|elif|while)\s*\(.*\)/)) diagnostics.push(new vscode.Diagnostic(range, "Extra brackets in condition expression.", DiagnosticSeverity.Warning)); - if( i < lines.length-1) { + if(line.match(/([^\w]if|elif|else|for|while|func|class[^\w]).*\:[ \t]+[^#\s]+/)) + return + else if( i < lines.length-1) { let next = i+1; let nextline = lines[next]; - while (!nextline || /\s+$/gm.test(nextline) && next < lines.length-1) //changes nextline until finds a line containg text or comes to the last line - { - nextline = lines[next]; + // changes nextline until finds a line containg text or comes to the last line + while ((!nextline || nextline.match(/\s+$/)) && next < lines.length-1) { ++next; + nextline = lines[next]; } let nextLineStartAt = -1; let match = /[^\s]+.*/.exec(nextline); diff --git a/src/gdscript/symbolparser.ts b/src/gdscript/symbolparser.ts index 558026c..1a25f5e 100644 --- a/src/gdscript/symbolparser.ts +++ b/src/gdscript/symbolparser.ts @@ -177,6 +177,7 @@ class GDScriptSymbolParser { script.classes[key] = determRange(key, classes); script.documents[key] = parseDocument(r); } + // console.log(script); return script; }