Ejemplo n.º 1
0
        /// <summary>
        /// Consumes a class declaration statement.
        /// </summary>
        private ClassStatement ClassDeclaration()
        {
            var name = Consume(TokenType.Identifier, "Expected class name.");

            VariableExpression superClass = null;

            if (NextTokenMatches(TokenType.Colon))
            {
                var token = Consume(TokenType.Identifier, "Expected superclass name after ':'.");
                superClass = new VariableExpression(token);
            }

            Consume(TokenType.LeftCurlyBrace, "Expected '{' before class body.");

            var methods = new List <FunctionStatement>();

            while (!PeekMatches(TokenType.RightCurlyBrace) && !_atEndOfTokens)
            {
                methods.Add(Function(kind: "method"));
            }

            Consume(TokenType.RightCurlyBrace, "Expected '}' after class body.");
            return(new ClassStatement(name, superClass, methods));
        }
Ejemplo n.º 2
0
 public string VisitVariableExpression(VariableExpression expression)
 {
     throw new System.NotImplementedException();
 }