Expect() public méthode

public Expect ( int n ) : void
n int
Résultat void
Exemple #1
0
        public override Statement ParseNoNewContext(Parser parser)
        {
            var result   = new IfStatement();
            var labelled = parser.Labels(result);

            // Consume the if keyword.
            parser.Expect(KeywordToken.If);

            // Read the left parenthesis.
            parser.Expect(PunctuatorToken.LeftParenthesis);

            // Parse the condition.
            result.Condition = parser.ParseExpression(PunctuatorToken.RightParenthesis);

            // Read the right parenthesis.
            parser.Expect(PunctuatorToken.RightParenthesis);

            // Read the statements that will be executed when the condition is true.
            result.IfClause = parser.ParseStatement();

            // Optionally, read the else statement.
            if (parser.nextToken == KeywordToken.Else)
            {
                // Consume the else keyword.
                parser.Consume();

                // Read the statements that will be executed when the condition is false.
                result.ElseClause = parser.ParseStatement();
            }

            return(labelled);
        }
Exemple #2
0
        private MapNode DeserializeIsolatedNode(Parser r)
        {
            string text = null; NodePosition pos = NodePosition.Undefined; string id = null;

            string prop = r.Peek <Scalar>().Value;

            if (prop != null && prop.Equals(Text))
            {
                r.Expect <Scalar>();
                text = r.Expect <Scalar>().Value;
                prop = r.Peek <Scalar>().Value;
            }

            if (prop != null && prop.Equals(Pos))
            {
                r.Expect <Scalar>();
                pos = (NodePosition)Enum.Parse(typeof(NodePosition), r.Expect <Scalar>().Value);
                //prop = r.Peek<Scalar>().Value;
            }

            // Isolated nodes donot have Id
            //if (prop != null && prop.Equals(Id))
            //{
            //    r.Expect<Scalar>();
            //    id = r.Expect<Scalar>().Value;
            //    //prop = r.Peek<Scalar>().Value;
            //}

            MapNode node = MapNode.CreateIsolatedNode(pos);

            node.Text = text;
            return(node);
        }
Exemple #3
0
        public override Statement ParseNoNewContext(Parser parser)
        {
            // This statement is not allowed in strict mode.
            if (parser.StrictMode == true)
            {
                throw new JavaScriptException(parser.engine, "SyntaxError", "The with statement is not supported in strict mode", parser.LineNumber, parser.SourcePath);
            }

            var result   = new WithStatement();
            var labelled = parser.Labels(result);

            // Read past the "with" token.
            parser.Expect(KeywordToken.With);

            // Read a left parenthesis token "(".
            parser.Expect(PunctuatorToken.LeftParenthesis);

            // Read an object reference.
            var objectEnvironment = parser.ParseExpression(PunctuatorToken.RightParenthesis);

            // Read a right parenthesis token ")".
            parser.Expect(PunctuatorToken.RightParenthesis);

            // Create a new scope and assign variables within the with statement to the scope.
            result.Scope = ObjectScope.CreateWithScope(parser.currentLetScope, objectEnvironment, parser.OptimizationInfo);

            using (parser.CreateScopeContext(result.Scope, result.Scope))
            {
                // Read the body of the with statement.
                result.Body = parser.ParseStatement();
            }

            return(labelled);
        }
Exemple #4
0
        public override Statement ParseNoNewContext(Parser parser)
        {
            var result   = new DoWhileStatement();
            var labelled = parser.Labels(result);

            // Consume the do keyword.
            parser.Expect(KeywordToken.Do);

            // Read the statements that will be executed in the loop body.
            result.Body = parser.ParseStatement();

            // Read the while keyword.
            parser.Expect(KeywordToken.While);

            // Read the left parenthesis.
            parser.Expect(PunctuatorToken.LeftParenthesis);

            result.ConditionStatement = new ExpressionStatement(parser.ParseExpression(PunctuatorToken.RightParenthesis));

            // Read the right parenthesis.
            parser.Expect(PunctuatorToken.RightParenthesis);

            // Consume the end of the statement.
            parser.ExpectEndOfStatement();

            return(labelled);
        }
