1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
#region license
// Copyright (c) 2004-2005, Daniel Grunwald (daniel@danielgrunwald.de)
// Copyright (c) 2005, Peter Johanson (latexer@gentoo.org)
// All rights reserved.
//
// The BooBinding.Parser code is originally that of Daniel Grunwald
// (daniel@danielgrunwald.de) from the SharpDevelop BooBinding. The code has
// been imported here, and modified, including, but not limited to, changes
// to function with MonoDevelop, additions, refactorings, etc.
//
// BooBinding is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// BooBinding is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with BooBinding; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#endregion
/*
namespace BooBinding.Parser
import System
import System.Collections
import System.Diagnostics
import System.IO
import MonoDevelop.Core
import MonoDevelop.Projects
import MonoDevelop.Projects.Dom
import MonoDevelop.Projects.Dom.Parser
import MonoDevelop.Ide.Gui
import Boo.Lang.Compiler
import Boo.Lang.Compiler.IO
import Boo.Lang.Compiler.Pipelines
import Boo.Lang.Compiler.Steps
class BooParser(IParser):
private _lexerTags as (string)
private cuCache = Hashtable()
LexerTags as (string):
get:
return _lexerTags
set:
_lexerTags = value
def CreateExpressionFinder(fileName as string) as IExpressionFinder:
return BooBinding.Parser.ExpressionFinder()
def Parse(fileName as string) as ICompilationUnitBase:
content as string
using r = StreamReader(fileName):
content = r.ReadToEnd()
return Parse(fileName, content)
def Parse(fileName as string, fileContent as string) as ICompilationUnitBase:
Log ("Parse ${fileName} with content")
cr = char('\r')
ln = char('\n')
linecount = 1
for c as Char in fileContent:
linecount += 1 if c == ln
lineLength = array(int, linecount)
length = 0
i = 0
for c as Char in fileContent:
if c == ln:
lineLength[i] = length
i += 1
length = 0
elif c != cr:
length += 1
lineLength[i] = length
compiler = BooCompiler()
compiler.Parameters.Input.Add(StringInput(fileName, fileContent))
project as Project
for entry as Project in IdeApp.Workspace.GetAllProjects():
if entry.IsFileInProject(fileName):
project = entry
if project is not null and cast(DotNetProject,project).References is not null:
for projectRef as ProjectReference in cast(DotNetProject,project).References:
for asmName as string in projectRef.GetReferencedFileNames (ProjectService.DefaultConfiguration):
compiler.Parameters.References.Add(System.Reflection.Assembly.LoadFile(asmName))
return Parse(fileName, lineLength, compiler)
private def Parse(fileName as string, lineLength as (int), compiler as BooCompiler):
compiler.Parameters.OutputWriter = StringWriter()
compiler.Parameters.TraceSwitch.Level = TraceLevel.Warning
compilePipe = Compile()
parsingStep as Boo.Lang.Parser.BooParsingStep = compilePipe[0]
parsingStep.TabSize = 1
//num = compilePipe.Find(typeof(ProcessMethodBodiesWithDuckTyping))
// Include ProcessMethodBodies step now, as it solves issue
// with [Propert(foo)] with an untyped 'foo'
num = compilePipe.Find(typeof(StricterErrorChecking))
visitor = Visitor(LineLength:lineLength)
compilePipe[num] = visitor
// Remove unneccessary compiler steps
while compilePipe.Count > num + 1:
compilePipe.RemoveAt(compilePipe.Count - 1)
num = compilePipe.Find(typeof(TransformCallableDefinitions))
compilePipe.RemoveAt(num)
//for i in range(compilePipe.Count):
// print compilePipe[i].ToString()
compilePipe.BreakOnErrors = false
compiler.Parameters.Pipeline = compilePipe
try:
compiler.Run()
// somehow the SD parser thread goes into an endless loop if this flag is not set
visitor.Cu.ErrorsDuringCompile = true //context.Errors.Count > 0
except e:
Error (e.ToString ())
for c as IClass in visitor.Cu.Classes:
if c.Region is not null:
c.Region.FileName = fileName
// The following returns the "last known good" parse results
// for a given file. Keeps our parse info from disappearing
// when there is a parsing error in a file.
if visitor.HadErrors:
if cuCache[fileName] is null:
return DefaultCompilationUnit()
return cuCache[fileName] as ICompilationUnitBase
cuCache[fileName] = visitor.Cu
return visitor.Cu
def CtrlSpace(parserContext as IParserContext, caretLine as int, caretColumn as int, fileName as string) as LanguageItemCollection:
Log ("Ctrl-Space (${caretLine}/${caretColumn})")
try:
return Resolver(parserContext).CtrlSpace(caretLine, caretColumn, fileName)
except e:
//ShowException(e)
return null
def IsAsResolve (parserContext as IParserContext, expression as string , caretLineNumber as int , caretColumn as int , fileName as string , fileContent as string, include_ifaces as bool) as LanguageItemCollection:
return Resolver (parserContext).IsAsResolve (expression, caretLineNumber, caretColumn, fileName, fileContent, include_ifaces)
def Resolve(parserContext as IParserContext, expression as string, caretLineNumber as int, caretColumn as int, fileName as string, fileContent as string) as ResolveResult:
Log ("Resolve ${expression} (${caretLineNumber}/${caretColumn})")
try:
return Resolver(parserContext).Resolve(expression, caretLineNumber, caretColumn, fileName, fileContent)
except e:
Error (e.ToString ())
return null
def MonodocResolver(parserContext as IParserContext, expression as string, caretLineNumber as int, caretColumn as int, fileName as string, fileContent as string) as string:
Log ("MonodocResolver ${expression} (${caretLineNumber}/${caretColumn})")
try:
return Resolver(parserContext).MonodocResolver(expression, caretLineNumber, caretColumn, fileName, fileContent)
except e:
//ShowException(e)
return null
def ResolveIdentifier (parserContext as IParserContext, id as string , caretLineNumber as int , caretColumn as int , fileName as string , fileContent as string ) as ILanguageItem:
return null
private def Log (message):
Log (self.GetType(), message)
private def Error (message):
Error (self.GetType(), message)
static def Log (type, message):
MonoDevelop.Core.LoggingService.LogDebug (type.ToString () + message)
static def Error (type, message):
MonoDevelop.Core.LoggingService.LogError (type.ToString () + message)
*/
|