From 3dce122f8cb4e9cea6b3d309969ff0ccc5d87727 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Sun, 11 Nov 2012 00:14:07 -0800 Subject: [PATCH] Start haml --- demo/kitchen-sink/doclist.js | 1 + demo/kitchen-sink/docs/haml.haml | 40 ++++ demo/kitchen-sink/modelist.js | 1 + lib/ace/mode/haml.js | 60 ++++++ lib/ace/mode/haml_highlight_rules.js | 264 +++++++++++++++++++++++++++ 5 files changed, 366 insertions(+) create mode 100644 demo/kitchen-sink/docs/haml.haml create mode 100644 lib/ace/mode/haml.js create mode 100644 lib/ace/mode/haml_highlight_rules.js diff --git a/demo/kitchen-sink/doclist.js b/demo/kitchen-sink/doclist.js index 70b23e0d..d87ef15d 100644 --- a/demo/kitchen-sink/doclist.js +++ b/demo/kitchen-sink/doclist.js @@ -76,6 +76,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", diff --git a/demo/kitchen-sink/docs/haml.haml b/demo/kitchen-sink/docs/haml.haml new file mode 100644 index 00000000..aa29cb6a --- /dev/null +++ b/demo/kitchen-sink/docs/haml.haml @@ -0,0 +1,40 @@ +!!!5 + +-# +-# +-# +-# + +# file: app/controllers/movies_controller.rb + +class MoviesController < ApplicationController + def index + @title = "Teen Wolf" + end +end +/adasdasdad +%div{:id => "#{@item.type}_#{@item.number}", :class => "#{@item.type} #{@item.urgency}"} +-# file: app/views/movies/index.html.haml +\d +%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 + +%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! \ No newline at end of file diff --git a/demo/kitchen-sink/modelist.js b/demo/kitchen-sink/modelist.js index 06c62362..5080b0b4 100644 --- a/demo/kitchen-sink/modelist.js +++ b/demo/kitchen-sink/modelist.js @@ -46,6 +46,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"], diff --git a/lib/ace/mode/haml.js b/lib/ace/mode/haml.js new file mode 100644 index 00000000..64b0040f --- /dev/null +++ b/lib/ace/mode/haml.js @@ -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; +}); \ No newline at end of file diff --git a/lib/ace/mode/haml_highlight_rules.js b/lib/ace/mode/haml_highlight_rules.js new file mode 100644 index 00000000..065def6a --- /dev/null +++ b/lib/ace/mode/haml_highlight_rules.js @@ -0,0 +1,264 @@ +/* ***** 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 HamlHighlightRules = function() { + + // regexp must not have capturing parentheses. Use (?:) instead. + // regexps are ordered -> the first match is used + + this.$rules = + { + "start": [ + { + "token": "string.quoted.double", + "regex": "==.+?==" + }, + { + "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" + //}, + { + "token": ["meta.tag.haml", "punctuation.definition.tag.haml", "entity.name.tag.haml"], + "regex": /^\s*(?:((%)([\w:]+))|(?=\.|#))/, + "next": "tag_single" + }, + { + "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": [ + { + "include": "text.haml" + }, + { + "token": "TODO", + "regex": "^(?!\\1 )", + "next": "start" + } + ],*/ + "tag_single": [ + { + "token": "suport.type.attribute.class.jade", + "regex": "\\.[\\w-]+" + }, + { + "token": "suport.type.attribute.id.jade", + "regex": "#[\\w-]+" + }, + //{ + // "token": "meta.section.attributes.haml", + // "regex": "" + //}, + //{ + // "token": "meta.section.object.haml", + // "regex": "" + //}, + //{ + // "include": "#rubyline" + //}, + //{ + // "token": "punctuation.terminator.tag.haml", + // "regex": "/" + //}, + //{ + // "token": "TODO", + // "regex": "$|(?!\\.|#|\\{|\\[|=|-|~|/)", + // "next": "start" + //} + ]/*, + "state_7": [ + { + "include": "#rubyline" + }, + { + "token": "TODO", + "regex": "$", + "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; +}); \ No newline at end of file