Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh(autodetect) multiple autodetect fixes #2745

Merged
merged 30 commits into from Nov 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ca540b0
fix(autodetect) swift should not get double relevance for `import`
joshgoebel Oct 8, 2020
d6e9d22
fix(autodetect) css can include a forward slash
joshgoebel Oct 8, 2020
f55bc37
fix(autodetect) css class selectors must be valid identifiers
joshgoebel Oct 8, 2020
dd02953
fix(autodetect) css: allow extra ;
joshgoebel Oct 8, 2020
5bdd357
fix(autodetect) improve rule matcher
joshgoebel Oct 8, 2020
dc6bbaf
enh(autodetect) csharp: improve autodetection
joshgoebel Oct 8, 2020
8e7b582
enh(autodetect) clojure: reduce runaway relevance
joshgoebel Oct 8, 2020
aa45193
enh(autodetect) matlab: remove relevancy from `i` and `j`
joshgoebel Oct 8, 2020
ad2aea4
enh(autodetect) groovy
joshgoebel Oct 9, 2020
659f794
enh(autodetect) lisp: tune relevancy
joshgoebel Oct 9, 2020
c4062f3
enh(autodetect) php: improve auto-detection
joshgoebel Oct 9, 2020
36ab9a2
enh(autodetect) add additional common keywords
joshgoebel Oct 9, 2020
e36c161
enh(autodetect) java: relevance boost for `import java.*.`
joshgoebel Oct 9, 2020
250fa62
enh(autodetect) python: self is super common convention
joshgoebel Oct 10, 2020
cb66c9f
enh(autodetect) ruby improvements
joshgoebel Oct 10, 2020
e4319db
enh(autodetect) groovy: reduce @meta tags relevance
joshgoebel Oct 10, 2020
2421e24
enh(autodetect) vbscript: improve auto-detection
joshgoebel Oct 10, 2020
656402c
enh(autodetect) r: detect `<-`, illegal: `->`
joshgoebel Oct 10, 2020
de11ad1
enh(autodetect) fewer false positives on variables
joshgoebel Oct 12, 2020
49f430a
fix(autodetect) yaml: simple numbers should not add relevancy
joshgoebel Oct 12, 2020
de74ab8
fix(autodetect) crystal: lower function relevance (5 -> 2)
joshgoebel Oct 13, 2020
f92cc46
fix(autodetect) hy/scheme: bring in line with new `name` relevance fr…
joshgoebel Oct 13, 2020
c8c52e8
fix(autodetect) protobuf: tighten enum item rule
joshgoebel Oct 29, 2020
b60b1c4
fix(ocaml) `=>` does not actually seem to be a part of language
joshgoebel Oct 29, 2020
d39c107
fix(parser) add `value` to common keywords (0 relevance)
joshgoebel Oct 30, 2020
7c60e51
fix(n1ql) do not hobble relevancy of strings
joshgoebel Oct 31, 2020
8e55681
fix(javascript) remove relevance of `ident =>`
joshgoebel Oct 31, 2020
50a0483
fix(angelscript/lsl) no relevance for simple numbers
joshgoebel Nov 3, 2020
b0de56d
fix(properties) auto-detect: no points for ident[space]ident
joshgoebel Nov 3, 2020
9d06fe9
add comment, fix typos
joshgoebel Nov 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/languages/angelscript.js
Expand Up @@ -113,6 +113,7 @@ export default function(hljs) {

{ // numbers
className: 'number',
relevance: 0,
begin: '(-?)(\\b0[xXbBoOdD][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?f?|\\.\\d+f?)([eE][-+]?\\d+f?)?)'
}
]
Expand Down
7 changes: 6 additions & 1 deletion src/languages/bash.js
Expand Up @@ -6,6 +6,8 @@ Website: https://www.gnu.org/software/bash/
Category: common
*/

import * as regex from '../lib/regex.js';

