chadw75 / syntaxhighlighter

Automatically exported from code.google.com/p/syntaxhighlighter
GNU General Public License v3.0
0 stars 0 forks source link

Enhancement: Erlang brush (source included) #68

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I have implemented an erlang brush which I would like to contribute back as it 
may be
useful for others:

/**
 * Erlang Brush for DP Syntax Highlighter by Alex Gorbatchev
 *
 *   http://code.google.com/p/syntaxhighlighter/
 *
 * Copyright (C) 2008 Darach Ennis.
 *
 * 
 * This library is free software; you can redistribute it and/or modify it under the terms of the 
GNU Lesser General 
 * Public License as published by the Free Software Foundation; either version 2.1 of the License, 
or (at your option) 
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
without even the implied 
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 
General Public License for more 
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this 
library; if not, write to 
 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
 */

dp.sh.Brushes.Erlang = function()
{
    var keywords = 
         '-module -import -export -compile -type -spec -file -record catch' +
     'orelse andalso bor bxor bsl bsr or xor div rem band and bnot not' +
     'begin end if case of when receive after fun query test record'
     'true false';

    var ppkeywords =
     '-include -include_lib -define -undef -ifdef -ifndef -else -endif';

    this.regexList = [
      { regex: new RegExp("%.*$","gm"), css: 'comment' },
      { regex: dp.sh.RegexLib.DoubleQuotedString, css: 'string' },
      { regex: dp.sh.RegexLib.SingleQuotedString, css: 'variable' },    
      { regex: new RegExp('[A-Z][A-Za-z0-9_@]*','gm'), css: 'variable' },
      { regex: new RegExp('^_+[A-Za-z0-0_@]*','m'), css: 'variable' },
      { regex: new RegExp('^-[a-z]*', 'gm'), css: 'preprocessor' },
      { regex: new RegExp(this.GetKeywords(keywords),'gm'), css: 'keyword' }
        ];

    this.CssClass = 'dp-erlang';
}

dp.sh.Brushes.Erlang.prototype  = new dp.sh.Highlighter();
dp.sh.Brushes.Erlang.Aliases    = ['erlang', 'erl', 'hrl', 'yrl'];

I have also added an item to the css for the 'variable' highlighting:

.dp-highlighter .variable { color: navy; font-weight: bold; background-color: 
inherit; }

Original issue reported on code.google.com by dar...@gmail.com on 1 Apr 2008 at 4:30

GoogleCodeExporter commented 8 years ago

Original comment by alex.gor...@gmail.com on 9 Oct 2008 at 1:31

GoogleCodeExporter commented 8 years ago

Original comment by alex.gor...@gmail.com on 9 Oct 2008 at 5:18

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Thanks Darach, I needed this. I copied the above and dropped it into my own site
(nealabq.com/blog). One small bug: the concat strings assigned to var keywords 
need
to have spaces at the ends of them. So 'catch' 'not' and 'record' need to be 
followed
by a space.

Maybe you or Alex have already fixed this somewhere else. I didn't look around, 
just
used what's here.

-nealabq (-at- gmail dot com)

Original comment by Neal...@gmail.com on 10 Feb 2009 at 11:25

GoogleCodeExporter commented 8 years ago
Oops, also the var keywords line that ends in 'record' needs to have a plus at 
the
end. So this line:

'begin end if case of when receive after fun query test record'

Should be this instead:

'begin end if case of when receive after fun query test record ' +

nealabq (-at- gmail)

Original comment by Neal...@gmail.com on 10 Feb 2009 at 11:32