Skip to content

Commit

Permalink
Merge branch 'main' into leaf
Browse files Browse the repository at this point in the history
  • Loading branch information
dannflor authored Jul 21, 2023
2 parents 86ee142 + e5e0220 commit 35c7a9b
Show file tree
Hide file tree
Showing 30 changed files with 646 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [16.x, 18.x, 20.x]
build-how: ["node", "browser", "browser -n", "cdn :common"]

steps:
Expand Down
20 changes: 18 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Version 11.9.0 (next release)

Supported Node.js versions:

- (chore) Drops support for Node 14.x, which is no longer supported by Node.js.

Parser:

- (enh) prevent rehighlighting of an element [joshgoebel][]
Expand All @@ -11,8 +15,17 @@ Core Grammars:
- fix(haxe) fixed metadata arguments and support non-colon syntax [Robert Borghese][]
- fix(haxe) differentiate `abstract` declaration from keyword [Robert Borghese][]
- fix(bash) do not delimit a string by an escaped apostrophe [hancar][]

Dev tool:
- enh(swift) support `macro` keyword [Bradley Mackey][]
- enh(swift) support parameter pack keywords [Bradley Mackey][]
- enh(swift) regex literal support [Bradley Mackey][]
- enh(swift) `@unchecked` and `@Sendable` support [Bradley Mackey][]
- enh(scala) add using directives support `//> using foo bar` [Jamie Thompson][]
- enh(swift) ownership modifiers support [Bradley Mackey][]
- enh(nsis) Add `!assert` compiler flag [idleberg][]
- fix(haskell) do not treat double dashes inside infix operators as comments [Zlondrej][]
- enh(rust) added `eprintln!` macro [qoheniac][]

Dev tool:

- (chore) Update dev tool to use the new `highlight` API. [Shah Shabbir Ahmmed][]
- (enh) Auto-update the highlighted output when the language dropdown changes. [Shah Shabbir Ahmmed][]
Expand All @@ -21,6 +34,8 @@ Dev tool:
[Shah Shabbir Ahmmed]: https://github.com/shabbir23ah
[Josh Goebel]: https://github.com/joshgoebel
[Checconio]: https://github.com/Checconio
[Bradley Mackey]: https://github.com/bradleymackey
[qoheniac]: https://github.com/qoheniac


## Version 11.8.0
Expand Down Expand Up @@ -72,6 +87,7 @@ Core Grammars:
[Keyacom]: https://github.com/Keyacom
[Boris Verkhovskiy]: https://github.com/verhovsky
[Cyrus Kao]: https://github.com/CyrusKao
[Zlondrej]: https://github.com/zlondrej

## Version 11.7.0

