Exemplo n.º 1
0
        private SectionProperties ParseProperties()
        {
            SectionProperties ast           = new SectionProperties();
            Token             headFistToken = tape.Current;
            string            headFirstText = headFistToken.GetText();

            if (headFirstText.Length > 2)
            {
                string baseTypeName = headFirstText.Substring(0, headFirstText.Length - 2);
                ast.TypeToken = new Token(baseTypeName, TokenKind.Ident, headFistToken.Line, headFistToken.Col);
                ast.KeyToken  = new Token("属性", TokenKind.Ident, headFistToken.Line, headFistToken.Col + headFirstText.Length - 2);
            }
            else
            {
                ast.KeyToken = headFistToken;
            }

            tape.MoveNext();
            tape.Match(TokenKind.Colon);

            while (tape.CurrentKind != TokenKind.EOF && tape.CurrentKind != TokenKind.NewLine)
            {
                if (tape.CurrentKind == TokenKind.Ident)
                {
                    PropertyAST property = ParseProperty();
                    if (property != null)
                    {
                        ast.AddProperty(property);
                    }
                }
                else if (tape.CurrentKind == TokenKind.Comma)
                {
                    tape.MoveNext();
                }
                else
                {
                    tape.error(string.Format("类型'{0}'不是正确的属性", tape.Current.GetText()));
                    tape.MoveNext();
                }
            }
            SkipNewLine();
            return(ast);
        }