Beispiel #1
0
        public LexemeValue(string content, SourceSpan span)
        {
            CodeContract.RequiresArgumentNotNull(span, "span");

            Content = content;
            Span = span;
        }
Beispiel #2
0
 public static CatchBlock Catch(SourceSpan span, SourceLocation header, Type type, Variable target, Statement body)
 {
     Contract.RequiresNotNull(type, "type");
     Contract.Requires(target == null || TypeUtils.CanAssign(target.Type, type), "target");
     Contract.RequiresNotNull(body, "body");
     return new CatchBlock(span, header, type, target, body);
 }
Beispiel #3
0
 /// <summary>
 /// Called by <see cref="DoStatementBuilder"/>.
 /// </summary>
 internal DoStatement(SourceSpan span, SourceLocation header, Expression /*!*/ test, Statement /*!*/ body)
     : base(AstNodeType.DoStatement, span)
 {
     _header = header;
     _test = test;
     _body = body;
 }
        internal DoStatementBuilder(SourceSpan statementSpan, SourceLocation location, Statement body) {
            Contract.RequiresNotNull(body, "body");

            _body = body;
            _doLocation = location;
            _statementSpan = statementSpan;
        }
        public static ScopeStatement Scope(SourceSpan span, Expression scope, Statement body) {
            Contract.RequiresNotNull(scope, "scope");
            Contract.RequiresNotNull(body, "body");
            Contract.Requires(TypeUtils.CanAssign(typeof(IAttributesCollection), scope.Type), "scope", "Scope must be IAttributesCollection");

            return new ScopeStatement(span, scope, body);
        }
 public static TryStatement TryCatchFinally(SourceSpan span, SourceLocation header, Statement body, CatchBlock[] handlers, Statement @finally)
 {
     return new TryStatement(
         span, header,
          body, CollectionUtils.ToReadOnlyCollection(handlers), @finally
     );
 }
Beispiel #7
0
 public CustomErrorCorrection(int errorId, SourceSpan errorSpan, params object[] parameters)
     : base(CorrectionMethod.Custom)
 {
     ErrorId = errorId;
     ErrorSpan = errorSpan;
     Parameters = parameters;
 }
Beispiel #8
0
 public static ThrowStatement Throw(SourceSpan span, Expression value)
 {
     if (value != null) {
         Contract.Requires(TypeUtils.CanAssign(typeof(Exception), value.Type));
     }
     return new ThrowStatement(span, value);
 }
Beispiel #9
0
        public static SwitchStatement Switch(SourceSpan span, SourceLocation header, Expression value, params SwitchCase[] cases)
        {
            Contract.RequiresNotNull(value, "value");
            Contract.Requires(value.Type == typeof(int), "value", "Value must be int");
            Contract.RequiresNotEmpty(cases, "cases");
            Contract.RequiresNotNullItems(cases, "cases");

            bool @default = false;
            int max = Int32.MinValue;
            int min = Int32.MaxValue;
            foreach (SwitchCase sc in cases) {
                if (sc.IsDefault) {
                    Contract.Requires(@default == false, "cases", "Only one default clause allowed");
                    @default = true;
                } else {
                    int val = sc.Value;
                    if (val > max) max = val;
                    if (val < min) min = val;
                }
            }

            Contract.Requires(UniqueCaseValues(cases, min, max), "cases", "Case values must be unique");

            return new SwitchStatement(span, header, value, CollectionUtils.ToReadOnlyCollection(cases));
        }
Beispiel #10
0
 /// <summary>
 /// Called by <see cref="TryStatementBuilder"/>.
 /// Creates a try/catch/finally/else block.
 /// 
 /// The body is protected by the try block.
 /// The handlers consist of a set of language-dependent tests which call into the LanguageContext.
 /// The elseSuite runs if no exception is thrown.
 /// The finallySuite runs regardless of how control exits the body.
 /// </summary>
 internal TryStatement(SourceSpan span, SourceLocation header, Statement body, ReadOnlyCollection<CatchBlock> handlers, Statement @finally)
     : base(AstNodeType.TryStatement, span)
 {
     _body = body;
     _handlers = handlers;
     _finally = @finally;
     _header = header;
 }
