public void Analyse(string code, int line = -1) { Code.Clear(); Regex regex = new Regex(REGEX_BRACKETS); //For each block of text = brackets int currentLine = 1; foreach (Match ItemMatch in regex.Matches(code)) { try { Assignation tempo = new Assignation(1); tempo.Analyse(ItemMatch.Value, currentLine); Code.Add(tempo); currentLine += ItemMatch.Value.Count(s => s == '\n') + 1; } catch (RecursiveCodeException e) { //TODO: Add language support ErrorLogger.Instance.AddLogLine("Error during script Loading"); ErrorLogger.Instance.AddLogLine("\t" + e.Message); } catch (Exception) { //TODO: Add language support ErrorLogger.Instance.AddLogLine("Unknown error in script"); continue; } } }
public void Analyse(string code, int line = -1) { Regex regex = new Regex(Script.REGEX_BRACKETS); //For each block of text = brackets foreach (Match ItemMatch in regex.Matches(code)) { int firstIndex = ItemMatch.Value.IndexOf('='); int lastIndex = ItemMatch.Value.LastIndexOf('='); //If it was an inline with more than one assignations if (firstIndex >= 0 && firstIndex != lastIndex && ItemMatch.Value.IndexOf('\n') <= 0 && ItemMatch.Value.IndexOf('{') <= 0) { //We got more than one equal in one line and there was //no brackets, it is a inline multi assignation Regex regex2 = new Regex(Script.REGEX_INLINE_ASSIGNATIONS); foreach (Match inlines in regex2.Matches(ItemMatch.Value)) { Assignation tempo = new Assignation(Level + 1); tempo.Analyse(inlines.Value, line); //If tempo has a value if (!String.IsNullOrEmpty(tempo.Assignee)) { Code.Add(tempo); } } } else { Assignation tempo = new Assignation(Level + 1); tempo.Analyse(ItemMatch.Value, line + 1); //If tempo has a value if (!String.IsNullOrEmpty(tempo.Assignee)) { Code.Add(tempo); } } line += ItemMatch.Value.Count(s => s == '\n'); } }
internal RecursiveCodeLog Analyse(List <SyntaxGroup> code) { if (!code.Any()) { return(null); } foreach (SyntaxGroup group in code) { //Check if there is an assignation or code value at the end of the code Assignation last = Code.LastOrDefault() as Assignation; if (last != null) { //set its end line as this line's end - 1 last.EndLine = group.Component.line - 1; } Assignation tempo = new Assignation(Level + 1); RecursiveCodeLog log = tempo.Analyse(group); if (log != null) { return(log); } //If tempo has a value if (!string.IsNullOrEmpty(tempo.Assignee)) { Code.Add(tempo); } } //Check if there is an assignation or code value at the end of the code Assignation Verylast = Code.LastOrDefault() as Assignation; if (Verylast != null) { //set its end line as this line's end - 1 Verylast.EndLine = code.Last().Component.line - 1; } return(null); }
public void Analyse(string code, int line = -1) { Code.Clear(); Tokenizer tokenizer = new Tokenizer(); List <SyntaxGroup> list = tokenizer.GroupTokensByBlocks(tokenizer.Tokenize(code, this)) as List <SyntaxGroup>; //Set this logger as the tokenizer logger Logger.Errors = tokenizer.Logger.Errors; //Check if there are errors. if (Logger.hasErrors()) { return; } //Return if list is null if (list == null || !list.Any()) { return; } foreach (SyntaxGroup group in list) { try { //Check if there is an assignation or code value at the end of the code Assignation last = Code.LastOrDefault() as Assignation; if (last != null) { //set its end line as this line's end - 1 last.EndLine = group.Component.line - 1; } Assignation tempo = new Assignation(1); RecursiveCodeLog log = tempo.Analyse(group); if (log != null) { Logger.Errors.Add(new SyntaxError(log.Message)); //We don't want to add broken code if possible continue; } Code.Add(tempo); } catch (Exception) { //TODO: Add language support Logger.Errors.Add(new SyntaxError("Unknown error in script")); } } //Check if there is an assignation or code value at the end of the code Assignation Verylast = Code.LastOrDefault() as Assignation; if (Verylast != null) { //Check if the last is Empty if (list.Last().Component.line == Verylast.Line) { //Empty block, set the end line as starting line + 2 Verylast.EndLine = Verylast.Line + 2; } else { //Set its end line as this line's end - 1 Verylast.EndLine = list.Last().Component.line - 1; } } }