private expression convert_expression(ICSharpCode.NRefactory.Ast.Expression expr) { if (expr is ICSharpCode.NRefactory.Ast.IdentifierExpression) { return(convert_identifier_expression(expr as ICSharpCode.NRefactory.Ast.IdentifierExpression)); } if (expr is ICSharpCode.NRefactory.Ast.BinaryOperatorExpression) { return(convert_binary_expression(expr as ICSharpCode.NRefactory.Ast.BinaryOperatorExpression)); } if (expr is ICSharpCode.NRefactory.Ast.UnaryOperatorExpression) { return(convert_unary_expression(expr as ICSharpCode.NRefactory.Ast.UnaryOperatorExpression)); } if (expr is ICSharpCode.NRefactory.Ast.InvocationExpression) { return(convert_invocation_expression(expr as ICSharpCode.NRefactory.Ast.InvocationExpression)); } /*if (expr is ICSharpCode.NRefactory.Ast.FieldReferenceExpression) * return convert_field_reference_expression(expr as ICSharpCode.NRefactory.Ast.FieldReferenceExpression); * if (expr is ICSharpCode.NRefactory.Ast.NullExpression) * return new nil_const();*/ if (expr is ICSharpCode.NRefactory.Ast.PrimitiveExpression) { return(convert_primitive_expression(expr as ICSharpCode.NRefactory.Ast.PrimitiveExpression)); } if (expr is ICSharpCode.NRefactory.Ast.TypeReferenceExpression) { return(convert_type_reference_expression(expr as ICSharpCode.NRefactory.Ast.TypeReferenceExpression)); } if (expr is ICSharpCode.NRefactory.Ast.TypeOfExpression) { return(convert_typeof_expression(expr as ICSharpCode.NRefactory.Ast.TypeOfExpression)); } if (expr is ICSharpCode.NRefactory.Ast.CastExpression) { return(convert_cast_expression(expr as ICSharpCode.NRefactory.Ast.CastExpression)); } if (expr is ICSharpCode.NRefactory.Ast.ParenthesizedExpression) { return(convert_expression((expr as ICSharpCode.NRefactory.Ast.ParenthesizedExpression).Expression)); } return(null); }
public syntax_tree_node BuildTree(string FileName, string Text, ParseMode ParseMode, List <string> DefinesList = null) { if (string.IsNullOrEmpty(Text)) { return(null); } ICSharpCode.NRefactory.IParser parser = ICSharpCode.NRefactory.ParserFactory.CreateParser(ICSharpCode.NRefactory.SupportedLanguage.VBNet, new StringReader(Text)); syntax_tree_node cu = null; ASTConverter conv = new ASTConverter(); if (ParseMode == ParseMode.Expression) { ICSharpCode.NRefactory.Ast.Expression expr = parser.ParseExpression(); cu = conv.get_expression(expr); } else { parser.Parse(); cu = conv.get_syntax_tree(parser.CompilationUnit, FileName); } parser.Dispose(); return(cu); }
protected override void ScanSpan(ref int i) { if (CSharpSyntaxMode.DisableConditionalHighlighting) { base.ScanSpan(ref i); return; } int textOffset = i - StartOffset; if (CurText.IsAt(textOffset, "#else")) { if (!spanStack.Any(s => s is IfBlockSpan || s is ElseIfBlockSpan)) { base.ScanSpan(ref i); return; } bool previousResult = false; foreach (Span span in spanStack) { if (span is IfBlockSpan) { previousResult = ((IfBlockSpan)span).IsValid; } if (span is ElseIfBlockSpan) { previousResult |= ((ElseIfBlockSpan)span).IsValid; } } // LineSegment line = doc.GetLineByOffset (i); // int length = line.Offset + line.EditableLength - i; while (spanStack.Count > 0 && !(CurSpan is IfBlockSpan || CurSpan is ElseIfBlockSpan)) { spanStack.Pop(); } IfBlockSpan ifBlock = CurSpan as IfBlockSpan; ElseIfBlockSpan elseIfBlock = CurSpan as ElseIfBlockSpan; ElseBlockSpan elseBlockSpan = new ElseBlockSpan(!previousResult); if (ifBlock != null) { elseBlockSpan.Disabled = ifBlock.Disabled; } else if (elseIfBlock != null) { elseBlockSpan.Disabled = elseIfBlock.Disabled; } FoundSpanBegin(elseBlockSpan, i, "#else".Length); i += "#else".Length; // put pre processor eol span on stack, so that '#elif' gets the correct highlight Span preprocessorSpan = CreatePreprocessorSpan(); FoundSpanBegin(preprocessorSpan, i, 0); return; } if (CurRule.Name == "<root>" && CurText.IsAt(textOffset, "#if")) { int length = CurText.Length - textOffset; string parameter = CurText.Substring(textOffset + 3, length - 3); ICSharpCode.NRefactory.Parser.CSharp.Lexer lexer = new ICSharpCode.NRefactory.Parser.CSharp.Lexer(new System.IO.StringReader(parameter)); ICSharpCode.NRefactory.Ast.Expression expr = lexer.PPExpression(); bool result = false; if (expr != null && !expr.IsNull) { object o = expr.AcceptVisitor(new ConditinalExpressionEvaluator(doc), null); if (o is bool) { result = (bool)o; } } IfBlockSpan ifBlockSpan = new IfBlockSpan(result); foreach (Span span in spanStack) { if (span is AbstractBlockSpan) { AbstractBlockSpan parentBlock = (AbstractBlockSpan)span; ifBlockSpan.Disabled = parentBlock.Disabled || !parentBlock.IsValid; break; } } FoundSpanBegin(ifBlockSpan, i, length); i += length - 1; return; } if (CurText.IsAt(textOffset, "#elif") && spanStack.Any(span => span is IfBlockSpan)) { LineSegment line = doc.GetLineByOffset(i); int length = line.Offset + line.EditableLength - i; string parameter = doc.GetTextAt(i + 5, length - 5); ICSharpCode.NRefactory.Parser.CSharp.Lexer lexer = new ICSharpCode.NRefactory.Parser.CSharp.Lexer(new System.IO.StringReader(parameter)); ICSharpCode.NRefactory.Ast.Expression expr = lexer.PPExpression(); bool result = !expr.IsNull ? (bool)expr.AcceptVisitor(new ConditinalExpressionEvaluator(doc), null) : false; IfBlockSpan containingIf = null; if (result) { bool previousResult = false; foreach (Span span in spanStack) { if (span is IfBlockSpan) { containingIf = (IfBlockSpan)span; previousResult = ((IfBlockSpan)span).IsValid; break; } if (span is ElseIfBlockSpan) { previousResult |= ((ElseIfBlockSpan)span).IsValid; } } result = !previousResult; } ElseIfBlockSpan elseIfBlockSpan = new ElseIfBlockSpan(result); if (containingIf != null) { elseIfBlockSpan.Disabled = containingIf.Disabled; } FoundSpanBegin(elseIfBlockSpan, i, 0); // put pre processor eol span on stack, so that '#elif' gets the correct highlight Span preprocessorSpan = CreatePreprocessorSpan(); FoundSpanBegin(preprocessorSpan, i, 0); //i += length - 1; return; } if (CurRule.Name == "<root>" && CurText[textOffset] == '#') { Span preprocessorSpan = CreatePreprocessorSpan(); FoundSpanBegin(preprocessorSpan, i, 1); } base.ScanSpan(ref i); }
public expression get_expression(ICSharpCode.NRefactory.Ast.Expression expr) { return(convert_expression(expr)); }