Пример #1
0
        public static EntitySet Parse(Lexer lexer)
        {
            var result = new EntitySet();

            var token = lexer.Scan();

            Entity lastEntity = null;
            Link lastLink = null;
            var isValues = false;

            var shouldBreak = false;
            while (!shouldBreak && token.type != TokenType.Error)
            {
                switch (token.type)
                {
                    case TokenType.Entity:
                        lastEntity = new Entity(token.value);
                        result.Entities.Add(lastEntity);
                        isValues = false;
                        lastLink = null;
                        break;

                    case TokenType.Values:
                        isValues = true;
                        break;

                    case TokenType.Alternative:
                        if (lastLink == null)
                            lastEntity.Type = EntityType.Secondary;
                        else
                            lastLink.Type = LinkType.Primary;
                        break;

                    case TokenType.Property:
                        if (isValues)
                        {
                            lastEntity.Values.Add(token.value);
                        }
                        else
                        {
                            lastEntity.Properties.Add(token.value);
                        }
                        break;

                    case TokenType.Link:
                        lastLink = new Link(token.value);
                        lastEntity.Links.Add(lastLink);
                        break;

                    case TokenType.Name:
                        lastLink.Name = token.value;
                        break;

                    case TokenType.EOF:
                        shouldBreak = true;
                        break;
                    case TokenType.Error:
                        Console.WriteLine("Error: {0}", token.value);
                        shouldBreak = true;
                        break;
                }

                token = lexer.Scan();
            }

            return result;
        }
Пример #2
0
 public static EntitySet Parse(string location, string source)
 {
     using (var lexer = new Lexer(location, source))
         return Parse(lexer);
 }