Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/mkouhia/highlight.js into…
Browse files Browse the repository at this point in the history
… gams
  • Loading branch information
isagalaev committed Mar 15, 2016
2 parents c7e0b9c + f960db8 commit 5dd83df
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 65 deletions.
1 change: 0 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ Improvements to existing languages and styles:
[Taras]: https://github.com/oxdef
[Robert Dodier]: https://github.com/robert-dodier


## Version 9.1.0

New languages:
Expand Down
3 changes: 2 additions & 1 deletion src/languages/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ function(hljs) {
// because it doesn’t let it to be parsed as
// a rule set but instead drops parser into
// the default mode which is how it should be.
illegal: /:/, // break on Less variables @var: ...
contains: [
{
className: 'keyword',
begin: /\S+/
begin: /\w+/
},
{
begin: /\s/, endsWithParent: true, excludeEnd: true,
Expand Down
98 changes: 48 additions & 50 deletions src/languages/gams.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,30 @@
*/

function (hljs) {
var KEYWORDS =
'abort acronym acronyms alias all and assign binary card diag display else eps eq equation equations file files ' +
'for free ge gt if inf integer le loop lt maximizing minimizing model models na ne negative no not option ' +
'options or ord parameter parameters positive prod putpage puttl repeat sameas scalar scalars semicont semiint ' +
'set sets smax smin solve sos1 sos2 sum system table then until using variable variables while xor yes';
var KEYWORDS = {
'keyword':
'abort acronym acronyms alias all and assign binary card diag display ' +
'else eq file files for free ge gt if integer le loop lt maximizing ' +
'minimizing model models ne negative no not option options or ord ' +
'positive prod put putpage puttl repeat sameas semicont semiint smax ' +
'smin solve sos1 sos2 sum system table then until using while xor yes',
'literal': 'eps inf na',
'built-in':
'abs arccos arcsin arctan arctan2 Beta betaReg binomial ceil centropy ' +
'cos cosh cvPower div div0 eDist entropy errorf execSeed exp fact ' +
'floor frac gamma gammaReg log logBeta logGamma log10 log2 mapVal max ' +
'min mod ncpCM ncpF ncpVUpow ncpVUsin normal pi poly power ' +
'randBinomial randLinear randTriangle round rPower sigmoid sign ' +
'signPower sin sinh slexp sllog10 slrec sqexp sqlog10 sqr sqrec sqrt ' +
'tan tanh trunc uniform uniformInt vcPower bool_and bool_eqv bool_imp ' +
'bool_not bool_or bool_xor ifThen rel_eq rel_ge rel_gt rel_le rel_lt ' +
'rel_ne gday gdow ghour gleap gmillisec gminute gmonth gsecond gyear ' +
'jdate jnow jstart jtime errorLevel execError gamsRelease gamsVersion ' +
'handleCollect handleDelete handleStatus handleSubmit heapFree ' +
'heapLimit heapSize jobHandle jobKill jobStatus jobTerminate ' +
'licenseLevel licenseStatus maxExecError sleep timeClose timeComp ' +
'timeElapsed timeExec timeStart'
};
var PARAMS = {
className: 'params',
begin: /\(/, end: /\)/,
Expand All @@ -26,7 +45,7 @@ function (hljs) {
{begin: /\$/},
]
};
var COMMSTR = {
var QSTR = { // One-line quoted comment string
className: 'comment',
variants: [
{begin: '\'', end: '\''},
Expand All @@ -36,24 +55,29 @@ function (hljs) {
contains: [hljs.BACKSLASH_ESCAPE]
};
var ASSIGNMENT = {
className: 'number',
begin: '/',
end: '/',
// contains: [COMMSTR],
keywords: KEYWORDS,
contains: [
QSTR,
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
hljs.QUOTE_STRING_MODE,
hljs.APOS_STRING_MODE,
hljs.C_NUMBER_MODE,
],
};
var DESCTEXT = { // Parameter/set/variable description text
begin: /[a-z][a-z0-9_]*(\([a-z0-9_, ]*\))?[ \t]+/,
excludeBegin: true,
end: '$',
endsWithParent: true,
contains: [
COMMSTR,
QSTR,
ASSIGNMENT,
{
className: 'comment',
variants: [
{begin: /([ ]*[a-z0-9&#*=?@>\\<:\-,()$\[\]_.{}!+%^]+)+/},
],
begin: /([ ]*[a-z0-9&#*=?@>\\<:\-,()$\[\]_.{}!+%^]+)+/,
},
],
};
Expand Down Expand Up @@ -88,6 +112,9 @@ function (hljs) {
'scalar scalars equation equations',
end: ';',
contains: [
hljs.COMMENT('^\\*', '$'),
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
hljs.QUOTE_STRING_MODE,
hljs.APOS_STRING_MODE,
ASSIGNMENT,
Expand All @@ -102,62 +129,33 @@ function (hljs) {
{ // table header row
beginKeywords: 'table',
end: '$',
contains: [
hljs.QUOTE_STRING_MODE,
hljs.APOS_STRING_MODE,
DESCTEXT,
],
contains: [DESCTEXT],
},
hljs.COMMENT('^\\*', '$'),
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
hljs.QUOTE_STRING_MODE,
hljs.APOS_STRING_MODE,
hljs.C_NUMBER_MODE,
// Table does not contain DESCTEXT or ASSIGNMENT
]
},
// Function definitions
{
className: 'function',
begin: /^[a-z][a-z0-9_, ()$]+\.{2}/,
end: ';',
keywords: KEYWORDS,
begin: /^[a-z][a-z0-9_,\-+' ()$]+\.{2}/,
returnBegin: true,
contains: [
{ // Function headline
begin: /^[a-z][a-z0-9_]*/,
returnBegin: true,
returnEnd: true,
end: /\.{2}/,
contains: [
{ // Function title
className: 'title',
begin: /[a-z][a-z0-9_]+(?![^(]*\))/,
begin: /^[a-z][a-z0-9_]+/,
},
PARAMS,
SYMBOLS,
],
},
SYMBOLS,
hljs.C_NUMBER_MODE,
],
},
{
beginKeywords: 'model',
end: ';',
contains: [
COMMSTR,
{
className: 'number',
begin: '/',
end: '/',
keywords: 'all',
},
],
},
hljs.C_NUMBER_MODE,
// ASSIGNMENT,
SYMBOLS,
{
className: 'meta',
begin: /\.(lo|up|fx|l|m|scale|prior)/,
},
]
};
}

25 changes: 17 additions & 8 deletions src/languages/less.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,19 @@ function(hljs) {
/* Rule-Level Modes */

var RULE_MODE = {
className: 'attribute',
begin: INTERP_IDENT_RE, end: ':', excludeEnd: true,
contains: [hljs.C_LINE_COMMENT_MODE, hljs.C_BLOCK_COMMENT_MODE],
illegal: /\S/,
starts: {end: '[;}]', returnEnd: true, contains: VALUE, illegal: '[<=$]'}
begin: INTERP_IDENT_RE + '\\s*:', returnBegin: true, end: '[;}]',
relevance: 0,
contains: [
{
className: 'attribute',
begin: INTERP_IDENT_RE, end: ':', excludeEnd: true,
starts: {
endsWithParent: true, illegal: '[<=$]',
relevance: 0,
contains: VALUE
}
}
]
};

var AT_RULE_MODE = {
Expand Down Expand Up @@ -95,7 +103,7 @@ function(hljs) {
// then fall into the scary lookahead-discriminator variant.
// this mode also handles mixin definitions and calls
variants: [{
begin: '[\\.#:&\\[]', end: '[;{}]' // mixin calls end with ';'
begin: '[\\.#:&\\[>]', end: '[;{}]' // mixin calls end with ';'
}, {
begin: INTERP_IDENT_RE + '[^;]*{',
end: '{'
Expand All @@ -114,6 +122,7 @@ function(hljs) {
IDENT_MODE('selector-class', '\\.' + INTERP_IDENT_RE, 0),
IDENT_MODE('selector-tag', '&', 0),
{className: 'selector-attr', begin: '\\[', end: '\\]'},
{className: 'selector-pseudo', begin: /:(:)?[a-zA-Z0-9\_\-\+\(\)"'.]+/},
{begin: '\\(', end: '\\)', contains: VALUE_WITH_RULESETS}, // argument list of parametric mixins
{begin: '!important'} // eat !important after mixin call or it will be colored as tag
]
Expand All @@ -124,8 +133,8 @@ function(hljs) {
hljs.C_BLOCK_COMMENT_MODE,
AT_RULE_MODE,
VAR_RULE_MODE,
SELECTOR_MODE,
RULE_MODE
RULE_MODE,
SELECTOR_MODE
);

return {
Expand Down
15 changes: 15 additions & 0 deletions test/detect/gams/default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,18 @@ TABLE D(I,J) distance in thousands of miles
SEATTLE 2.5 1.7 1.8
SAN-DIEGO 2.5 1.8 1.4 ;
SCALAR F freight in dollars per case per thousand miles /90/ ;
PARAMETER C(I,J) transport cost in thousands of dollars per case ;
C(I,J) = F * D(I,J) / 1000 ;
VARIABLES
X(I,J) shipment quantities in cases
Z total transportation costs in thousands of dollars ;
POSITIVE VARIABLE X ;
EQUATIONS
COST define objective function
SUPPLY(I) observe supply limit at plant i
DEMAND(J) satisfy demand at market j ;
COST .. Z =E= SUM((I,J), C(I,J)*X(I,J)) ;
SUPPLY(I) .. SUM(J, X(I,J)) =L= A(I) ;
DEMAND(J) .. SUM(I, X(I,J)) =G= B(J) ;
MODEL TRANSPORT /ALL/ ;
SOLVE TRANSPORT USING LP MINIMIZING Z ;
5 changes: 0 additions & 5 deletions test/detect/less/default.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/*
Using the most minimal language subset to ensure we
have enough relevance hints for proper Less detection
*/

@import "fruits";

@rhythm: 1.5em;
Expand Down
8 changes: 8 additions & 0 deletions test/markup/less/selectors.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<span class="hljs-selector-id">#foo</span> {
<span class="hljs-selector-tag">tag</span> <span class="hljs-selector-id">#bar</span> {}
&gt; <span class="hljs-selector-id">#bar</span> {}
<span class="hljs-selector-id">#bar</span> {}
<span class="hljs-selector-tag">&amp;</span><span class="hljs-selector-id">#bar</span> {}
<span class="hljs-selector-tag">&amp;</span><span class="hljs-selector-pseudo">:hover</span> {}
<span class="hljs-attribute">height</span>: <span class="hljs-string">~"@{height}px"</span>;
}
8 changes: 8 additions & 0 deletions test/markup/less/selectors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#foo {
tag #bar {}
> #bar {}
#bar {}
&#bar {}
&:hover {}
height: ~"@{height}px";
}

0 comments on commit 5dd83df

Please sign in to comment.