Ejemplo n.º 1
0
        private SyntaxTree ParseTree(TokFlow flow)
        {
            while (true)
            {
                flow.SkipNewLines();
                if (flow.IsDoneOrEof())
                {
                    break;
                }

                _attributes        = flow.ReadAttributes();
                _startOfTheLine    = flow.IsStartOfTheLine();
                _exprStartPosition = flow.Current.Start;

                var e = SyntaxNodeReader.ReadNodeOrNull(flow)
                        ?? throw ErrorFactory.UnknownValueAtStartOfExpression(_exprStartPosition, flow.Current);

                if (e is TypedVarDefSyntaxNode typed)
                {
                    if (flow.IsCurrent(TokType.Def))
                    {
                        ReadEquation(typed, typed.Id);
                    }
                    else
                    {
                        ReadInputVariableSpecification(typed);
                    }
                }
                else if (flow.IsCurrent(TokType.Def) || flow.IsCurrent(TokType.Colon))
                {
                    if (e is NamedIdSyntaxNode variable)
                    {
                        ReadEquation(variable, variable.Id);
                    }
                    //Fun call can be used as fun definition
                    else if (e is FunCallSyntaxNode fun && !fun.IsOperator)
                    {
                        ReadUserFunction(fun);
                    }
                    else
                    {
                        throw ErrorFactory.ExpressionBeforeTheDefinition(_exprStartPosition, e, flow.Current);
                    }
                }
Ejemplo n.º 2
0
        private static ExprListError SpecifyArrayInitError(
            IList <ISyntaxNode> arguments, TokFlow flow, TokType openBrack, TokType closeBrack)
        {
            var firstToken      = flow.Current;
            int lastArgPosition = arguments.LastOrDefault()?.Interval.Finish ?? flow.Position;

            flow.SkipNewLines();

            var hasAnyBeforeStop = flow.MoveUntilOneOfThe(
                TokType.Sep, openBrack, closeBrack, TokType.NewLine, TokType.Eof)
                                   .Any();

            if (firstToken.Is(TokType.Sep))
            {
                //[x,y, {someshit} , ...
                return(new ExprListError(
                           ExprListErrorType.ArgumentIsInvalid,
                           arguments,
                           new Interval(firstToken.Start, flow.Position)));
            }


            var errorStart = lastArgPosition;

            if (flow.Position == errorStart)
            {
                errorStart = arguments.Last().Interval.Start;
            }
            //[x, {y someshit} , ...
            if (!hasAnyBeforeStop)
            {
                //[x,y {no ']' here}
                return(new ExprListError(
                           ExprListErrorType.CloseBracketIsMissing,
                           arguments,
                           new Interval(errorStart, flow.Position)));
            }
            //LastArgument is a part of error
            return(new ExprListError(
                       ExprListErrorType.LastArgumentIsInvalid,
                       arguments,
                       new Interval(arguments.Last().Interval.Start, flow.Position)));
        }