Expand Down
2 changes: 1 addition & 1 deletion SUPPORTED_LANGUAGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ The table below shows the full list of languages (and corresponding classes/alia
| X++ | axapta, x++ | |
| x86 Assembly | x86asm | |
| XL | xl, tao | |
| XQuery | xquery, xpath, xq | |
| XQuery | xquery, xpath, xq, xqm | |
| YAML | yml, yaml | |
| ZenScript | zenscript, zs |[highlightjs-zenscript](https://github.com/highlightjs/highlightjs-zenscript) |
| Zephir | zephir, zep | |
Expand Down
42 changes: 28 additions & 14 deletions src/languages/haskell.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,32 @@ Category: functional
*/

export default function(hljs) {

/* See:
- https://www.haskell.org/onlinereport/lexemes.html
- https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/binary_literals.html
- https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/numeric_underscores.html
- https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/hex_float_literals.html
*/
const decimalDigits = '([0-9]_*)+';
const hexDigits = '([0-9a-fA-F]_*)+';
const binaryDigits = '([01]_*)+';
const octalDigits = '([0-7]_*)+';
const ascSymbol = '[!#$%&*+.\\/<=>?@\\\\^~-]';
const uniSymbol = '(\\p{S}|\\p{P})' // Symbol or Punctuation
const special = '[(),;\\[\\]`|{}]';
const symbol = `(${ascSymbol}|(?!(${special}|[_:"']))${uniSymbol})`;

const COMMENT = { variants: [
hljs.COMMENT('--', '$'),
// Double dash forms a valid comment only if it's not part of legal lexeme.
// See: Haskell 98 report: https://www.haskell.org/onlinereport/lexemes.html
//
// The commented code does the job, but we can't use negative lookbehind,
// due to poor support by Safari browser.
// > hljs.COMMENT(`(?<!${symbol})--+(?!${symbol})`, '$'),
// So instead, we'll add a no-markup rule before the COMMENT rule in the rules list
// to match the problematic infix operators that contain double dash.
hljs.COMMENT('--+', '$'),
hljs.COMMENT(
/\{-/,
/-\}/,
Expand Down Expand Up @@ -56,19 +80,6 @@ export default function(hljs) {
contains: LIST.contains
};

/* See:
- https://www.haskell.org/onlinereport/lexemes.html
- https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/binary_literals.html
- https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/numeric_underscores.html
- https://downloads.haskell.org/ghc/9.0.1/docs/html/users_guide/exts/hex_float_literals.html
*/
const decimalDigits = '([0-9]_*)+';
const hexDigits = '([0-9a-fA-F]_*)+';
const binaryDigits = '([01]_*)+';
const octalDigits = '([0-7]_*)+';

const NUMBER = {
className: 'number',
relevance: 0,
Expand All @@ -92,6 +103,7 @@ export default function(hljs) {
+ 'qualified type data newtype deriving class instance as default '
+ 'infix infixl infixr foreign export ccall stdcall cplusplus '
+ 'jvm dotnet safe unsafe family forall mdo proc rec',
unicodeRegex: true,
contains: [
// Top-level constructions.
{
Expand Down Expand Up @@ -193,6 +205,8 @@ export default function(hljs) {
NUMBER,
CONSTRUCTOR,
hljs.inherit(hljs.TITLE_MODE, { begin: '^[_a-z][\\w\']*' }),
// No markup, prevents infix operators from being recognized as comments.
{ begin: `(?!-)${symbol}--+|--+(?!-)${symbol}`},
COMMENT,
{ // No markup, relevance booster
begin: '->|<-' }
Expand Down
8 changes: 8 additions & 0 deletions src/languages/lib/kws_swift.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,24 @@ export const keywords = [
/as\?/, // operator
/as!/, // operator
'as', // operator
'borrowing', // contextual
'break',
'case',
'catch',
'class',
'consume', // contextual
'consuming', // contextual
'continue',
'convenience', // contextual
'copy', // contextual
'default',
'defer',
'deinit',
'didSet', // contextual
'distributed',
'do',
'dynamic', // contextual
'each',
'else',
'enum',
'extension',
Expand All @@ -79,6 +84,7 @@ export const keywords = [
'nonisolated', // contextual
'lazy', // contextual
'let',
'macro',
'mutating', // contextual
'nonmutating', // contextual
/open\(set\)/, // contextual
Expand Down Expand Up @@ -303,8 +309,10 @@ export const keywordAttributes = [
'propertyWrapper',
'requires_stored_property_inits',
'resultBuilder',
'Sendable',
'testable',
'UIApplicationMain',
'unchecked',
'unknown',
'usableFromInline'
];
Expand Down
1 change: 1 addition & 0 deletions src/languages/nsis.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export default function(hljs) {
"addincludedir",
"addplugindir",
"appendfile",
"assert",
"cd",
"define",
"delfile",
Expand Down
1 change: 1 addition & 0 deletions src/languages/rust.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export default function(hljs) {
"debug_assert!",
"debug_assert_eq!",
"env!",
"eprintln!",
"panic!",
"file!",
"format!",
Expand Down
29 changes: 29 additions & 0 deletions src/languages/scala.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,42 @@ export default function(hljs) {
beginScope: { 2: "keyword", }
};

// glob all non-whitespace characters as a "string"
// sourced from https://github.com/scala/docs.scala-lang/pull/2845
const DIRECTIVE_VALUE = {
className: 'string',
begin: /\S+/,
}

// directives
// sourced from https://github.com/scala/docs.scala-lang/pull/2845
const USING_DIRECTIVE = {
begin: [
'//>',
/\s+/,
/using/,
/\s+/,
/\S+/
],
beginScope: {
1: "comment",
3: "keyword",
5: "type"
},
end: /$/,
contains: [
DIRECTIVE_VALUE,
]
}

return {
name: 'Scala',
keywords: {
literal: 'true false null',
keyword: 'type yield lazy override def with val var sealed abstract private trait object if then forSome for while do throw finally protected extends import final return else break new catch super class case package default try this match continue throws implicit export enum given transparent'
},
contains: [
USING_DIRECTIVE,
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
STRING,
Expand Down
60 changes: 54 additions & 6 deletions src/languages/swift.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,50 @@ export default function(hljs) {
]
};

const REGEXP_CONTENTS = [
hljs.BACKSLASH_ESCAPE,
{
begin: /\[/,
end: /\]/,
relevance: 0,
contains: [ hljs.BACKSLASH_ESCAPE ]
}
];

const BARE_REGEXP_LITERAL = {
begin: /\/[^\s](?=[^/\n]*\/)/,
end: /\//,
contains: REGEXP_CONTENTS
};

const EXTENDED_REGEXP_LITERAL = (rawDelimiter) => {
const begin = concat(rawDelimiter, /\//);
const end = concat(/\//, rawDelimiter);
return {
begin,
end,
contains: [
...REGEXP_CONTENTS,
{
scope: "comment",
begin: `#(?!.*${end})`,
end: /$/,
},
],
};
};

// https://docs.swift.org/swift-book/documentation/the-swift-programming-language/lexicalstructure/#Regular-Expression-Literals
const REGEXP = {
scope: "regexp",
variants: [
EXTENDED_REGEXP_LITERAL('###'),
EXTENDED_REGEXP_LITERAL('##'),
EXTENDED_REGEXP_LITERAL('#'),
BARE_REGEXP_LITERAL
]
};

// https://docs.swift.org/swift-book/ReferenceManual/LexicalStructure.html#ID412
const QUOTED_IDENTIFIER = { match: concat(/`/, Swift.identifier, /`/) };
const IMPLICIT_PARAMETER = {
Expand All @@ -199,7 +243,7 @@ export default function(hljs) {
// https://docs.swift.org/swift-book/ReferenceManual/Attributes.html
const AVAILABLE_ATTRIBUTE = {
match: /(@|#(un)?)available/,
className: "keyword",
scope: 'keyword',
starts: { contains: [
{
begin: /\(/,
Expand All @@ -214,11 +258,11 @@ export default function(hljs) {
] }
};
const KEYWORD_ATTRIBUTE = {
className: 'keyword',
scope: 'keyword',
match: concat(/@/, either(...Swift.keywordAttributes))
};
const USER_DEFINED_ATTRIBUTE = {
className: 'meta',
scope: 'meta',
match: concat(/@/, Swift.identifier)
};
const ATTRIBUTES = [
Expand Down Expand Up @@ -286,6 +330,7 @@ export default function(hljs) {
'self',
TUPLE_ELEMENT_NAME,
...COMMENTS,
REGEXP,
...KEYWORD_MODES,
...BUILT_INS,
...OPERATORS,
Expand All @@ -300,6 +345,7 @@ export default function(hljs) {
const GENERIC_PARAMETERS = {
begin: /</,
end: />/,
keywords: 'repeat each',
contains: [
...COMMENTS,
TYPE
Expand Down Expand Up @@ -342,9 +388,10 @@ export default function(hljs) {
illegal: /["']/
};
// https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#ID362
const FUNCTION = {
// https://docs.swift.org/swift-book/documentation/the-swift-programming-language/declarations/#Macro-Declaration
const FUNCTION_OR_MACRO = {
match: [
/func/,
/(func|macro)/,
/\s+/,
either(QUOTED_IDENTIFIER.match, Swift.identifier, Swift.operator)
],
Expand Down Expand Up @@ -441,7 +488,7 @@ export default function(hljs) {
keywords: KEYWORDS,
contains: [
...COMMENTS,
FUNCTION,
FUNCTION_OR_MACRO,
INIT_SUBSCRIPT,
{
beginKeywords: 'struct protocol class extension enum actor',
Expand All @@ -464,6 +511,7 @@ export default function(hljs) {
contains: [ ...COMMENTS ],
relevance: 0
},
REGEXP,
...KEYWORD_MODES,
...BUILT_INS,
...OPERATORS,
Expand Down
3 changes: 2 additions & 1 deletion src/languages/xquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ export default function(_hljs) {
name: 'XQuery',
aliases: [
'xpath',
'xq'
'xq',
'xqm'
],
case_insensitive: false,
illegal: /(proc)|(abstract)|(extends)|(until)|(#)/,
Expand Down
Loading

0 comments on commit 35c7a9b

Please sign in to comment.