Exemple #5
0
        public void Deserialize()
        {
            var sut  = new MapYamlSerializer();
            var node = MapNode.CreateIsolatedNode(NodePosition.Left);

            node.Text  = "Node1";
            node.Label = "This is the Label";
            node.Color = Color.Azure;

            var writer  = new StringWriter();
            var emitter = new Emitter(writer);

            emitter.Emit(new StreamStart());
            emitter.Emit(new DocumentStart());

            sut.Serialize(node, emitter);

            emitter.Emit(new DocumentEnd(true));
            emitter.Emit(new StreamEnd());

            string text = writer.ToString();

            var parser = new Parser(new StringReader(text));

            parser.Expect <StreamStart>();
            parser.Expect <DocumentStart>();
            var result = sut.Deserialize(parser);

            parser.Expect <DocumentEnd>();
            parser.Expect <StreamEnd>();

            Assert.AreEqual(Color.Azure, result.Color);
            Assert.IsNull(result.Image);
            Assert.AreEqual("This is the Label", result.Label);
        }
        private void DeserializeNodeStyles(MetaModel.MetaModel metaModel, Parser r)
        {
            r.Expect <SequenceStart>();

            while (r.Accept <MappingStart>())
            {
                DeserializeNodeStyle(metaModel, r);
            }

            r.Expect <SequenceEnd>();
        }
        private void DeserializeRecentFiles(MetaModel.MetaModel metaModel, Parser r)
        {
            r.Expect <SequenceStart>();

            while (r.Accept <Scalar>())
            {
                metaModel.RecentFiles.Add(r.Expect <Scalar>().Value);
            }

            r.Expect <SequenceEnd>();
        }
Exemple #8
0
        public override Statement ParseNoNewContext(Parser parser)
        {
            var result   = new TryCatchFinallyStatement();
            var labelled = parser.Labels(result);

            // Consume the try keyword.
            parser.Expect(KeywordToken.Try);

            // Parse the try block.
            result.TryBlock = parser.ParseBlock();

            // The next token is either 'catch' or 'finally'.
            if (parser.nextToken == KeywordToken.Catch)
            {
                // Consume the catch token.
                parser.Expect(KeywordToken.Catch);

                // Read the left parenthesis.
                parser.Expect(PunctuatorToken.LeftParenthesis);

                // Read the name of the variable to assign the exception to.
                result.CatchVariableName = parser.ExpectIdentifier();
                parser.ValidateVariableName(result.CatchVariableName);

                // Read the right parenthesis.
                parser.Expect(PunctuatorToken.RightParenthesis);

                // Create a new scope for the catch variable.
                result.CatchScope = DeclarativeScope.CreateCatchScope(parser.currentLetScope, result.CatchVariableName);
                using (parser.CreateScopeContext(result.CatchScope, result.CatchScope))
                {
                    // Parse the statements inside the catch block.
                    result.CatchBlock = parser.ParseBlock();
                }
            }

            if (parser.nextToken == KeywordToken.Finally)
            {
                // Consume the finally token.
                parser.Expect(KeywordToken.Finally);

                // Read the finally statements.
                result.FinallyBlock = parser.ParseBlock();
            }

            // There must be a catch or finally block.
            if (result.CatchBlock == null && result.FinallyBlock == null)
            {
                throw new JavaScriptException(parser.engine, "SyntaxError", "Missing catch or finally after try", parser.LineNumber, parser.SourcePath);
            }

            return(labelled);
        }
Exemple #9
0
        /// <summary>
        /// Deserializes an isolated node
        /// </summary>
        /// <param name="r"></param>
        /// <returns></returns>
        public MapNode Deserialize(Parser r)
        {
            r.Expect <MappingStart>();

            MapNode n = DeserializeIsolatedNode(r);

            DeserializeScalarProperties(n, r);

            r.Expect <MappingEnd>();

            return(n);
        }
