protected bool ParsePPSymbol(string line, FGTextBuffer.FormatedLine formatedLine, ref int startAt) { var word = FGParser.ScanIdentifierOrKeyword(line, ref startAt); if (word == null) { return(true); } word.tokenKind = SyntaxToken.Kind.PreprocessorSymbol; formatedLine.tokens.Add(word); word.formatedLine = formatedLine; if (word.text == "true") { return(true); } if (word.text == "false") { return(false); } if (scriptDefines == null) { scriptDefines = new HashSet <string>(UnityEditor.EditorUserBuildSettings.activeScriptCompilationDefines); } var isDefined = scriptDefines.Contains(word.text); return(isDefined); }
protected bool ParsePPUnaryExpression(string line, FGTextBuffer.FormatedLine formatedLine, ref int startAt) { if (startAt >= line.Length) { //TODO: Insert missing token return true; } if (line[startAt] == '!') { formatedLine.tokens.Add(new SyntaxToken(SyntaxToken.Kind.PreprocessorArguments, "!") { formatedLine = formatedLine }); ++startAt; var ws = ScanWhitespace(line, ref startAt); if (ws != null) { formatedLine.tokens.Add(ws); ws.formatedLine = formatedLine; } var result = ParsePPUnaryExpression(line, formatedLine, ref startAt); ws = ScanWhitespace(line, ref startAt); if (ws != null) { formatedLine.tokens.Add(ws); ws.formatedLine = formatedLine; } return !result; } return ParsePPPrimaryExpression(line, formatedLine, ref startAt); }
protected bool ParsePPPrimaryExpression(string line, FGTextBuffer.FormatedLine formatedLine, ref int startAt) { if (line[startAt] == '(') { formatedLine.tokens.Add(new SyntaxToken(SyntaxToken.Kind.PreprocessorArguments, "(") { formatedLine = formatedLine }); ++startAt; var ws = ScanWhitespace(line, ref startAt); if (ws != null) { formatedLine.tokens.Add(ws); ws.formatedLine = formatedLine; } var result = ParsePPOrExpression(line, formatedLine, ref startAt); if (startAt >= line.Length) { //TODO: Insert missing token return(result); } if (line[startAt] == ')') { formatedLine.tokens.Add(new SyntaxToken(SyntaxToken.Kind.PreprocessorArguments, ")") { formatedLine = formatedLine }); ++startAt; ws = ScanWhitespace(line, ref startAt); if (ws != null) { formatedLine.tokens.Add(ws); ws.formatedLine = formatedLine; } return(result); } //TODO: Insert missing token return(result); } var symbolResult = ParsePPSymbol(line, formatedLine, ref startAt); var ws2 = ScanWhitespace(line, ref startAt); if (ws2 != null) { formatedLine.tokens.Add(ws2); ws2.formatedLine = formatedLine; } return(symbolResult); }
protected void OpenRegion(FGTextBuffer.FormatedLine formatedLine, FGTextBuffer.RegionTree.Kind regionKind) { var parentRegion = formatedLine.regionTree; FGTextBuffer.RegionTree reuseRegion = null; switch (regionKind) { case FGTextBuffer.RegionTree.Kind.Else: case FGTextBuffer.RegionTree.Kind.Elif: case FGTextBuffer.RegionTree.Kind.InactiveElse: case FGTextBuffer.RegionTree.Kind.InactiveElif: parentRegion = parentRegion.parent; break; } if (parentRegion.children != null) { for (var i = parentRegion.children.Count; i-- > 0;) { if (parentRegion.children[i].line == formatedLine) { reuseRegion = parentRegion.children[i]; break; } } } if (reuseRegion != null) { if (reuseRegion.kind == regionKind) { formatedLine.regionTree = reuseRegion; return; } reuseRegion.parent = null; parentRegion.children.Remove(reuseRegion); } formatedLine.regionTree = new FGTextBuffer.RegionTree { parent = parentRegion, kind = regionKind, line = formatedLine, }; if (parentRegion.children == null) { parentRegion.children = new List <FGTextBuffer.RegionTree>(); } parentRegion.children.Add(formatedLine.regionTree); }
protected bool ParsePPEqualityExpression(string line, FGTextBuffer.FormatedLine formatedLine, ref int startAt) { if (startAt >= line.Length) { //TODO: Insert missing token return(true); } var lhs = ParsePPUnaryExpression(line, formatedLine, ref startAt); var ws = ScanWhitespace(line, ref startAt); if (ws != null) { formatedLine.tokens.Add(ws); ws.formatedLine = formatedLine; } if (startAt + 1 < line.Length && (line[startAt] == '=' || line[startAt + 1] == '!') && line[startAt + 1] == '=') { var equality = line[startAt] == '='; formatedLine.tokens.Add(new SyntaxToken(SyntaxToken.Kind.PreprocessorArguments, equality ? "==" : "!=") { formatedLine = formatedLine }); startAt += 2; ws = ScanWhitespace(line, ref startAt); if (ws != null) { formatedLine.tokens.Add(ws); ws.formatedLine = formatedLine; } var rhs = ParsePPEqualityExpression(line, formatedLine, ref startAt); ws = ScanWhitespace(line, ref startAt); if (ws != null) { formatedLine.tokens.Add(ws); ws.formatedLine = formatedLine; } return(equality ? lhs == rhs : lhs != rhs); } return(lhs); }
protected bool ParsePPAndExpression(string line, FGTextBuffer.FormatedLine formatedLine, ref int startAt) { if (startAt >= line.Length) { //TODO: Insert missing token return(true); } var lhs = ParsePPEqualityExpression(line, formatedLine, ref startAt); var ws = ScanWhitespace(line, ref startAt); if (ws != null) { formatedLine.tokens.Add(ws); ws.formatedLine = formatedLine; } if (startAt + 1 < line.Length && line[startAt] == '&' && line[startAt + 1] == '&') { formatedLine.tokens.Add(new SyntaxToken(SyntaxToken.Kind.PreprocessorArguments, "&&") { formatedLine = formatedLine }); startAt += 2; ws = ScanWhitespace(line, ref startAt); if (ws != null) { formatedLine.tokens.Add(ws); ws.formatedLine = formatedLine; } var rhs = ParsePPAndExpression(line, formatedLine, ref startAt); ws = ScanWhitespace(line, ref startAt); if (ws != null) { formatedLine.tokens.Add(ws); ws.formatedLine = formatedLine; } return(lhs && rhs); } return(lhs); }
protected virtual void Tokenize(string line, FGTextBuffer.FormatedLine formatedLine) { }
protected void CloseRegion(FGTextBuffer.FormatedLine formatedLine) { formatedLine.regionTree = formatedLine.regionTree.parent; }