public
Last active

Fortran brush for SyntaxHighlighter

  • Download Gist
shBrushFortran.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
/*
* Fortran brush for SyntaxHighlighter
*
* SyntaxHighlighter by Alex Gorbatchev
* http://alexgorbatchev.com/
*
* Fortran brush by Shawn Chin
* Last update : 16 April 2011
* Homepage : http://shawnchin.github.com
* Brush page : http://gist.github.com/gists/517349
*
*/
;(function()
{
//CommonJS
typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
 
function Brush() {
 
// Fortran 77 keywords
var keywords = "access assign backspace blank block call close common ";
keywords += "continue data dimension direct do else endif enddo ";
keywords += "end entry eof equivalence err exist external file ";
keywords += "fmt form format formatted function goto if implicit ";
keywords += "include inquire intrinsic iostat logical named ";
keywords += "namelist nextrec number open opened parameter pause ";
keywords += "print program read rec recl return rewind sequential ";
keywords += "status stop subroutine then type unformatted unit write save";
 
// Fortran 90 keywords
keywords += "allocate allocatable case contains cycle deallocate default ";
keywords += "elsewhere exit interface intent module only operator ";
keywords += "optional pointer private procedure public result recursive ";
keywords += "select sequence target use while where ";
 
// Fortran 95 keywords
keywords += "elemental forall pure ";
 
// Fortran 2003 keywords
keywords += "abstract associate class decimal decorate delegate encoding ";
keywords += "endfile enum enumerator extends extensible flush generic ";
keywords += "iomsg import move_alloc nextrec non_overridable pass ";
keywords += "pending reference round sign static typealias ";
 
// Fortran 2003 attributes
keywords += "asynchronous bind protected volatile ";
 
// some non-standard keywords accepted by specific compilers
// keywords += "accept array byte decode encode extrinsic nullify none options ";
 
// standard datatypes
var datatypes = "character complex double precision double ";
datatypes += "complex integer logical real ";
 
// Fortran 77 intrinsic functions
var functions = "abs achar acos aimag aint alog alog10 amax0 amax1 ";
functions += "amin0 amin1 amod anint asin atan atan2 cabs ccos cexp ";
functions += "char clog cmplx conjg cos cosh csin csqrt dabs dacos ";
functions += "dasin datan datan2 dble dcos dcosh ddim dexp dim dint ";
functions += "dlog dlog10 dmax1 dmin1 dmod dnint dprod dsign dsinh dsin ";
functions += "dsqrt dtanh dtan dtime exp float iabs idim idint idnint ";
functions += "ifix index int isign len lge lgt lle llt log log10 max ";
functions += "min mod nint real sign sin sngl sqrt tan tanh ";
 
// Fortran 95 intrinsic functions
functions += "adjustl adjustr all allocated any associated bit_size ";
functions += "btest ceiling count cpu_time cshift date_and_time digits ";
functions += "dot_product eoshift epsilon exponent floor fraction ";
functions += "huge iachar iand ibclr ibits ibset ichar ieor ior ";
functions += "ishft ishftc kind lbound len_trim logical matmul ";
functions += "maxexponent maxloc maxval merge minexponent minloc ";
functions += "minval modulo mvbits nearest not null pack precision ";
functions += "present product radix random_number random_seed range ";
functions += "repeat reshape rrspacing scale scan selected_int_kind ";
functions += "selected_real_kind set_exponent shape sinh size spacing ";
functions += "spread sum system_clock tiny transfer transpose trim ";
functions += "ubound unpack verify ";
 
// Fortran 2003 intrinsic functions
functions += "c_associated c_f_pointer c_f_procpointer c_funloc c_loc ";
functions += "command_argument_count get_command get_command_argument ";
functions += "get_environment_variable is_iostat_end is_iostat_eor ";
functions += "move_alloc new_line ";
 
// GNU extensions
functions += "abort access acosh alarm and asinh atanh besj0 besj1 "
functions += "besjn besjn besy0 besy1 besyn besyn chdir chmod ctime ";
functions += "dcmplx dfloat erf erfc etime exit fdate fget fgetc flush ";
functions += "fnum fputc fput free fseek fstat ftell gamma gerror ";
functions += "getarg getcwd getenv getgid getlog getpid getuid ";
functions += "gmtime hostnm iargc idate ierrno imagpart int2 int8";
functions += "irand isatty isnan itime kill lgamma link lnblnk loc ";
functions += "long lshift lstat ltime malloc mclock mclock8 or perror ";
functions += "ran rand realpart rename rshift secnds second short ";
functions += "signal sizeof sleep srand stat symlnk system time time8 ";
functions += "ttynam umask unlink xor ";
 
// f2c extensions
functions += "imag zabs zcos zexp zlog zsin zsqrt ";
 
// operators
var operators = "==|<=|>=|<|>|\/=|\\+|-|\/|\\*|\\*\\*|\/|";
operators += "\\.eq\\.|\\.ne\\.|\\.lt\\.|\\.le\\.|\\.gt\\.|";
operators += "\\.ge\\.|\\.not\\.|\\.and\\.|\\.or\\.|";
operators += "\\.eqv\\.|\\.neqv\\.|\\.true\\.|\\.false\\.";
 
// misc symbols
var symbols = "=|::|:|\\(|\\)|,|&|%|\\[|\\]|;";
 
// literal number (integer and float)
// FIXME: This also matches numbers in var names
var literal_num = "\[+-\]?\\d+(\\.\\d+([eEdD][+-]?\\d+)?)?";
 
// map pattern to CSS style
this.regexList = [
{ regex: new RegExp("^C(.*)$","gm"), css:'comments' },
{ regex: new RegExp("!(.*)$","gm"), css:'comments' },
{ regex: SyntaxHighlighter.regexLib.doubleQuotedString, css:'string' },
{ regex: SyntaxHighlighter.regexLib.singleQuotedString, css:'string' },
{ regex: new RegExp(this.getKeywords(datatypes), 'gmi'), css:'keyword' },
{ regex: new RegExp(this.getKeywords(keywords), 'gmi'), css:'keyword' },
{ regex: new RegExp(this.getKeywords(functions), 'gmi'), css:'functions' },
{ regex: new RegExp(symbols, 'gmi'), css:'color1 bold' },
{ regex: new RegExp(operators, 'gmi'), css:'color2 bold' },
{ regex: new RegExp(literal_num, 'gm'), css:'value bold' }
];
 
};
 
Brush.prototype = new SyntaxHighlighter.Highlighter();
Brush.aliases = ['fortran' ];
 
SyntaxHighlighter.brushes.Fortran = Brush;
 
// CommonJS
typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
}) ();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.