Example #1
0
        public override void EnterFieldDeclaration([NotNull] NovaParser.FieldDeclarationContext context)
        {
            NovaParser.MemberDeclarationContext parent = (NovaParser.MemberDeclarationContext)context.parent;
            ModifiersEnum modifiers = ParserUtils.ParseModifier(parent.modifier().classModifier().GetText());

            VariableDeclaratorContext declarator = context.variableDeclarator();

            string type = context.typeType().GetText();
            string name = declarator.variableDeclaratorId().GetText();

            Field field = new Field(Class, Class.PopFieldId(), modifiers, new Variable(name, type, context.variableDeclarator()));

            ExpressionNode value = new ExpressionNode(field);

            var initializer = declarator.variableInitializer();

            if (initializer != null)
            {
                ExpressionContext expressionContext = initializer.expression();

                ExpressionListener listener = new ExpressionListener(field); // same here

                foreach (var expression in expressionContext.GetRuleContexts <ParserRuleContext>())
                {
                    expression.EnterRule(listener);
                }

                value = listener.GetResult();
            }

            field.Value = value;

            Class.Fields.Add(field.Name, field);
        }
Example #2
0
 public override void EnterMemberDeclaration([NotNull] NovaParser.MemberDeclarationContext context)
 {
     foreach (var memberDeclaration in context.GetRuleContexts <ParserRuleContext>())
     {
         memberDeclaration.EnterRule(this);
     }
 }
Example #3
0
        public override void EnterConstructorDeclaration([NotNull] NovaParser.ConstructorDeclarationContext context)
        {
            NovaParser.MemberDeclarationContext parent = (NovaParser.MemberDeclarationContext)context.parent;

            string        returnType = string.Empty;           // must be unit
            string        methodName = context.IDENTIFIER().GetText();
            ModifiersEnum modifiers  = ModifiersEnum.@private; // this is not a modifier !

            AddMethod(methodName, returnType, MethodType.Method, modifiers, context, context.formalParameters());
        }
Example #4
0
        public override void EnterMethodDeclaration([NotNull] NovaParser.MethodDeclarationContext context)
        {
            NovaParser.MemberDeclarationContext parent = (NovaParser.MemberDeclarationContext)context.parent;

            string        returnType = context.typeTypeOrUnit().GetText();
            string        methodName = context.IDENTIFIER().GetText();
            ModifiersEnum modifiers  = ParserUtils.ParseModifier(parent.modifier().classModifier().GetText());

            AddMethod(methodName, returnType, MethodType.Method, modifiers, context, context.formalParameters());
        }