CsvParser Example - grabbing of preceding blanks for unquoted fields #108

Closed
JuPfu opened this Issue Nov 17, 2014 · 1 comment

Comments

Projects
None yet
2 participants
@JuPfu

JuPfu commented Nov 17, 2014

The combined field separator separatedBy(fieldDelimiter ~ OWS) of the record rule grabs the blanks preceding a field. This is a desired behavior for quoted fields, but for unquoted fields preceding blanks should be part of the field. My point of view is supported by the fact, that trailing blanks are captured for unquoted fields in the CsvGrammer example.

A proposal to remedy the grasping of preceding blanks for unquoted fields is to simplify the field separator in the record rule to separatedBy(fieldDelimiter). This infers some small changes to the NL and quoted-field rules.

def record = rule { oneOrMore(field).separatedBy(fieldDelimiter) ~> Record }

def field = rule { quoted-field | unquoted-field }

def quoted-field = rule {
OWS ~ '"' ~ clearSB() ~ zeroOrMore((QTEXTDATA | '"' ~ '"') ~ appendSB()) ~ '"' ~ OWS ~ push(sb.toString)
}

def unquoted-field = rule { capture(zeroOrMore(TEXTDATA)) }

def NL = rule { optional('\r') ~ '\n' }

def OWS = rule { zeroOrMore(' ') }

@sirthias

This comment has been minimized.

Show comment
Hide comment
@sirthias

sirthias Nov 18, 2014

Owner

Thanks!

Owner

sirthias commented Nov 18, 2014

Thanks!

@sirthias sirthias closed this in c85face Feb 20, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment