Merge pull request #1101 from ajaxorg/mode/haml

Mode/haml
This commit is contained in:
Harutyun Amirjanyan 2012-11-15 04:38:29 -08:00
commit c36f8b7560
12 changed files with 306 additions and 32 deletions

View file

@ -77,6 +77,7 @@ var docs = {
"docs/glsl.glsl": "Glsl",
"docs/golang.go": "Go",
"docs/groovy.groovy": "Groovy",
"docs/haml.haml": "Haml",
"docs/Haxe.hx": "haXe",
"docs/html.html": "HTML",
"docs/jade.jade": "Jade",

View file

@ -0,0 +1,36 @@
!!!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]-->
/adasdasdad
%div{:id => "#{@item.type}_#{@item.number}", :class => '#{@item.type} #{@item.urgency}', :phoney => `asdasdasd`}
/ file: app/views/movies/index.html.haml
\d
%ads:{:bleh => 33}
%p==ddd==
Date/Time:
- now = DateTime.now
%strong= now
= if now DateTime.parse("December 31, 2006")
= "Happy new " + "year!"
%sfd.dfdfg
#content
.title
%h1= @title
= link_to 'Home', home_url
#contents
%div#content
%div.articles
%div.article.title Blah
%div.article.date 2006-11-05
%div.article.entry
Neil Patrick Harris
%div[@user, :greeting]
%bar[290]/
==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

@ -47,6 +47,7 @@ var modesByName = {
golang: ["Go" , "go"],
groovy: ["Groovy" , "groovy"],
haxe: ["haXe" , "hx"],
haml: ["HAML" , "haml"],
html: ["HTML" , "htm|html|xhtml"],
c_cpp: ["C/C++" , "c|cc|cpp|cxx|h|hh|hpp"],
clojure: ["Clojure" , "clj"],

View file

@ -65,7 +65,7 @@ var c_cppHighlightRules = function() {
"NULL|true|false|TRUE|FALSE"
);
var keywordMapper = exports.keywordMapper = this.createKeywordMapper({
var keywordMapper = this.$keywords = this.createKeywordMapper({
"keyword.control" : keywordControls,
"storage.type" : storageType,
"storage.modifier" : storageModifiers,

60
lib/ace/mode/haml.js Normal file
View file

@ -0,0 +1,60 @@
/* ***** 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 mode.tmpl.js
*/
define(function(require, exports, module) {
"use strict";
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var Tokenizer = require("../tokenizer").Tokenizer;
var HamlHighlightRules = require("./haml_highlight_rules").HamlHighlightRules;
var Mode = function() {
var highlighter = new HamlHighlightRules();
this.$tokenizer = new Tokenizer(highlighter.getRules());
};
oop.inherits(Mode, TextMode);
(function() {
// Extra logic goes here.
}).call(Mode.prototype);
exports.Mode = Mode;
});

View file

@ -0,0 +1,132 @@
define(function(require, exports, module) {
"use strict";
var oop = require("../lib/oop");
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var RubyExports = require("./ruby_highlight_rules");
var RubyHighlightRules = RubyExports.RubyHighlightRules;
var HamlHighlightRules = function() {
// regexp must not have capturing parentheses. Use (?:) instead.
// regexps are ordered -> the first match is used
this.$rules =
{
"start": [
{
"token" : "punctuation.section.comment",
"regex" : /^\s*\/.*/
},
{
"token" : "punctuation.section.comment",
"regex" : /^\s*#.*/
},
{
"token": "string.quoted.double",
"regex": "==.+?=="
},
{
"token": "keyword.other.doctype",
"regex": "^!!!\\s*(?:[a-zA-Z0-9-_]+)?"
},
RubyExports.qString,
RubyExports.qqString,
RubyExports.tString,
{
"token": ["entity.name.tag.haml"],
"regex": /^\s*%[\w:]+/,
"next": "tag_single"
},
{
"token": [ "meta.escape.haml" ],
"regex": "^\\s*\\\\."
},
RubyExports.constantNumericHex,
RubyExports.constantNumericFloat,
RubyExports.constantOtherSymbol,
{
"token": "text",
"regex": "=|-|~",
"next": "embedded_ruby"
}
],
"tag_single": [
{
"token": "entity.other.attribute-name.class.haml",
"regex": "\\.[\\w-]+"
},
{
"token": "entity.other.attribute-name.id.haml",
"regex": "#[\\w-]+"
},
{
"token": "punctuation.section",
"regex": "\\{",
"next": "section"
},
RubyExports.constantOtherSymbol,
{
"token": "text",
"regex": /\s/,
"next": "start"
},
{
"token": ["text", "punctuation"],
"regex": "($)|((?!\\.|#|\\{|\\[|=|-|~|\\/))",
"next": "start"
}
],
"section": [
RubyExports.constantOtherSymbol,
RubyExports.qString,
RubyExports.qqString,
RubyExports.tString,
RubyExports.constantNumericHex,
RubyExports.constantNumericFloat,
{
"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"
}
]
}
};
oop.inherits(HamlHighlightRules, TextHighlightRules);
exports.HamlHighlightRules = HamlHighlightRules;
});

View file

@ -206,11 +206,11 @@ var JadeHighlightRules = function() {
],*/
"tag_single": [
{
"token": "suport.type.attribute.class.jade",
"token": "entity.other.attribute-name.class.jade",
"regex": "\\.[\\w-]+"
},
{
"token": "suport.type.attribute.id.jade",
"token": "entity.other.attribute-name.id.jade",
"regex": "#[\\w-]+"
},
{

View file

@ -28,7 +28,8 @@ var ObjectiveCHighlightRules = function() {
}
];
var cRules = new CHighlightRules().getRules();
var cObj = new CHighlightRules();
var cRules = cObj.getRules();
this.$rules =
{
@ -168,7 +169,7 @@ var ObjectiveCHighlightRules = function() {
"regex": C_Highlight_File.cFunctions
},
{
"token" : C_Highlight_File.keywordMapper,
"token" : cObj.getKeywords(),
"regex" : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
},
{

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,28 @@ 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,
constantNumericHex,
constantNumericFloat,
{
token : "constant.language.boolean",
regex : "(?:true|false)\\b"
}, {
@ -144,6 +169,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

@ -48,10 +48,10 @@ module.exports = {
"test: symbol tokenizer" : function() {
// https://gist.github.com/1072693
assertValidTokens(this.tokenizer, "string",
assertValidTokens(this.tokenizer, "constant.other.symbol.ruby",
[":@thing", ":$thing", ":_thing", ":thing", ":Thing", ":thing1", ":thing_a",
":THING", ":thing!", ":thing=", ":thing?", ":t?"]);
assertInvalidTokens(this.tokenizer, "string",
assertInvalidTokens(this.tokenizer, "constant.other.symbol.ruby",
[":", ":@", ":$", ":1", ":1thing", ":th?ing", ":thi=ng", ":1thing",
":th!ing", ":thing#"]);
},
@ -61,9 +61,9 @@ module.exports = {
var tokens = this.tokenizer.getLineTokens(line, "start").tokens;
assert.equal(3, tokens.length);
assert.equal("variable.class", tokens[0].type);
assert.equal("support.class", tokens[0].type);
assert.equal("text", tokens[1].type);
assert.equal("variable.class", tokens[2].type);
assert.equal("support.class", tokens[2].type);
},
"test: hex tokenizer" : function() {

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;