syntax gem
Gem details
Documentation
Install the Gem:
gem install syntax
There are primarily two uses for the Syntax library:
Convert text from a supported syntax to a supported highlight format (like HTML).
Tokenize text in a supported syntax and process the tokens directly.
Highlighting a supported syntax
require 'syntax/convertors/html' convertor = Syntax::Convertors::HTML.for_syntax "ruby" puts convertor.convert( File.read( "file.rb" ) )
The above snippet will emit HTML, using spans and CSS to indicate the different highlight "groups". (Sample CSS files are included in the "data" directory.)
Tokenize text
require 'syntax' tokenizer = Syntax.load "ruby" tokenizer.tokenize( File.read( "file.rb" ) ) do |token| puts "group(#{token.group}, #{token.instruction}) lexeme(#{token})" end
Edit Gem | (0 older versions) | Last edited by: Guest, 6 months ago

