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 INode VisitQuestion([NotNull] QLParser.QuestionContext context) { var identifier = context.Identifier().GetText(); var body = context.StringLiteral().GetText(); body = Utility.String.TrimQuotes(body); IType type = GetTypeFromString(context.Type().GetText()); return(new Question(identifier, body, type)); }
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); }
private Type GetQuestionType(QLParser.QuestionContext question) { switch (question.questionType().chosenType.Type) { case QLParser.BOOLTYPE: return(typeof(bool)); case QLParser.STRINGTYPE: return(typeof(string)); case QLParser.INTTYPE: return(typeof(int)); case QLParser.DATETYPE: return(typeof(DateTime)); case QLParser.DECIMALTYPE: return(typeof(decimal)); default: throw new QlParserException( $@"QuestionType '{question.questionType().chosenType.Type}' handled in the parse tree but not by the AST", null); } }