Add haml support

This commit is contained in:
Garen Torikian 2012-11-13 14:19:20 -08:00 committed by nightwing
commit 5f5663dfe3
5 changed files with 143 additions and 238 deletions

View file

@ -1,21 +1,21 @@
!!!5
-# <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
-# <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
-# <!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
-# <!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
# <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
# <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
# <!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
# <!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
/adasdasdad
%div{:id => "#{@item.type}_#{@item.number}", :class => "#{@item.type} #{@item.urgency}"}
-# file: app/views/movies/index.html.haml
%div{:id => "#{@item.type}_#{@item.number}", :class => '#{@item.type} #{@item.urgency}', :phoney => `asdasdasd`}
/ file: app/views/movies/index.html.haml
\d
%ads:
%ads:{:bleh => 33}
%p==ddd==
Date/Time:
- now = DateTime.now
%strong= now
- if now > DateTime.parse("December 31, 2006")
= if now DateTime.parse("December 31, 2006")
= "Happy new " + "year!"
%sfd.dfdfg
#content
@ -33,4 +33,4 @@
%div[@user, :greeting]
%bar[290]/
Hello!
==Hello!==

View file

@ -9,4 +9,15 @@ def fact(n)
end
end
puts fact(ARGV[0].to_i)
puts fact(ARGV[0].to_i)
class Range
def to_json(*a)
{
'json_class' => self.class.name, # = 'Range'
'data' => [ first, last, exclude_end? ]
}.to_json(*a)
end
end
{:id => 34, :sdfasdfasdf => "asdasdads"}

View file

