Skip to content

Commit

Permalink
Merge branch 'master' into expression-variants
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Oct 15, 2019
2 parents 6ebaa5f + e859d30 commit 640db25
Show file tree
Hide file tree
Showing 180 changed files with 491 additions and 122 deletions.
2 changes: 2 additions & 0 deletions AUTHORS.en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,5 @@ Contributors:
- Taif Alimov <inzeppelin@gmail.com>
- Yuri Mazursky <mail@colomolome.com>
- Carl Baxter <carl@cbax.tech>
- Thomas Reichel <tom.p.reichel@gmail.com>

10 changes: 10 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@ New styles:
- *Night Owl* by [Carl Baxter][]

Improvements:
- blacklist super-common keywords from having relevance (#2179)
- fix(swift): support for `@dynamicMemberLookup` and `@propertyWrapper` (#2202)
- fix(typescript): constructor in declaration doesn't break highlighting
- fix(typescript): only match function keyword as a separate identifier (#2191)
- feature(arduino) make arduino a super-set of cpp grammar
- fix(javascript): fix object attributes immediately following line comments
- fix(xml): remove `vbscript` as potential script tag subLanguage
- fix(Elixir): improve regex for numbers
- fix(YAML): improve matching for keys
- fix(Pony): improve regex for numbers
- fix(handlebars): add support for raw-blocks and triple-mustaches (#2175)
- JSON: support for comments in JSON (#2016)
- fix(cpp): improve string literal matching
- fix(highlight.js): omit empty span-tags in the output (#2182)
- fix(Go): improve function declaration matching
- fix(python): added support for f-string literal curly braces (#2195)
- fix(cpp): add `future` built-in (#1610)

[Carl Baxter]: https://github.com/cdbax

Expand Down
70 changes: 47 additions & 23 deletions src/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ https://highlightjs.org/
languagePrefixRe = /\blang(?:uage)?-([\w-]+)\b/i,
fixMarkupRe = /((^(<[^>]+>|\t|)+|(?:\n)))/gm;

// The object will be assigned by the build tool. It used to synchronize API
// The object will be assigned by the build tool. It used to synchronize API
// of external language files with minified version of the highlight.js library.
var API_REPLACES;

Expand All @@ -56,6 +56,9 @@ https://highlightjs.org/
languages: undefined
};

// keywords that should have no default relevance value
var COMMON_KEYWORDS = 'of and for in not or if then'.split(' ')


/* Utility functions */

Expand Down Expand Up @@ -238,6 +241,44 @@ https://highlightjs.org/
}
}

function compileKeywords(rawKeywords, case_insensitive) {
var compiled_keywords = {};

if (typeof rawKeywords === 'string') { // string
splitAndCompile('keyword', rawKeywords);
} else {
objectKeys(rawKeywords).forEach(function (className) {
splitAndCompile(className, rawKeywords[className]);
});
}
return compiled_keywords;

// ---

function splitAndCompile(className, str) {
if (case_insensitive) {
str = str.toLowerCase();
}
str.split(' ').forEach(function(keyword) {
var pair = keyword.split('|');
compiled_keywords[pair[0]] = [className, scoreForKeyword(pair[0], pair[1])];
});
};
}

function scoreForKeyword(keyword, providedScore) {
// manual scores always win over common keywords
// so you can force a score of 1 if you really insist
if (providedScore)
return Number(providedScore)

return commonKeyword(keyword) ? 0 : 1;
}

function commonKeyword(word) {
return COMMON_KEYWORDS.indexOf(word.toLowerCase()) != -1
}

function compileLanguage(language) {

function reStr(re) {
Expand Down Expand Up @@ -298,28 +339,9 @@ https://highlightjs.org/
mode.compiled = true;

mode.keywords = mode.keywords || mode.beginKeywords;
if (mode.keywords) {
var compiled_keywords = {};

var flatten = function(className, str) {
if (language.case_insensitive) {
str = str.toLowerCase();
}
str.split(' ').forEach(function(kw) {
var pair = kw.split('|');
compiled_keywords[pair[0]] = [className, pair[1] ? Number(pair[1]) : 1];
});
};
if (mode.keywords)
mode.keywords = compileKeywords(mode.keywords, language.case_insensitive)

if (typeof mode.keywords === 'string') { // string
flatten('keyword', mode.keywords);
} else {
objectKeys(mode.keywords).forEach(function (className) {
flatten(className, mode.keywords[className]);
});
}
mode.keywords = compiled_keywords;
}
mode.lexemesRe = langRe(mode.lexemes || /\w+/, true);

if (parent) {
Expand Down Expand Up @@ -364,7 +386,7 @@ https://highlightjs.org/
.filter(Boolean);
mode.terminators = terminators.length ? langRe(joinRe(terminators, '|'), true) : {exec: function(/*s*/) {return null;}};
}

compileMode(language);
}

Expand Down Expand Up @@ -751,6 +773,8 @@ https://highlightjs.org/
function registerLanguage(name, language) {
var lang = languages[name] = language(hljs);
restoreLanguageApi(lang);
lang.rawDefinition = language.bind(null,hljs);

if (lang.aliases) {
lang.aliases.forEach(function(alias) {aliases[alias] = name;});
}
Expand Down
1 change: 1 addition & 0 deletions src/languages/abnf.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Language: Augmented Backus-Naur Form
Author: Alex McKibben <alex@nullscope.net>
Website: https://tools.ietf.org/html/rfc5234
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/accesslog.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Language: Access log
Author: Oleg Efimov <efimovov@gmail.com>
Description: Apache/Nginx Access Logs
Website: https://httpd.apache.org/docs/2.4/logs.html#accesslog
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/angelscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Language: AngelScript
Author: Melissa Geels <melissa@nimble.tools>
Category: scripting
Website: https://www.angelcode.com/angelscript/
*/

function(hljs) {
Expand Down
2 changes: 1 addition & 1 deletion src/languages/apache.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Language: Apache
Author: Ruslan Keba <rukeba@gmail.com>
Contributors: Ivan Sagalaev <maniac@softwaremaniacs.org>
Website: http://rukeba.com/
Website: https://httpd.apache.org
Description: language definition for Apache configuration files (httpd.conf & .htaccess)
Category: common, config
*/
Expand Down
1 change: 1 addition & 0 deletions src/languages/applescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Language: AppleScript
Authors: Nathan Grigg <nathan@nathanamy.org>, Dr. Drang <drdrang@gmail.com>
Category: scripting
Website: https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/arcade.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Language: ArcGIS Arcade
Category: scripting
Author: John Foster <jfoster@esri.com>
Website: https://developers.arcgis.com/arcade/
Description: ArcGIS Arcade is an expression language used in many Esri ArcGIS products such as Pro, Online, Server, Runtime, JavaScript, and Python
*/
function(hljs) {
Expand Down
30 changes: 15 additions & 15 deletions src/languages/arduino.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ Language: Arduino
Author: Stefania Mellai <s.mellai@arduino.cc>
Description: The Arduino® Language is a superset of C++. This rules are designed to highlight the Arduino® source code. For info about language see http://www.arduino.cc.
Requires: cpp.js
Website: https://www.arduino.cc
*/

function(hljs) {
var CPP = hljs.getLanguage('cpp').exports;
return {
keywords: {

ARDUINO_KW = {
keyword:
'boolean byte word string String array ' + CPP.keywords.keyword,
'boolean byte word String',
built_in:
'setup loop while catch for if do goto try switch case else ' +
'default break continue return ' +
'setup loop' +
'KeyboardController MouseController SoftwareSerial ' +
'EthernetServer EthernetClient LiquidCrystal ' +
'RobotControl GSMVoiceCall EthernetUDP EsploraTFT ' +
Expand Down Expand Up @@ -93,14 +92,15 @@ function(hljs) {
'SET_PIN_MODE INTERNAL2V56 SYSTEM_RESET LED_BUILTIN ' +
'INTERNAL1V1 SYSEX_START INTERNAL EXTERNAL ' +
'DEFAULT OUTPUT INPUT HIGH LOW'
},
contains: [
CPP.preprocessor,
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
hljs.APOS_STRING_MODE,
hljs.QUOTE_STRING_MODE,
hljs.C_NUMBER_MODE
]
};

var ARDUINO = hljs.getLanguage('cpp').rawDefinition();

var kws = ARDUINO.keywords;

kws.keyword += ' ' + ARDUINO_KW.keyword;
kws.literal += ' ' + ARDUINO_KW.literal;
kws.built_in += ' ' + ARDUINO_KW.built_in;

return ARDUINO;
}
2 changes: 1 addition & 1 deletion src/languages/asciidoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Language: AsciiDoc
Requires: xml.js
Author: Dan Allen <dan.j.allen@gmail.com>
Website: http://google.com/profiles/dan.j.allen
Website: http://asciidoc.org
Description: A semantic, text-based document format that can be exported to HTML, DocBook and other backends.
Category: markup
*/
Expand Down
1 change: 1 addition & 0 deletions src/languages/aspectj.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Language: AspectJ
Author: Hakan Ozler <ozler.hakan@gmail.com>
Website: https://www.eclipse.org/aspectj/
Description: Syntax Highlighting for the AspectJ Language which is a general-purpose aspect-oriented extension to the Java programming language.
*/
function (hljs) {
Expand Down
3 changes: 2 additions & 1 deletion src/languages/avrasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Language: AVR Assembler
Author: Vladimir Ermakov <vooon341@gmail.com>
Category: assembler
Website: https://www.microchip.com/webdoc/avrassembler/avrassembler.wb_instruction_list.html
*/

function(hljs) {
Expand Down Expand Up @@ -58,7 +59,7 @@ function(hljs) {
},
{className: 'symbol', begin: '^[A-Za-z0-9_.$]+:'},
{className: 'meta', begin: '#', end: '$'},
{ // подстановка в «.macro»
{ // substitution within a macro
className: 'subst',
begin: '@[0-9]+'
}
Expand Down
2 changes: 1 addition & 1 deletion src/languages/awk.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Language: Awk
Author: Matthew Daly <matthewbdaly@gmail.com>
Website: http://matthewdaly.co.uk/
Website: https://www.gnu.org/software/gawk/manual/gawk.html
Description: language definition for Awk scripts
*/

Expand Down
3 changes: 2 additions & 1 deletion src/languages/axapta.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Language: Axapta
Language: Microsoft Axapta (now Dynamics 365)
Author: Dmitri Roudakov <dmitri@roudakov.ru>
Website: https://dynamics.microsoft.com/en-us/ax-overview/
Category: enterprise
*/

Expand Down
1 change: 1 addition & 0 deletions src/languages/bash.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Language: Bash
Author: vah <vahtenberg@gmail.com>
Contributrors: Benjamin Pannell <contact@sierrasoftworks.com>
Website: https://www.gnu.org/software/bash/
Category: common
*/

Expand Down
3 changes: 2 additions & 1 deletion src/languages/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Language: Basic
Author: Raphaël Assénat <raph@raphnet.net>
Description: Based on the BASIC reference from the Tandy 1000 guide
Website: https://en.wikipedia.org/wiki/Tandy_1000
*/
function(hljs) {
return {
Expand All @@ -15,7 +16,7 @@ function(hljs) {
'CLEAR CLOSE CLS COLOR COM COMMON CONT COS CSNG CSRLIN CVD CVI CVS DATA DATE$ ' +
'DEFDBL DEFINT DEFSNG DEFSTR DEF|0 SEG USR DELETE DIM DRAW EDIT END ENVIRON ENVIRON$ ' +
'EOF EQV ERASE ERDEV ERDEV$ ERL ERR ERROR EXP FIELD FILES FIX FOR|0 FRE GET GOSUB|10 GOTO ' +
'HEX$ IF|0 THEN ELSE|0 INKEY$ INP INPUT INPUT# INPUT$ INSTR IMP INT IOCTL IOCTL$ KEY ON ' +
'HEX$ IF THEN ELSE|0 INKEY$ INP INPUT INPUT# INPUT$ INSTR IMP INT IOCTL IOCTL$ KEY ON ' +
'OFF LIST KILL LEFT$ LEN LET LINE LLIST LOAD LOC LOCATE LOF LOG LPRINT USING LSET ' +
'MERGE MID$ MKDIR MKD$ MKI$ MKS$ MOD NAME NEW NEXT NOISE NOT OCT$ ON OR PEN PLAY STRIG OPEN OPTION ' +
'BASE OUT PAINT PALETTE PCOPY PEEK PMAP POINT POKE POS PRINT PRINT] PSET PRESET ' +
Expand Down
1 change: 1 addition & 0 deletions src/languages/bnf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Language: Backus–Naur Form
Website: https://en.wikipedia.org/wiki/Backus–Naur_form
Author: Oleg Efimov <efimovov@gmail.com>
*/

Expand Down
1 change: 1 addition & 0 deletions src/languages/brainfuck.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Language: Brainfuck
Author: Evgeny Stepanischev <imbolk@gmail.com>
Website: https://esolangs.org/wiki/Brainfuck
*/

function(hljs){
Expand Down
1 change: 1 addition & 0 deletions src/languages/cal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Language: C/AL
Author: Kenneth Fuglsang Christensen <kfuglsang@gmail.com>
Description: Provides highlighting of Microsoft Dynamics NAV C/AL code files
Website: https://docs.microsoft.com/en-us/dynamics-nav/programming-in-c-al
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/capnproto.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Language: Cap’n Proto
Author: Oleg Efimov <efimovov@gmail.com>
Description: Cap’n Proto message definition format
Website: https://capnproto.org/capnp-tool.html
Category: protocols
*/

Expand Down
1 change: 1 addition & 0 deletions src/languages/ceylon.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Language: Ceylon
Author: Lucas Werkmeister <mail@lucaswerkmeister.de>
Website: https://ceylon-lang.org
*/
function(hljs) {
// 2.3. Identifiers and keywords
Expand Down
1 change: 1 addition & 0 deletions src/languages/clojure-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Language: Clojure REPL
Description: Clojure REPL sessions
Author: Ivan Sagalaev <maniac@softwaremaniacs.org>
Requires: clojure.js
Website: https://clojure.org
Category: lisp
*/

Expand Down
1 change: 1 addition & 0 deletions src/languages/clojure.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Language: Clojure
Description: Clojure syntax (based on lisp.js)
Author: mfornos
Contributors: Martin Clausen <martin.clausene@gmail.com>
Website: https://clojure.org
Category: lisp
*/

Expand Down
2 changes: 1 addition & 1 deletion src/languages/cmake.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Language: CMake
Description: CMake is an open-source cross-platform system for build automation.
Author: Igor Kalnitsky <igor@kalnitsky.org>
Website: http://kalnitsky.org/
Website: https://cmake.org
*/

function(hljs) {
Expand Down
1 change: 1 addition & 0 deletions src/languages/coffeescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Author: Dmytrii Nagirniak <dnagir@gmail.com>
Contributors: Oleg Efimov <efimovov@gmail.com>, Cédric Néhémie <cedric.nehemie@gmail.com>
Description: CoffeeScript is a programming language that transcompiles to JavaScript. For info about language see http://coffeescript.org/
Category: common, scripting
Website: https://coffeescript.org
*/

function(hljs) {
Expand Down

0 comments on commit 640db25

Please sign in to comment.