Esempio n. 1
0
        public override Node VisitPropertyDeclaration(DustParser.PropertyDeclarationContext context)
        {
            Expression initializer = null;
            string     name        = context.identifierName().GetText();
            bool       isMutable   = context.declaration().GetText().Contains("mut");

            if (context.expression() != null)
            {
                initializer = (Expression)Visit(context.expression());
            }

            if (visitorContext.ContainsPropety(name))
            {
                visitorContext.ErrorHandler.ThrowError(new SyntaxError($"Identifier '{name}' is already defined", context.identifierName().GetRange()));

                return(null);
            }

            IdentifierExpression identifier = new IdentifierExpression(name, isMutable, context.identifierName().GetRange());

            visitorContext.AddProperty(identifier);

            return(new PropertyDeclaration(initializer, identifier, context.GetRange()));
        }
Esempio n. 2
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="DustParser.propertyDeclaration"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitPropertyDeclaration([NotNull] DustParser.PropertyDeclarationContext context)
 {
     return(VisitChildren(context));
 }
Esempio n. 3
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="DustParser.propertyDeclaration"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitPropertyDeclaration([NotNull] DustParser.PropertyDeclarationContext context)
 {
 }