Beispiel #11
0
        internal Lexeme(ScannerInfo scannerInfo, int state, SourceSpan span, string content)
        {
            m_scannerInfo = scannerInfo;
            m_stateIndex = state;
            Value = new LexemeValue(content, span);

            m_trivia = s_emptyTrivia;
        }
Beispiel #12
0
 internal Lexeme(ScannerInfo scannerInfo, int state, SourceSpan span, string value, int skippedTokenCount)
 {
     m_scannerInfo = scannerInfo;
     m_stateIndex = state;
     Span = span;
     Value = value;
     SkippedTokenCount = skippedTokenCount;
 }
Beispiel #13
0
 /// <summary>
 /// Null test means infinite loop.
 /// </summary>
 internal LoopStatement(SourceSpan span, SourceLocation header, Expression test, Expression increment, Statement /*!*/ body, Statement @else)
     : base(AstNodeType.LoopStatement, span) {
     _test = test;
     _increment = increment;
     _body = body;
     _else = @else;
     _header = header;
 }
        internal SwitchStatement(SourceSpan span, SourceLocation header, Expression/*!*/ testValue, ReadOnlyCollection<SwitchCase>/*!*/ cases)
            : base(AstNodeType.SwitchStatement, span) {
            Assert.NotNullItems(cases);

            _testValue = testValue;
            _cases = cases;
            _header = header;
        }
Beispiel #15
0
        public static IfStatementTest IfCondition(SourceSpan span, SourceLocation header, Expression test, Statement body)
        {
            Contract.RequiresNotNull(test, "test");
            Contract.RequiresNotNull(body, "body");
            Contract.Requires(test.Type == typeof(bool), "test", "Test must be boolean");

            return new IfStatementTest(span, header, test, body);
        }
 /// <summary>
 /// Initializes an instance of the ReportItem class.
 /// </summary>
 /// <param name="descriptor">A message descriptor.</param>
 /// <param name="sourceFile">A source file.</param>
 /// <param name="sourceSpan">A source span.</param>
 /// <param name="sourceLine">A source line.</param>
 /// <param name="args">Some arguments required by the message descriptor.</param>
 public ReportItem(MessageDescriptor descriptor, SourceFile sourceFile, SourceSpan sourceSpan,
                   TokenList sourceLine, params string[] args)
 {
     MessageDescriptor = descriptor;
     SourceFile = sourceFile;
     SourceSpan = sourceSpan;
     SourceLine = sourceLine;
     Arguments = args;
 }
Beispiel #17
0
 private SourceSpan Add(string message, SourceSpan span, Severity severity)
 {
     if (severity == Severity.Warning) {
         Warnings.Add(new ErrorResult(message, span));
     } else if (severity == Severity.FatalError || severity == Severity.Error) {
         Errors.Add(new ErrorResult(message, span));
     }
     return span;
 }
Beispiel #18
0
 internal IfStatementTest(SourceSpan span, SourceLocation header, Expression /*!*/ test, Statement /*!*/ body)
     : base(AstNodeType.IfStatementTest)
 {
     _test = test;
     _body = body;
     _header = header;
     _start = span.Start;
     _end = span.End;
 }
        public static CodeBlock Generator(SourceSpan span, string name, Type generator, Type next)
        {
            Contract.RequiresNotNull(name, "name");
            Contract.RequiresNotNull(generator, "generator");
            Contract.RequiresNotNull(next, "next");
            Contract.Requires(TypeUtils.CanAssign(typeof(Generator), generator), "generator", "The generator type must inherit from Generator");

            return new GeneratorCodeBlock(span, name, generator, next);
        }
 public static IfStatement IfThenElse(SourceSpan span, Expression test, Statement body, Statement @else)
 {
     return If(
         span,
         new IfStatementTest[] {
             Ast.IfCondition(SourceSpan.None, SourceLocation.None, test, body)
         },
         @else
     );
 }
Beispiel #21
0
        private bool _yield; // The catch block contains a yield

        #endregion Fields

        #region Constructors

        internal CatchBlock(SourceSpan span, SourceLocation header, Type /*!*/ test, Variable target, Statement /*!*/ body)
            : base(AstNodeType.CatchBlock)
        {
            _test = test;
            _var = target;
            _body = body;
            _start = span.Start;
            _header = header;
            _end = span.End;
        }
