public void Parse(Lexer lexer) { this.errors = lexer.Errors; this.lexer = lexer; errors.SynErr = new ErrorCodeProc(SynErr); lexer.NextToken(); VBNET(); }
public Expression ParseExpression(Lexer lexer) { this.errors = lexer.Errors; this.lexer = lexer; errors.SynErr = new ErrorCodeProc(SynErr); lexer.NextToken(); Expression expr; Expr(out expr); return expr; }
public ArrayList IsAsResolve(string expression, int caretLine, int caretColumn, string fileName, string fileContent) { //Console.WriteLine("Entering IsAsResolve for " + expression); ArrayList result = new ArrayList (); this.caretLine = caretLine; this.caretColumn = caretColumn; IParseInformation parseInfo = parserContext.GetParseInformation (fileName); ICSharpCode.SharpRefactory.Parser.AST.VB.CompilationUnit fcu = parseInfo.MostRecentCompilationUnit.Tag as ICSharpCode.SharpRefactory.Parser.AST.VB.CompilationUnit; if (fcu == null) return null; ICSharpCode.SharpRefactory.Parser.VB.Parser p = new ICSharpCode.SharpRefactory.Parser.VB.Parser (); Lexer l = new Lexer (new StringReader (expression)); Expression expr = p.ParseExpression(l); if (expr == null) return null; lookupTableVisitor = new LookupTableVisitor (); lookupTableVisitor.Visit (fcu, null); TypeVisitor typeVisitor = new TypeVisitor (this); VBNetVisitor vbVisitor = new VBNetVisitor (); cu = (ICompilationUnit)vbVisitor.Visit (fcu, null); if (cu != null) { callingClass = GetInnermostClass (); } IReturnType type = expr.AcceptVisitor (typeVisitor, null) as IReturnType; if (type == null || type.PointerNestingLevel != 0) { fcu = parserContext.ParseFile (fileName, fileContent).MostRecentCompilationUnit.Tag as ICSharpCode.SharpRefactory.Parser.AST.VB.CompilationUnit; lookupTableVisitor.Visit (fcu, null); cu = (ICompilationUnit)vbVisitor.Visit (fcu, null); if (cu != null) { callingClass = GetInnermostClass (); } type = expr.AcceptVisitor (typeVisitor, null) as IReturnType; if (type == null) return null; } if (type.ArrayDimensions != null && type.ArrayDimensions.Length > 0) type = new ReturnType ("System.Array"); // IClass returnClass = SearchType (type.FullyQualifiedName, null, cu); IClass returnClass = parserContext.SearchType (type.FullyQualifiedName, null, cu); if (returnClass == null) return null; foreach (IClass iclass in parserContext.GetClassInheritanceTree (returnClass)) { if (!result.Contains (iclass)) result.Add (iclass); } return result; }
public ICompilationUnitBase Parse(string fileName) { ICSharpCode.SharpRefactory.Parser.VB.Parser p = new ICSharpCode.SharpRefactory.Parser.VB.Parser(); Lexer lexer = new Lexer(new FileReader(fileName)); lexer.SpecialCommentTags = lexerTags; p.Parse(lexer); VBNetVisitor visitor = new VBNetVisitor(); visitor.Visit(p.compilationUnit, null); //visitor.Cu.FileName = fileName; visitor.Cu.ErrorsDuringCompile = p.Errors.count > 0; RetrieveRegions(visitor.Cu, lexer.SpecialTracker); AddCommentTags(visitor.Cu, lexer.TagComments); return visitor.Cu; }
public IReturnType internalResolve(string expression, int caretLineNumber, int caretColumn, string fileName, string fileContent) { try{ //Console.WriteLine("Start Resolving " + expression); if (expression == null) { return null; } expression = expression.TrimStart(null); if (expression == "") { return null; } this.caretLine = caretLineNumber; this.caretColumn = caretColumn; IParseInformation parseInfo = parserContext.GetParseInformation(fileName); ICSharpCode.SharpRefactory.Parser.AST.VB.CompilationUnit fileCompilationUnit = parseInfo.MostRecentCompilationUnit.Tag as ICSharpCode.SharpRefactory.Parser.AST.VB.CompilationUnit; if (fileCompilationUnit == null) { ICSharpCode.SharpRefactory.Parser.VB.Parser fileParser = new ICSharpCode.SharpRefactory.Parser.VB.Parser(); fileParser.Parse(new Lexer(new StringReader(fileContent))); //Console.WriteLine("!Warning: no parseinformation!"); return null; } /* //// try to find last expression in original string, it could be like " if (act!=null) act" //// in this case only "act" should be parsed as expression !!is so!! don't change things that work Expression expr=null; // tentative expression Lexer l=null; ICSharpCode.SharpRefactory.Parser.Parser p = new ICSharpCode.SharpRefactory.Parser.Parser(); while (expression.Length > 0) { l = new Lexer(new StringReader(expression)); expr = p.ParseExpression(l); if (l.LookAhead.val != "" && expression.LastIndexOf(l.LookAhead.val) >= 0) { if (expression.Substring(expression.LastIndexOf(l.LookAhead.val) + l.LookAhead.val.Length).Length > 0) expression=expression.Substring(expression.LastIndexOf(l.LookAhead.val) + l.LookAhead.val.Length).Trim(); else { expression=l.LookAhead.val.Trim(); l=new Lexer(new StringReader(expression)); expr=p.ParseExpression(l); break; } } else { if (l.Token.val!="" || expr!=null) break; } } //// here last subexpression should be fixed in expr if it should be changed in expressionfinder don't fix it here */ ICSharpCode.SharpRefactory.Parser.VB.Parser p = new ICSharpCode.SharpRefactory.Parser.VB.Parser(); Lexer l = new Lexer(new StringReader(expression)); Expression expr = p.ParseExpression(l); if (expr == null) { return null; //}else{ //Console.WriteLine(expr.ToString()); } lookupTableVisitor = new LookupTableVisitor(); lookupTableVisitor.Visit(fileCompilationUnit, null); //Console.WriteLine("Visited lookup table"); TypeVisitor typeVisitor = new TypeVisitor(this); VBNetVisitor vbVisitor = new VBNetVisitor(); cu = (ICompilationUnit)vbVisitor.Visit(fileCompilationUnit, null); //Console.WriteLine("Visited VBNetVisitor"); if (cu != null) { callingClass = GetInnermostClass(); //Console.WriteLine("CallingClass is " + callingClass == null ? "null" : callingClass.Name); } // Console.WriteLine("expression = " + expr.ToString()); IReturnType type = expr.AcceptVisitor(typeVisitor, null) as IReturnType; //Console.WriteLine("type visited"); if (type == null || type.PointerNestingLevel != 0) { //Console.WriteLine("Type == null || type.PointerNestingLevel != 0"); //if (type != null) { //Console.WriteLine("Accepted visitor: " + type.FullyQualifiedName); //Console.WriteLine("PointerNestingLevel is " + type.PointerNestingLevel); //} else { //Console.WriteLine("Type == null"); //} //// when type is null might be file needs to be reparsed - some vars were lost fileCompilationUnit=parserContext.ParseFile(fileName, fileContent).MostRecentCompilationUnit.Tag as ICSharpCode.SharpRefactory.Parser.AST.VB.CompilationUnit; lookupTableVisitor.Visit(fileCompilationUnit,null); //Console.WriteLine("Lookup table visited again"); cu = (ICompilationUnit)vbVisitor.Visit(fileCompilationUnit, null); if (cu != null) { callingClass = GetInnermostClass(); //Console.WriteLine("Got new cu, calling class = " + callingClass.FullyQualifiedName); } type=expr.AcceptVisitor(typeVisitor,null) as IReturnType; //Console.WriteLine("Type visited again"); if (type==null) return null; } if (type.ArrayDimensions != null && type.ArrayDimensions.Length > 0) { type = new ReturnType("System.Array"); } //Console.WriteLine("Here: Type is " + type.FullyQualifiedName); return type; }catch(Exception ex){ //Console.WriteLine("Exception in internalResolve: " + ex.Message); //Console.WriteLine(ex.StackTrace); return null; } }