Skip to content

Commit

Permalink
Simplify regexes more
Browse files Browse the repository at this point in the history
  • Loading branch information
Altai-man committed May 17, 2018
1 parent 93f0058 commit b2524e3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions tap4j/src/main/java/org/tap4j/model/Patterns.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ private Patterns() { // hidden as this is a final utility class
/**
* TAP Text Regex.
*/
static final String REGEX_TEXT = "((\\s|\\t)*)(.*)";
static final String REGEX_TEXT = "(\\s*)(.*)";

/**
* TAP Header Regex.
*/
static final String REGEX_HEADER = "((\\s|\\t)*)?TAP\\s*version\\s*(\\d+)\\s*(#\\s*(.*))?";
static final String REGEX_HEADER = "(\\s*)TAP\\s*version\\s*(\\d+)\\s*(#\\s*(.*))?";

/**
* TAP Plan Regex.
*/
static final String REGEX_PLAN = "((\\s|\\t)*)?(\\d+)(\\.{2})(\\d+)"
static final String REGEX_PLAN = "(\\s*)(\\d+)(\\.{2})(\\d+)"
+ "\\s*(#\\s*(SKIP|skip)\\s*([^#]+))?\\s*(#\\s*(.*))?";

/**
Expand All @@ -64,17 +64,17 @@ private Patterns() { // hidden as this is a final utility class
/**
* TAP Bail Out! Regex.
*/
static final String REGEX_BAIL_OUT = "((\\s|\\t)*)?Bail out!\\s*([^#]+)?\\s*(#\\s*(.*))?";
static final String REGEX_BAIL_OUT = "(\\s*)Bail out!\\s*([^#]+)?\\s*(#\\s*(.*))?";

/**
* TAP Comment Regex.
*/
static final String REGEX_COMMENT = "((\\s|\\t)*)?#\\s*(.*)";
static final String REGEX_COMMENT = "(\\s*)#\\s*(.*)";

/**
* TAP Footer Regex.
*/
static final String REGEX_FOOTER = "((\\s|\\t)*)?TAP\\s*([^#]*)?\\s*(#\\s*(.*))?";
static final String REGEX_FOOTER = "(\\s*)TAP\\s*([^#]*)?\\s*(#\\s*(.*))?";

/* -- Patterns -- */

Expand Down
20 changes: 10 additions & 10 deletions tap4j/src/main/java/org/tap4j/model/TapElementFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,42 +71,42 @@ public static TapElement createTapElement(String tapLine) {

m = Patterns.COMMENT_PATTERN.matcher(tapLine);
if (m.matches()) {
Comment comment = new Comment(m.group(3), false);
Comment comment = new Comment(m.group(2), false);
comment.indentation = m.group(1).length();
return comment;
}

m = Patterns.HEADER_PATTERN.matcher(tapLine);
if (m.matches()) {
Header header = new Header(Integer.parseInt(m.group(3)));
Header header = new Header(Integer.parseInt(m.group(2)));
header.indentation = m.group(1).length();
addComment(header, m.group(5));
addComment(header, m.group(4));
return header;
}

m = Patterns.FOOTER_PATTERN.matcher(tapLine);
if (m.matches()) {
Footer footer = new Footer(m.group(3));
addComment(footer, m.group(5));
Footer footer = new Footer(m.group(2));
addComment(footer, m.group(4));
footer.indentation = m.group(1).length();
return footer;
}

m = Patterns.PLAN_PATTERN.matcher(tapLine);
if (m.matches()) {
String skip = m.group(8);
String comment = m.group(10);
String skip = m.group(7);
String comment = m.group(9);
SkipPlan skipPlan = skip != null && skip.trim().length() > 0 ? new SkipPlan(skip) : null;
Plan plan = new Plan(Integer.parseInt(m.group(3)), Integer.parseInt(m.group(5)), skipPlan);
Plan plan = new Plan(Integer.parseInt(m.group(2)), Integer.parseInt(m.group(4)), skipPlan);
addComment(plan, comment);
plan.indentation = m.group(1).length();
return plan;
}

m = Patterns.BAIL_OUT_PATTERN.matcher(tapLine);
if (m.matches()) {
String reason = m.group(3);
String comment = m.group(5);
String reason = m.group(2);
String comment = m.group(4);
BailOut bailOut = new BailOut(reason);
addComment(bailOut, comment);
bailOut.indentation = m.group(1).length();
Expand Down

0 comments on commit b2524e3

Please sign in to comment.