diff --git a/demo/kitchen-sink/docs/elixir.ex b/demo/kitchen-sink/docs/elixir.ex index ec0cfb59..693a4bb1 100644 --- a/demo/kitchen-sink/docs/elixir.ex +++ b/demo/kitchen-sink/docs/elixir.ex @@ -1 +1,24 @@ -TODO add a nice demo! \ No newline at end of file +defmodule HelloModule do + # A "Hello world" function + def some_fun do + IO.puts "Juhu Kinners!" + end + # A private function + defp priv do + is_regex ~r""" + This is a regex + spanning several + lines. + """ + x = elem({ :a, :b, :c }, 0) #=> :a + end +end + +test_fun = fn(x) -> + cond do + x > 10 -> + :greater_than_ten + true -> + :maybe_ten + end +end \ No newline at end of file diff --git a/lib/ace/mode/elixir.js b/lib/ace/mode/elixir.js index c64f5cce..c55ea366 100644 --- a/lib/ace/mode/elixir.js +++ b/lib/ace/mode/elixir.js @@ -39,7 +39,7 @@ var oop = require("../lib/oop"); var TextMode = require("./text").Mode; var ElixirHighlightRules = require("./elixir_highlight_rules").ElixirHighlightRules; // TODO: pick appropriate fold mode -var FoldMode = require("./folding/cstyle").FoldMode; +var FoldMode = require("./folding/coffee").FoldMode; var Mode = function() { this.HighlightRules = ElixirHighlightRules; @@ -48,7 +48,7 @@ var Mode = function() { oop.inherits(Mode, TextMode); (function() { - // this.lineCommentStart = ""@(?:module|type)?doc \"""; + this.lineCommentStart = "#"; // this.blockComment = {start: ""/*"", end: ""*/""}; // Extra logic goes here. this.$id = "ace/mode/elixir" diff --git a/lib/ace/mode/elixir_highlight_rules.js b/lib/ace/mode/elixir_highlight_rules.js index a52bdf4f..a13492be 100644 --- a/lib/ace/mode/elixir_highlight_rules.js +++ b/lib/ace/mode/elixir_highlight_rules.js @@ -101,11 +101,11 @@ var ElixirHighlightRules = function() { { defaultToken: 'comment.documentation.string' } ], comment: '@doc with string is treated as documentation' }, { token: 'keyword.control.elixir', - regex: '(?_?[\\da-fA-F])*|\\d(?>_?\\d)*(?:\\.(?![^[:space:][:digit:]])(?>_?\\d)*)?(?:[eE][-+]?\\d(?>_?\\d)*)?|0b[01]+|0o[0-7]+)\\b', + regex: '\\b(?:0x[\\da-fA-F](?:_?[\\da-fA-F])*|\\d(?:_?\\d)*(?:\\.(?![^[:space:][:digit:]])(?:_?\\d)*)?(?:[eE][-+]?\\d(?:_?\\d)*)?|0b[01]+|0o[0-7]+)\\b', TODO: 'FIXME: regexp doesn\'t have js equivalent', originalRegex: '\\b(0x\\h(?>_?\\h)*|\\d(?>_?\\d)*(\\.(?![^[:space:][:digit:]])(?>_?\\d)*)?([eE][-+]?\\d(?>_?\\d)*)?|0b[01]+|0o[0-7]+)\\b' }, { token: 'punctuation.definition.constant.elixir', @@ -146,7 +146,7 @@ var ElixirHighlightRules = function() { { include: '#escaped_char' }, { defaultToken: 'constant.other.symbol.double-quoted.elixir' } ] }, { token: 'punctuation.definition.string.begin.elixir', - regex: '(?>\'\'\')', + regex: '(?:\'\'\')', TODO: 'FIXME: regexp doesn\'t have js equivalent', originalRegex: '(?>\'\'\')', push: @@ -168,7 +168,7 @@ var ElixirHighlightRules = function() { { defaultToken: 'support.function.variable.quoted.single.elixir' } ], comment: 'single quoted string (allows for interpolation)' }, { token: 'punctuation.definition.string.begin.elixir', - regex: '(?>""")', + regex: '(?:""")', TODO: 'FIXME: regexp doesn\'t have js equivalent', originalRegex: '(?>""")', push: @@ -190,7 +190,7 @@ var ElixirHighlightRules = function() { { defaultToken: 'string.quoted.double.elixir' } ], comment: 'double quoted string (allows for interpolation)' }, { token: 'punctuation.definition.string.begin.elixir', - regex: '~[a-z](?>""")', + regex: '~[a-z](?:""")', TODO: 'FIXME: regexp doesn\'t have js equivalent', originalRegex: '~[a-z](?>""")', push: @@ -253,7 +253,7 @@ var ElixirHighlightRules = function() { { defaultToken: 'string.interpolated.elixir' } ], comment: 'sigil (allow for interpolation)' }, { token: 'punctuation.definition.string.begin.elixir', - regex: '~[A-Z](?>""")', + regex: '~[A-Z](?:""")', TODO: 'FIXME: regexp doesn\'t have js equivalent', originalRegex: '~[A-Z](?>""")', push: @@ -302,26 +302,26 @@ var ElixirHighlightRules = function() { next: 'pop' }, { defaultToken: 'string.quoted.other.literal.upper.elixir' } ], comment: 'sigil (without interpolation)' }, - { token: 'punctuation.definition.constant.elixir', - regex: '(?[a-zA-Z_][\\w@]*(?>[?!]|=(?![>=]))?|\\<\\>|===?|!==?|<<>>|<<<|>>>|~~~|::|<\\-|\\|>|=>|~|~=|=|/|\\\\\\\\|\\*\\*?|\\.\\.?\\.?|>=?|<=?|&&?&?|\\+\\+?|\\-\\-?|\\|\\|?\\|?|\\!|@|\\%?\\{\\}|%|\\[\\]|\\^(?:\\^\\^)?)', + { token: ['punctuation.definition.constant.elixir', 'constant.other.symbol.elixir'], + regex: '(:)([a-zA-Z_][\\w@]*(?:[?!]|=(?![>=]))?|\\<\\>|===?|!==?|<<>>|<<<|>>>|~~~|::|<\\-|\\|>|=>|~|~=|=|/|\\\\\\\\|\\*\\*?|\\.\\.?\\.?|>=?|<=?|&&?&?|\\+\\+?|\\-\\-?|\\|\\|?\\|?|\\!|@|\\%?\\{\\}|%|\\[\\]|\\^(?:\\^\\^)?)', TODO: 'FIXME: regexp doesn\'t have js equivalent', originalRegex: '(?[a-zA-Z_][\\w@]*(?>[?!]|=(?![>=]))?|\\<\\>|===?|!==?|<<>>|<<<|>>>|~~~|::|<\\-|\\|>|=>|~|~=|=|/|\\\\\\\\|\\*\\*?|\\.\\.?\\.?|>=?|<=?|&&?&?|\\+\\+?|\\-\\-?|\\|\\|?\\|?|\\!|@|\\%?\\{\\}|%|\\[\\]|\\^(\\^\\^)?)', comment: 'symbols' }, { token: 'punctuation.definition.constant.elixir', - regex: '(?>[a-zA-Z_][\\w@]*(?>[?!])?):(?!:)', + regex: '(?:[a-zA-Z_][\\w@]*(?:[?!])?):(?!:)', TODO: 'FIXME: regexp doesn\'t have js equivalent', originalRegex: '(?>[a-zA-Z_][\\w@]*(?>[?!])?)(:)(?!:)', comment: 'symbols' }, { token: [ 'punctuation.definition.comment.elixir', 'comment.line.number-sign.elixir' ], - regex: '(?:^[ \\t]+)?(#)(.*$)' }, + regex: '(#)(.*)' }, { token: 'constant.numeric.elixir', - regex: '(?=?' }, { token: 'keyword.operator.bitwise.elixir', - regex: '\\|\\|\\||&&&|^^^|<<<|>>>|~~~' }, + regex: '\\|{3}|&{3}|\\^{3}|<{3}|>{3}|~{3}' }, { token: 'keyword.operator.logical.elixir', - regex: '(?<=[ \\t])!+|\\bnot\\b|&&|\\band\\b|\\|\\||\\bor\\b|\\bxor\\b', - TODO: 'FIXME: regexp doesn\'t have js equivalent', + regex: '!+|\\bnot\\b|&&|\\band\\b|\\|\\||\\bor\\b|\\bxor\\b', originalRegex: '(?<=[ \\t])!+|\\bnot\\b|&&|\\band\\b|\\|\\||\\bor\\b|\\bxor\\b' }, { token: 'keyword.operator.arithmetic.elixir', regex: '\\*|\\+|\\-|/' }, @@ -411,8 +410,7 @@ var ElixirHighlightRules = function() { { token: [ 'punctuation.definition.comment.elixir', 'comment.line.number-sign.elixir' ], - regex: '(?<=^|\\s)(#)(\\s[[a-zA-Z0-9,. \\t?!-][^\\x00-\\x7F]]*$)', - TODO: 'FIXME: regexp doesn\'t have js equivalent', + regex: '(?:^|\\s)(#)(\\s[[a-zA-Z0-9,. \\t?!-][^\\x00-\\x7F]]*$)', originalRegex: '(?<=^|\\s)(#)\\s[[a-zA-Z0-9,. \\t?!-][^\\x{00}-\\x{7F}]]*$', comment: 'We are restrictive in what we allow to go after the comment character to avoid false positives, since the availability of comments depend on regexp flags.' } ] }