From 3dce122f8cb4e9cea6b3d309969ff0ccc5d87727 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Sun, 11 Nov 2012 00:14:07 -0800 Subject: [PATCH 1/6] 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 From c5a3cac12f034963e30fbb082598b4cbf1dbef5a Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Sun, 11 Nov 2012 22:22:28 -0800 Subject: [PATCH 2/6] More haml work --- demo/kitchen-sink/docs/haml.haml | 10 +++------- lib/ace/mode/haml_highlight_rules.js | 28 ++++++++++++++-------------- lib/ace/mode/jade_highlight_rules.js | 4 ++-- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/demo/kitchen-sink/docs/haml.haml b/demo/kitchen-sink/docs/haml.haml index aa29cb6a..b3c6debb 100644 --- a/demo/kitchen-sink/docs/haml.haml +++ b/demo/kitchen-sink/docs/haml.haml @@ -5,20 +5,15 @@ -# -# -# 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 +%ads: %p==ddd== Date/Time: - - now = DateTime.now + - now = DateTime.now %strong= now - if now > DateTime.parse("December 31, 2006") = "Happy new " + "year!" @@ -28,6 +23,7 @@ end %h1= @title = link_to 'Home', home_url + #contents %div#content %div.articles %div.article.title Blah diff --git a/lib/ace/mode/haml_highlight_rules.js b/lib/ace/mode/haml_highlight_rules.js index 065def6a..fb3da22f 100644 --- a/lib/ace/mode/haml_highlight_rules.js +++ b/lib/ace/mode/haml_highlight_rules.js @@ -76,9 +76,9 @@ var HamlHighlightRules = function() { // "regex": "^( *)(/)\\s*$", // "next": "state_4" //}, - { - "token": ["meta.tag.haml", "punctuation.definition.tag.haml", "entity.name.tag.haml"], - "regex": /^\s*(?:((%)([\w:]+))|(?=\.|#))/, + { + "token": ["entity.name.tag.haml"], + "regex": /^\s*%[\w:]+/, "next": "tag_single" }, { @@ -154,17 +154,17 @@ var HamlHighlightRules = function() { ],*/ "tag_single": [ { - "token": "suport.type.attribute.class.jade", + "token": "entity.other.attribute-name.class.haml", "regex": "\\.[\\w-]+" }, { - "token": "suport.type.attribute.id.jade", + "token": "entity.other.attribute-name.id.haml", "regex": "#[\\w-]+" }, - //{ - // "token": "meta.section.attributes.haml", - // "regex": "" - //}, + { + "token": "meta.section.attributes.haml", + "regex": "\\{(?=.*\\}|.*\\|\\s*$)" + }, //{ // "token": "meta.section.object.haml", // "regex": "" @@ -176,11 +176,11 @@ var HamlHighlightRules = function() { // "token": "punctuation.terminator.tag.haml", // "regex": "/" //}, - //{ - // "token": "TODO", - // "regex": "$|(?!\\.|#|\\{|\\[|=|-|~|/)", - // "next": "start" - //} + { + "token": ["text", "punctuation"], + "regex": "($)|((?!\\.|#|=|-))", + "next": "start" + } ]/*, "state_7": [ { diff --git a/lib/ace/mode/jade_highlight_rules.js b/lib/ace/mode/jade_highlight_rules.js index bf266ce7..1f8b5875 100644 --- a/lib/ace/mode/jade_highlight_rules.js +++ b/lib/ace/mode/jade_highlight_rules.js @@ -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-]+" }, { From 5f5663dfe30c5576dba7acb935ed74f0a155cd72 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Tue, 13 Nov 2012 14:19:20 -0800 Subject: [PATCH 3/6] Add haml support --- demo/kitchen-sink/docs/haml.haml | 18 +- demo/kitchen-sink/docs/ruby.rb | 13 +- lib/ace/mode/haml_highlight_rules.js | 276 +++++++-------------------- lib/ace/mode/ruby_highlight_rules.js | 70 ++++--- lib/ace/mode/text_highlight_rules.js | 4 + 5 files changed, 143 insertions(+), 238 deletions(-) diff --git a/demo/kitchen-sink/docs/haml.haml b/demo/kitchen-sink/docs/haml.haml index b3c6debb..d07ed4a2 100644 --- a/demo/kitchen-sink/docs/haml.haml +++ b/demo/kitchen-sink/docs/haml.haml @@ -1,21 +1,21 @@ !!!5 --# --# --# --# +# +# +# +# /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! \ No newline at end of file + ==Hello!== diff --git a/demo/kitchen-sink/docs/ruby.rb b/demo/kitchen-sink/docs/ruby.rb index afe2efa0..48e26ae0 100644 --- a/demo/kitchen-sink/docs/ruby.rb +++ b/demo/kitchen-sink/docs/ruby.rb @@ -9,4 +9,15 @@ def fact(n) end end -puts fact(ARGV[0].to_i) \ No newline at end of file +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"} \ No newline at end of file diff --git a/lib/ace/mode/haml_highlight_rules.js b/lib/ace/mode/haml_highlight_rules.js index fb3da22f..31429028 100644 --- a/lib/ace/mode/haml_highlight_rules.js +++ b/lib/ace/mode/haml_highlight_rules.js @@ -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; -}); \ No newline at end of file +}); diff --git a/lib/ace/mode/ruby_highlight_rules.js b/lib/ace/mode/ruby_highlight_rules.js index 92e6044f..f2db5b57 100644 --- a/lib/ace/mode/ruby_highlight_rules.js +++ b/lib/ace/mode/ruby_highlight_rules.js @@ -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)" diff --git a/lib/ace/mode/text_highlight_rules.js b/lib/ace/mode/text_highlight_rules.js index e342c355..6a2c5807 100644 --- a/lib/ace/mode/text_highlight_rules.js +++ b/lib/ace/mode/text_highlight_rules.js @@ -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; From 1158798094f99b03a1edf86c5eee6710fb07962e Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Tue, 13 Nov 2012 14:22:36 -0800 Subject: [PATCH 4/6] Support new getKeywords function --- lib/ace/mode/c_cpp_highlight_rules.js | 2 +- lib/ace/mode/objectivec_highlight_rules.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/ace/mode/c_cpp_highlight_rules.js b/lib/ace/mode/c_cpp_highlight_rules.js index 9d57e46c..7ab22467 100644 --- a/lib/ace/mode/c_cpp_highlight_rules.js +++ b/lib/ace/mode/c_cpp_highlight_rules.js @@ -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, diff --git a/lib/ace/mode/objectivec_highlight_rules.js b/lib/ace/mode/objectivec_highlight_rules.js index a1f35080..2d557688 100644 --- a/lib/ace/mode/objectivec_highlight_rules.js +++ b/lib/ace/mode/objectivec_highlight_rules.js @@ -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" }, { From fdb22c5b142558a035fa34d8358cc1207f8782a4 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Tue, 13 Nov 2012 14:25:00 -0800 Subject: [PATCH 5/6] Support hash comment --- lib/ace/mode/haml_highlight_rules.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/ace/mode/haml_highlight_rules.js b/lib/ace/mode/haml_highlight_rules.js index 31429028..7d71b67c 100644 --- a/lib/ace/mode/haml_highlight_rules.js +++ b/lib/ace/mode/haml_highlight_rules.js @@ -18,6 +18,10 @@ var HamlHighlightRules = function() { "token" : "punctuation.section.comment", "regex" : /^\s*\/.*/ }, + { + "token" : "punctuation.section.comment", + "regex" : /^\s*#.*/ + }, { "token": "string.quoted.double", "regex": "==.+?==" From 15d25743dc0c84c9e5bddbe7be1167be28a99545 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Tue, 13 Nov 2012 14:33:31 -0800 Subject: [PATCH 6/6] Reinsert numerics, fix up tests --- lib/ace/mode/ruby_highlight_rules.js | 4 +++- lib/ace/mode/ruby_highlight_rules_test.js | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/ace/mode/ruby_highlight_rules.js b/lib/ace/mode/ruby_highlight_rules.js index f2db5b57..2522525a 100644 --- a/lib/ace/mode/ruby_highlight_rules.js +++ b/lib/ace/mode/ruby_highlight_rules.js @@ -158,7 +158,9 @@ var RubyHighlightRules = function() { }, constantOtherSymbol, - + constantNumericHex, + constantNumericFloat, + { token : "constant.language.boolean", regex : "(?:true|false)\\b" diff --git a/lib/ace/mode/ruby_highlight_rules_test.js b/lib/ace/mode/ruby_highlight_rules_test.js index 2f52b3e7..66d7edbd 100644 --- a/lib/ace/mode/ruby_highlight_rules_test.js +++ b/lib/ace/mode/ruby_highlight_rules_test.js @@ -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() {