opwvhk commented on code in PR #2885:
URL: https://github.com/apache/avro/pull/2885#discussion_r1590665091
##########
lang/java/idl/src/main/java/org/apache/avro/idl/IdlSchemaParser.java:
##########
@@ -27,14 +27,17 @@
import java.util.regex.Pattern;
public class IdlSchemaParser implements FormattedSchemaParser {
+ private static final Pattern START_OF_IDL_PATTERN = Pattern.compile("\\A" +
// Start of input
+ "(?:\\s*+|/\\*(?:[^*]|\\*(?!/))*+\\*/|//(?:(?!\\R).)*+\\R)*+" + //
Initial whitespace & comments
+ "(?:@|(?:namespace|schema|protocol|record|enum|fixed|import)\\s)", //
First keyword mor @
+ Pattern.UNICODE_CHARACTER_CLASS | Pattern.MULTILINE);
@Override
public Schema parse(ParseContext parseContext, URI baseUri, CharSequence
formattedSchema)
throws IOException, SchemaParseException {
- boolean valid = Pattern.compile("^\\A*!" + // Initial whitespace
- "(?:/\\*(?:[^*]|\\*[^/])*!\\*/\\s*!|//(!=\\R)*!\\R\\s*!)*!" + //
Comments
- "(?:namespace|schema|protocol|record|enum|fixed|import)\\s", // First
keyword
- Pattern.UNICODE_CHARACTER_CLASS |
Pattern.MULTILINE).matcher(formattedSchema).find();
+ // This pattern matches initial whitespace/comments, plus all possible
starting
Review Comment:
And important, IMHO. I'm moving this comment to the javadoc of the pattern,
and I'll add a bit of explanation explaining how it is designed to fail fast.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]