@ -1,48 +1,10 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2012, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* Contributor(s):
*
* Garen J. Torikian < gjtorikian AT gmail DOT com >
*
* ***** END LICENSE BLOCK ***** */
/*
THIS FILE WAS AUTOGENERATED BY Haml.tmlanguage (UUID: 3D727049-DD05-45DF-92A5-D50EA36FD035) */
define(function(require, exports, module) {
"use strict";
var oop = require("../lib/oop");
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var RubyHighlightRules = require("./ruby_highlight_rules").RubyHighlightRules;
var RubyExports = require("./ruby_highlight_rules");
var RubyHighlightRules = RubyExports.RubyHighlightRules;
var HamlHighlightRules = function() {
@ -52,6 +14,10 @@ var HamlHighlightRules = function() {
this.$rules =
{
"start": [
{
"token" : "punctuation.section.comment",
"regex" : /^\s*\/.*/
},
{
"token": "string.quoted.double",
"regex": "==.+?=="
@ -60,22 +26,9 @@ var HamlHighlightRules = function() {
"token": "keyword.other.doctype",
"regex": "^!!!\\s*(?:[a-zA-Z0-9-_]+)?"
},
{
token : "comment",
regex : /\/.*$/
},
//{
// "token": [
// {
// "2": {
// "name": "punctuation.section.comment.haml"
// }
// },
// "comment.block.haml"
// ],
// "regex": "^( *)(/)\\s*$",
// "next": "state_4"
//},
RubyExports.qString,
RubyExports.qqString,
RubyExports.tString,
{
"token": ["entity.name.tag.haml"],
"regex": /^\s*%[\w:]+/,
@ -85,73 +38,16 @@ var HamlHighlightRules = function() {
"token": [ "meta.escape.haml" ],
"regex": "^\\s*\\\\."
},
//{
// "token": [
// null
// ],
// "regex": "^\\s*(?==|-|~)",
// "next": "state_7"
//}
],
/*"interpolated_ruby": [
{
"token": [ "punctuation.section.embedded.ruby", "source.ruby.embedded.source.empty",
"regex": "(?:#\\{(\\}))",
},
{
"begin": "#\\{",
"captures": {
"0": {
"name": "punctuation.section.embedded.ruby"
}
},
"end": "(\\})",
"name": "source.ruby.embedded.source",
"patterns": [
{
"include": "#nest_curly_and_self"
},
]
},
{
"captures": {
"1": {
"name": "punctuation.definition.variable.ruby"
}
},
"regex": "(#@)[a-zA-Z_]\\w*",
"name": "variable.other.readwrite.instance.ruby"
},
{
"captures": {
"1": {
"name": "punctuation.definition.variable.ruby"
}
},
"regex": "(#@@)[a-zA-Z_]\\w*",
"name": "variable.other.readwrite.class.ruby"
},
{
"captures": {
"1": {
"name": "punctuation.definition.variable.ruby"
}
},
"regex": "(#\\$)[a-zA-Z_]\\w*",
"name": "variable.other.readwrite.global.ruby"
}
]
],*//*
"state_4": [
RubyExports.constantNumericHex,
RubyExports.constantNumericFloat,
RubyExports.constantOtherSymbol,
{
"include": "text.haml"
},
{
"token": "TODO",
"regex": "^(?!\\1 )",
"next": "start"
"token": "text",
"regex": "=|-|~",
"next": "embedded_ruby"
}
],*/
],
"tag_single": [
{
"token": "entity.other.attribute-name.class.haml",
@ -162,103 +58,71 @@ var HamlHighlightRules = function() {
"regex": "#[\\w-]+"
},
{
"token": "meta.section.attributes.haml",
"regex": "\\{(?=.*\\}|.*\\|\\s*$)"
"token": "punctuation.section",
"regex": "\\{",
"next": "section"
},
RubyExports.constantOtherSymbol,
{
"token": "text",
"regex": /\s/,
"next": "start"
},
//{
// "token": "meta.section.object.haml",
// "regex": ""
//},
//{
// "include": "#rubyline"
//},
//{
// "token": "punctuation.terminator.tag.haml",
// "regex": "/"
//},
{
"token": ["text", "punctuation"],
"regex": "($)|((?!\\.|#|=|-))",
"regex": "($)|((?!\\.|#|\\{|\\[|=|-|~|\\/))",
"next": "start"
}
]/*,
"state_7": [
],
"section": [
RubyExports.constantOtherSymbol,
RubyExports.qString,
RubyExports.qqString,
RubyExports.tString,
RubyExports.constantNumericHex,
RubyExports.constantNumericFloat,
{
"include": "#rubyline"
},
{
"token": "TODO",
"regex": "$",
"token": "punctuation.section",
"regex": "\\}",
"next": "start"
}
],
"embedded_ruby": [
RubyExports.constantNumericHex,
RubyExports.constantNumericFloat,
{
token : "support.class", // class name
regex : "[A-Z][a-zA-Z_\\d]+"
},
{
"token" : new RubyHighlightRules().getKeywords(),
"regex" : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
},
{
"token" : ["keyword", "text", "text"],
"regex" : "(?:do|\\{)(?: \\|[^|]+\\|)?$",
"next" : "start"
},
{
"token" : ["text"],
"regex" : "^$",
"next" : "start"
},
{
"token" : ["text"],
"regex" : "^(?!.*\\|\\s*$)",
"next" : "start"
}
]*/
]
}
/*** START REPOSITORY RULES
{
"continuation": {
"captures": {
"1": {
"name": "punctuation.separator.continuation.haml"
}
},
"regex": "(\\|)\\s*\\n"
},
},
"nest_curly_and_self": {
"patterns": [
{
"begin": "\\{",
"captures": {
"0": {
"name": "punctuation.section.scope.ruby"
}
},
"end": "\\}",
"patterns": [
{
"include": "#nest_curly_and_self"
}
]
},
{
"include": "source.ruby"
}
]
},
"rubyline": {
"begin": "=|-|~",
"contentName": "source.ruby.embedded.haml",
"end": "((do|\\{)( \\|[^|]+\\|)?)$|$|^(?!.*\\|\\s*$)",
"endCaptures": {
"1": {
"name": "source.ruby.embedded.html"
},
"2": {
"name": "keyword.control.ruby.start-block"
}
},
"name": "meta.line.ruby.haml",
"patterns": [
{
"comment": "Hack to let ruby comments work in this context properly",
"regex": "#.*$",
"name": "comment.line.number-sign.ruby"
},
{
"include": "source.ruby.rails"
},
{
"include": "#continuation"
}
]
}
}
END REPOSITORY RULES ***/
};
oop.inherits(HamlHighlightRules, TextHighlightRules);
exports.HamlHighlightRules = HamlHighlightRules;
});
});

