Read TextMate syntax files and parse text with them.
Improvements over old textpow:
- Ruby 1.8 and 1.9 support
- Tested, documented, refactored and made +faster+
- Added tons of syntax files (li/textpow/syntax)
- Most included syntaxes work out of the box
INSTALL:
gem install textpow1x
Ruby 1.8
Install oniguruma
# Ubuntu
sudo apt-get -y install libonig-dev
gem install oniguruma
# OsX (no idea if this works...)
port install oniguruma4
USAGE:
-
Load a Syntax File list of included syntax
require 'textpow'
syntax = Textpow.syntax('ruby') # or Textpow::Syntax.load(syntax_file)
-
Initialize a processor:
processor = Textpow::DebugProcessor.new
-
Parse some text:
syntax.parse(text, processor)
Syntax-files
Syntax files are written with Textmate grammer. They are written in text/binary/xml/yaml format (all can be translated into each other). Textpow can understand the yaml form (ending in .syntax) and the xml form (ending in .tmSyntax or .plist) via plist library, but not the text or binary form. All syntax files shipped with textpow are in the yaml form, since its easiest to read and less verbose.
Adding a new syntax:
-
use
rake convert[filename]
to convert it into yaml format -
drop it into the lib/textpow/syntax folder
-
run tests
rake
to see if the syntax is parseable
Processors
A processors is a hook that is called while parsing a text. It must implement these methods:
class MyProcessor
def open_tag(tag_name, position_in_current_line); end
def close_tag(tag_name, position_in_current_line); end
# called before processing a line
def new_line(line_content); end
# called before parsing anything
def start_parsing(scope_name); end
# called before parsing everything
def end_parsing(scope_name); end
end
Textpow ensures that the methods are called in parsing order. If there are two subsequent calls to open_tag
, the first having name="text.string", position=10
and the second having name="markup.string", position=10
, it means that the "markup.string"
tag is inside the "text.string"
tag.
TODO
-
parse text plist files example
-
parse tmLanguage files example
-
document / spec / fix include languages (they dont work very well)
LICENSE: MIT
-
Copyright © 2011 Michael Grosser
-
Copyright © 2010 Chris Hoffman
-
Copyright © 2009 Spox
-
Copyright © 2007-2008 Dizan Vasquez