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())); }
/// <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)); }
/// <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) { }