3
// This file was derived from a file from #Develop.
5
// Copyright (C) 2001-2007 Andrea Paatz <andrea@icsharpcode.net>
7
// This program is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation; either version 2 of the License, or
10
// (at your option) any later version.
12
// This program is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
17
// You should have received a copy of the GNU General Public License
18
// along with this program; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
using System.Collections.Generic;
24
using MonoDevelop.Core;
25
using MonoDevelop.Projects.Parser;
26
using MonoDevelop.Projects;
27
using VBBinding.Parser.SharpDevelopTree;
29
using ICSharpCode.NRefactory;
30
using ICSharpCode.NRefactory.Parser;
33
namespace VBBinding.Parser
35
public class TParser : MonoDevelop.Projects.Parser.IParser
38
public TParser() : base(){
39
//Console.WriteLine("Entering VB.NET parser");
42
///<summary>IParser Interface</summary>
44
public string[] LexerTags {
45
//// Alex: get accessor needed
54
public IExpressionFinder CreateExpressionFinder (string file)
56
return new ExpressionFinder ();
59
public bool CanParse (string fileName)
61
return System.IO.Path.GetExtension (fileName).ToLower () == ".vb";
64
void RetrieveRegions(CompilationUnit cu, SpecialTracker tracker)
66
for (int i = 0; i < tracker.CurrentSpecials.Count; ++i) {
67
PreprocessingDirective directive = tracker.CurrentSpecials[i] as PreprocessingDirective;
68
if (directive != null) {
69
if (directive.Cmd.ToLower() == "#region") {
71
for (int j = i + 1; j < tracker.CurrentSpecials.Count; ++j) {
72
PreprocessingDirective nextDirective = tracker.CurrentSpecials[j] as PreprocessingDirective;
73
if(nextDirective != null) {
74
switch (nextDirective.Cmd.ToLower()) {
79
if (nextDirective.Arg.ToLower() == "region") {
82
cu.FoldingRegions.Add(new FoldingRegion(directive.Arg.Trim('"'), new DefaultRegion(new Point (directive.StartPosition.X, directive.StartPosition.Y) , new Point (nextDirective.EndPosition.X, nextDirective.EndPosition.Y))));
96
public ICompilationUnitBase Parse(string fileName)
98
using (ICSharpCode.NRefactory.IParser p = ICSharpCode.NRefactory.ParserFactory.CreateParser (SupportedLanguage.VBNet, new StreamReader(fileName))) {
99
return Parse (p, fileName);
103
public ICompilationUnitBase Parse(string fileName, string fileContent)
105
using (ICSharpCode.NRefactory.IParser p = ICSharpCode.NRefactory.ParserFactory.CreateParser (SupportedLanguage.VBNet, new StringReader(fileContent))) {
106
return Parse (p, fileName);
110
ICompilationUnit Parse (ICSharpCode.NRefactory.IParser p, string fileName)
114
VBNetVisitor visitor = new VBNetVisitor();
115
visitor.VisitCompilationUnit(p.CompilationUnit, null);
116
visitor.Cu.ErrorsDuringCompile = p.Errors.Count > 0;
117
visitor.Cu.Tag = p.CompilationUnit;
118
RetrieveRegions(visitor.Cu, p.Lexer.SpecialTracker);
119
foreach (IClass c in visitor.Cu.Classes)
120
c.Region.FileName = fileName;
121
AddCommentTags(visitor.Cu, p.Lexer.TagComments);
125
void AddCommentTags(ICompilationUnit cu, List<TagComment> tagComments)
127
foreach (ICSharpCode.NRefactory.Parser.TagComment tagComment in tagComments) {
128
DefaultRegion tagRegion = new DefaultRegion(tagComment.StartPosition.Y, tagComment.StartPosition.X);
129
MonoDevelop.Projects.Parser.Tag tag = new MonoDevelop.Projects.Parser.Tag(tagComment.Tag, tagRegion);
130
tag.CommentString = tagComment.CommentText;
131
cu.TagComments.Add(tag);
137
public LanguageItemCollection CtrlSpace (IParserContext parserContext, int caretLine, int caretColumn, string fileName)
139
return new Resolver(parserContext).CtrlSpace (caretLine, caretColumn, fileName);
142
public ResolveResult Resolve (IParserContext parserContext, string expression, int caretLineNumber, int caretColumn, string fileName, string fileContent)
144
return new Resolver(parserContext).Resolve (expression, caretLineNumber, caretColumn, fileName, fileContent);
147
public LanguageItemCollection IsAsResolve (IParserContext parserContext, string expression, int caretLineNumber, int caretColumn, string fileName, string fileContent)
149
return new Resolver (parserContext).IsAsResolve (expression, caretLineNumber, caretColumn, fileName, fileContent);
152
public ILanguageItem ResolveIdentifier (IParserContext parserContext, string id, int caretLineNumber, int caretColumn, string fileName, string fileContent)
157
///////// IParser Interface END