protected void DisallowIncrement(Parsed.Object expr)
 {
     if (expr is Parsed.IncDecExpression)
     {
         Error("Can't use increment/decrement here. It can only be used on a ~ line");
     }
 }
Ejemplo n.º 2
0
        CommandLineInputResult ExecuteImmediateStatement(Parsed.Object parsedObj)
        {
            var result = new CommandLineInputResult();

            // Variable assignment: create in Parsed.Story as well as the Runtime.Story
            // so that we don't get an error message during reference resolution
            if (parsedObj is Parsed.VariableAssignment)
            {
                var varAssign = (Parsed.VariableAssignment)parsedObj;
                if (varAssign.isNewTemporaryDeclaration)
                {
                    _parsedStory.TryAddNewVariableDeclaration(varAssign);
                }
            }

            parsedObj.parent = _parsedStory;
            var runtimeObj = parsedObj.runtimeObject;

            parsedObj.ResolveReferences(_parsedStory);

            if (!_parsedStory.hadError)
            {
                // Divert
                if (parsedObj is Parsed.Divert)
                {
                    var parsedDivert = parsedObj as Parsed.Divert;
                    result.divertedPath = parsedDivert.runtimeDivert.targetPath.ToString();
                }

                // Expression or variable assignment
                else if (parsedObj is Parsed.Expression || parsedObj is Parsed.VariableAssignment)
                {
                    var evalResult = _runtimeStory.EvaluateExpression((Runtime.Container)runtimeObj);
                    if (evalResult != null)
                    {
                        result.output = evalResult.ToString();
                    }
                }
            }
            else
            {
                _parsedStory.ResetError();
            }

            return(result);
        }
Ejemplo n.º 3
0
        protected Parsed.Object InnerLogic()
        {
            Whitespace();

            // Explicitly try the combinations of inner logic
            // that could potentially have conflicts first.

            // Explicit sequence annotation?
            SequenceType?explicitSeqType = (SequenceType?)ParseObject(SequenceTypeAnnotation);

            if (explicitSeqType != null)
            {
                var contentLists = (List <ContentList>)Expect(InnerSequenceObjects, "sequence elements (for cycle/stoping etc)");
                return(new Sequence(contentLists, (SequenceType)explicitSeqType));
            }

            // Conditional with expression?
            var initialQueryExpression = Parse(ConditionExpression);

            if (initialQueryExpression)
            {
                var conditional = (Conditional)Expect(() => InnerConditionalContent(initialQueryExpression), "conditional content following query (i.e. '" + initialQueryExpression + "'");
                return(conditional);
            }

            // Now try to evaluate each of the "full" rules in turn
            ParseRule[] rules =
            {
                // Conditional still necessary, since you can have a multi-line conditional
                // without an initial query expression:
                // {
                //   - true:  this is true
                //   - false: this is false
                // }
                InnerConditionalContent,
                InnerSequence,
                InnerExpression,
            };

            // Adapted from "OneOf" structuring rule except that in
            // order for the rule to succeed, it has to maximally
            // cover the entire string within the { }. Used to
            // differentiate between:
            //  {myVar}                 -- Expression (try first)
            //  {my content is jolly}   -- sequence with single element
            foreach (ParseRule rule in rules)
            {
                int ruleId = BeginRule();

                Parsed.Object result = ParseObject(rule) as Parsed.Object;
                if (result)
                {
                    // Not yet at end?
                    if (Peek(Spaced(String("}"))) == null)
                    {
                        FailRule(ruleId);
                    }

                    // Full parse of content within braces
                    else
                    {
                        return((Parsed.Object)SucceedRule(ruleId, result));
                    }
                }
                else
                {
                    FailRule(ruleId);
                }
            }

            return(null);
        }
Ejemplo n.º 4
0
 protected void ErrorWithParsedObject(string message, Parsed.Object result, bool isWarning = false)
 {
     ErrorOnLine(message, result.debugMetadata.startLineNumber, isWarning);
 }