Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby -w
- # escape text for use in a TextMate snippet
- def e_sn(str)
- str.to_s.gsub(/(?=[$`\\])/, '\\')
- end
- DATA.each do |example|
- puts "Input:"
- puts example
- puts "Output:"
- ### Parsing starts here ###
- snippet_counter = 0
- result = example.gsub(/[(,]\s*[\w.]+\s*(?:=\s*(?:"((?:\\\\|\\[^\\]|[^"\\]+)*)"|([^\s,]+))\s*)?/) do |match|
- snippet = match[0] == ?( ? "(${#{snippet_counter += 1}:#{e_sn(match[1..-1])}}" :
- "${#{snippet_counter += 1}:#{e_sn(match)}}"
- value = $1 || $2
- if value && ( snippet =~ /^([^"]+").+("\s*\})$/ ||
- snippet =~ /^([^=]+=\s*).+?(\s*\})$/ )
- $1 + "${#{snippet_counter += 1}#{':' if value != ''}#{e_sn(value)}}" + $2
- else
- snippet
- end
- end
- ### Parser ends here ###
- puts result
- puts
- end
- __END__
- read.table(file, header = FALSE, sep = "", quote = "\"'", dec = ".", row.names, col.names, as.is = FALSE, na.strings = "NA", colClasses = NA, nrows = -1, skip = 0, check.names = TRUE, fill = !blank.lines.skip, strip.white = FALSE, blank.lines.skip = TRUE, comment.char = "#", allowEscapes = FALSE)
- read.csv(file, header = TRUE, sep = ",", quote="\"", dec=".", fill = TRUE, ...)
- read.csv2(file, header = TRUE, sep = ";", quote="\"", dec=",", fill = TRUE, ...)
- read.delim(file, header = TRUE, sep = "\t", quote="\"", dec=".", fill = TRUE, ...)
- read.delim2(file, header = TRUE, sep = "\t", quote="\"", dec=",", fill = TRUE, ...)
Add Comment
Please, Sign In to add comment