/** @type LanguageFn */
export default function(hljs) {
const VAR = {};
Expand All @@ -23,7 +25,10 @@ export default function(hljs) {
Object.assign(VAR,{
className: 'variable',
variants: [
{begin: /\$[\w\d#@][\w\d_]*/},
{begin: regex.concat(/\$[\w\d#@][\w\d_]*/,
// negative look-ahead tries to avoid matching patterns that are not
// Perl at all like $ident$, @ident@, etc.
`(?![\\w\\d])(?![$])`) },
BRACED_VAR
]
});
Expand Down
6 changes: 4 additions & 2 deletions src/languages/clojure.js
Expand Up @@ -16,7 +16,7 @@ export default function(hljs) {
'builtin-name':
// Clojure keywords
globals + ' ' +
'cond apply if-not if-let if not not= = < > <= >= == + / * - rem ' +
'cond apply if-not if-let if not not= =|0 <|0 >|0 <=|0 >=|0 ==|0 +|0 /|0 *|0 -|0 rem ' +
'quot neg? pos? delay? symbol? keyword? true? false? integer? empty? coll? list? ' +
'set? ifn? fn? associative? sequential? sorted? counted? reversible? number? decimal? ' +
'class? distinct? isa? float? rational? reduced? ratio? odd? even? char? seq? vector? ' +
Expand Down Expand Up @@ -88,7 +88,9 @@ export default function(hljs) {
};
var NAME = {
keywords: keywords,
className: 'name', begin: SYMBOL_RE,
className: 'name',
begin: SYMBOL_RE,
relevance: 0,
starts: BODY
};
var DEFAULT_CONTAINS = [LIST, STRING, HINT, HINT_COL, COMMENT, KEY, COLLECTION, NUMBER, LITERAL, SYMBOL];
Expand Down
2 changes: 1 addition & 1 deletion src/languages/crystal.js
Expand Up @@ -158,7 +158,7 @@ export default function(hljs) {
endsParent: true
})
],
relevance: 5
relevance: 2
},
{
className: 'symbol',
Expand Down
19 changes: 14 additions & 5 deletions src/languages/csharp.js
Expand Up @@ -139,7 +139,7 @@ export default function(hljs) {
'select',
'set',
'unmanaged',
'value',
'value|0',
'var',
'when',
'where',
Expand Down Expand Up @@ -274,7 +274,9 @@ export default function(hljs) {
STRING,
NUMBERS,
{
beginKeywords: 'class interface', end: /[{;=]/,
beginKeywords: 'class interface',
relevance: 0,
end: /[{;=]/,
illegal: /[^\s:,]/,
contains: [
{ beginKeywords: "where class" },
Expand All @@ -285,7 +287,9 @@ export default function(hljs) {
]
},
{
beginKeywords: 'namespace', end: /[{;=]/,
beginKeywords: 'namespace',
relevance: 0,
end: /[{;=]/,
illegal: /[^\s:]/,
contains: [
TITLE_MODE,
Expand All @@ -294,7 +298,9 @@ export default function(hljs) {
]
},
{
beginKeywords: 'record', end: /[{;=]/,
beginKeywords: 'record',
relevance: 0,
end: /[{;=]/,
illegal: /[^\s:]/,
contains: [
TITLE_MODE,
Expand Down Expand Up @@ -324,7 +330,10 @@ export default function(hljs) {
keywords: KEYWORDS,
contains: [
// prevents these from being highlighted `title`
{ beginKeywords: FUNCTION_MODIFIERS.join(" ")},
{
beginKeywords: FUNCTION_MODIFIERS.join(" "),
relevance: 0
},
{
begin: hljs.IDENT_RE + '\\s*(<.+>)?\\s*\\(', returnBegin: true,
contains: [
Expand Down
7 changes: 4 additions & 3 deletions src/languages/css.js
Expand Up @@ -49,7 +49,7 @@ export default function(hljs) {
var AT_PROPERTY_RE = /@-?\w[\w]*(-\w+)*/ // @-webkit-keyframes
var IDENT_RE = '[a-zA-Z-][a-zA-Z0-9_-]*';
var RULE = {
begin: /(?:[A-Z_.-]+|--[a-zA-Z0-9_-]+)\s*:/, returnBegin: true, end: ';', endsWithParent: true,
begin: /([*]\s?)?(?:[A-Z_.\-\\]+|--[a-zA-Z0-9_-]+)\s*(\/\*\*\/)?:/, returnBegin: true, end: ';', endsWithParent: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What /**/ is meant for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Common css hack from the old days.

contains: [
ATTRIBUTE
]
Expand All @@ -58,14 +58,14 @@ export default function(hljs) {
return {
name: 'CSS',
case_insensitive: true,
illegal: /[=\/|'\$]/,
illegal: /[=|'\$]/,
contains: [
hljs.C_BLOCK_COMMENT_MODE,
{
className: 'selector-id', begin: /#[A-Za-z0-9_-]+/
},
{
className: 'selector-class', begin: /\.[A-Za-z0-9_-]+/
className: 'selector-class', begin: '\\.' + IDENT_RE
},
{
className: 'selector-attr',
Expand Down Expand Up @@ -125,6 +125,7 @@ export default function(hljs) {
illegal: /\S/,
contains: [
hljs.C_BLOCK_COMMENT_MODE,
{ begin: /;/ }, // empty ; rule
RULE,
]
}
Expand Down
10 changes: 8 additions & 2 deletions src/languages/groovy.js
Expand Up @@ -78,7 +78,10 @@ export default function(hljs) {
'throw throws try catch finally implements extends new import package return instanceof'
},
contains: [
hljs.SHEBANG(),
hljs.SHEBANG({
binary: "groovy",
relevance: 10
}),
COMMENT,
STRING,
REGEXP,
Expand All @@ -93,7 +96,9 @@ export default function(hljs) {
]
},
{
className: 'meta', begin: '@[A-Za-z]+'
className: 'meta',
begin: '@[A-Za-z]+',
relevance: 0
},
{
// highlight map keys and named parameters as attrs
Expand All @@ -104,6 +109,7 @@ export default function(hljs) {
// to avoid highlight it as a label, named parameter, or map key
begin: /\?/,
end: /:/,
relevance: 0,
contains: [
COMMENT,
STRING,
Expand Down
4 changes: 3 additions & 1 deletion src/languages/hy.js
Expand Up @@ -86,8 +86,10 @@ export default function(hljs) {
relevance: 0
};
var NAME = {
className: 'name',
relevance: 0,
keywords: keywords,
className: 'name', begin: SYMBOL_RE,
begin: SYMBOL_RE,
starts: BODY
};
var DEFAULT_CONTAINS = [LIST, STRING, HINT, HINT_COL, COMMENT, KEY, COLLECTION, NUMBER, LITERAL, SYMBOL];
Expand Down
6 changes: 6 additions & 0 deletions src/languages/java.js
Expand Up @@ -84,6 +84,12 @@ export default function(hljs) {
]
}
),
// relevance boost
{
begin: /import java\.[a-z]+\./,
keywords: "import",
relevance: 2
},
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
hljs.APOS_STRING_MODE,
Expand Down
3 changes: 2 additions & 1 deletion src/languages/javascript.js
Expand Up @@ -292,7 +292,8 @@ export default function(hljs) {
className: 'params',
variants: [
{
begin: hljs.UNDERSCORE_IDENT_RE
begin: hljs.UNDERSCORE_IDENT_RE,
relevance: 0
},
{
className: null,
Expand Down
5 changes: 4 additions & 1 deletion src/languages/lisp.js
Expand Up @@ -80,7 +80,10 @@ export default function(hljs) {
{
className: 'name',
variants: [
{begin: LISP_IDENT_RE},
{
begin: LISP_IDENT_RE,
relevance: 0,
},
{begin: MEC_RE}
]
},
Expand Down
1 change: 1 addition & 0 deletions src/languages/lsl.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/languages/matlab.js
Expand Up @@ -38,8 +38,8 @@ export default function(hljs) {
'eye repmat rand randn linspace logspace freqspace meshgrid accumarray size length ' +
'ndims numel disp isempty isequal isequalwithequalnans cat reshape diag blkdiag tril ' +
'triu fliplr flipud flipdim rot90 find sub2ind ind2sub bsxfun ndgrid permute ipermute ' +
'shiftdim circshift squeeze isscalar isvector ans eps realmax realmin pi i inf nan ' +
'isnan isinf isfinite j why compan gallery hadamard hankel hilb invhilb magic pascal ' +
'shiftdim circshift squeeze isscalar isvector ans eps realmax realmin pi i|0 inf nan ' +
'isnan isinf isfinite j|0 why compan gallery hadamard hankel hilb invhilb magic pascal ' +
'rosser toeplitz vander wilkinson max min nanmax nanmin mean nanmean type table ' +
'readtable writetable sortrows sort figure plot plot3 scatter scatter3 cellfun ' +
'legend intersect ismember procrustes hold num2cell '
Expand Down
6 changes: 2 additions & 4 deletions src/languages/n1ql.js
Expand Up @@ -52,14 +52,12 @@ export default function(hljs) {
{
className: 'string',
begin: '\'', end: '\'',
contains: [hljs.BACKSLASH_ESCAPE],
relevance: 0
contains: [hljs.BACKSLASH_ESCAPE]
},
{
className: 'string',
begin: '"', end: '"',
contains: [hljs.BACKSLASH_ESCAPE],
relevance: 0
contains: [hljs.BACKSLASH_ESCAPE]
},
{
className: 'symbol',
Expand Down
2 changes: 1 addition & 1 deletion src/languages/ocaml.js
Expand Up @@ -73,7 +73,7 @@ export default function(hljs) {
relevance: 0
},
{
begin: /[-=]>/ // relevance booster
begin: /->/ // relevance booster
}
]
}
Expand Down
10 changes: 9 additions & 1 deletion src/languages/perl.js
Expand Up @@ -5,6 +5,9 @@ Website: https://www.perl.org
Category: common
*/

import * as regex from '../lib/regex.js';

/** @type LanguageFn */
export default function(hljs) {
var PERL_KEYWORDS = {
$pattern: /[\w.]+/,
Expand Down Expand Up @@ -40,7 +43,12 @@ export default function(hljs) {
var VAR = {
variants: [
{begin: /\$\d/},
{begin: /[$%@](\^\w\b|#\w+(::\w+)*|\{\w+\}|\w+(::\w*)*)/},
{begin: regex.concat(
/[$%@](\^\w\b|#\w+(::\w+)*|\{\w+\}|\w+(::\w*)*)/,
// negative look-ahead tries to avoid matching patterns that are not
// Perl at all like $ident$, @ident@, etc.
`(?![A-Za-z])(?![@$%])`
)},
{begin: /[$%@][^\s\w{]/, relevance: 0}
]
};
Expand Down
31 changes: 23 additions & 8 deletions src/languages/php.js
Expand Up @@ -13,7 +13,10 @@ Category: common
export default function(hljs) {
const VARIABLE = {
className: 'variable',
begin: '\\$+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'
begin: '\\$+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' +
// negative look-ahead tries to avoid matching patterns that are not
// Perl at all like $ident$, @ident@, etc.
`(?![A-Za-z0-9])(?![$])`
};
const PREPROCESSOR = {
className: 'meta',
Expand Down Expand Up @@ -71,7 +74,11 @@ export default function(hljs) {
// Other keywords:
// <https://www.php.net/manual/en/reserved.php>
// <https://www.php.net/manual/en/language.types.type-juggling.php>
'array abstract and as binary bool boolean break callable case catch class clone const continue declare default do double else elseif empty enddeclare endfor endforeach endif endswitch endwhile eval extends final finally float for foreach from global goto if implements instanceof insteadof int integer interface isset iterable list match new object or private protected public real return string switch throw trait try unset use var void while xor yield',
'array abstract and as binary bool boolean break callable case catch class clone const continue declare ' +
'default do double else elseif empty enddeclare endfor endforeach endif endswitch endwhile eval extends ' +
'final finally float for foreach from global goto if implements instanceof insteadof int integer interface ' +
'isset iterable list match|0 new object or private protected public real return string switch throw trait ' +
'try unset use var void while xor yield',
literal: 'false null true',
built_in:
// Standard PHP library:
Expand Down Expand Up @@ -123,10 +130,14 @@ export default function(hljs) {
},
{
className: 'function',
relevance: 0,
beginKeywords: 'fn function', end: /[;{]/, excludeEnd: true,
illegal: '[$%\\[]',
contains: [
hljs.UNDERSCORE_TITLE_MODE,
{
begin: '=>' // No markup, just a relevance booster
},
{
className: 'params',
begin: '\\(', end: '\\)',
Expand All @@ -145,25 +156,29 @@ export default function(hljs) {
},
{
className: 'class',
beginKeywords: 'class interface', end: /\{/, excludeEnd: true,
beginKeywords: 'class interface',
relevance: 0,
end: /\{/,
excludeEnd: true,
illegal: /[:($"]/,
contains: [
{beginKeywords: 'extends implements'},
hljs.UNDERSCORE_TITLE_MODE
]
},
{
beginKeywords: 'namespace', end: ';',
beginKeywords: 'namespace',
relevance: 0,
end: ';',
illegal: /[.']/,
contains: [hljs.UNDERSCORE_TITLE_MODE]
},
{
beginKeywords: 'use', end: ';',
beginKeywords: 'use',
relevance: 0,
end: ';',
contains: [hljs.UNDERSCORE_TITLE_MODE]
},
{
begin: '=>' // No markup, just a relevance booster
},
STRING,
NUMBER
]
Expand Down
9 changes: 7 additions & 2 deletions src/languages/properties.js
Expand Up @@ -11,7 +11,9 @@ export default function(hljs) {
var WS0 = '[ \\t\\f]*';
var WS1 = '[ \\t\\f]+';
// delimiter
var DELIM = '(' + WS0+'[:=]'+WS0+ '|' + WS1 + ')';
var EQUAL_DELIM = WS0+'[:=]'+WS0;
var WS_DELIM = WS1;
var DELIM = '(' + EQUAL_DELIM + '|' + WS_DELIM + ')';
var KEY_ALPHANUM = '([^\\\\\\W:= \\t\\f\\n]|\\\\.)+';
var KEY_OTHER = '([^\\\\:= \\t\\f\\n]|\\\\.)+';

Expand Down Expand Up @@ -39,8 +41,11 @@ export default function(hljs) {
// key: everything until whitespace or = or : (taking into account backslashes)
// case of a "normal" key
{
begin: KEY_ALPHANUM + DELIM,
returnBegin: true,
variants: [
{ begin: KEY_ALPHANUM + EQUAL_DELIM, relevance: 1 },
{ begin: KEY_ALPHANUM + WS_DELIM, relevance: 0 }
],
contains: [
{
className: 'attr',
Expand Down