本文整理汇总了C#中SourceUnit类的典型用法代码示例。如果您正苦于以下问题:C# SourceUnit类的具体用法?C# SourceUnit怎么用?C# SourceUnit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SourceUnit类属于命名空间,在下文中一共展示了SourceUnit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
});
}
示例2: OptimizedScriptCode
public OptimizedScriptCode(Scope optimizedScope, DlrMainCallTarget optimizedTarget, SourceUnit sourceUnit)
: base(sourceUnit) {
ContractUtils.RequiresNotNull(optimizedScope, "optimizedScope");
_optimizedScope = optimizedScope;
_optimizedTarget = optimizedTarget;
}
示例3: SourceUnitReader
internal SourceUnitReader(SourceUnit sourceUnit, TextReader textReader)
{
Assert.NotNull(sourceUnit, textReader);
_textReader = textReader;
_sourceUnit = sourceUnit;
}
示例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;
}
示例5: HappySourceLocation
HappySourceLocation(SourceUnit unit, SourceSpan span)
{
//ContractUtils.RequiresNotNull(unit, "unit");
ContractUtils.RequiresNotNull(span, "span");
this.Unit = unit;
this.Span = span;
}
示例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;
}
示例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));
}
示例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);
}
示例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);
}
}
示例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);
}
示例11: LuaScriptCode
public LuaScriptCode(CodeContext context, SourceUnit sourceUnit, Expression<Func<IDynamicMetaObjectProvider, dynamic>> chunk)
: base(sourceUnit)
{
Contract.Requires(chunk != null);
Context = context;
_exprLambda = chunk;
}
示例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;
}
}
示例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));
}
}
示例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;
}
示例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();
}
}