Beispiel #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);
            }
        }
Beispiel #2
0
        public override AstNode VisitQuestion([NotNull] QLParser.QuestionContext context)
        {
            var question = new Question
            {
                Id   = context.ID().GetText(),
                Text = StripQuotes(context.QUOTED_STRING().GetText()),
                Type = context.type().Accept(this) as BaseType
            };

            return(question);
        }