Beispiel #22
0
        protected internal static long SpanToLong(SourceSpan span)
        {
            if (!span.IsValid)
              {
            return 0;
              }

              var start = span.Start;
              var end = span.End;
              var st = (uint)((start.Line << 10) | (start.Column));
              var en = (uint)((end.Line << 10) | (end.Column));
              return (long) (((ulong)en) << 32 | st);
        }
Beispiel #23
0
        public bool CanSetNextStatement(string sourceFile, SourceSpan sourceSpan) {
            VerifyNotClosed();
            ContractUtils.RequiresNotNull(sourceFile, "sourceFile");
            ContractUtils.Requires(sourceSpan != SourceSpan.Invalid && sourceSpan != SourceSpan.None, ErrorStrings.InvalidSourceSpan);

            // Find the thread object.  We also check if the current thread is in FrameExit traceback.
            DebugFrame traceFrame = _traceFrame.Value;
            if (traceFrame == null) {
                return false;
            }

            return GetSequencePointIndexForSourceSpan(sourceFile, sourceSpan, traceFrame) != Int32.MaxValue;
        }
 public override void SetLoc(SourceSpan span)
 {
   if (span.IsValid)
   {
     foreach (var expr in _expressions)
     {
       if (!expr.Span.IsValid)
       {
         expr.SetLoc(span);
       }
     }
     //_expressions[ValueIndex].SetLoc(span);
   }
 }
Beispiel #25
0
        public override void Add(SourceUnit sourceUnit, string message, SourceSpan span, int errorCode, Severity severity) {
            if (_listener != null) {

                ScriptSource scriptSource;
                if (sourceUnit != _source.SourceUnit) {
                    scriptSource = new ScriptSource(_source.Engine.Runtime.GetEngine(sourceUnit.LanguageContext), sourceUnit);
                } else {
                    scriptSource = _source;
                }

                _listener.ErrorReported(scriptSource, message, span, errorCode, severity);
            } else {
                throw new SyntaxErrorException(message, sourceUnit, span, errorCode, severity);
            }
        }
        public override void ErrorReported(ScriptSource source, string message, SourceSpan span, int errorCode, Severity severity) {
            // Note that we cannot use "source.SourceUnit" since "source" may be a proxy object, and we will not be able to marshall 
            // "source.SourceUnit" to the current AppDomain

            string code = null;
            string line = null;
            try {
                code = source.GetCode();
                line = source.GetCodeLine(span.Start.Line);
            } catch (System.IO.IOException) {
                // could not get source code.
            }

            _errorSink.Add(message, source.Path, code, line, span, errorCode, severity);
        }
Beispiel #27
0
        internal Lexeme(ScannerInfo scannerInfo, int state, SourceSpan span, string content, List<Lexeme> trivia)
        {
            m_scannerInfo = scannerInfo;
            m_stateIndex = state;
            Value = new LexemeValue(content, span);

            if (trivia != null)
            {
                m_triviaArray = trivia.ToArray();
                m_trivia = new ReadOnlyCollection<Lexeme>(m_triviaArray);

            }
            else
            {
                m_triviaArray = null;
                m_trivia = new ReadOnlyCollection<Lexeme>(s_emptyTrivia);
            }
        }
Beispiel #28
0
        public void SetNextStatement(string sourceFile, SourceSpan sourceSpan) {
            VerifyNotClosed();
            ContractUtils.RequiresNotNull(sourceFile, "sourceFile");
            ContractUtils.Requires(sourceSpan != SourceSpan.Invalid && sourceSpan != SourceSpan.None, ErrorStrings.InvalidSourceSpan);  

            // Find the thread object
            DebugFrame traceFrame = _traceFrame.Value;
            if (traceFrame == null) {
                throw new InvalidOperationException(ErrorStrings.SetNextStatementOnlyAllowedInsideTraceback);
            }

            int sequencePointIndex = GetSequencePointIndexForSourceSpan(sourceFile, sourceSpan, traceFrame);
            if (sequencePointIndex == Int32.MaxValue) {
                throw new InvalidOperationException(ErrorStrings.InvalidSourceSpan);
            }

            traceFrame.CurrentSequencePointIndex = sequencePointIndex;
        }
 public LambdaExpression(SourceSpan span, IEnumerable <ParameterDeclaration> parameters, BlockStatement body) : base(span)
 {
     Parameters = parameters;
     Body       = body;
 }
