forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Looks like `cargo publish` requires that `sway.js` live inside the `forc-doc` directory. Otherwise, the file is not found. I'm simply moving `sway.js` to `forc-doc/src/assets` and updating the code to point to that location instead.
- Loading branch information
1 parent
ed1610a
commit 9f02b5a
Showing
2 changed files
with
186 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
/* | ||
Language: Sway | ||
Author: Fuel Labs [email protected] | ||
Contributors: Fuel Labs <[email protected]>, | ||
Website: https://fuel.sh | ||
Category: smart contracts, layer 2, blockchain, | ||
*/ | ||
|
||
import * as regex from '../lib/regex.js'; | ||
|
||
/** @type LanguageFn */ | ||
export default function(hljs) { | ||
const FUNCTION_INVOKE = { | ||
className: "title.function.invoke", | ||
relevance: 0, | ||
begin: regex.concat( | ||
/\b/, | ||
/(?!let\b)/, | ||
hljs.IDENT_RE, | ||
regex.lookahead(/\s*\(/)) | ||
}; | ||
const NUMBER_SUFFIX = '([u](8|16|32|64))\?'; | ||
|
||
const KEYWORDS = [ | ||
"abi", | ||
"as", | ||
"asm", | ||
"break", | ||
"const", | ||
"continue", | ||
"contract", | ||
"dep", | ||
"deref", | ||
"else", | ||
"enum", | ||
"fn", | ||
"for", | ||
"if", | ||
"impl", | ||
"let", | ||
"library", | ||
"match", | ||
"mut", | ||
"predicate", | ||
"pub", | ||
"ref", | ||
"return", | ||
"script", | ||
"Self", | ||
"self", | ||
"storage", | ||
"str", | ||
"struct", | ||
"trait", | ||
"use", | ||
"where", | ||
"while", | ||
]; | ||
const LITERALS = [ | ||
"true", | ||
"false", | ||
"Some", | ||
"None", | ||
"Ok", | ||
"Err", | ||
]; | ||
const BUILTINS = [ | ||
|
||
]; | ||
const TYPES = [ | ||
"bool", "char", "u8", "u16", "u32", "u64", "b256", "str", "Self" | ||
]; | ||
return { | ||
name: 'Sway', | ||
aliases: [ 'sw' ], | ||
keywords: { | ||
$pattern: hljs.IDENT_RE + '!?', | ||
keyword: KEYWORDS, | ||
literal: LITERALS, | ||
built_in: TYPES | ||
}, | ||
illegal: '</', | ||
contains: [ | ||
hljs.C_LINE_COMMENT_MODE, | ||
hljs.COMMENT('/\\*', '\\*/', { | ||
contains: [ 'self' ] | ||
}), | ||
hljs.inherit(hljs.QUOTE_STRING_MODE, { | ||
begin: /b?"/, | ||
illegal: null | ||
}), | ||
{ | ||
className: 'string', | ||
variants: [ | ||
{ | ||
begin: /b?r(#*)"(.|\n)*?"\1(?!#)/ | ||
}, | ||
{ | ||
begin: /b?'\\?(x\w{2}|u\w{4}|U\w{8}|.)'/ | ||
} | ||
] | ||
}, | ||
{ | ||
className: 'symbol', | ||
begin: /'[a-zA-Z_][a-zA-Z0-9_]*/ | ||
}, | ||
{ | ||
className: 'number', | ||
variants: [ | ||
{ | ||
begin: '\\b0b([01_]+)' + NUMBER_SUFFIX | ||
}, | ||
{ | ||
begin: '\\b0o([0-7_]+)' + NUMBER_SUFFIX | ||
}, | ||
{ | ||
begin: '\\b0x([A-Fa-f0-9_]+)' + NUMBER_SUFFIX | ||
}, | ||
{ | ||
begin: '\\b(\\d[\\d_]*(\\.[0-9_]+)?([eE][+-]?[0-9_]+)?)' + | ||
NUMBER_SUFFIX | ||
} | ||
], | ||
relevance: 0 | ||
}, | ||
{ | ||
begin: [ | ||
/fn/, | ||
/\s+/, | ||
hljs.UNDERSCORE_IDENT_RE | ||
], | ||
className: { | ||
1: "keyword", | ||
3: "title.function" | ||
} | ||
}, | ||
{ | ||
begin: [ | ||
/(let|const)/, /\s+/, | ||
/(?:mut\s+)?/, | ||
hljs.UNDERSCORE_IDENT_RE | ||
], | ||
className: { | ||
1: "keyword", | ||
3: "keyword", | ||
4: "variable" | ||
} | ||
}, | ||
{ | ||
begin: [ | ||
/type/, | ||
/\s+/, | ||
hljs.UNDERSCORE_IDENT_RE | ||
], | ||
className: { | ||
1: "keyword", | ||
3: "title.class" | ||
} | ||
}, | ||
{ | ||
begin: [ | ||
/(?:trait|enum|struct|impl|for|library|abi)/, | ||
/\s+/, | ||
hljs.UNDERSCORE_IDENT_RE | ||
], | ||
className: { | ||
1: "keyword", | ||
3: "title.class" | ||
} | ||
}, | ||
{ | ||
begin: hljs.IDENT_RE + '::', | ||
keywords: { | ||
keyword: "Self", | ||
built_in: BUILTINS | ||
} | ||
}, | ||
{ | ||
className: "punctuation", | ||
begin: '->' | ||
}, | ||
FUNCTION_INVOKE | ||
] | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters