Skip to content

Commit 08aec33

Browse files
committed
[bugfix] Fix whitespace issue and also allow combinatorial expressions to be used inside if expressions
1 parent 8910f9d commit 08aec33

File tree

1 file changed

+6
-5
lines changed
  • csv-validator-core/src/main/scala/uk/gov/nationalarchives/csv/validator/schema

1 file changed

+6
-5
lines changed

csv-validator-core/src/main/scala/uk/gov/nationalarchives/csv/validator/schema/SchemaParser.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import uk.gov.nationalarchives.csv.validator.{SchemaMessage, FailMessage}
2121

2222
trait SchemaParser extends RegexParsers {
2323

24-
override protected val whiteSpace = """[ \t]+""".r
24+
override protected val whiteSpace = """[ \t]*""".r
2525

2626
//val white: Parser[String] = whiteSpace
2727

@@ -95,8 +95,8 @@ trait SchemaParser extends RegexParsers {
9595

9696
def multiLineComment: Parser[String] = """\/\*(?:[^*\r\n]+|(?:\r?\n))*\*\/(?:\r?\n)?""".r
9797

98-
//def columnDefinitions = (positioned(columnDefinition))
99-
def columnDefinitions = columnDefinition
98+
def columnDefinitions = (positioned(columnDefinition))
99+
//def columnDefinitions = columnDefinition
100100

101101
def columnDefinition: Parser[ColumnDefinition] = (
102102
((columnIdentifier | quotedColumnIdentifier) <~ ":") ~ columnRule <~ (endOfColumnDefinition | comment) ^^ {
@@ -339,7 +339,8 @@ trait SchemaParser extends RegexParsers {
339339
// case cond ~ bdy ~ optBdy => IfRule(cond, bdy, optBdy)
340340
// }) | failure("Invalid rule")
341341

342-
def ifExpr: Parser[IfRule] = (("if(" ~> nonConditionalExpr <~ ",") ~ rep1(columnValidationExpr) ~ opt("," ~> rep1(columnValidationExpr)) <~ ")" ^^ {
342+
//TODO update EBNF to match this
343+
def ifExpr: Parser[IfRule] = (("if(" ~> (combinatorialExpr | nonConditionalExpr) <~ ",") ~ rep1(columnValidationExpr) ~ opt("," ~> rep1(columnValidationExpr)) <~ ")" ^^ {
343344
case cond ~ bdy ~ optBdy => IfRule(cond, bdy, optBdy)
344345
}) | failure("Invalid rule")
345346

@@ -364,7 +365,7 @@ trait SchemaParser extends RegexParsers {
364365

365366
def algorithmExpr: Parser[String] = "\"" ~> stringRegex <~ "\"" ^^ { a => a }
366367

367-
private def endOfColumnDefinition: Parser[Any] = eol | endOfInput | failure("Invalid column definition")
368+
private def endOfColumnDefinition: Parser[Any] = whiteSpace ~ (eol | endOfInput | failure("Invalid column definition"))
368369

369370
private def endOfInput: Parser[Any] = new Parser[Any] {
370371
def apply(input: Input) = {

0 commit comments

Comments
 (0)