本文整理汇总了C#中Mono.CSharp.SeekableStreamReader类的典型用法代码示例。如果您正苦于以下问题:C# SeekableStreamReader类的具体用法?C# SeekableStreamReader怎么用?C# SeekableStreamReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SeekableStreamReader类属于Mono.CSharp命名空间,在下文中一共展示了SeekableStreamReader类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: tokenize_file
void tokenize_file (CompilationUnit file, CompilerContext ctx)
{
Stream input;
try {
input = File.OpenRead (file.Name);
} catch {
Report.Error (2001, "Source file `" + file.Name + "' could not be found");
return;
}
using (input){
SeekableStreamReader reader = new SeekableStreamReader (input, RootContext.Encoding);
Tokenizer lexer = new Tokenizer (reader, file, ctx);
int token, tokens = 0, errors = 0;
while ((token = lexer.token ()) != Token.EOF){
tokens++;
if (token == Token.ERROR)
errors++;
}
Console.WriteLine ("Tokenized: " + tokens + " found " + errors + " errors");
}
return;
}
开发者ID:nekresh,项目名称:mono,代码行数:26,代码来源:driver.cs
示例2: Parse
public static void Parse(SeekableStreamReader reader, SourceFile sourceFile, ModuleContainer module, ParserSession session, Report report)
{
var file = new CompilationSourceFile(module, sourceFile);
module.AddTypeContainer(file);
CSharpParser parser = new CSharpParser(reader, file, report, session);
parser.parse();
}
开发者ID:Nystul-the-Magician,项目名称:daggerfall-unity,代码行数:8,代码来源:CustomDynamicDriver.cs
示例3: tokenize_file
void tokenize_file (SourceFile sourceFile, ModuleContainer module, ParserSession session)
{
Stream input;
try {
input = File.OpenRead (sourceFile.Name);
} catch {
Report.Error (2001, "Source file `" + sourceFile.Name + "' could not be found");
return;
}
using (input) {
SeekableStreamReader reader = new SeekableStreamReader (input, ctx.Settings.Encoding);
var file = new CompilationSourceFile (module, sourceFile);
if (sourceFile.FileType == SourceFileType.CSharp) {
Tokenizer lexer = new Tokenizer (reader, file, session);
int token, tokens = 0, errors = 0;
while ((token = lexer.token ()) != Token.EOF){
tokens++;
if (token == Token.ERROR)
errors++;
}
} else {
Mono.PlayScript.Tokenizer lexer = new Mono.PlayScript.Tokenizer (reader, file, session);
lexer.ParsingPlayScript = sourceFile.PsExtended;
int token, tokens = 0, errors = 0;
while ((token = lexer.token ()) != Mono.PlayScript.Token.EOF){
tokens++;
if (token == Mono.PlayScript.Token.ERROR)
errors++;
}
}
}
return;
}
开发者ID:robterrell,项目名称:playscript-mono,代码行数:39,代码来源:driver.cs
示例4: ParseFile
public static CompilerCompilationUnit ParseFile(string[] args, Stream input, string inputFile, ReportPrinter reportPrinter)
{
lock (parseLock) {
try {
Driver d = Driver.Create (args, false, null, reportPrinter);
if (d == null)
return null;
Location.AddFile (null, inputFile);
Location.Initialize ();
// TODO: encoding from driver
SeekableStreamReader reader = new SeekableStreamReader (input, Encoding.Default);
CompilerContext ctx = new CompilerContext (new Report (reportPrinter));
RootContext.ToplevelTypes = new ModuleContainer (ctx);
CompilationUnit unit = null;
try {
unit = (CompilationUnit) Location.SourceFiles [0];
} catch (Exception) {
string path = Path.GetFullPath (inputFile);
unit = new CompilationUnit (inputFile, path, 0);
}
CSharpParser parser = new CSharpParser (reader, unit, RootContext.ToplevelTypes);
parser.Lexer.TabSize = 1;
parser.Lexer.sbag = new SpecialsBag ();
parser.LocationsBag = new LocationsBag ();
parser.UsingsBag = new UsingsBag ();
parser.parse ();
return new CompilerCompilationUnit () { ModuleCompiled = RootContext.ToplevelTypes, LocationsBag = parser.LocationsBag, UsingsBag = parser.UsingsBag, SpecialsBag = parser.Lexer.sbag };
} finally {
Reset ();
}
}
}
开发者ID:richardschneider,项目名称:ILSpy,代码行数:37,代码来源:driver.cs
示例5: Parse
void Parse(CompilationUnit file, ModuleContainer module)
{
Stream input;
try {
input = File.OpenRead (file.Name);
} catch {
Report.Error (2001, "Source file `{0}' could not be found", file.Name);
return;
}
// Check 'MZ' header
if (input.ReadByte () == 77 && input.ReadByte () == 90) {
Report.Error (2015, "Source file `{0}' is a binary file and not a text file", file.Name);
input.Close ();
return;
}
input.Position = 0;
SeekableStreamReader reader = new SeekableStreamReader (input, ctx.Settings.Encoding);
Parse (reader, file, module);
reader.Dispose ();
input.Close ();
}
开发者ID:RainsSoft,项目名称:MonoCompilerAsAService,代码行数:25,代码来源:driver.cs
示例6: GenerateEmbedClasses
public static void GenerateEmbedClasses(ModuleContainer module, ParserSession session, Report report)
{
List<EmbedData> embeds = new List<EmbedData>();
FindEmbedClasses(module, module, embeds);
if (embeds.Count == 0)
return;
var os = new StringWriter();
os.Write (@"
// Generated embed loader classes
");
foreach (var e in embeds) {
var loc = e._field.Location;
e._field.Initializer = new TypeOf(new MemberAccess(new SimpleName("_embed_loaders", loc), e._className), loc);
os.Write (@"
namespace _embed_loaders {{
internal class {1} : PlayScript.EmbedLoader {{
public {1}() : base({2}, {3}, {4}, {5}, {6}) {{
}}
}}
}}
", PsConsts.PsRootNamespace, e._className, e.source, e.mimeType, e.embedAsCFF, e.fontFamily, e.symbol);
}
string fileStr = os.ToString();
var path = System.IO.Path.Combine (System.IO.Path.GetDirectoryName(System.IO.Path.GetFullPath(module.Compiler.Settings.OutputFile)), "embed.g.cs");
System.IO.File.WriteAllText(path, fileStr);
byte[] byteArray = Encoding.ASCII.GetBytes( fileStr );
var input = new MemoryStream( byteArray, false );
var reader = new SeekableStreamReader (input, System.Text.Encoding.UTF8);
SourceFile file = new SourceFile(path, path, 0);
file.FileType = SourceFileType.CSharp;
Driver.Parse (reader, file, module, session, report);
}
开发者ID:rlfqudxo,项目名称:playscript-mono,代码行数:46,代码来源:ps-codegen.cs
示例7: Parse
void Parse (SeekableStreamReader reader, CompilationUnit file)
{
CSharpParser parser = new CSharpParser (reader, file, ctx);
parser.parse ();
}
开发者ID:Ein,项目名称:monodevelop,代码行数:5,代码来源:driver.cs
示例8: ToplevelOrStatement
//
// Deambiguates the input string to determine if we
// want to process a statement or if we want to
// process a compilation unit.
//
// This is done using a top-down predictive parser,
// since the yacc/jay parser can not deambiguage this
// without more than one lookahead token. There are very
// few ambiguities.
//
InputKind ToplevelOrStatement (SeekableStreamReader seekable)
{
Tokenizer tokenizer = new Tokenizer (seekable, source_file);
int t = tokenizer.token ();
switch (t){
case Token.EOF:
return InputKind.EOF;
// These are toplevels
case Token.EXTERN:
case Token.OPEN_BRACKET:
case Token.ABSTRACT:
case Token.CLASS:
case Token.ENUM:
case Token.INTERFACE:
case Token.INTERNAL:
case Token.NAMESPACE:
case Token.PRIVATE:
case Token.PROTECTED:
case Token.PUBLIC:
case Token.SEALED:
case Token.STATIC:
case Token.STRUCT:
return InputKind.CompilationUnit;
// Definitely expression
case Token.FIXED:
case Token.BOOL:
case Token.BYTE:
case Token.CHAR:
case Token.DECIMAL:
case Token.DOUBLE:
case Token.FLOAT:
case Token.INT:
case Token.LONG:
case Token.NEW:
case Token.OBJECT:
case Token.SBYTE:
case Token.SHORT:
case Token.STRING:
case Token.UINT:
case Token.ULONG:
return InputKind.StatementOrExpression;
// These need deambiguation help
case Token.USING:
t = tokenizer.token ();
if (t == Token.EOF)
return InputKind.EOF;
if (t == Token.IDENTIFIER)
return InputKind.CompilationUnit;
return InputKind.StatementOrExpression;
// Distinguish between:
// delegate opt_anonymous_method_signature block
// delegate type
case Token.DELEGATE:
t = tokenizer.token ();
if (t == Token.EOF)
return InputKind.EOF;
if (t == Token.OPEN_PARENS || t == Token.OPEN_BRACE)
return InputKind.StatementOrExpression;
return InputKind.CompilationUnit;
// Distinguih between:
// unsafe block
// unsafe as modifier of a type declaration
case Token.UNSAFE:
t = tokenizer.token ();
if (t == Token.EOF)
return InputKind.EOF;
if (t == Token.OPEN_PARENS)
return InputKind.StatementOrExpression;
return InputKind.CompilationUnit;
// These are errors: we list explicitly what we had
// from the grammar, ERROR and then everything else
case Token.READONLY:
case Token.OVERRIDE:
case Token.ERROR:
return InputKind.Error;
// This catches everything else allowed by
// expressions. We could add one-by-one use cases
// if needed.
default:
//.........这里部分代码省略.........
开发者ID:KAW0,项目名称:Alter-Native,代码行数:101,代码来源:eval.cs
示例9: CSharpParser
public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report)
{
this.file = file;
current_container = current_namespace = file;
this.module = file.Module;
this.compiler = file.Compiler;
this.settings = compiler.Settings;
this.report = report;
lang_version = settings.Version;
yacc_verbose_flag = settings.VerboseParserFlag;
doc_support = settings.DocumentationFile != null;
oob_stack.Clear ();
lexer = new Tokenizer (reader, file);
#if FULL_AST
lbag = new LocationsBag ();
#else
lbag = null;
#endif
use_global_stacks = true;
}
开发者ID:xamarin-release-manager,项目名称:monodevelop,代码行数:24,代码来源:cs-parser.cs
示例10: CSharpParser
public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
{
this.file = file;
current_container = current_namespace = file;
this.module = file.Module;
this.compiler = file.Compiler;
this.settings = compiler.Settings;
this.report = report;
lang_version = settings.Version;
yacc_verbose_flag = settings.VerboseParserFlag;
doc_support = settings.DocumentationFile != null;
lexer = new Tokenizer (reader, file, session);
oob_stack = new Stack<object> ();
lbag = session.LocationsBag;
use_global_stacks = session.UseJayGlobalArrays;
parameters_bucket = session.ParametersStack;
}
开发者ID:segaman,项目名称:NRefactory,代码行数:19,代码来源:cs-parser.cs
示例11: Parse
SyntaxTree Parse(ITextSource program, string fileName, int initialLine, int initialColumn)
{
lock (parseLock) {
errorReportPrinter = new ErrorReportPrinter("");
var ctx = new CompilerContext(compilerSettings.ToMono(), errorReportPrinter);
ctx.Settings.TabSize = 1;
var reader = new SeekableStreamReader(program);
var file = new SourceFile(fileName, fileName, 0);
Location.Initialize(new List<SourceFile>(new [] { file }));
var module = new ModuleContainer(ctx);
var session = new ParserSession();
session.LocationsBag = new LocationsBag();
var report = new Report(ctx, errorReportPrinter);
var parser = Driver.Parse(reader, file, module, session, report, initialLine - 1, initialColumn - 1);
var top = new CompilerCompilationUnit {
ModuleCompiled = module,
LocationsBag = session.LocationsBag,
SpecialsBag = parser.Lexer.sbag,
Conditionals = parser.Lexer.SourceFile.Conditionals
};
var unit = Parse(top, fileName);
unit.Errors.AddRange(errorReportPrinter.Errors);
CompilerCallableEntryPoint.Reset();
return unit;
}
}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:26,代码来源:CSharpParser.cs
示例12: Parse
public CompilationUnit Parse(Stream stream, string fileName, int lineModifier = 0)
{
lock (parseLock) {
errorReportPrinter = new ErrorReportPrinter ("");
var ctx = new CompilerContext (CompilerSettings, errorReportPrinter);
ctx.Settings.TabSize = 1;
var reader = new SeekableStreamReader (stream, Encoding.UTF8);
var file = new SourceFile (fileName, fileName, 0);
Location.Initialize (new List<SourceFile> (new [] { file }));
var module = new ModuleContainer (ctx);
var parser = Driver.Parse (reader, file, module, lineModifier);
var top = new CompilerCompilationUnit () {
ModuleCompiled = module,
LocationsBag = parser.LocationsBag,
SpecialsBag = parser.Lexer.sbag
};
var unit = Parse (top, fileName, lineModifier);
unit.Errors.AddRange (errorReportPrinter.Errors);
CompilerCallableEntryPoint.Reset ();
return unit;
}
}
开发者ID:head-thrash,项目名称:monodevelop,代码行数:23,代码来源:CSharpParser.cs
示例13: Parse
void Parse (SeekableStreamReader reader, CompilationUnit file)
{
CSharpParser parser = new CSharpParser (reader, file);
parser.ErrorOutput = Report.Stderr;
try {
parser.parse ();
} catch (Exception ex) {
Report.Error(589, parser.Lexer.Location,
"Compilation aborted in file `{0}', {1}", file.Name, ex);
}
}
开发者ID:lewurm,项目名称:benchmarker,代码行数:11,代码来源:driver.cs
示例14: CSharpParser
public CSharpParser (SeekableStreamReader reader, CompilationUnit file, CompilerContext ctx)
{
if (RootContext.EvalMode)
undo = new Undo ();
this.file = file;
this.compiler = ctx;
current_namespace = new NamespaceEntry (ctx, null, file, null);
current_class = current_namespace.SlaveDeclSpace;
current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
oob_stack.Clear ();
lexer = new Tokenizer (reader, file, ctx);
use_global_stacks = true;
}
开发者ID:Ein,项目名称:monodevelop,代码行数:15,代码来源:cs-parser.cs
示例15: Tokenizer
public Tokenizer (SeekableStreamReader input, CompilationUnit file, CompilerContext ctx)
{
this.ref_name = file;
this.file_name = file;
this.context = ctx;
reader = input;
putback_char = -1;
xml_comment_buffer = new StringBuilder ();
//
// FIXME: This could be `Location.Push' but we have to
// find out why the MS compiler allows this
//
Mono.CSharp.Location.Push (file, file);
}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:17,代码来源:cs-tokenizer.cs
示例16: Parse
public static CSharpParser Parse(SeekableStreamReader reader, SourceFile sourceFile, ModuleContainer module, ParserSession session, Report report, int lineModifier = 0, int colModifier = 0)
{
var file = new CompilationSourceFile (module, sourceFile);
module.AddTypeContainer(file);
CSharpParser parser = new CSharpParser (reader, file, report, session);
parser.Lexer.Line += lineModifier;
parser.Lexer.Column += colModifier;
parser.Lexer.sbag = new SpecialsBag ();
parser.parse ();
return parser;
}
开发者ID:riviti,项目名称:NRefactory,代码行数:12,代码来源:driver.cs
示例17: CSharpParser
public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file)
{
this.file = file;
current_namespace = file.NamespaceContainer;
this.module = current_namespace.Module;
this.compiler = module.Compiler;
this.settings = compiler.Settings;
lang_version = settings.Version;
doc_support = settings.Documentation != null;
current_class = current_namespace.SlaveDeclSpace;
current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
oob_stack.Clear ();
lexer = new Tokenizer (reader, file, compiler);
use_global_stacks = true;
}
开发者ID:okrmartin,项目名称:monodevelop,代码行数:17,代码来源:cs-parser.cs
示例18: HandleXrefCommon
//
// Processes "see" or "seealso" elements from cref attribute.
//
void HandleXrefCommon (MemberCore mc, TypeContainer ds, XmlElement xref)
{
string cref = xref.GetAttribute ("cref");
// when, XmlReader, "if (cref == null)"
if (!xref.HasAttribute ("cref"))
return;
// Nothing to be resolved the reference is marked explicitly
if (cref.Length > 2 && cref [1] == ':')
return;
// Additional symbols for < and > are allowed for easier XML typing
cref = cref.Replace ('{', '<').Replace ('}', '>');
var encoding = module.Compiler.Settings.Encoding;
var s = new MemoryStream (encoding.GetBytes (cref));
SeekableStreamReader seekable = new SeekableStreamReader (s, encoding);
var source_file = new CompilationSourceFile (doc_module);
var report = new Report (doc_module.Compiler, new NullReportPrinter ());
var parser = new CSharpParser (seekable, source_file, report);
ParsedParameters = null;
ParsedName = null;
ParsedBuiltinType = null;
ParsedOperator = null;
parser.Lexer.putback_char = Tokenizer.DocumentationXref;
parser.Lexer.parsing_generic_declaration_doc = true;
parser.parse ();
if (report.Errors > 0) {
Report.Warning (1584, 1, mc.Location, "XML comment on `{0}' has syntactically incorrect cref attribute `{1}'",
mc.GetSignatureForError (), cref);
xref.SetAttribute ("cref", "!:" + cref);
return;
}
MemberSpec member;
string prefix = null;
FullNamedExpression fne = null;
//
// Try built-in type first because we are using ParsedName as identifier of
// member names on built-in types
//
if (ParsedBuiltinType != null && (ParsedParameters == null || ParsedName != null)) {
member = ParsedBuiltinType.Type;
} else {
member = null;
}
if (ParsedName != null || ParsedOperator.HasValue) {
TypeSpec type = null;
string member_name = null;
if (member == null) {
if (ParsedOperator.HasValue) {
type = mc.CurrentType;
} else if (ParsedName.Left != null) {
fne = ResolveMemberName (mc, ParsedName.Left);
if (fne != null) {
var ns = fne as Namespace;
if (ns != null) {
fne = ns.LookupTypeOrNamespace (mc, ParsedName.Name, ParsedName.Arity, LookupMode.Probing, Location.Null);
if (fne != null) {
member = fne.Type;
}
} else {
type = fne.Type;
}
}
} else {
fne = ResolveMemberName (mc, ParsedName);
if (fne == null) {
type = mc.CurrentType;
} else if (ParsedParameters == null) {
member = fne.Type;
} else if (fne.Type.MemberDefinition == mc.CurrentType.MemberDefinition) {
member_name = Constructor.ConstructorName;
type = fne.Type;
}
}
} else {
type = (TypeSpec) member;
member = null;
}
if (ParsedParameters != null) {
var old_printer = mc.Module.Compiler.Report.SetPrinter (new NullReportPrinter ());
foreach (var pp in ParsedParameters) {
pp.Resolve (mc);
}
mc.Module.Compiler.Report.SetPrinter (old_printer);
}
if (type != null) {
if (member_name == null)
//.........这里部分代码省略.........
开发者ID:royleban,项目名称:mono,代码行数:101,代码来源:doc.cs
示例19: GenerateDynamicPartialClasses
public static void GenerateDynamicPartialClasses(ModuleContainer module, ParserSession session, Report report)
{
List<Class> classes = new List<Class>();
FindDynamicClasses(module, classes);
if (classes.Count == 0)
return;
var os = new StringWriter();
os.Write (@"
// Generated dynamic class partial classes
");
foreach (var cl in classes) {
os.Write (@"
namespace {1} {{
partial class {2} : PlayScript.IDynamicClass {{
private PlayScript.IDynamicClass __dynamicProps;
dynamic PlayScript.IDynamicClass.__GetDynamicValue(string name) {{
object value = null;
if (__dynamicProps != null) {{
value = __dynamicProps.__GetDynamicValue(name);
}}
return value;
}}
bool PlayScript.IDynamicClass.__TryGetDynamicValue(string name, out object value) {{
if (__dynamicProps != null) {{
return __dynamicProps.__TryGetDynamicValue(name, out value);
}} else {{
value = null;
return false;
}}
}}
void PlayScript.IDynamicClass.__SetDynamicValue(string name, object value) {{
if (__dynamicProps == null) {{
__dynamicProps = new PlayScript.DynamicProperties(this);
}}
__dynamicProps.__SetDynamicValue(name, value);
}}
bool PlayScript.IDynamicClass.__DeleteDynamicValue(object name) {{
if (__dynamicProps != null) {{
return __dynamicProps.__DeleteDynamicValue(name);
}}
return false;
}}
bool PlayScript.IDynamicClass.__HasDynamicValue(string name) {{
if (__dynamicProps != null) {{
return __dynamicProps.__HasDynamicValue(name);
}}
return false;
}}
System.Collections.IEnumerable PlayScript.IDynamicClass.__GetDynamicNames() {{
if (__dynamicProps != null) {{
return __dynamicProps.__GetDynamicNames();
}}
return null;
}}
}}
}}
", PsConsts.PsRootNamespace, ((ITypeDefinition)cl).Namespace, cl.MemberName.Basename);
}
string fileStr = os.ToString();
var path = System.IO.Path.Combine (System.IO.Path.GetDirectoryName(System.IO.Path.GetFullPath(module.Compiler.Settings.OutputFile)), "dynamic.g.cs");
System.IO.File.WriteAllText(path, fileStr);
byte[] byteArray = Encoding.ASCII.GetBytes( fileStr );
var input = new MemoryStream( byteArray, false );
var reader = new SeekableStreamReader (input, System.Text.Encoding.UTF8);
SourceFile file = new SourceFile(path, path, 0);
file.FileType = SourceFileType.CSharp;
Driver.Parse (reader, file, module, session, report);
}
开发者ID:rlfqudxo,项目名称:playscript-mono,代码行数:87,代码来源:ps-codegen.cs
示例20: Parse
public void Parse (SourceFile file, ModuleContainer module, ParserSession session, Report report)
{
Stream input;
try {
input = File.OpenRead (file.Name);
} catch {
report.Error (2001, "Source file `{0}' could not be found", file.Name);
return;
}
// Check 'MZ' header
if (input.ReadByte () == 77 && input.ReadByte () == 90) {
report.Error (2015, "Source file `{0}' is a binary file and not a text file", file.Name);
input.Close ();
return;
}
input.Position = 0;
SeekableStreamReader reader = new SeekableStreamReader (input, ctx.Settings.Encoding, session.StreamReaderBuffer);
Parse (reader, file, module, session, report);
if (ctx.Settings.GenerateDebugInfo && report.Errors == 0 && !file.HasChecksum) {
input.Position = 0;
var checksum = session.GetChecksumAlgorithm ();
file.SetChecksum (checksum.ComputeHash (input));
}
reader.Dispose ();
input.Close ();
}
开发者ID:Profit0004,项目名称:mono,代码行数:33,代码来源:driver.cs
注:本文中的Mono.CSharp.SeekableStreamReader类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论