Exemple #10
0
        public void Deserialize_AllProperties()
        {
            var sut  = new MapYamlSerializer();
            var node = MapNode.CreateIsolatedNode(NodePosition.Left);

            node.Text           = "Text";
            node.Folded         = true;
            node.BackColor      = Color.Aqua;
            node.Bold           = true;
            node.FontName       = "Arial";
            node.FontSize       = 15;
            node.ImageAlignment = ImageAlignment.AboveStart;
            node.ImageSize      = new Size(22, 21);
            node.Italic         = true;
            node.Label          = "label";
            node.LineColor      = Color.BlueViolet;
            node.LinePattern    = DashStyle.Dot;
            node.LineWidth      = 4;
            node.NoteText       = "Note";
            node.Shape          = NodeShape.Box;
            node.Strikeout      = true;
            node.Link           = "link";
            node.Color          = Color.Azure;

            var writer  = new StringWriter();
            var emitter = new Emitter(writer);

            emitter.Emit(new StreamStart());
            emitter.Emit(new DocumentStart());

            sut.Serialize(node, emitter);

            emitter.Emit(new DocumentEnd(true));
            emitter.Emit(new StreamEnd());

            string text = writer.ToString();

            var parser = new Parser(new StringReader(text));

            parser.Expect <StreamStart>();
            parser.Expect <DocumentStart>();
            var result = sut.Deserialize(parser);

            parser.Expect <DocumentEnd>();
            parser.Expect <StreamEnd>();

            Assert.AreEqual(Color.Azure, result.Color);
            Assert.IsNotNull(result.Label);
            Assert.IsNotNull(result.Text);
            Assert.AreEqual("link", result.Link);
            Assert.AreEqual(22, result.ImageSize.Width);
        }
Exemple #11
0
        public override Statement ParseNoNewContext(Parser parser)
        {
            var result   = new VarStatement(this == KeywordToken.Var ? parser.currentVarScope : parser.currentLetScope);
            var labelled = parser.Labels(result);

            // Read past the first token (var, let or const).
            parser.Expect(this);

            // There can be multiple declarations.
            while (true)
            {
                var declaration = new VariableDeclaration();

                // The next token must be a variable name.
                declaration.VariableName = parser.ExpectIdentifier();
                parser.ValidateVariableName(declaration.VariableName);

                // Add the variable to the current function's list of local variables.
                parser.currentVarScope.AddVariable(declaration.VariableName, null,
                                                   parser.context == CodeContext.Function ? null : new LiteralExpression(Undefined.Value));

                // The next token is either an equals sign (=), a semi-colon or a comma.
                if (parser.nextToken == PunctuatorToken.Assignment)
                {
                    // Read past the equals token (=).
                    parser.Expect(PunctuatorToken.Assignment);

                    // Read the setter expression.
                    declaration.InitExpression = parser.ParseExpression(PunctuatorToken.Semicolon, PunctuatorToken.Comma);
                }

                // Add the declaration to the result.
                result.Declarations.Add(declaration);

                // Check if we are at the end of the statement.
                if (parser.AtValidEndOfStatement() && parser.nextToken != PunctuatorToken.Comma)
                {
                    break;
                }

                // Read past the comma token.
                parser.Expect(PunctuatorToken.Comma);
            }

            // Consume the end of the statement.
            parser.ExpectEndOfStatement();

            return(labelled);
        }
Exemple #12
0
        public override Statement ParseNoNewContext(Parser parser)
        {
            // Consume the function keyword.
            parser.Expect(KeywordToken.Function);

            // Read the function name.
            var functionName = parser.ExpectIdentifier();

            parser.ValidateVariableName(functionName);

            // Parse the function declaration.
            var expression = parser.ParseFunction(FunctionDeclarationType.Declaration, parser.initialScope, functionName);

            // Add the function to the top-level scope.
            Type vType = expression.GetResultType(parser.OptimizationInfo);

            Variable variable = parser.initialScope.AddVariable(expression.FunctionName, vType, expression);

            // Try setting a constant value:
            variable.TrySetConstant(expression.Context);

            // Function declarations do nothing at the point of declaration - everything happens
            // at the top of the function/global code.
            return(parser.Labels(new EmptyStatement()));
        }
        private void DeserializeNodeStyle(MetaModel.MetaModel metaModel, Parser r)
        {
            var s = new NodeStyle();

            r.Expect <MappingStart>();

            r.Expect <Scalar>(); //Title
            s.Title = r.Expect <Scalar>().Value;

            r.Expect <Scalar>(); //RefNode
            s.RefNode = new MapYamlSerializer().Deserialize(r);

            r.Expect <MappingEnd>();

            metaModel.NodeStyles.Add(s);
        }
