README.txt 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. = polyglot
  2. * http://github.com/cjheath/polyglot
  3. == DESCRIPTION:
  4. Author: Clifford Heath, 2007
  5. The Polyglot library allows a Ruby module to register a loader
  6. for the file type associated with a filename extension, and it
  7. augments 'require' to find and load matching files.
  8. This supports the creation of DSLs having a syntax that is most
  9. appropriate to their purpose, instead of abusing the Ruby syntax.
  10. Files are sought using the normal Ruby search path.
  11. == EXAMPLE:
  12. In file rubyglot.rb, define and register a file type handler:
  13. require 'polyglot'
  14. class RubyglotLoader
  15. def self.load(filename, options = nil, &block)
  16. File.open(filename) {|file|
  17. # Load the contents of file as Ruby code:
  18. # Implement your parser here instead!
  19. Kernel.eval(file.read)
  20. }
  21. end
  22. end
  23. Polyglot.register("rgl", RubyglotLoader)
  24. In file test.rb:
  25. require 'rubyglot' # Create my file type handler
  26. require 'hello' # Can add extra options or even a block here
  27. puts "Ready to go"
  28. Hello.new
  29. In file hello.rgl (this simple example uses Ruby code):
  30. puts "Initializing"
  31. class Hello
  32. def initialize()
  33. puts "Hello, world\n"
  34. end
  35. end
  36. Run:
  37. $ ruby test.rb
  38. Initializing
  39. Ready to go
  40. Hello, world
  41. $
  42. == INSTALL:
  43. sudo gem install polyglot
  44. == LICENSE:
  45. (The MIT License)
  46. Copyright (c) 2007 Clifford Heath
  47. Permission is hereby granted, free of charge, to any person obtaining
  48. a copy of this software and associated documentation files (the
  49. "Software"), to deal in the Software without restriction, including
  50. without limitation the rights to use, copy, modify, merge, publish,
  51. distribute, sublicense, and/or sell copies of the Software, and to
  52. permit persons to whom the Software is furnished to do so, subject to
  53. the following conditions:
  54. The above copyright notice and this permission notice shall be
  55. included in all copies or substantial portions of the Software.
  56. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  57. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  58. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  59. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  60. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  61. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  62. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.