Skip to content

Commit

Permalink
Add support of Scilab
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre authored and Sylvestre Ledru committed Jul 3, 2013
1 parent 182b265 commit b33bf6c
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
2 changes: 2 additions & 0 deletions AUTHORS.en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,5 @@ Contributors:
- Poren Chiang <[email protected]>
- Kelley van Evert <[email protected]>
- Kurt Emch <[email protected]>
- Sylvestre Ledru <[email protected]>

11 changes: 11 additions & 0 deletions classref.txt
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,17 @@ Matlab ("matlab"):
matrix matrix in [ .. ]
cell cell in { .. }

Scilab ("scilab"):

comment comment
string string
number number
keyword keyword
title function name
function function
param params of function
matrix matrix in [ .. ]

R ("r"):

comment comment
Expand Down
65 changes: 65 additions & 0 deletions src/languages/scilab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Language: Scilab
Author: Denis Bardadym <[email protected]>
Author: Sylvestre Ledru <[email protected]>
(Scilab port)
*/

function(hljs) {

var COMMON_CONTAINS = [
hljs.C_NUMBER_MODE,
{
className: 'string',
begin: '\'|\"', end: '\'|\"',
contains: [hljs.BACKSLASH_ESCAPE, {begin: '\'\''}],
relevance: 0
}
];

return {
keywords: {
keyword: 'abort break case clear catch continue do elseif else endfunction end for function'+
'global if pause return resume select try then while'+
'%f %F %t %T %pi %eps %inf %nan %e %i %z %s',
built_in: // Scilab has more than 2000 functions. Just list the most commons
'abs and acos asin atan ceil cd chdir clearglobal cosh cos cumprod deff disp error'+
'exec execstr exists exp eye gettext floor fprintf fread fsolve imag isdef isempty'+
'isinfisnan isvector lasterror length load linspace list listfiles log10 log2 log'+
'max min msprintf mclose mopen ones or pathconvert poly printf prod pwd rand real'+
'round sinh sin size gsort sprintf sqrt strcat strcmps tring sum system tanh tan'+
'type typename warning zeros matrix'
},
illegal: '("|#|/\\*|\\s+/\\w+)',
contains: [
{
className: 'function',
beginWithKeyword: true, end: '$',
keywords: 'function endfunction|10',
contains: [
{
className: 'title',
begin: hljs.UNDERSCORE_IDENT_RE
},
{
className: 'params',
begin: '\\(', end: '\\)'
},
],
},
{
className: 'transposed_variable',
begin: '[a-zA-Z_][a-zA-Z_0-9]*(\'+[\\.\']*|[\\.\']+)', end: ''
},
{
className: 'matrix',
begin: '\\[', end: '\\]\'*[\\.\']*',
contains: COMMON_CONTAINS
},
{
className: 'comment',
begin: '//', end: '$'
}
].concat(COMMON_CONTAINS)
};
}
21 changes: 21 additions & 0 deletions src/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -2281,6 +2281,27 @@ <h2>Automatically detected languages</h2>

foo_matrix = [1, 2, 3; 4, 5, 6]''';
foo_cell = {1, 2, 3; 4, 5, 6}''.'.';
</code></pre>

<tr>
<th>Scilab
<td class="scilab">
<pre><code>
// A comment
function I = foo(dims, varargin)
d=[1; matrix(dims(1:$-1),-1,1)]
for i=1:size(varargin)
if varargin(i)==[] then
I=[],
return;
end
end
endfunction

b = cos(a) + cosh(a);
bar_matrix = [ "Hello", "world" ];
foo_matrix = [1, 2, 3; 4, 5, 6];

</code></pre>

<tr>
Expand Down

0 comments on commit b33bf6c

Please sign in to comment.