Exemple #14
0
        /// <summary>
        /// Run Statement
        /// </summary>
        /// <param name="BasicIntrepeter">Basic Intrepeter that called the Statement</param>
        public override void ExcecuteStatement(Basic BasicIntrepeter)
        {
            int var;

            BasicIntrepeter.CodeParser.Expect(typeof(NextToken));
            var = Parser.CurrentToken.asVariableID(BasicIntrepeter);
            BasicIntrepeter.CodeParser.Expect(typeof(NumericVariableToken));

            if ((BasicIntrepeter.FORStackPosition > 0) && (BasicIntrepeter.FORStack[BasicIntrepeter.FORStackPosition - 1].ForVariable == var))
            {
                ((Basic.NumericBasicVariable)BasicIntrepeter.NumericVariables[var]).Value += BasicIntrepeter.FORStack[BasicIntrepeter.FORStackPosition - 1].Step;

                if (((Basic.NumericBasicVariable)BasicIntrepeter.NumericVariables[var]).Value <= BasicIntrepeter.FORStack[BasicIntrepeter.FORStackPosition - 1].To)
                {
                    Parser.ProgramPosition = BasicIntrepeter.FORStack[BasicIntrepeter.FORStackPosition - 1].TokenAfterFor;
                    Parser.Next();
                }
                else
                {
                    ((Basic.NumericBasicVariable)BasicIntrepeter.NumericVariables[var]).Value -= BasicIntrepeter.FORStack[BasicIntrepeter.FORStackPosition - 1].Step;
                    BasicIntrepeter.FORStackPosition--;
                    Parser.Expect(typeof(EndOfLineToken));
                }
            }
            else
            {
                throw new MFBasic.Exceptions.BasicLanguageException(MFBasic.Exceptions.BasicLanguageException.NEXT_WITHOUT_FOR);
            }
        }
Exemple #15
0
        public SiteConfiguration ParseConfig(TextReader configReader)
        {
            var parser = new Parser(configReader);

            parser.Expect <StreamStart>();

            return(_deserializer.Deserialize <SiteConfiguration>(parser) ?? SiteConfiguration.Default);
        }
Exemple #16
0
        public bool ParseHeader(ref string source, out Dictionary <string, object> pageContext)
        {
            var input = new StringReader(source);

            var parser = new Parser(input);

            pageContext = null;

            int i;

            parser.Expect <StreamStart>();

            if (!parser.Accept <DocumentStart>())
            {
                return(false);
            }

            var doc = _deserializer.Deserialize(parser);

            if (doc == null)
            {
                return(false);
            }

            pageContext = ConvertDoc(doc) as Dictionary <string, object>;

            if (pageContext == null)
            {
                return(false);
            }

            if (!parser.Accept <DocumentStart>())
            {
                return(false);
            }

            i = parser.Current.End.Index - 1;

            char c;

            do
            {
                i++;

                if (i >= source.Length)
                {
                    source = string.Empty;
                    return(true);
                }

                c = source[i];
            } while (c == '\r' || c == '\n');

            source = source.Substring(i);

            return(true);
        }
        public override Statement ParseNoNewContext(Parser parser)
        {
            var result = parser.Labels(new EmptyStatement());

            // Read past the semicolon.
            parser.Expect(PunctuatorToken.Semicolon);

            return(result);
        }
Exemple #18
0
        private static int Parse(Parser p)
        {
            Symbol endSym = Symbol.RSqBracket;

            if (p.Accept(Symbol.LBracket))
            {
                endSym = Symbol.RBracket;
            }
            else
            {
                p.Expect(Symbol.LSqBracket);
            }

            List <int> numbers  = new();
            bool       redFound = false;

            while (!p.Done() && p.PeekSymbol() != endSym)
            {
                switch (p.PeekSymbol())
                {
                case Symbol.LBracket:
                    numbers.Add(Parse(p));
                    break;

                case Symbol.LSqBracket:
                    numbers.Add(Parse(p));
                    break;

                case Symbol.Ident:
                {
                    int val;
                    if (p.Accept("red"))
                    {
                        redFound = endSym == Symbol.RBracket;
                    }
                    else if (p.AcceptNumber(out val))
                    {
                        numbers.Add(val);
                    }
                    else
                    {
                        p.Burn();
                    }
                }
                break;

                default:
                    p.Burn();
                    break;
                }
            }

            p.Burn();

            return(redFound ? 0 : numbers.Sum());
        }
