private IQuestionType GetQuestionType(QlParser.QuestionContext question)
        {
            switch (question.questionType().chosenType.Type)
            {
            case QlParser.BOOLTYPE: return(new BooleanQuestionType());

            case QlParser.STRINGTYPE: return(new StringQuestionType());

            case QlParser.INTTYPE: return(new IntegerQuestionType());

            case QlParser.DATETYPE: return(new DateQuestionType());

            case QlParser.DECIMALTYPE: return(new DecimalQuestionType());

            default:
                throw new ParserException(
                          $@"QuestionType '{question.questionType().chosenType.Type}' handled in the parse tree but not by the AST",
                          null);
            }
        }
Exemple #2
0
        public override AstNode VisitQuestion([NotNull] QlParser.QuestionContext context)
        {
            var id    = context.Identifier().GetText();
            var label = new StringLiteral(context.label.Text);
            var type  = context.Type().GetText();

            var        computedValue = context.expression();
            Expression value         = null;

            if (computedValue != null)
            {
                value = this.Visit(context.expression()) as Expression;
            }

            switch (type)
            {
            case "boolean":
                return(new QuestionStatement(id, new BooleanValueType(), label, value));

            case "integer":
                return(new QuestionStatement(id, new IntegerValueType(), label, value));

            case "decimal":
                return(new QuestionStatement(id, new DecimalValueType(), label, value));

            case "money":
                return(new QuestionStatement(id, new MoneyValueType(), label, value));

            case "string":
                return(new QuestionStatement(id, new StringValueType(), label, value));

            case "date":
                return(new QuestionStatement(id, new DateValueType(), label, value));

            default:
                throw new ArgumentOutOfRangeException(nameof(type), "Invalid question type.");
            }
        }