Guest User

Untitled

a guest
Feb 20th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #!/usr/bin/env ruby -w
  2.  
  3. # escape text for use in a TextMate snippet
  4. def e_sn(str)
  5. str.to_s.gsub(/(?=[$`\\])/, '\\')
  6. end
  7.  
  8. DATA.each do |example|
  9. puts "Input:"
  10. puts example
  11. puts "Output:"
  12. ### Parsing starts here ###
  13. snippet_counter = 0
  14. result = example.gsub(/[(,]\s*[\w.]+\s*(?:=\s*(?:"((?:\\\\|\\[^\\]|[^"\\]+)*)"|([^\s,]+))\s*)?/) do |match|
  15. snippet = match[0] == ?( ? "(${#{snippet_counter += 1}:#{e_sn(match[1..-1])}}" :
  16. "${#{snippet_counter += 1}:#{e_sn(match)}}"
  17. value = $1 || $2
  18. if value && ( snippet =~ /^([^"]+").+("\s*\})$/ ||
  19. snippet =~ /^([^=]+=\s*).+?(\s*\})$/ )
  20. $1 + "${#{snippet_counter += 1}#{':' if value != ''}#{e_sn(value)}}" + $2
  21. else
  22. snippet
  23. end
  24. end
  25. ### Parser ends here ###
  26. puts result
  27. puts
  28. end
  29.  
  30. __END__
  31. 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)
  32. read.csv(file, header = TRUE, sep = ",", quote="\"", dec=".", fill = TRUE, ...)
  33. read.csv2(file, header = TRUE, sep = ";", quote="\"", dec=",", fill = TRUE, ...)
  34. read.delim(file, header = TRUE, sep = "\t", quote="\"", dec=".", fill = TRUE, ...)
  35. read.delim2(file, header = TRUE, sep = "\t", quote="\"", dec=",", fill = TRUE, ...)
Add Comment
Please, Sign In to add comment