Beispiel #30
0
 public virtual void Add(string message, SourceSpan span, int errorCode, Severity severity)
 {
 }
Beispiel #31
0
 public SourceSpan MapLine(SourceSpan span)
 {
     return(new SourceSpan(_unit.MakeLocation(span.Start), _unit.MakeLocation(span.End)));
 }
Beispiel #32
0
 public NamespaceExpression(NamespaceTracker tracker, SourceSpan span)
 {
     _tracker        = tracker;
     ExpressionClass = ExpressionClass.Namespace;
     Span            = span;
 }
Beispiel #33
0
 public virtual void StartName(SourceSpan span, string name) {
 }
Beispiel #34
0
 public InternalErrorException(Exception e, SourceSpan location)
     : base(string.Format("Internal error at location '{0}'.", location), e)
 {
 }
Beispiel #35
0
 public ScriptRuntimeException(SourceSpan span, string message) : base(message)
 {
     Span = span;
 }
Beispiel #36
0
 public EncodingExpression(SourceSpan location)
     : base(location)
 {
 }
        public async Task <CompletionList> Handle(CompletionParams request, CancellationToken cancellationToken)
        {
            _foregroundDispatcher.AssertBackgroundThread();

            var document = await Task.Factory.StartNew(() =>
            {
                _documentResolver.TryResolveDocument(request.TextDocument.Uri.GetAbsoluteOrUNCPath(), out var documentSnapshot);

                return(documentSnapshot);
            }, CancellationToken.None, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler);

            if (document is null || cancellationToken.IsCancellationRequested)
            {
                return(new CompletionList(isIncomplete: false));
            }

            var codeDocument = await document.GetGeneratedOutputAsync();

            if (codeDocument.IsUnsupported())
            {
                return(new CompletionList(isIncomplete: false));
            }

            var syntaxTree = codeDocument.GetSyntaxTree();
            var tagHelperDocumentContext = codeDocument.GetTagHelperContext();

            var sourceText = await document.GetTextAsync();

            var linePosition      = new LinePosition((int)request.Position.Line, (int)request.Position.Character);
            var hostDocumentIndex = sourceText.Lines.GetPosition(linePosition);
            var location          = new SourceSpan(hostDocumentIndex, 0);

            var directiveCompletionItems = _completionFactsService.GetCompletionItems(syntaxTree, tagHelperDocumentContext, location);

            _logger.LogTrace($"Found {directiveCompletionItems.Count} directive completion items.");

            var completionItems = new List <CompletionItem>();

            foreach (var razorCompletionItem in directiveCompletionItems)
            {
                if (TryConvert(razorCompletionItem, out var completionItem))
                {
                    completionItems.Add(completionItem);
                }
            }

            var parameterCompletions = completionItems.Where(completionItem => completionItem.TryGetRazorCompletionKind(out var completionKind) && completionKind == RazorCompletionItemKind.DirectiveAttributeParameter);

            if (parameterCompletions.Any())
            {
                // Parameters are present in the completion list, even though TagHelpers are technically valid we shouldn't flood the completion list
                // with non parameter completions. Filter out the rest.
                completionItems = parameterCompletions.ToList();
            }
            else
            {
                var tagHelperCompletionItems = _tagHelperCompletionService.GetCompletionsAt(location, codeDocument);

                _logger.LogTrace($"Found {tagHelperCompletionItems.Count} TagHelper completion items.");

                completionItems.AddRange(tagHelperCompletionItems);
            }

            var completionList = new CompletionList(completionItems, isIncomplete: false);

            return(completionList);
        }
Beispiel #38
0
 public SyntaxToken(SyntaxTokenKind kind, SourceSpan location) : base(location) => Kind = kind;
