diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRLexer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRLexer.java index 9ac1d7a70..d2387f0f7 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRLexer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRLexer.java @@ -50,20 +50,31 @@ import org.hl7.fhir.utilities.Utilities; public class FHIRLexer { public class FHIRLexerException extends FHIRException { - public FHIRLexerException() { - super(); - } + private SourceLocation location; - public FHIRLexerException(String message, Throwable cause) { - super(message, cause); - } +// public FHIRLexerException() { +// super(); +// } +// +// public FHIRLexerException(String message, Throwable cause) { +// super(message, cause); +// } +// +// public FHIRLexerException(String message) { +// super(message); +// } +// +// public FHIRLexerException(Throwable cause) { +// super(cause); +// } - public FHIRLexerException(String message) { + public FHIRLexerException(String message, SourceLocation location) { super(message); + this.location = location; } - public FHIRLexerException(Throwable cause) { - super(cause); + public SourceLocation getLocation() { + return location; } } @@ -145,11 +156,11 @@ public class FHIRLexer { } public FHIRLexerException error(String msg) { - return error(msg, currentLocation.toString()); + return error(msg, currentLocation.toString(), currentLocation); } - public FHIRLexerException error(String msg, String location) { - return new FHIRLexerException("Error @"+location+": "+msg); + public FHIRLexerException error(String msg, String location, SourceLocation loc) { + return new FHIRLexerException("Error @"+location+": "+msg, loc); } public void next() throws FHIRLexerException { @@ -450,7 +461,7 @@ public class FHIRLexer { i = i + 4; break; default: - throw new FHIRLexerException("Unknown character escape \\"+s.charAt(i)); + throw new FHIRLexerException("Unknown character escape \\"+s.charAt(i), currentLocation); } } else { b.append(ch); @@ -499,7 +510,7 @@ public class FHIRLexer { i = i + 4; break; default: - throw new FHIRLexerException("Unknown character escape \\"+s.charAt(i)); + throw new FHIRLexerException("Unknown character escape \\"+s.charAt(i), currentLocation); } } else { b.append(ch); diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java index ce7111350..4b3267538 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/FHIRPathEngine.java @@ -1305,14 +1305,14 @@ public class FHIRPathEngine { private boolean checkParamCount(FHIRLexer lexer, SourceLocation location, ExpressionNode exp, int count) throws FHIRLexerException { if (exp.getParameters().size() != count) { - throw lexer.error("The function \""+exp.getName()+"\" requires "+Integer.toString(count)+" parameters", location.toString()); + throw lexer.error("The function \""+exp.getName()+"\" requires "+Integer.toString(count)+" parameters", location.toString(), location); } return true; } private boolean checkParamCount(FHIRLexer lexer, SourceLocation location, ExpressionNode exp, int countMin, int countMax) throws FHIRLexerException { if (exp.getParameters().size() < countMin || exp.getParameters().size() > countMax) { - throw lexer.error("The function \""+exp.getName()+"\" requires between "+Integer.toString(countMin)+" and "+Integer.toString(countMax)+" parameters", location.toString()); + throw lexer.error("The function \""+exp.getName()+"\" requires between "+Integer.toString(countMin)+" and "+Integer.toString(countMax)+" parameters", location.toString(), location); } return true; } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/structuremap/StructureMapUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/structuremap/StructureMapUtilities.java index e893dcb0f..7dd33b49a 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/structuremap/StructureMapUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/structuremap/StructureMapUtilities.java @@ -72,6 +72,9 @@ import org.hl7.fhir.utilities.CommaSeparatedStringBuilder; import org.hl7.fhir.utilities.SourceLocation; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.validation.ValidationMessage; +import org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity; +import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType; +import org.hl7.fhir.utilities.validation.ValidationMessage.Source; import org.hl7.fhir.utilities.validation.ValidationOptions; import org.hl7.fhir.utilities.xhtml.NodeType; import org.hl7.fhir.utilities.xhtml.XhtmlNode; @@ -640,26 +643,32 @@ public class StructureMapUtilities { return result; } - public Element parseEM(String text, String srcName) throws FHIRException { + public Element parseEM(String text, String srcName, List list) throws FHIRException { FHIRLexer lexer = new FHIRLexer(text, srcName); if (lexer.done()) throw lexer.error("Map Input cannot be empty"); lexer.token("map"); Element result = Manager.build(worker, worker.fetchTypeDefinition("StructureMap")); - result.makeElement("url").markLocation(lexer.getCurrentLocation()).setValue(lexer.readConstant("url")); - lexer.token("="); - result.makeElement("name").markLocation(lexer.getCurrentLocation()).setValue(lexer.readConstant("name")); - result.makeElement("description").markLocation(lexer.getCurrentLocation()).setValue(lexer.getAllComments()); - while (lexer.hasToken("conceptmap")) - parseConceptMapEM(result, lexer); + try { + result.makeElement("url").markLocation(lexer.getCurrentLocation()).setValue(lexer.readConstant("url")); + lexer.token("="); + result.makeElement("name").markLocation(lexer.getCurrentLocation()).setValue(lexer.readConstant("name")); + result.makeElement("description").markLocation(lexer.getCurrentLocation()).setValue(lexer.getAllComments()); + while (lexer.hasToken("conceptmap")) + parseConceptMapEM(result, lexer); - while (lexer.hasToken("uses")) - parseUsesEM(result, lexer); - while (lexer.hasToken("imports")) - parseImportsEM(result, lexer); + while (lexer.hasToken("uses")) + parseUsesEM(result, lexer); + while (lexer.hasToken("imports")) + parseImportsEM(result, lexer); - while (!lexer.done()) { - parseGroupEM(result, lexer); + while (!lexer.done()) { + parseGroupEM(result, lexer); + } + } catch (FHIRLexerException e) { + list.add(new ValidationMessage(Source.InstanceValidator, IssueType.INVALID, e.getLocation().getLine(), e.getLocation().getColumn(), null, e.getMessage(), IssueSeverity.FATAL)); + } catch (Exception e) { + list.add(new ValidationMessage(Source.InstanceValidator, IssueType.INVALID, null, e.getMessage(), IssueSeverity.FATAL)); } return result; @@ -3076,8 +3085,4 @@ public class StructureMapUtilities { this.terminologyServiceOptions = terminologyServiceOptions; } - public Element parseForValidation(ByteArrayInputStream byteArrayInputStream, String version, List errors) { - return null; - } - } \ No newline at end of file diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/StructureMapUtilitiesTest.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/StructureMapUtilitiesTest.java index adba23e34..4f4bfbd12 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/StructureMapUtilitiesTest.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/test/StructureMapUtilitiesTest.java @@ -98,7 +98,7 @@ public class StructureMapUtilitiesTest implements ITransformerServices { String fileMap = TestingUtilities.loadTestResource("r5", "structure-mapping", "syntax.map"); System.out.println(fileMap); - Element structureMap = scu.parseEM(fileMap, "Syntax"); + Element structureMap = scu.parseEM(fileMap, "Syntax", null); // assertSerializeDeserialize(structureMap); // // String renderedMap = StructureMapUtilities.render(structureMap);