Skip to content

Commit

Permalink
beginWithKeyword replaced by a simpler beginKeywords.
Browse files Browse the repository at this point in the history
  • Loading branch information
isagalaev committed Dec 13, 2013
1 parent a3c2db5 commit 6c7fdea
Show file tree
Hide file tree
Showing 29 changed files with 66 additions and 103 deletions.
8 changes: 5 additions & 3 deletions docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ Sometimes a mode can end not by itself but implicitly with its containing (paren
This is achieved with :ref:`endsWithParent <endsWithParent>` attribute.


beginWithKeyword
beginKeywords
^^^^^^^^^^^^^^^^

**type**: boolean
**type**: string

Used instead of ``begin`` for modes starting with keywords to avoid needless repetition:

Expand All @@ -97,9 +97,11 @@ Used instead of ``begin`` for modes starting with keywords to avoid needless rep
::

{
beginWithKeyword: true, keywords: 'extends implements'
beginKeywords: 'extends implements'
}

Unlike the ``[[#keywords]]`` attribute, this one allows only a simple list of space separated keywords. If you do need additional features of ``keywords`` or you just need more keywords for this mode you may include ``keywords`` along with ``beginKeywords``.


.. _endsWithParent:

Expand Down
8 changes: 4 additions & 4 deletions src/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function() {
return;
mode.compiled = true;

var keywords = []; // used later with beginWithKeyword but filled as a side-effect of keywords compilation
mode.keywords = mode.keywords || mode.beginKeywords;
if (mode.keywords) {
var compiled_keywords = {};

Expand All @@ -177,7 +177,6 @@ function() {
str.split(' ').forEach(function(kw) {
var pair = kw.split('|');
compiled_keywords[pair[0]] = [className, pair[1] ? Number(pair[1]) : 1];
keywords.push(pair[0]);
});
}

Expand All @@ -193,9 +192,10 @@ function() {
}
mode.keywords = compiled_keywords;
}

if (parent) {
if (mode.beginWithKeyword) {
mode.begin = '\\b(' + keywords.join('|') + ')\\b(?!\\.)\\s*';
if (mode.beginKeywords) {
mode.begin = '\\b(' + mode.beginKeywords.split(/\s+/).join('|') + ')\\b(?!\\.)\\s*';
}
mode.beginRe = langRe(mode.begin ? mode.begin : '\\B|\\b');
if (!mode.end && !mode.endsWithParent)
Expand Down
15 changes: 5 additions & 10 deletions src/languages/actionscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,26 @@ function(hljs) {
hljs.C_NUMBER_MODE,
{
className: 'package',
beginWithKeyword: true, end: '{',
keywords: 'package',
beginKeywords: 'package', end: '{',
contains: [TITLE_MODE]
},
{
className: 'class',
beginWithKeyword: true, end: '{',
keywords: 'class interface',
beginKeywords: 'class interface', end: '{',
contains: [
{
beginWithKeyword: true,
keywords: 'extends implements'
beginKeywords: 'extends implements'
},
TITLE_MODE
]
},
{
className: 'preprocessor',
beginWithKeyword: true, end: ';',
keywords: 'import include'
beginKeywords: 'import include', end: ';'
},
{
className: 'function',
beginWithKeyword: true, end: '[{;]',
keywords: 'function',
beginKeywords: 'function', end: '[{;]',
illegal: '\\S',
contains: [
TITLE_MODE,
Expand Down
3 changes: 1 addition & 2 deletions src/languages/applescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ function(hljs) {
},
{
className: 'function_start',
beginWithKeyword: true,
keywords: 'on',
beginKeywords: 'on',
illegal: '[${=;\\n]',
contains: [TITLE, PARAMS]
}
Expand Down
3 changes: 1 addition & 2 deletions src/languages/autohotkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ function(hljs) {
},
{
className: 'built_in',
beginWithKeyword: true,
keywords: 'ComSpec Clipboard ClipboardAll ErrorLevel'
beginKeywords: 'ComSpec Clipboard ClipboardAll ErrorLevel'
}
];

Expand Down
6 changes: 2 additions & 4 deletions src/languages/axapta.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ function(hljs) {
},
{
className: 'class',
beginWithKeyword: true, end: '{',
beginKeywords: 'class interface', end: '{',
illegal: ':',
keywords: 'class interface',
contains: [
{
className: 'inheritance',
beginWithKeyword: true,
keywords: 'extends implements',
beginKeywords: 'extends implements',
relevance: 10
},
{
Expand Down
4 changes: 2 additions & 2 deletions src/languages/coffeescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ function(hljs) {
},
{
className: 'class',
beginWithKeyword: true, keywords: 'class',
beginKeywords: 'class',
end: '$',
illegal: /[:="\[\]]/,
contains: [
{
beginWithKeyword: true, keywords: 'extends',
beginKeywords: 'extends',
endsWithParent: true,
illegal: /[:="\[\]]/,
contains: [TITLE]
Expand Down
26 changes: 11 additions & 15 deletions src/languages/cs.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,22 @@ function(hljs) {
hljs.QUOTE_STRING_MODE,
hljs.C_NUMBER_MODE,
{
beginWithKeyword: true, end: '{',
keywords: 'class namespace',
beginKeywords: 'class namespace', end: '{',
contains: [
TITLE
]
},
{
beginWithKeyword: true, keywords: 'protected public private internal',
starts: {
end: '{|;',
keywords: KEYWORDS,
contains: [
{
begin: hljs.IDENT_RE + '\\s*\\(', returnBegin: true,
contains: [
TITLE
]
}
]
}
beginKeywords: 'protected public private internal', end: '{|;',
keywords: KEYWORDS,
contains: [
{
begin: hljs.IDENT_RE + '\\s*\\(', returnBegin: true,
contains: [
TITLE
]
}
]
}
]
};
Expand Down
2 changes: 1 addition & 1 deletion src/languages/delphi.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function(hljs) {
};
var FUNCTION = {
className: 'function',
beginWithKeyword: true, end: /[:;]/,
beginKeywords: 'function constructor destructor procedure', end: /[:;]/,
keywords: 'function constructor|10 destructor|10 procedure|10',
contains: [
{
Expand Down
3 changes: 1 addition & 2 deletions src/languages/fsharp.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ function(hljs) {
},
{
className: 'class',
beginWithKeyword: true, end: '\\(|=|$',
keywords: 'type',
beginKeywords: 'type', end: '\\(|=|$',
contains: [
{
className: 'title',
Expand Down
6 changes: 2 additions & 4 deletions src/languages/haskell.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,12 @@ function(hljs) {
},
{
className: 'default',
beginWithKeyword: true, end: '$',
keywords: 'default',
beginKeywords: 'default', end: '$',
contains: [CONSTRUCTOR, LIST, COMMENT]
},
{
className: 'infix',
beginWithKeyword: true, end: '$',
keywords: 'infix infixl infixr',
beginKeywords: 'infix infixl infixr', end: '$',
contains: [hljs.C_NUMBER_MODE, COMMENT]
},
{
Expand Down
6 changes: 2 additions & 4 deletions src/languages/java.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ function(hljs) {
hljs.QUOTE_STRING_MODE,
{
className: 'class',
beginWithKeyword: true, end: '{',
keywords: 'class interface',
beginKeywords: 'class interface', end: '{',
excludeEnd: true,
illegal: ':',
contains: [
{
beginWithKeyword: true,
keywords: 'extends implements',
beginKeywords: 'extends implements',
relevance: 10
},
{
Expand Down
3 changes: 1 addition & 2 deletions src/languages/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ function(hljs) {
},
{
className: 'function',
beginWithKeyword: true, end: /{/,
keywords: 'function',
beginKeywords: 'function', end: /\{/,
contains: [
{
className: 'title', begin: /[A-Za-z$_][0-9A-Za-z$_]*/
Expand Down
2 changes: 1 addition & 1 deletion src/languages/lasso.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function(hljs) {
},
{
className: 'class',
beginWithKeyword: true, keywords: 'define',
beginKeywords: 'define',
returnEnd: true, end: '\\(|=>',
contains: [
{
Expand Down
12 changes: 4 additions & 8 deletions src/languages/livecodeserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ function(hljs) {
},
{
className: 'function',
beginWithKeyword: true, end: '$',
keywords: 'function',
beginKeywords: 'function', end: '$',
contains: [
VARIABLE,
{
Expand All @@ -131,8 +130,7 @@ function(hljs) {
},
{
className: 'function',
beginWithKeyword: true, end: '$',
keywords: 'end',
beginKeywords: 'end', end: '$',
contains: [
{
className: 'title',
Expand All @@ -142,8 +140,7 @@ function(hljs) {
},
{
className: 'command',
beginWithKeyword: true, end: '$',
keywords: 'command on',
beginKeywords: 'command on', end: '$',
contains: [
VARIABLE,
{
Expand All @@ -154,8 +151,7 @@ function(hljs) {
},
{
className: 'command',
beginWithKeyword: true, end: '$',
keywords: 'end',
beginKeywords: 'end', end: '$',
contains: [
{
className: 'title',
Expand Down
3 changes: 1 addition & 2 deletions src/languages/lua.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ function(hljs) {
contains: COMMENTS.concat([
{
className: 'function',
beginWithKeyword: true, end: '\\)',
keywords: 'function',
beginKeywords: 'function', end: '\\)',
contains: [
{
className: 'title',
Expand Down
3 changes: 1 addition & 2 deletions src/languages/matlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ function(hljs) {
contains: [
{
className: 'function',
beginWithKeyword: true, end: '$',
keywords: 'function',
beginKeywords: 'function', end: '$',
contains: [
{
className: 'title',
Expand Down
3 changes: 1 addition & 2 deletions src/languages/ocaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ function(hljs) {
},
{
className: 'class',
beginWithKeyword: true, end: '\\(|=|$',
keywords: 'type',
beginKeywords: 'type', end: '\\(|=|$',
contains: [
{
className: 'title',
Expand Down
2 changes: 1 addition & 1 deletion src/languages/oxygene.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function(hljs) {
};
var FUNCTION = {
className: 'function',
beginWithKeyword: true, end: '[:;]',
beginKeywords: 'function constructor destructor procedure method', end: '[:;]',
keywords: 'function constructor|10 destructor|10 procedure|10 method|10',
contains: [
{
Expand Down
3 changes: 1 addition & 2 deletions src/languages/perl.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ function(hljs) {
},
{
className: 'sub',
beginWithKeyword: true, end: '(\\s*\\(.*?\\))?[;{]',
keywords: 'sub',
beginKeywords: 'sub', end: '(\\s*\\(.*?\\))?[;{]',
relevance: 5
},
{
Expand Down
9 changes: 3 additions & 6 deletions src/languages/php.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ function(hljs) {
VARIABLE,
{
className: 'function',
beginWithKeyword: true, end: /[;{]/,
keywords: 'function',
beginKeywords: 'function', end: /[;{]/,
illegal: '\\$|\\[|%',
contains: [
TITLE,
Expand All @@ -89,13 +88,11 @@ function(hljs) {
},
{
className: 'class',
beginWithKeyword: true, end: '{',
keywords: 'class',
beginKeywords: 'class', end: '{',
illegal: '[:\\(\\$]',
contains: [
{
beginWithKeyword: true, endsWithParent: true,
keywords: 'extends',
beginKeywords: 'extends', endsWithParent: true,
contains: [TITLE]
},
TITLE
Expand Down
6 changes: 3 additions & 3 deletions src/languages/python.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function(hljs) {
contains: ['self', PROMPT, NUMBER, STRING]
};
var FUNC_CLASS_PROTO = {
beginWithKeyword: true, end: /:/,
end: /:/,
illegal: /[${=;\n]/,
contains: [TITLE, PARAMS]
};
Expand All @@ -75,8 +75,8 @@ function(hljs) {
NUMBER,
STRING,
hljs.HASH_COMMENT_MODE,
hljs.inherit(FUNC_CLASS_PROTO, {className: 'function', keywords: 'def', relevance: 10}),
hljs.inherit(FUNC_CLASS_PROTO, {className: 'class', keywords: 'class'}),
hljs.inherit(FUNC_CLASS_PROTO, {className: 'function', beginKeywords: 'def', relevance: 10}),
hljs.inherit(FUNC_CLASS_PROTO, {className: 'class', beginKeywords: 'class'}),
{
className: 'decorator',
begin: /@/, end: /$/
Expand Down
Loading

0 comments on commit 6c7fdea

Please sign in to comment.