public override List <Diagnostic> VisitStructuredTemplateBody([NotNull] LGFileParser.StructuredTemplateBodyContext context) { var result = new List <Diagnostic>(); if (context.structuredBodyNameLine().errorStructuredName() != null) { result.Add(BuildLGDiagnostic(TemplateErrors.InvalidStrucName, context: context.structuredBodyNameLine())); } if (context.structuredBodyEndLine() == null) { result.Add(BuildLGDiagnostic(TemplateErrors.MissingStrucEnd, context: context)); } var errors = context.errorStructureLine(); if (errors != null && errors.Length > 0) { foreach (var error in errors) { result.Add(BuildLGDiagnostic(TemplateErrors.InvalidStrucBody, context: error)); } } else { var bodys = context.structuredBodyContentLine(); if (bodys == null || bodys.Length == 0) { result.Add(BuildLGDiagnostic(TemplateErrors.EmptyStrucContent, context: context)); } else { foreach (var body in bodys) { if (body.objectStructureLine() != null) { result.AddRange(CheckExpression(body.objectStructureLine().GetText(), body.objectStructureLine())); } else { // KeyValueStructuredLine var structureValues = body.keyValueStructureLine().keyValueStructureValue(); var errorPrefix = "Property '" + body.keyValueStructureLine().STRUCTURE_IDENTIFIER().GetText() + "':"; foreach (var structureValue in structureValues) { foreach (var expression in structureValue.EXPRESSION_IN_STRUCTURE_BODY()) { result.AddRange(CheckExpression(expression.GetText(), structureValue, errorPrefix)); } } } } } } return(result); }
public override List <Diagnostic> VisitStructuredTemplateBody([NotNull] LGFileParser.StructuredTemplateBodyContext context) { var result = new List <Diagnostic>(); if (context.structuredBodyNameLine().errorStructuredName() != null) { result.Add(BuildLGDiagnostic($"structured name format error.", context: context.structuredBodyNameLine())); } if (context.structuredBodyEndLine() == null) { result.Add(BuildLGDiagnostic($"structured LG missing ending ']'", context: context)); } var bodys = context.structuredBodyContentLine(); if (bodys == null || bodys.Length == 0) { result.Add(BuildLGDiagnostic($"Structured content is empty", context: context)); } else { foreach (var body in bodys) { if (body.errorStructureLine() != null) { result.Add(BuildLGDiagnostic($"structured body format error.", context: body.errorStructureLine())); } else if (body.objectStructureLine() != null) { result.AddRange(CheckExpression(body.objectStructureLine().GetText(), body.objectStructureLine())); } else { // KeyValueStructuredLine var structureValues = body.keyValueStructureLine().keyValueStructureValue(); foreach (var structureValue in structureValues) { foreach (var expression in structureValue.EXPRESSION_IN_STRUCTURE_BODY()) { result.AddRange(CheckExpression(expression.GetText(), context)); } } } } } return(result); }
public override List <Diagnostic> VisitStructuredTemplateBody([NotNull] LGFileParser.StructuredTemplateBodyContext context) { var result = new List <Diagnostic>(); var typeName = context.structuredBodyNameLine().STRUCTURED_CONTENT().GetText().Trim(); if (!structuredNameRegex.IsMatch(typeName)) { result.Add(BuildLGDiagnostic($"Structured type {typeName} is invalid. Letter, number, '_', '-' and '.' is allowed.", context: context.structuredBodyContentLine())); } if (context.structuredBodyEndLine() == null) { result.Add(BuildLGDiagnostic($"structured LG missing ending ']'", context: context.structuredBodyContentLine())); } var bodys = context.structuredBodyContentLine()?.STRUCTURED_CONTENT(); if (bodys == null || bodys.Length == 0 || bodys.All(u => string.IsNullOrEmpty(u.GetText()))) { result.Add(BuildLGDiagnostic($"Structured content is empty", context: context.structuredBodyContentLine())); } else { foreach (var body in bodys) { var line = body.GetText().Trim(); if (!string.IsNullOrWhiteSpace(line)) { var start = line.IndexOf('='); if (start < 0 && !Evaluator.IsPureExpression(line)) { result.Add(BuildLGDiagnostic($"Structured content does not support", context: context.structuredBodyContentLine())); } else { if (start > 0) { var property = line.Substring(0, start).Trim().ToLower(); var originValue = line.Substring(start + 1).Trim(); var valueArray = Evaluator.EscapeSeperatorRegex.Split(originValue); if (valueArray.Length == 1) { result.AddRange(CheckText(originValue, context.structuredBodyContentLine())); } else { foreach (var item in valueArray) { result.AddRange(CheckText(item.Trim(), context.structuredBodyContentLine())); } } } else if (Evaluator.IsPureExpression(line)) { result.AddRange(CheckExpression(line, context.structuredBodyContentLine())); } } } } } return(result); }