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.
added sway highlight.js (FuelLabs#129)
* added sway highlight.js * added higlightjs/sway and its build script * added initial prism for sway * added script for prism * added prism-sway and instructions * rename to all caps * update build scripts * added missing dots
- Loading branch information
1 parent
cf8e9ce
commit 919c18c
Showing
9 changed files
with
898 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,15 @@ | ||
## Instructions | ||
|
||
Update "sway.js" file. | ||
|
||
Then run: | ||
|
||
```sh | ||
$ ./build.sh | ||
``` | ||
|
||
If you are actively developing and testing and want to keep `highlight.js` directory add `keep` in the command | ||
|
||
```sh | ||
$ ./build.sh keep | ||
``` |
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,21 @@ | ||
#!/bin/bash | ||
project="highlight.js" | ||
sway="sway.js" | ||
|
||
if ! test -d ./${project}; then | ||
git clone [email protected]:highlightjs/highlight.js.git | ||
fi | ||
|
||
cp ${sway} ${project}/src/languages | ||
cd ${project} | ||
npm install | ||
|
||
rm -rf build | ||
node tools/build.js sway | ||
cp build/highlight.min.js ../../../docs/theme/highlight.js | ||
|
||
# add "keep" in order to keep highlight.js repo | ||
if [[ ${1} != "keep" ]]; then | ||
cd ../ | ||
rm -rf ${project} | ||
fi |
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,175 @@ | ||
/* | ||
Language: Sway | ||
Author: Fuel [email protected] | ||
Contributors: Elvis Dedic <[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 = [ | ||
"as", | ||
"asm", | ||
"contract", | ||
"deref", | ||
"enum", | ||
"fn", | ||
"impl", | ||
"let", | ||
"library", | ||
"match", | ||
"mut", | ||
"predicate", | ||
"ref", | ||
"return", | ||
"script", | ||
"Self", | ||
"self", | ||
"str", | ||
"struct", | ||
"trait", | ||
"use", | ||
"where", | ||
"while", | ||
]; | ||
const LITERALS = [ | ||
"true", | ||
"false", | ||
]; | ||
const BUILTINS = [ | ||
|
||
]; | ||
const TYPES = [ | ||
"u8", | ||
"u16", | ||
"u32", | ||
"u64", | ||
]; | ||
return { | ||
name: 'Sway', | ||
aliases: [ 'sw' ], | ||
keywords: { | ||
$pattern: hljs.IDENT_RE + '!?', | ||
type: TYPES, | ||
keyword: KEYWORDS, | ||
literal: LITERALS, | ||
built_in: BUILTINS | ||
}, | ||
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/, /\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)/, | ||
/\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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
## Instructions | ||
|
||
Update "prism-sway.js" file. | ||
|
||
Then run: | ||
|
||
```sh | ||
$ ./build.sh | ||
``` | ||
|
||
If you are actively developing and testing and want to keep `prism` (repo) directory add `keep` in the command | ||
|
||
```sh | ||
$ ./build.sh keep | ||
``` | ||
|
||
### Testing | ||
|
||
If you want to test it in html, `keep` the "prism" folder, and open "test-suite.html" and start writing Sway. |
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,22 @@ | ||
#!/bin/bash | ||
project="prism" | ||
components="components.json" | ||
sway="prism-sway.js" | ||
|
||
if ! test -d ./${project}; then | ||
git clone [email protected]:PrismJS/prism.git | ||
fi | ||
|
||
cp ${sway} ${project}/components | ||
cp ${components} ${project} | ||
cd ${project} | ||
npm ci | ||
|
||
npm run build | ||
cp components/prism-sway.min.js ../prism-sway.min.js | ||
|
||
# add "keep" in order to keep highlight.js repo | ||
if [[ ${1} != "keep" ]]; then | ||
cd ../ | ||
rm -rf ${project} | ||
fi |
Oops, something went wrong.