private FieldTypeString StringTypeFromContext(DmolParser.TypeContext context) { var maxChars = 0; var parameters = context.typeParameters()?.typeParameter() ?? Array.Empty <TypeParameterContext>(); if (parameters.Length > 0) { if (parameters[0].INTEGER() != null) { maxChars = Convert.ToInt32(parameters[0].INTEGER().GetText()); } else { ErrorListener.SemanticError(context, "The parameter must be an INTEGER."); return(null); } } if (parameters.Length > 1) { var typeName = context.typeName().STRING().GetText(); ErrorListener.SemanticError(context, $"The '{typeName}' type only accepts one parameter."); return(null); } return(new FieldTypeString(maxChars)); }
private FieldType TypeFromContext(DmolParser.TypeContext context) { if (context.typeName().STRING() != null) { return(StringTypeFromContext(context)); } else if (context.typeName().DECIMAL() != null) { return(DecimalTypeFromContext(context)); } else if (context.typeName().DOUBLE() != null) { return(DoubleTypeFromContext(context)); } else if (context.typeName().INT() != null) { return(IntTypeFromContext(context)); } else if (context.typeName().BOOL() != null) { return(BoolTypeFromContext(context)); } else if (context.typeName().DATETIME() != null) { return(DateTimeTypeFromContext(context)); } else { ErrorListener.SemanticError(context, $"Unrecognized type '{context.typeName().GetText()}'"); return(null); } }
private FieldTypeBool BoolTypeFromContext(DmolParser.TypeContext context) { var parameters = context.typeParameters()?.typeParameter() ?? Array.Empty <TypeParameterContext>(); if (parameters.Length > 0) { var typeName = context.typeName().BOOL().GetText(); ErrorListener.SemanticError(context, $"The '{typeName}' type does not accept parameters."); return(null); } return(new FieldTypeBool()); }
private FieldTypeDecimal DecimalTypeFromContext(DmolParser.TypeContext context) { var precision = 18; var scale = 2; var parameters = context.typeParameters()?.typeParameter() ?? Array.Empty <TypeParameterContext>(); if (parameters.Length > 0) { if (parameters[0].INTEGER() != null) { precision = Convert.ToInt32(parameters[0].INTEGER().GetText()); } else { ErrorListener.SemanticError(context, "The parameter must be an INTEGER."); return(null); } } if (parameters.Length > 1) { if (parameters[1].INTEGER() != null) { scale = Convert.ToInt32(parameters[1].INTEGER().GetText()); } else { ErrorListener.SemanticError(context, "The parameter must be an INTEGER."); return(null); } } if (parameters.Length > 2) { var typeName = context.typeName().DECIMAL().GetText(); ErrorListener.SemanticError(context, $"The '{typeName}' type only accepts two parameters."); return(null); } return(new FieldTypeDecimal(precision, scale)); }
/// <summary> /// Visit a parse tree produced by <see cref="DmolParser.type"/>. /// <para> /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/> /// on <paramref name="context"/>. /// </para> /// </summary> /// <param name="context">The parse tree.</param> /// <return>The visitor result.</return> public virtual Result VisitType([NotNull] DmolParser.TypeContext context) { return(VisitChildren(context)); }