Exemple #19
0
        public override Statement ParseNoNewContext(Parser parser)
        {
            var result = parser.Labels(new DebuggerStatement());

            // Consume the debugger keyword.
            parser.Expect(KeywordToken.Debugger);

            // Consume the end of the statement.
            parser.ExpectEndOfStatement();

            return(result);
        }
        public void FromString(string content)
        {
            StringReader input        = new StringReader(content);
            Deserializer deserializer = new DeserializerBuilder().Build();
            Parser       parser       = new Parser(input);

            parser.Expect <StreamStart>();

            while (parser.Accept <DocumentStart>())
            {
                documents.Add(deserializer.Deserialize <Document>(parser));
            }
        }
        public void Verify_CalledParser()
        {
            //arrange
            string expression = "bla-bla-bla";
            _parser = MockRepository.GenerateStrictMock<Parser<Variable[]>>();
            _parser.Expect(x=>x.Verify(expression)).Return(false);

            //act
            CreateService().Verify(expression);

            //assert
            _parser.VerifyAllExpectations();
        }
        public void ParseIdentifierTest()
        {
            var commentSql1 = "COMMENT ON COLUMN \"Supplier\".\"PrimaryContactId\" IS 'Gets or sets the Id of the primary contact.';";
            var parser      = new Parser(commentSql1);

            parser.Expect("COMMENT", "ON", "COLUMN");
            parser.ParseIdentifier().Should().Be("\"Supplier\".\"PrimaryContactId\"");

            var commentSql2 = "COMMENT ON COLUMN public.\"Supplier\".\"PrimaryContactId\" IS 'Gets or sets the Id of the primary contact.';";

            parser = new Parser(commentSql2);
            parser.Expect("COMMENT", "ON", "COLUMN");
            parser.ParseIdentifier().Should().Be("public.\"Supplier\".\"PrimaryContactId\"");
        }
Exemple #23
0
        public Post ReadHeader(string fileText)
        {
            //Ref: https://markheath.net/post/markdown-html-yaml-front-matter
            var yamlDeserializer = new DeserializerBuilder()
                                   .WithNamingConvention(new CamelCaseNamingConvention())
                                   .Build();
            Post post = null;
            var  text = fileText;

            try
            {
                using (var input = new StringReader(text))
                {
                    var parser = new Parser(input);
                    parser.Expect <StreamStart>();
                    parser.Expect <DocumentStart>();
                    post = yamlDeserializer.Deserialize <Post>(parser);
                    parser.Expect <DocumentEnd>();
                }
            } catch (Exception ex)
            { post = null; }
            return(post);
        }
        public void Parse_CalledParser()
        {
            //arrange
            string expression = "bla-bla-bla";

            _parser = MockRepository.GenerateStrictMock <Parser <Variable[]> >();
            _parser.Expect(x => x.Parse(expression)).Return(null);

            //act
            CreateService().Parse(expression);

            //assert
            _parser.VerifyAllExpectations();
        }
Exemple #25
0
        /// <summary>
        /// 文書内の先頭のYAMLをデシリアライズする
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="reader"></param>
        /// <returns></returns>
        private static TResult DeserializeFirst <TResult>(TextReader reader)
        {
            var parser = new Parser(reader);

            parser.Expect <StreamStart>();

            var deserializer = new DeserializerBuilder().Build();

            if (parser.Accept <DocumentStart>())
            {
                return(deserializer.Deserialize <TResult>(parser));
            }

            throw new ArgumentException();
        }
