Esempio n. 1
0
        public override Statement VisitQuestion(QLParser.QuestionContext context)
        {
            DataType   type       = StringEnum.GetEnumerationValue <DataType>(context.TYPE().GetText());
            Identifier id         = new Identifier(context.ID().GetText(), context.GetTextPosition());
            string     label      = context.STRING().GetText();
            Expression expression = null;

            // Remove the leading and trailing '"' characters from the string literal.
            label = label.Trim('"');

            if (context.expr() != null)
            {
                expression = context.expr().Accept(new ExpressionBuilder());
            }

            switch (type)
            {
            case DataType.Boolean:
                return(new BooleanQuestion(id, label, expression, context.GetTextPosition()));

            case DataType.Date:
                return(new DateQuestion(id, label, expression, context.GetTextPosition()));

            case DataType.Integer:
                return(new IntegerQuestion(id, label, expression, context.GetTextPosition()));

            case DataType.String:
                return(new StringQuestion(id, label, expression, context.GetTextPosition()));

            default:
                string message = String.Format("Data type '{0}' is not supported for questions.");
                throw new NotSupportedException(message);
            }
        }
        public override Expression VisitNegation(QLParser.NegationContext context)
        {
            Expression operand   = context.expr().Accept(this);
            Operation  operation = StringEnum.GetEnumerationValue <Operation>(context.GetChild(0).GetText());

            return(new Negation(operation, operand, context.GetTextPosition()));
        }
        public override Expression VisitOr(QLParser.OrContext context)
        {
            Expression left      = context.expr(0).Accept(this);
            Expression right     = context.expr(1).Accept(this);
            Operation  operation = StringEnum.GetEnumerationValue <Operation>(context.GetChild(1).GetText());

            return(new Or(operation, left, right, context.GetTextPosition()));
        }
Esempio n. 4
0
        public override DefaultStyle VisitDefaultStyle(QLSParser.DefaultStyleContext context)
        {
            DataType dataType        = StringEnum.GetEnumerationValue <DataType>(context.TYPE().GetText());
            var      styleAttributes = new List <StyleAttribute>();

            foreach (var styleAttributeContext in context.style_attr())
            {
                styleAttributes.Add(styleAttributeContext.Accept(new StyleAttributeBuilder()));
            }

            return(new DefaultStyle(dataType, styleAttributes, context.GetTextPosition()));
        }
        public override Expression VisitEquality(QLParser.EqualityContext context)
        {
            Expression left      = context.expr(0).Accept(this);
            Expression right     = context.expr(1).Accept(this);
            Operation  operation = StringEnum.GetEnumerationValue <Operation>(context.GetChild(1).GetText());

            switch (operation)
            {
            case Operation.EqualTo:
                return(new EqualTo(operation, left, right, context.GetTextPosition()));

            case Operation.NotEqualTo:
                return(new NotEqualTo(operation, left, right, context.GetTextPosition()));

            default:
                throw new NotSupportedException("Unexpected operator symbol encountered.");
            }
        }