本文整理汇总了C#中SourceUnit.GetReader方法的典型用法代码示例。如果您正苦于以下问题:C# SourceUnit.GetReader方法的具体用法?C# SourceUnit.GetReader怎么用?C# SourceUnit.GetReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SourceUnit
的用法示例。
在下文中一共展示了SourceUnit.GetReader方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add
public override void Add(SourceUnit sourceUnit, string message, SourceSpan span, int errorCode, Severity severity) {
if (severity == Severity.Warning && !ReportWarning(_context.Verbose, errorCode)) {
return;
}
CountError(severity);
string path;
string codeLine;
RubyEncoding encoding;
int line = span.Start.Line;
if (sourceUnit != null) {
path = sourceUnit.Path;
using (SourceCodeReader reader = sourceUnit.GetReader()) {
if (line > 0) {
reader.SeekLine(line);
codeLine = reader.ReadLine();
} else {
codeLine = null;
}
encoding = RubyEncoding.GetRubyEncoding(reader.Encoding);
}
} else {
path = null;
codeLine = null;
encoding = RubyEncoding.UTF8;
}
if (severity == Severity.Error || severity == Severity.FatalError) {
throw new SyntaxError(message, path, line, span.Start.Column, codeLine);
} else {
if (_WriteSite == null) {
Interlocked.CompareExchange(
ref _WriteSite,
CallSite<Func<CallSite, object, object, object>>.Create(RubyCallAction.Make(_context, "write", 1)),
null
);
}
message = RubyContext.FormatErrorMessage(message, "warning", path, line, span.Start.Column, null);
_WriteSite.Target(_WriteSite, _context.StandardErrorOutput, MutableString.Create(message, encoding));
}
}
示例2: Add
public override void Add(SourceUnit sourceUnit, string message, SourceSpan span, int errorCode, Severity severity)
{
if (severity == Severity.Warning && !ReportWarning(_context.Verbose, errorCode)) {
return;
}
CountError(severity);
string path;
string codeLine;
RubyEncoding encoding;
int line = span.Start.Line;
if (sourceUnit != null) {
path = sourceUnit.Path;
using (SourceCodeReader reader = sourceUnit.GetReader()) {
if (line > 0) {
try {
reader.SeekLine(line);
codeLine = reader.ReadLine();
} catch (Exception) {
codeLine = null;
}
} else {
codeLine = null;
}
encoding = reader.Encoding != null ? RubyEncoding.GetRubyEncoding(reader.Encoding) : RubyEncoding.UTF8;
}
} else {
path = null;
codeLine = null;
encoding = RubyEncoding.UTF8;
}
if (severity == Severity.Error || severity == Severity.FatalError) {
throw new SyntaxError(message, path, line, span.Start.Column, codeLine);
} else {
WriteMessage(
MutableString.Create(RubyContext.FormatErrorMessage(message, "warning", path, line, span.Start.Column, null), encoding)
);
}
}
示例3: Initialize
public void Initialize(SourceUnit/*!*/ sourceUnit) {
ContractUtils.RequiresNotNull(sourceUnit, "sourceUnit");
Initialize(null, sourceUnit.GetReader(), sourceUnit, SourceLocation.MinValue);
}
示例4: AddScriptLines
/// <summary>
/// If the SCRIPT_LINES__ constant is set, we need to publish the file being loaded,
/// along with the contents of the file
/// </summary>
private void AddScriptLines(SourceUnit file) {
ConstantStorage storage;
if (!_context.ObjectClass.TryResolveConstant(null, "SCRIPT_LINES__", out storage)) {
return;
}
IDictionary scriptLines = storage.Value as IDictionary;
if (scriptLines == null) {
return;
}
lock (scriptLines) {
// Read in the contents of the file
RubyArray lines = new RubyArray();
SourceCodeReader reader = file.GetReader();
RubyEncoding encoding = RubyEncoding.GetRubyEncoding(reader.Encoding);
using (reader) {
reader.SeekLine(1);
while (true) {
string lineStr = reader.ReadLine();
if (lineStr == null) {
break;
}
MutableString line = MutableString.CreateMutable(lineStr.Length + 1, encoding);
line.Append(lineStr).Append('\n');
lines.Add(line);
}
}
// Publish the contents of the file, keyed by the file name
MutableString path = MutableString.Create(file.Document.FileName, _context.GetPathEncoding());
scriptLines[path] = lines;
}
}
示例5: GetSourceCode
private string GetSourceCode(SourceUnit source, SourceSpan span)
{
if (!span.IsValid)
return "invalid location";
char[] buffer = new char[span.Length];
using (var reader = source.GetReader())
{
reader.Read(buffer, span.Start.Index, buffer.Length);
return new string(buffer);
}
}
示例6: Initialize
public void Initialize(SourceUnit sourceUnit) {
ContractUtils.RequiresNotNull(sourceUnit, "sourceUnit");
Initialize(null, sourceUnit.GetReader(), sourceUnit, SourceLocation.MinValue, DefaultBufferCapacity);
}
示例7: InputReader
public InputReader(SourceUnit sourceUnit)
{
_sourceUnit = sourceUnit;
_reader = sourceUnit.GetReader();
}