Exemple #26
0
        public List <TType> FromString <TType>(string data)
        {
            List <TType> list   = new List <TType>();
            StringReader input  = new StringReader(data);
            Parser       parser = new Parser(input);

            // Consume the stream start event "manually"
            parser.Expect <StreamStart>();

            while (parser.Accept <DocumentStart>())
            {
                list.Add(deserializer.Deserialize <TType>(parser));
            }

            return(list);
        }
        /// <summary>
        /// Pass in YAML in the form of a string and return a ParseResult with one or more Actions deserialized.
        /// </summary>
        /// <param name="yaml"></param>
        /// <returns></returns>
        public ParseResult Parse(string yaml)
        {
            ParseResult result = new ParseResult();

            if (string.IsNullOrWhiteSpace(yaml))
            {
                Exception e = new Exception("Empty or null YAML string.");
                result.CatchError(e);
            }
            else
            {
                yaml = ParsingHelper.CleanseYaml(yaml);
                StringReader input        = new StringReader(yaml);
                var          deserializer = new DeserializerBuilder()
                                            .WithNamingConvention(new CamelCaseNamingConvention())
                                            .Build();

                var parser = new Parser(input);
                parser.Expect <StreamStart>();

                while (parser.Accept <DocumentStart>())
                {
                    try
                    {
                        var doc = deserializer.Deserialize <Action>(parser);
                        doc.YamlArtifactID = -1;
                        result.Library.Actions.Add(doc);
                    }
                    catch (Exception e)
                    {
                        if (e.InnerException != null)
                        {
                            if (e.InnerException.Message.Contains("not found"))
                            {
                                result.CatchError(Constants.ParseErrors.YamlParsingErrorInvalidTypeName, Constants.ParseErrors.YamlParsingErrorInvalidTypeComment, e);
                            }
                        }
                        else
                        {
                            result.CatchError(e);
                        }
                    }
                }
            }

            return(result);
        }
Exemple #28
0
        public YamlOctopusModel[] Read(Stream stream)
        {
            var models = new List <YamlOctopusModel>();

            using (var reader = new StreamReader(stream))
            {
                var parser = new Parser(reader);
                parser.Expect <StreamStart>();

                while (parser.Accept <DocumentStart>())
                {
                    models.Add(_deserializer.Deserialize <YamlOctopusModel>(parser));
                }

                return(models.ToArray());
            }
        }
Exemple #29
0
        /// <summary>
        /// Searches for WEND
        /// </summary>
        internal void SearchForWEND()
        {
            // Repeat until we've hit WEND
            while (!Parser.CurrentToken.GetType().Equals(typeof(WendToken)))
            {
                // If we hit a WHILE then look for that WEND first
                if (Parser.CurrentToken.GetType().Equals(typeof(WhileToken)))
                {
                    Parser.Next();
                    SearchForWEND();
                }

                Parser.Next();
            }

            // Skip Wend
            Parser.Expect(typeof(WendToken));
        }
Exemple #30
0
        public static IEnumerable <TStub> ReadStubs <TStub>(string endpointFolder) where TStub : Stub
        {
            var stringProperties = typeof(TStub).GetProperties().Where(p => p.PropertyType == typeof(String)).ToArray();

            foreach (var stubFile in Directory.GetFiles(endpointFolder, StubFilePattern, SearchOption.AllDirectories))
            {
                if (stubFile.Contains(@"\_Missing\"))
                {
                    continue;
                }

                using (var fileContent = new StringReader(File.ReadAllText(stubFile)))
                {
                    var parser = new Parser(fileContent);
                    parser.Expect <StreamStart>();

                    int docIndex = 1;
                    while (parser.Accept <DocumentStart>())
                    {
                        var stub = YamlDesirializer.Deserialize <TStub>(parser);

                        foreach (var property in stringProperties)
                        {
                            var value = property.GetValue(stub) as String;
                            if (!String.IsNullOrWhiteSpace(value))
                            {
                                var newValue = value.TrimEnd().Replace("\n", "\r\n");
                                property.SetValue(stub, newValue);
                            }
                        }

                        stub.FilePath      = stubFile;
                        stub.Name          = Path.GetFileName(stubFile);
                        stub.FolderPath    = endpointFolder;
                        stub.DocumentIndex = docIndex;

                        yield return(stub);

                        docIndex++;
                    }
                }
            }
        }
Exemple #31
0
        public IExpression Parse(Parser parser, Token token)
        {
            var exprs = new List <IExpression>();

            while (parser.TokenStream.Peek().Type != TokenType.CBRACE)
            {
                var expr = parser.ParseExpression(GetPrecedence());
                exprs.Add(expr);

                if (parser.TokenStream.Peek().Type == TokenType.SEMICOLON)
                {
                    parser.TokenStream.Read();
                }
            }

            parser.Expect(TokenType.CBRACE);

            return(new BlockExpression(token.Line, token.Column, exprs));
        }