View file

@ -34,6 +34,37 @@ define(function(require, exports, module) {
var oop = require("../lib/oop");
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
// exports is for Haml
var constantOtherSymbol = exports.constantOtherSymbol = {
token : "constant.other.symbol.ruby", // symbol
regex : "[:](?:[A-Za-z_]|[@$](?=[a-zA-Z0-9_]))[a-zA-Z0-9_]*[!=?]?"
};
var qString = exports.qString = {
token : "string", // single line
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
};
var qqString = exports.qqString = {
token : "string", // single line
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
};
var tString = exports.tString = {
token : "string", // backtick string
regex : "[`](?:(?:\\\\.)|(?:[^'\\\\]))*?[`]"
};
var constantNumericHex = exports.constantNumericHex = {
token : "constant.numeric", // hex
regex : "0[xX][0-9a-fA-F](?:[0-9a-fA-F]|_(?=[0-9a-fA-F]))*\\b"
};
var constantNumericFloat = exports.constantNumericFloat = {
token : "constant.numeric", // float
regex : "[+-]?\\d(?:\\d|_(?=\\d))*(?:(?:\\.\\d(?:\\d|_(?=\\d))*)?(?:[eE][+-]?\\d+)?)?\\b"
};
var RubyHighlightRules = function() {
var builtinFunctions = (
@ -85,7 +116,7 @@ var RubyHighlightRules = function() {
"$!|root_url|flash|session|cookies|params|request|response|logger|self"
);
var keywordMapper = this.createKeywordMapper({
var keywordMapper = this.$keywords = this.createKeywordMapper({
"keyword": keywords,
"constant.language": buildinConstants,
"variable.language": builtinVariables,
@ -109,34 +140,26 @@ var RubyHighlightRules = function() {
}, {
token : "string.regexp",
regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
}, {
token : "string", // single line
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
}, {
token : "string", // single line
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
}, {
token : "string", // backtick string
regex : "[`](?:(?:\\\\.)|(?:[^'\\\\]))*?[`]"
}, {
},
qString,
qqString,
tString,
{
token : "text", // namespaces aren't symbols
regex : "::"
}, {
token : "variable.instance", // instance variable
regex : "@{1,2}[a-zA-Z_\\d]+"
}, {
token : "variable.class", // class name
token : "support.class", // class name
regex : "[A-Z][a-zA-Z_\\d]+"
}, {
token : "string", // symbol
regex : "[:](?:[A-Za-z_]|[@$](?=[a-zA-Z0-9_]))[a-zA-Z0-9_]*[!=?]?"
}, {
token : "constant.numeric", // hex
regex : "0[xX][0-9a-fA-F](?:[0-9a-fA-F]|_(?=[0-9a-fA-F]))*\\b"
}, {
token : "constant.numeric", // float
regex : "[+-]?\\d(?:\\d|_(?=\\d))*(?:(?:\\.\\d(?:\\d|_(?=\\d))*)?(?:[eE][+-]?\\d+)?)?\\b"
}, {
},
constantOtherSymbol,
{
token : "constant.language.boolean",
regex : "(?:true|false)\\b"
}, {
@ -144,6 +167,9 @@ var RubyHighlightRules = function() {
// TODO: Unicode escape sequences
// TODO: Unicode identifiers
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
}, {
token : "punctuation.separator.key-value",
regex : "=>"
}, {
token : "keyword.operator",
regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"

View file

@ -107,6 +107,10 @@ var TextHighlightRules = function() {
: function(value) {return keywords[value] || defaultToken };
}
this.getKeywords = function() {
return this.$keywords;
};
}).call(TextHighlightRules.prototype);
exports.TextHighlightRules = TextHighlightRules;