Beispiel #39
0
        public override IReadOnlyList <RazorCompletionItem> GetCompletionItems(RazorCompletionContext context, SourceSpan location)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (context.TagHelperDocumentContext is null)
            {
                throw new ArgumentNullException(nameof(context.TagHelperDocumentContext));
            }

            if (!FileKinds.IsComponent(context.SyntaxTree.Options.FileKind))
            {
                // Directive attributes are only supported in components
                return(s_noDirectiveAttributeCompletionItems);
            }

            var change = new SourceChange(location, string.Empty);
            var owner  = context.SyntaxTree.Root.LocateOwner(change);

            if (owner is null)
            {
                return(s_noDirectiveAttributeCompletionItems);
            }

            if (!TryGetAttributeInfo(owner, out _, out var attributeName, out var attributeNameLocation, out _, out _))
            {
                // Either we're not in an attribute or the attribute is so malformed that we can't provide proper completions.
                return(s_noDirectiveAttributeCompletionItems);
            }

            if (!attributeNameLocation.IntersectsWith(location.AbsoluteIndex))
            {
                // We're trying to retrieve completions on a portion of the name that is not supported (such as a parameter).
                return(s_noDirectiveAttributeCompletionItems);
            }

            if (!TryGetElementInfo(owner.Parent.Parent, out var containingTagName, out var attributes))
            {
                // This should never be the case, it means that we're operating on an attribute that doesn't have a tag.
                return(s_noDirectiveAttributeCompletionItems);
            }

            // At this point we've determined that completions have been requested for the name portion of the selected attribute.

            var completionItems = GetAttributeCompletions(attributeName, containingTagName, attributes, context.TagHelperDocumentContext);

            // We don't provide Directive Attribute completions when we're in the middle of
            // another unrelated (doesn't start with @) partially completed attribute.
            // <svg xml:| ></svg> (attributeName = "xml:") should not get any directive attribute completions.
            if (string.IsNullOrWhiteSpace(attributeName) || attributeName.StartsWith("@", StringComparison.Ordinal))
            {
                return(completionItems);
            }

            return(s_noDirectiveAttributeCompletionItems);
        }
Beispiel #40
0
 public BigDelimeterAtom(SourceSpan source, Atom delimeterAtom, int size)
     : base(source)
 {
     this.DelimeterAtom = delimeterAtom;
     this.Size          = size;
 }
Beispiel #41
0
 public ScriptParserRuntimeException(SourceSpan span, string message, List <LogMessage> parserMessages) : this(span, message, parserMessages, null)
 {
 }
Beispiel #42
0
 public FractionAtom(SourceSpan source, Atom numerator, Atom denominator, TexUnit unit, double thickness)
     : this(source, numerator, denominator, false, unit, thickness)
 {
 }
Beispiel #43
0
 public ScriptRuntimeException(SourceSpan span, string message, Exception innerException) : base(message, innerException)
 {
     Span = span;
 }
Beispiel #44
0
 public WriteLine(Expression value, SourceSpan writelineSpan)
 {
     Value         = value;
     WriteLineSpan = writelineSpan;
 }
 public CaseStatement(SourceSpan span, IEnumerable <Expression> cases, IEnumerable <SyntaxNode> body) : base(span)
 {
     Body  = body;
     Cases = cases;
 }
Beispiel #46
0
 public int GetLength(TemplateContext context, SourceSpan span, object target)
 {
     return(((IList)target).Count);
 }
Beispiel #47
0
 public abstract IReadOnlyList <RazorCompletionItem> GetCompletionItems(RazorCompletionContext razorCompletionContext, SourceSpan location);
 public override void ErrorReported(ScriptSource source, string message, SourceSpan span, int errorCode, Severity severity)
 {
     Errors.Add(string.Format("{0} (line {1})", message, span.Start.Line));
 }
Beispiel #49
0
 public FractionAtom(SourceSpan source, Atom numerator, Atom denominator, bool drawLine)
     : this(source, numerator, denominator, drawLine, TexUnit.Pixel, 0d)
 {
 }
 public WhileStatement(SourceSpan span, bool isDoWhile, Expression predicate, BlockStatement body) : base(span)
 {
     Body      = body;
     Predicate = predicate;
     IsDoWhile = isDoWhile;
 }
