本文整理汇总了C#中SourceUnit类的典型用法代码示例。如果您正苦于以下问题:C# SourceUnit类的具体用法?C# SourceUnit怎么用?C# SourceUnit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SourceUnit类属于命名空间,在下文中一共展示了SourceUnit类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GeneratorTest
public void GeneratorTest(SourceUnit sourceUnit, bool useLua52)
{
var options = new LuaCompilerOptions()
{
SkipFirstLine = true,
UseLua52Features = useLua52,
};
var reader = TestUtils.OpenReaderOrIgnoreTest(sourceUnit.GetReader);
TestUtils.AssertSyntaxError(() =>
{
var tokenizer = new Tokenizer(ErrorSink.Default, options);
tokenizer.Initialize(null, reader, sourceUnit, SourceLocation.MinValue);
var parser = new Parser(tokenizer, tokenizer.ErrorSink, options);
var ast = parser.Parse();
Assert.That(ast, Is.Not.Null);
var codeContext = new CodeContext((LuaContext)sourceUnit.LanguageContext);
var gen = new Generator(codeContext);
var expr = gen.Compile(ast, sourceUnit);
Assert.That(expr, Is.Not.Null);
});
}
开发者ID:SPARTAN563,项目名称:IronLua,代码行数:25,代码来源:GeneratorTests.cs
示例2: OptimizedScriptCode
public OptimizedScriptCode(Scope optimizedScope, DlrMainCallTarget optimizedTarget, SourceUnit sourceUnit)
: base(sourceUnit) {
ContractUtils.RequiresNotNull(optimizedScope, "optimizedScope");
_optimizedScope = optimizedScope;
_optimizedTarget = optimizedTarget;
}
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:7,代码来源:OptimizedScriptCode.cs
示例3: SourceUnitReader
internal SourceUnitReader(SourceUnit sourceUnit, TextReader textReader)
{
Assert.NotNull(sourceUnit, textReader);
_textReader = textReader;
_sourceUnit = sourceUnit;
}
开发者ID:robertlj,项目名称:IronScheme,代码行数:7,代码来源:SourceUnitReader.cs
示例4: Lexer
internal Lexer(SourceUnit unit, HappyLanguageContext languageContext)
{
_reader = new InputReader(unit);
_errorCollector = new ErrorCollector(languageContext.ErrorSink);
PushState(LexerMode.LexingStatement);
_keywords["if"] = HappyTokenKind.KeywordIf;
_keywords["else"] = HappyTokenKind.KeywordElse;
_keywords["while"] = HappyTokenKind.KeywordWhile;
_keywords["for"] = HappyTokenKind.KeywordFor;
_keywords["in"] = HappyTokenKind.KeywordIn;
_keywords["between"] = HappyTokenKind.KeywordBetween;
_keywords["where"] = HappyTokenKind.KeywordWhere;
_keywords["lookup"] = HappyTokenKind.KeywordLookup;
_keywords["default"] = HappyTokenKind.KeywordDefault;
_keywords["true"] = HappyTokenKind.LiteralBool;
_keywords["false"] = HappyTokenKind.LiteralBool;
_keywords["return"] = HappyTokenKind.KeywordReturn;
_keywords["def"] = HappyTokenKind.KeywordDef;
_keywords["null"] = HappyTokenKind.LiteralNull;
_keywords["load"] = HappyTokenKind.KeywordLoad;
_keywords["use"] = HappyTokenKind.KeywordUse;
_keywords["new"] = HappyTokenKind.KeywordNew;
_keywords["function"] = HappyTokenKind.KeywordFunction;
_keywords["break"] = HappyTokenKind.KeywordBreak;
_keywords["continue"] = HappyTokenKind.KeywordContinue;
_keywords["switch"] = HappyTokenKind.KeywordSwitch;
_keywords["case"] = HappyTokenKind.KeywordCase;
}
开发者ID:dlurton,项目名称:Happy,代码行数:29,代码来源:Lexer.cs
示例5: HappySourceLocation
HappySourceLocation(SourceUnit unit, SourceSpan span)
{
//ContractUtils.RequiresNotNull(unit, "unit");
ContractUtils.RequiresNotNull(span, "span");
this.Unit = unit;
this.Span = span;
}
开发者ID:dlurton,项目名称:Happy,代码行数:7,代码来源:HappySourceLocation.cs
示例6: Initialize
public override void Initialize(object state, TextReader textreader, SourceUnit sourceUnit, SS.SourceLocation initialLocation)
{
tokenizer = new Tokenizer (textreader.ReadToEnd ().ToCharArray (), new IdentifierTable ());
tokenizer.Position = ConvertToMJCSrcLocation(initialLocation);
this.sourceUnit = sourceUnit;
this.state = state;
}
开发者ID:alesliehughes,项目名称:olive,代码行数:7,代码来源:JSTokenizerService.cs
示例7: LambdaFunctionExpr
public LambdaFunctionExpr(SourceUnit/*!*/ sourceUnit,
Position position, Position entireDeclarationPosition, ShortPosition headingEndPosition, ShortPosition declarationBodyPosition,
Scope scope, NamespaceDecl ns,
bool aliasReturn, List<FormalParam>/*!*/ formalParams, List<FormalParam> useParams,
List<Statement>/*!*/ body)
: base(position)
{
Debug.Assert(formalParams != null && body != null);
// inject use parameters at the begining of formal parameters
if (useParams != null && useParams.Count > 0)
{
if (formalParams.Count == 0)
formalParams = useParams; // also we don't want to modify Parser.emptyFormalParamListIndex singleton.
else
formalParams.InsertRange(0, useParams);
}
//this.ns = ns;
this.signature = new Signature(aliasReturn, formalParams);
this.useParams = useParams;
//this.typeSignature = new TypeSignature(genericParams);
//this.attributes = new CustomAttributes(attributes);
this.body = body;
this.entireDeclarationPosition = entireDeclarationPosition;
this.headingEndPosition = headingEndPosition;
this.declarationBodyPosition = declarationBodyPosition;
//QualifiedName qn = (ns != null) ? new QualifiedName(this.name, ns.QualifiedName) : new QualifiedName(this.name);
//function = new PhpFunction(qn, memberAttributes, signature, typeSignature, isConditional, scope, sourceUnit, position);
function = new PhpLambdaFunction(this.signature, sourceUnit, position);
function.WriteUp(new TypeSignature(FormalTypeParam.EmptyList).ToPhpRoutineSignature(function));
}
开发者ID:Ashod,项目名称:Phalanger,代码行数:33,代码来源:LambdaFunctionExpr.cs
示例8: Add
public override void Add(SourceUnit sourceUnit, string message, SourceSpan span, int errorCode, Severity severity)
{
base.Add(sourceUnit, message, span, errorCode, severity);
Console.Error.WriteLine("{0}({1}:{2}): {3}: RB{4}: {5}", sourceUnit.Name, span.Start.Line, span.Start.Column,
severity, errorCode, message);
}
开发者ID:TerabyteX,项目名称:main,代码行数:7,代码来源:Program.cs
示例9: Add
public override void Add(SourceUnit sourceUnit, string message, SourceSpan span, int errorCode, Severity severity) {
if (severity == Severity.Warning) {
PythonOps.SyntaxWarning(message, sourceUnit, span, errorCode);
} else {
throw PythonOps.SyntaxError(message, sourceUnit, span, errorCode);
}
}
开发者ID:rchandrashekara,项目名称:main,代码行数:7,代码来源:_ast.cs
示例10: EvaluatePriorAnalysis
internal override Evaluation EvaluatePriorAnalysis(SourceUnit/*!*/ sourceUnit)
{
Evaluation left_eval = leftExpr.EvaluatePriorAnalysis(sourceUnit);
Evaluation right_eval = leftExpr.EvaluatePriorAnalysis(sourceUnit);
return Evaluation.ReadOnlyEvaluate(this, left_eval, right_eval);
}
开发者ID:Ashod,项目名称:Phalanger,代码行数:7,代码来源:BinaryEx.cs
示例11: LuaScriptCode
public LuaScriptCode(CodeContext context, SourceUnit sourceUnit, Expression<Func<IDynamicMetaObjectProvider, dynamic>> chunk)
: base(sourceUnit)
{
Contract.Requires(chunk != null);
Context = context;
_exprLambda = chunk;
}
开发者ID:SPARTAN563,项目名称:IronLua,代码行数:7,代码来源:LuaScriptCode.cs
示例12: CompileSourceCode
public override ScriptCode CompileSourceCode(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink)
{
try
{
switch (sourceUnit.Kind)
{
case SourceCodeKind.SingleStatement:
case SourceCodeKind.Expression:
case SourceCodeKind.AutoDetect:
case SourceCodeKind.InteractiveCode:
return new TotemScriptCode(
engine, engine.ParseExprToLambda(sourceUnit),
sourceUnit);
//case SourceCodeKind.Statements:
//case SourceCodeKind.File:
// return new TotemScriptCode(
// engine, engine.ParseFileToLambda(sourceUnit.Path, sourceUnit.GetCode()),
// sourceUnit);
default:
throw Assert.Unreachable;
}
}
catch (Exception e)
{
// Real language implementation would have a specific type
// of exception. Also, they would pass errorSink down into
// the parser and add messages while doing tighter error
// recovery and continuing to parse.
errorSink.Add(sourceUnit, e.Message, SourceSpan.None, 0,
Severity.FatalError);
return null;
}
}
开发者ID:Alxandr,项目名称:Totem-2.0,代码行数:35,代码来源:TotemContext.cs
示例13: 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;
int line = span.Start.Line;
if (sourceUnit != null) {
path = sourceUnit.Path;
codeLine = (line > 0) ? sourceUnit.GetCodeLine(line) : null;
} else {
path = null;
codeLine = null;
}
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.CreateMutable(message));
}
}
开发者ID:jcteague,项目名称:ironruby,代码行数:35,代码来源:RuntimeErrorSink.cs
示例14: ExecutionContextExpression
/// <summary>
/// Creates a wrapper around a function which represents entry into a chunk of code
/// </summary>
public ExecutionContextExpression(CodeContext context, Expression scopeVariable, SourceUnit source, Expression body)
{
_context = context;
_body = body;
_scope = scopeVariable;
_source = source;
}
开发者ID:SPARTAN563,项目名称:IronLua,代码行数:10,代码来源:ExecutionContextExpression.cs
示例15: Parse
private SourceUnitTree Parse(SourceUnit sourceUnit, bool allowSingle, out bool isExpression)
{
isExpression = false;
IronyParser parser = new IronyParser(allowSingle ? singleStatement : fullGrammar);
parser.Context.Mode = ParseMode.CommandLine;
scopes = new Stack<LexicalScopeBuilder>();
EnterTopLevelScope();
try
{
var parsedScript = parser.Parse(sourceUnit.GetCode());
if (parsedScript.HasErrors())
{
sourceUnit.CodeProperties = ScriptCodeParseResult.Invalid;
return null;
}
if (sourceUnit.Kind == SourceCodeKind.InteractiveCode && parser.Context.Status == ParserStatus.AcceptedPartial)
{
sourceUnit.CodeProperties = ScriptCodeParseResult.IncompleteStatement;
return null;
}
sourceUnit.CodeProperties = ScriptCodeParseResult.Complete;
return BuildSourceTree(parsedScript.Root, sourceUnit, allowSingle, out isExpression);
}
catch (Exception e)
{
throw;
}
finally
{
LeaveScope();
}
}
开发者ID:Alxandr,项目名称:Totem-2.0,代码行数:35,代码来源:Parser.cs
示例16: Analyze
public HappyLambdaScriptCode Analyze(Module module, SourceUnit sourceUnit)
{
Dictionary<string, HappyNamespaceTracker> rootNamespaces = LoadAllAssemblies(module.LoadDirectives);
AstVisitorBase[] visitors =
{
new BinaryExpressionFixerVisitor(),
new BuildSymbolTablesVisitor(this, _errorCollector, rootNamespaces),
new ResolveSymbolsVisitor(_errorCollector),
new SemanticVisitor(_errorCollector)
};
foreach (var v in visitors)
module.Accept(v);
prepareAssemblyGenerator();
module.Accept(this);
Expression expression = _expressionStack.Pop();
DebugAssert.IsZero(_expressionStack.Count, "AstAnalyzer didn't consume all expressions on the stack");
var runtimeContextInitializer = (LambdaExpression)expression;
return new HappyLambdaScriptCode(sourceUnit, compileDynamicAssembly(runtimeContextInitializer));
}
开发者ID:dlurton,项目名称:Happy,代码行数:25,代码来源:AstAnalyzer.Module.cs
示例17: ParseModule
public static Module ParseModule(SourceUnit sourceUnit, HappyLanguageContext languageContext)
{
Lexer lexer = new Lexer(sourceUnit, languageContext);
Parser parser = new Parser(lexer, languageContext);
Module retval = null;
try
{
retval = parser.Parse();
}
catch(AbortParseException)
{
//Left blank intentionally because AbortParseExceptions should never
//be allowed to bubble up to the caller.
}
catch(SyntaxErrorException)
{
//We actually want to allow this exception to propogate as-is back
//to the caller. This is needed because of the catch-all below
throw;
}
catch(Exception e)
{
//All other exceptions are to be considered an internal error
//We may not know the exact location of the error, but we'll just
//take the next token out of the lexer to give *some* kind of
//idea line might contain the error
DebugAssert.IsNotNull(e);
Token t = lexer.NextToken();
throw new InternalSourceException(e, t.Location,
"The parser threw an unhandled exception. This is usually caused by a syntax error " +
"in the script being parsed. The error ocurred at or before the this locaiton.");
}
return retval;
}
开发者ID:dlurton,项目名称:Happy,代码行数:34,代码来源:Parser.cs
示例18: LambdaFunctionExpr
public LambdaFunctionExpr(SourceUnit/*!*/ sourceUnit,
Text.Span span, Text.Span entireDeclarationPosition, int headingEndPosition, int declarationBodyPosition,
Scope scope, NamespaceDecl ns,
bool aliasReturn, List<FormalParam>/*!*/ formalParams, List<FormalParam> useParams,
List<Statement>/*!*/ body)
: base(span)
{
Debug.Assert(formalParams != null && body != null);
// inject use parameters at the begining of formal parameters
if (useParams != null && useParams.Count > 0)
{
if (formalParams.Count == 0)
formalParams = useParams; // also we don't want to modify Parser.emptyFormalParamListIndex singleton.
else
formalParams.InsertRange(0, useParams);
}
//this.ns = ns;
this.signature = new Signature(aliasReturn, formalParams);
this.useParams = useParams;
//this.typeSignature = new TypeSignature(genericParams);
//this.attributes = new CustomAttributes(attributes);
this.body = body;
this.entireDeclarationPosition = entireDeclarationPosition;
this.headingEndPosition = headingEndPosition;
this.declarationBodyPosition = declarationBodyPosition;
}
开发者ID:kaviarasankk,项目名称:Phalanger,代码行数:28,代码来源:LambdaFunctionExpr.cs
示例19: ParseExprToLambda
internal LightExpression<Func<TotemEngine, IDynamicMetaObjectProvider, object>> ParseExprToLambda(SourceUnit sourceUnit)
{
bool isExpression;
var ast = new Parser().ParseExpression(sourceUnit, out isExpression);
if (ast == null)
return null;
var scope = new AnalysisScope.TopLevel(
this,
Expression.Parameter(typeof(TotemEngine), "totemRuntime"),
Expression.Parameter(typeof(IDynamicMetaObjectProvider), "global"));
var ret = Expression.Variable(typeof(object), "#__returnVariable");
List<Expression> body = new List<Expression>();
var b = AstGenerator.Generate(ast, scope);
body.Add(Expression.Assign(ret, Expression.Convert(b, typeof(object))));
if (sourceUnit.Kind == SourceCodeKind.InteractiveCode)
{
if(isExpression) body.Add(Expression.Call(typeof(Console).GetMethod("WriteLine", new[] { typeof(object) }), ret));
body.Add(Expression.Call(typeof(Console).GetMethod("WriteLine", Type.EmptyTypes)));
body.Add(ret);
}
var moduleFun = Utils.LightLambda<Func<TotemEngine, IDynamicMetaObjectProvider, object>>(
typeof(object),
Expression.Block(new ParameterExpression[] { ret }, body),
"_snippet_",
new List<ParameterExpression>() { scope.RuntimeExpr, scope.GlobalExpr }
);
//var moduleFun = Expression.Lambda<Func<TotemEngine, IDynamicMetaObjectProvider, object>>(
// Expression.Block(new ParameterExpression[] { ret }, body),
// scope.RuntimeExpr,
// scope.ModuleExpr
//);
return moduleFun;
}
开发者ID:Alxandr,项目名称:Totem-2.0,代码行数:35,代码来源:TotemEngine.cs
示例20: RubyScriptCode
internal RubyScriptCode(ScriptCodeFunc/*!*/ target, SourceUnit/*!*/ sourceUnit, TopScopeFactoryKind kind)
: base(sourceUnit)
{
Assert.NotNull(target);
_target = target;
_kind = kind;
}
开发者ID:TerabyteX,项目名称:main,代码行数:7,代码来源:RubyScriptCode.cs
注:本文中的SourceUnit类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论