本文整理汇总了C#中Mono.CSharp.SeekableStreamReader类的典型用法代码示例。如果您正苦于以下问题:C# SeekableStreamReader类的具体用法?C# SeekableStreamReader怎么用?C# SeekableStreamReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SeekableStreamReader类属于Mono.CSharp命名空间,在下文中一共展示了SeekableStreamReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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();
}
示例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;
}
示例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 ();
}
}
}
示例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 ();
}
示例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);
}
示例7: Parse
void Parse (SeekableStreamReader reader, CompilationUnit file)
{
CSharpParser parser = new CSharpParser (reader, file, ctx);
parser.parse ();
}
示例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:
//.........这里部分代码省略.........
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
}
示例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);
}
}
示例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;
}
示例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);
}