Skip to content

Commit

Permalink
let radial accept \r\n strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed May 5, 2013
1 parent 81abe4d commit f532b2d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Expand Up @@ -4,6 +4,7 @@

== ruote - 2.3.1 not yet released

- let radial accept \r\n strings
- implement Dashboard#reply_to_parent(fei, wi=nil)
- fix issue with @seen in wait_logger on JRuby (thanks Mark Wotton)
- Receiver#flunk accepts stacktrace as final argument
Expand Down
18 changes: 12 additions & 6 deletions lib/ruote/reader/radial.rb
Expand Up @@ -37,9 +37,12 @@ module RadialReader
#
class Parser < Parslet::Parser

# TODO: do something about \r\n appearing in :spaces and in :lines

rule(:spaces) {
match('\s').repeat >>
(str('#') >> match('[^\n]').repeat >> str("\n").present?).maybe >>
match('\s').repeat >> (
str('#') >> match('[^\r\n]').repeat >> match('[\r\n]').present?
).maybe >>
match('\s').repeat
}
rule(:spaces?) { spaces.maybe }
Expand Down Expand Up @@ -113,7 +116,7 @@ class Parser < Parslet::Parser
rule(:line) {
(
str(' ').repeat.as(:ind) >>
match('[^ \n#"\',]').repeat(1).as(:exp) >>
match('[^ \r\n#"\',]').repeat(1).as(:exp) >>
(
(comma | blanks) >> attribute >> (comma >> attribute).repeat
).as(:atts).maybe
Expand All @@ -122,12 +125,15 @@ class Parser < Parslet::Parser

rule(:comment) {
str(' ').repeat >>
(str('#') >> match('[^\n]').repeat).maybe >>
str("\n").present?
(str('#') >> match('[^\r\n]').repeat).maybe >>
(str("\r") | str("\n")).present?
}

rule(:lines) {
(str("\n") >> (line | blank_line) >> comment.maybe).repeat
(
str("\r").maybe >> str("\n") >>
(line | blank_line) >> comment.maybe
).repeat
}

root(:lines)
Expand Down
14 changes: 14 additions & 0 deletions test/unit/ut_24_radial_reader.rb
Expand Up @@ -461,5 +461,19 @@ def test_regex_escape
]],
tree)
end

def test_crlf

tree =
Ruote::RadialReader.read(
"define\r\n participant nada, t: hello\r\n participant ulf, t: world")

assert_equal(
[ 'define', {}, [
[ 'participant', { 'nada' => nil, 't' => 'hello' }, [] ],
[ 'participant', { 'ulf' => nil, 't' => 'world' }, [] ]
]],
tree)
end
end

0 comments on commit f532b2d

Please sign in to comment.