Beispiel #51
0
 public virtual void StartParameters(SourceSpan context) {
 }
Beispiel #52
0
 public virtual object Transform(TemplateContext context, SourceSpan span, Func <object, object> apply, Type destType)
 {
     return(new ScriptRange(TransformImpl(apply)));
 }
Beispiel #53
0
        private static bool CompareTo(TemplateContext context, SourceSpan span, ScriptBinaryOperator op, IEnumerable <object> left, IEnumerable <object> right)
        {
            // Compare the length first
            var leftCount  = left.Count();
            var rightCount = right.Count();
            var compare    = leftCount.CompareTo(rightCount);

            switch (op)
            {
            case ScriptBinaryOperator.CompareEqual:
                if (compare != 0)
                {
                    return(false);
                }
                break;

            case ScriptBinaryOperator.CompareNotEqual:
                if (compare != 0)
                {
                    return(true);
                }
                if (leftCount == 0)
                {
                    return(false);
                }
                break;

            case ScriptBinaryOperator.CompareLessOrEqual:
            case ScriptBinaryOperator.CompareLess:
                if (compare < 0)
                {
                    return(true);
                }
                if (compare > 0)
                {
                    return(false);
                }
                if (leftCount == 0 && op == ScriptBinaryOperator.CompareLess)
                {
                    return(false);
                }
                break;

            case ScriptBinaryOperator.CompareGreaterOrEqual:
            case ScriptBinaryOperator.CompareGreater:
                if (compare < 0)
                {
                    return(false);
                }
                if (compare > 0)
                {
                    return(true);
                }
                if (leftCount == 0 && op == ScriptBinaryOperator.CompareGreater)
                {
                    return(false);
                }
                break;

            default:
                throw new ScriptRuntimeException(span, $"The operator `{op.ToText()}` is not supported between {context.GetTypeName(left)} and {context.GetTypeName(right)}.");
            }

            // Otherwise we need to compare each element

            var leftIterator  = left.GetEnumerator();
            var rightIterator = right.GetEnumerator();

            while (leftIterator.MoveNext() && rightIterator.MoveNext())
            {
                var leftValue  = leftIterator.Current;
                var rightValue = rightIterator.Current;
                var result     = (bool)ScriptBinaryExpression.Evaluate(context, span, op, leftValue, rightValue);
                if (!result)
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #54
0
        public bool TryEvaluate(TemplateContext context, SourceSpan span, ScriptBinaryOperator op, SourceSpan leftSpan, object leftValue, SourceSpan rightSpan, object rightValue, out object result)
        {
            result = null;
            var leftArray   = TryGetRange(leftValue);
            var rightArray  = TryGetRange(rightValue);
            int intModifier = 0;
            var intSpan     = leftSpan;

            var    errorSpan = span;
            string reason    = null;

            switch (op)
            {
            case ScriptBinaryOperator.BinaryOr:
            case ScriptBinaryOperator.BinaryAnd:
            case ScriptBinaryOperator.CompareEqual:
            case ScriptBinaryOperator.CompareNotEqual:
            case ScriptBinaryOperator.CompareLessOrEqual:
            case ScriptBinaryOperator.CompareGreaterOrEqual:
            case ScriptBinaryOperator.CompareLess:
            case ScriptBinaryOperator.CompareGreater:
            case ScriptBinaryOperator.Add:
                if (leftArray == null)
                {
                    errorSpan = leftSpan;
                    reason    = " Expecting an array for the left argument.";
                }
                if (rightArray == null)
                {
                    errorSpan = rightSpan;
                    reason    = " Expecting an array for the right argument.";
                }
                break;

            case ScriptBinaryOperator.Multiply:
                if (leftArray == null && rightArray == null || leftArray != null && rightArray != null)
                {
                    reason = " Expecting only one array for the left or right argument.";
                }
                else
                {
                    intModifier = context.ToInt(span, leftArray == null ? leftValue : rightValue);
                    if (rightArray == null)
                    {
                        intSpan = rightSpan;
                    }
                }
                break;

            case ScriptBinaryOperator.Divide:
            case ScriptBinaryOperator.DivideRound:
            case ScriptBinaryOperator.Modulus:
                if (leftArray == null)
                {
                    errorSpan = leftSpan;
                    reason    = " Expecting an array for the left argument.";
                }
                else
                {
                    intModifier = context.ToInt(span, rightValue);
                    intSpan     = rightSpan;
                }
                break;

            case ScriptBinaryOperator.ShiftLeft:
                if (leftArray == null)
                {
                    errorSpan = leftSpan;
                    reason    = " Expecting an array for the left argument.";
                }
                break;

            case ScriptBinaryOperator.ShiftRight:
                if (rightArray == null)
                {
                    errorSpan = rightSpan;
                    reason    = " Expecting an array for the right argument.";
                }
                break;

            default:
                reason = string.Empty;
                break;
            }

            if (intModifier < 0)
            {
                errorSpan = intSpan;
                reason    = $" Integer {intModifier} cannot be negative when multiplying";
            }

            if (reason != null)
            {
                throw new ScriptRuntimeException(errorSpan, $"The operator `{op.ToText()}` is not supported between {context.GetTypeName(leftValue)} and {context.GetTypeName(rightValue)}.{reason}");
            }

            switch (op)
            {
            case ScriptBinaryOperator.BinaryOr:
                result = BinaryOr(leftArray, rightArray);
                return(true);

            case ScriptBinaryOperator.BinaryAnd:
                result = BinaryAnd(leftArray, rightArray);
                return(true);

            case ScriptBinaryOperator.Add:
                result = Concat(leftArray, rightArray);
                return(true);

            case ScriptBinaryOperator.CompareEqual:
            case ScriptBinaryOperator.CompareNotEqual:
            case ScriptBinaryOperator.CompareLessOrEqual:
            case ScriptBinaryOperator.CompareGreaterOrEqual:
            case ScriptBinaryOperator.CompareLess:
            case ScriptBinaryOperator.CompareGreater:
                result = CompareTo(context, span, op, leftArray, rightArray);
                return(true);

            case ScriptBinaryOperator.Multiply:
            {
                // array with integer
                var array = leftArray ?? rightArray;
                if (intModifier == 0)
                {
                    result = new ScriptRange();
                    return(true);
                }

                result = Multiply(array, intModifier);
                return(true);
            }

            case ScriptBinaryOperator.Divide:
            case ScriptBinaryOperator.DivideRound:
            {
                // array with integer
                var array = leftArray ?? rightArray;
                if (intModifier == 0)
                {
                    throw new ScriptRuntimeException(intSpan, "Cannot divide by 0");
                }

                result = Divide(array, intModifier);
                return(true);
            }

            case ScriptBinaryOperator.Modulus:
            {
                // array with integer
                var array = leftArray ?? rightArray;
                if (intModifier == 0)
                {
                    throw new ScriptRuntimeException(intSpan, "Cannot divide by 0");
                }

                result = Modulus(array, intModifier);
                return(true);
            }

            case ScriptBinaryOperator.ShiftLeft:
                result = ShiftLeft(leftArray, rightValue);
                return(true);

            case ScriptBinaryOperator.ShiftRight:
                result = ShiftRight(leftValue, rightArray);
                return(true);
            }

            return(false);
        }
Beispiel #55
0
 public int GetMemberCount(TemplateContext context, SourceSpan span, object target)
 {
     // size
     return(1);
 }
Beispiel #56
0
 public MatchExpression(RegularExpression /*!*/ regex, Expression /*!*/ expression, SourceSpan location)
     : base(location)
 {
     _regex      = regex;
     _expression = expression;
 }
Beispiel #57
0
 internal LabeledStatement(SourceSpan span, Statement statement)
     : base(AstNodeType.LabeledStatement, span)
 {
     _statement = statement;
 }
Beispiel #58
0
 public IEnumerable <string> GetMembers(TemplateContext context, SourceSpan span, object target)
 {
     yield return("size");
 }
Beispiel #59
0
 public ErrorRecord(int? id, SourceSpan position)
 {
     ErrorId = id;
     ErrorPosition = position;
 }
Beispiel #60
0
 public bool HasMember(TemplateContext context, SourceSpan span, object target, string member)
 {
     return(member == "size");
 }