1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00

Merge pull request #1195 from Zokrates/update-syntax-highlighters

Update syntax highlighter definitions
This commit is contained in:
Thibaut Schaeffer 2022-08-09 10:55:39 +02:00 committed by GitHub
commit e940774d93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 54 additions and 819 deletions

View file

@ -0,0 +1 @@
Update syntax highlighters

View file

@ -1,4 +0,0 @@
### ZoKrates Ace Mode (Syntax Highlighting for Ace/Brace)
[Ace](https://ace.c9.io/) Edit Mode for [ZoKrates DSL](https://github.com/Zokrates/ZoKrates).
Compatible with browserify version of the ace editor, [brace](https://www.npmjs.com/package/brace).

View file

@ -1,121 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2019, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
ace.define("ace/mode/zokrates_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(acequire, exports, module) {
"use strict";
var oop = acequire("../lib/oop");
var TextHighlightRules = acequire("./text_highlight_rules").TextHighlightRules;
var ZoKratesHighlightRules = function () {
var keywords = (
"assert|as|bool|byte|const|def|do|else|endfor|export|false|field|for|if|then|fi|import|from|in|private|public|return|struct|true|type|u8|u16|u32|u64"
);
var keywordMapper = this.createKeywordMapper({
"keyword": keywords
}, "identifier");
var decimalInteger = "(?:(?:[1-9]\\d*)|(?:0))";
var decimalSuffix = "(?:_?(?:f|u(?:8|16|32|64)))?";
var hexInteger = "(?:0[xX][\\dA-Fa-f]+)";
var integer = "(?:" + decimalInteger + decimalSuffix + "|" + hexInteger + ")\\b";
this.$rules = {
"start": [
{
token: "comment", // single line comment
regex: "\\/\\/.*$"
}, {
token: "comment", // multi line comment
regex: "\\/\\*",
next: "comment"
}, {
token: "string", // single line
regex: '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
}, {
token: "constant.numeric", // integer
regex: integer
}, {
token: keywordMapper,
regex: "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
}, {
token: "keyword.operator",
regex: "\\+|\\-|\\*\\*?|\\/|\\|\\|?|&&?|\\^|!|<<?|>>?|<=|=>|==|!=|="
}, {
token: "punctuation",
regex: ",|:|;"
}, {
token: "lparen",
regex: "[[({]"
}, {
token: "rparen",
regex: "[\\])}]"
}, {
token: "text",
regex: "\\s+"
}
],
"comment": [
{
token: "comment", // closing comment
regex: "\\*\\/",
next: "start"
}, {
defaultToken: "comment"
}
]
};
};
oop.inherits(ZoKratesHighlightRules, TextHighlightRules);
exports.ZoKratesHighlightRules = ZoKratesHighlightRules;
});
ace.define("ace/mode/zokrates",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/zokrates_highlight_rules"], function(acequire, exports, module) {
"use strict";
var oop = acequire("../lib/oop");
var TextMode = acequire("./text").Mode;
var ZoKratesHighlightRules = acequire("./zokrates_highlight_rules").ZoKratesHighlightRules;
var Mode = function () {
this.HighlightRules = ZoKratesHighlightRules;
};
oop.inherits(Mode, TextMode);
(function () {
this.$id = "ace/mode/zokrates";
}).call(Mode.prototype);
exports.Mode = Mode;
});

View file

@ -1,17 +0,0 @@
{
"name": "ace-mode-zokrates",
"version": "1.0.4",
"description": "Ace Mode for ZoKrates DSL",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"zokrates",
"ace",
"mode",
"brace"
],
"author": "Darko Macesic",
"license": "LGPL"
}

View file

@ -0,0 +1 @@
*.tmLanguage.json

View file

@ -1,36 +1,36 @@
{
"name": "zokrates",
"displayName": "zokrates",
"description": "Syntax highlighting for the ZoKrates language",
"publisher": "zokrates",
"repository": "https://github.com/ZoKrates/ZoKrates",
"version": "0.0.2",
"engines": {
"vscode": "^1.53.0"
},
"categories": [
"Programming Languages"
],
"contributes": {
"languages": [
{
"id": "zokrates",
"aliases": [
"ZoKrates",
"zokrates"
],
"extensions": [
".zok"
],
"configuration": "./language-configuration.json"
}
],
"grammars": [
{
"language": "zokrates",
"scopeName": "source.zok",
"path": "./syntaxes/zokrates.tmLanguage.json"
}
]
}
}
"name": "zokrates",
"displayName": "zokrates",
"description": "Syntax highlighting for the ZoKrates language",
"publisher": "zokrates",
"repository": "https://github.com/ZoKrates/ZoKrates",
"version": "0.1.0",
"engines": {
"vscode": "^1.53.0"
},
"categories": [
"Programming Languages"
],
"contributes": {
"languages": [
{
"id": "zokrates",
"aliases": [
"ZoKrates",
"zokrates"
],
"extensions": [
".zok"
],
"configuration": "./language-configuration.json"
}
],
"grammars": [
{
"language": "zokrates",
"scopeName": "source.zok",
"path": "./syntaxes/zokrates.tmLanguage.json"
}
]
}
}

View file

@ -1,637 +0,0 @@
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "ZoKrates",
"fileTypes": [
"zok"
],
"scopeName": "source.zok",
"patterns": [
{
"comment": "attributes",
"name": "meta.attribute.zokrates",
"begin": "(#)(\\!?)(\\[)",
"beginCaptures": {
"1": {
"name": "punctuation.definition.attribute.zokrates"
},
"2": {
"name": "keyword.operator.attribute.inner.zokrates"
},
"3": {
"name": "punctuation.brackets.attribute.zokrates"
}
},
"end": "\\]",
"endCaptures": {
"0": {
"name": "punctuation.brackets.attribute.zokrates"
}
},
"patterns": [
{
"include": "#block-comments"
},
{
"include": "#comments"
},
{
"include": "#keywords"
},
{
"include": "#punctuation"
},
{
"include": "#strings"
},
{
"include": "#types"
}
]
},
{
"include": "#block-comments"
},
{
"include": "#comments"
},
{
"include": "#constants"
},
{
"include": "#functions"
},
{
"include": "#types"
},
{
"include": "#keywords"
},
{
"include": "#punctuation"
},
{
"include": "#strings"
},
{
"include": "#variables"
}
],
"repository": {
"comments": {
"patterns": [
{
"comment": "line comments",
"name": "comment.line.double-slash.zokrates",
"match": "\\s*//.*"
}
]
},
"block-comments": {
"patterns": [
{
"comment": "empty block comments",
"name": "comment.block.zokrates",
"match": "/\\*\\*/"
},
{
"comment": "block comments",
"name": "comment.block.zokrates",
"begin": "/\\*(?!\\*)",
"end": "\\*/",
"patterns": [
{
"include": "#block-comments"
}
]
}
]
},
"constants": {
"patterns": [
{
"comment": "ALL CAPS constants",
"name": "constant.other.caps.zokrates",
"match": "\\b[A-Z]{2}[A-Z0-9_]*\\b"
},
{
"comment": "decimal integers and floats",
"name": "constant.numeric.decimal.zokrates",
"match": "\\b\\d[\\d_]*(?:u128|u16|u32|u64|u8|f)?\\b"
},
{
"comment": "hexadecimal integers",
"name": "constant.numeric.hex.zokrates",
"match": "\\b0x[\\da-fA-F_]+\\b"
},
{
"comment": "booleans",
"name": "constant.language.bool.zokrates",
"match": "\\b(true|false)\\b"
}
]
},
"imports": {
"patterns": [
{
"comment": "explicit import statement",
"name": "meta.import.explicit.zokrates",
"match": "\\b(from)\\s+(\\\".*\\\")(import)\\s+([A-Za-z0-9_]+)\\s+((as)\\s+[A-Za-z0-9_]+)?\\b",
"patterns": [
{
"include": "#block-comments"
},
{
"include": "#comments"
},
{
"include": "#keywords"
},
{
"include": "#punctuation"
},
{
"include": "#types"
},
{
"include": "#strings"
}
]
},
{
"comment": "main import statement",
"name": "meta.import.explicit.zokrates",
"match": "\\b(import)\\s+(\\\".*\\\")\\s+((as)\\s+[A-Za-z0-9_]+)?\\b",
"patterns": [
{
"include": "#block-comments"
},
{
"include": "#comments"
},
{
"include": "#keywords"
},
{
"include": "#punctuation"
},
{
"include": "#types"
},
{
"include": "#strings"
}
]
}
]
},
"constant-definitions": {
"patterns": [
{
"comment": "constant definition",
"name": "constant.definition.zokrates",
"match": "\\b(const)\\s+([A-Za-z0-9_]+)\\s+([A-Za-z0-9_]+)\\s+=\\s+(?:.+)\\b",
"captures": {
"1": {
"name": "keyword.other.const.zokrates"
},
"2": {
"name": "entity.name.type.zokrates"
},
"3": {
"name": "entity.name.constant.zokrates"
}
},
"patterns": [
{
"include": "#block-comments"
},
{
"include": "#comments"
},
{
"include": "#keywords"
},
{
"include": "#constants"
},
{
"include": "#punctuation"
},
{
"include": "#types"
},
{
"include": "#variables"
}
]
}
]
},
"functions": {
"patterns": [
{
"comment": "function definition",
"name": "meta.function.definition.zokrates",
"begin": "\\b(def)\\s+([A-Za-z0-9_]+)((\\()|(<))",
"beginCaptures": {
"1": {
"name": "keyword.other.def.zokrates"
},
"2": {
"name": "entity.name.function.zokrates"
},
"4": {
"name": "punctuation.brackets.round.zokrates"
},
"5": {
"name": "punctuation.brackets.angle.zokrates"
}
},
"end": "\\:|;",
"endCaptures": {
"0": {
"name": "keyword.punctuation.colon.zokrates"
}
},
"patterns": [
{
"include": "#block-comments"
},
{
"include": "#comments"
},
{
"include": "#keywords"
},
{
"include": "#constants"
},
{
"include": "#functions"
},
{
"include": "#punctuation"
},
{
"include": "#strings"
},
{
"include": "#types"
},
{
"include": "#variables"
}
]
},
{
"comment": "function/method calls, chaining",
"name": "meta.function.call.zokrates",
"begin": "([A-Za-z0-9_]+)(\\()",
"beginCaptures": {
"1": {
"name": "entity.name.function.zokrates"
},
"2": {
"name": "punctuation.brackets.round.zokrates"
}
},
"end": "\\)",
"endCaptures": {
"0": {
"name": "punctuation.brackets.round.zokrates"
}
},
"patterns": [
{
"include": "#block-comments"
},
{
"include": "#comments"
},
{
"include": "#keywords"
},
{
"include": "#constants"
},
{
"include": "#functions"
},
{
"include": "#punctuation"
},
{
"include": "#strings"
},
{
"include": "#types"
},
{
"include": "#variables"
}
]
},
{
"comment": "function/method calls with turbofish",
"name": "meta.function.call.zokrates",
"begin": "([A-Za-z0-9_]+)(?=::<.*>\\()",
"beginCaptures": {
"1": {
"name": "entity.name.function.zokrates"
}
},
"end": "\\)",
"endCaptures": {
"0": {
"name": "punctuation.brackets.round.zokrates"
}
},
"patterns": [
{
"include": "#block-comments"
},
{
"include": "#comments"
},
{
"include": "#keywords"
},
{
"include": "#constants"
},
{
"include": "#functions"
},
{
"include": "#punctuation"
},
{
"include": "#strings"
},
{
"include": "#types"
},
{
"include": "#variables"
}
]
}
]
},
"keywords": {
"patterns": [
{
"comment": "argument visibility",
"name": "keyword.visibility.zokrates",
"match": "\\b(public|private)\\b"
},
{
"comment": "control flow keywords",
"name": "keyword.control.zokrates",
"match": "\\b(do|else|for|do|endfor|if|then|fi|return|assert)\\b"
},
{
"comment": "storage keywords",
"name": "storage.type.zokrates",
"match": "\\b(struct)\\b"
},
{
"comment": "const",
"name": "keyword.other.const.zokrates",
"match": "\\bconst\\b"
},
{
"comment": "def",
"name": "keyword.other.def.zokrates",
"match": "\\bdef\\b"
},
{
"comment": "import keywords",
"name": "keyword.other.import.zokrates",
"match": "\\b(import|from|as)\\b"
},
{
"comment": "logical operators",
"name": "keyword.operator.logical.zokrates",
"match": "(\\^|\\||\\|\\||&|&&|<<|>>|!)(?!=)"
},
{
"comment": "single equal",
"name": "keyword.operator.assignment.equal.zokrates",
"match": "(?<![<>])=(?!=|>)"
},
{
"comment": "comparison operators",
"name": "keyword.operator.comparison.zokrates",
"match": "(=(=)?(?!>)|!=|<=|(?<!=)>=)"
},
{
"comment": "math operators",
"name": "keyword.operator.math.zokrates",
"match": "(([+%]|(\\*(?!\\w)))(?!=))|(-(?!>))|(/(?!/))"
},
{
"comment": "less than, greater than (special case)",
"match": "(?:\\b|(?:(\\))|(\\])|(\\})))[ \\t]+([<>])[ \\t]+(?:\\b|(?:(\\()|(\\[)|(\\{)))",
"captures": {
"1": {
"name": "punctuation.brackets.round.zokrates"
},
"2": {
"name": "punctuation.brackets.square.zokrates"
},
"3": {
"name": "punctuation.brackets.curly.zokrates"
},
"4": {
"name": "keyword.operator.comparison.zokrates"
},
"5": {
"name": "punctuation.brackets.round.zokrates"
},
"6": {
"name": "punctuation.brackets.square.zokrates"
},
"7": {
"name": "punctuation.brackets.curly.zokrates"
}
}
},
{
"comment": "dot access",
"name": "keyword.operator.access.dot.zokrates",
"match": "\\.(?!\\.)"
},
{
"comment": "ranges, range patterns",
"name": "keyword.operator.range.zokrates",
"match": "\\.{2}(=|\\.)?"
},
{
"comment": "colon",
"name": "keyword.operator.colon.zokrates",
"match": ":(?!:)"
},
{
"comment": "dashrocket, skinny arrow",
"name": "keyword.operator.arrow.skinny.zokrates",
"match": "->"
}
]
},
"types": {
"patterns": [
{
"comment": "numeric types",
"match": "(?<![A-Za-z])(u128|u16|u32|u64|u8|field)\\b",
"captures": {
"1": {
"name": "entity.name.type.numeric.zokrates"
}
}
},
{
"comment": "parameterized types",
"begin": "\\b([A-Z][A-Za-z0-9]*)(<)",
"beginCaptures": {
"1": {
"name": "entity.name.type.zokrates"
},
"2": {
"name": "punctuation.brackets.angle.zokrates"
}
},
"end": ">",
"endCaptures": {
"0": {
"name": "punctuation.brackets.angle.zokrates"
}
},
"patterns": [
{
"include": "#block-comments"
},
{
"include": "#comments"
},
{
"include": "#keywords"
},
{
"include": "#punctuation"
},
{
"include": "#types"
},
{
"include": "#variables"
}
]
},
{
"comment": "primitive types",
"name": "entity.name.type.primitive.zokrates",
"match": "\\b(bool)\\b"
},
{
"comment": "struct declarations",
"match": "\\b(struct)\\s+([A-Z][A-Za-z0-9]*)\\b",
"captures": {
"1": {
"name": "storage.type.zokrates"
},
"2": {
"name": "entity.name.type.struct.zokrates"
}
}
},
{
"comment": "types",
"name": "entity.name.type.zokrates",
"match": "\\b[A-Z][A-Za-z0-9]*\\b(?!!)"
}
]
},
"punctuation": {
"patterns": [
{
"comment": "comma",
"name": "punctuation.comma.zokrates",
"match": ","
},
{
"comment": "parentheses, round brackets",
"name": "punctuation.brackets.round.zokrates",
"match": "[()]"
},
{
"comment": "square brackets",
"name": "punctuation.brackets.square.zokrates",
"match": "[\\[\\]]"
},
{
"comment": "angle brackets",
"name": "punctuation.brackets.angle.zokrates",
"match": "(?<!=)[<>]"
}
]
},
"strings": {
"patterns": [
{
"comment": "double-quoted strings and byte strings",
"name": "string.quoted.double.zokrates",
"begin": "(b?)(\")",
"beginCaptures": {
"1": {
"name": "string.quoted.byte.raw.zokrates"
},
"2": {
"name": "punctuation.definition.string.zokrates"
}
},
"end": "\"",
"endCaptures": {
"0": {
"name": "punctuation.definition.string.zokrates"
}
}
},
{
"comment": "double-quoted raw strings and raw byte strings",
"name": "string.quoted.double.zokrates",
"begin": "(b?r)(#*)(\")",
"beginCaptures": {
"1": {
"name": "string.quoted.byte.raw.zokrates"
},
"2": {
"name": "punctuation.definition.string.raw.zokrates"
},
"3": {
"name": "punctuation.definition.string.zokrates"
}
},
"end": "(\")(\\2)",
"endCaptures": {
"1": {
"name": "punctuation.definition.string.zokrates"
},
"2": {
"name": "punctuation.definition.string.raw.zokrates"
}
}
}
]
},
"variables": {
"patterns": [
{
"comment": "variables",
"name": "variable.other.zokrates",
"match": "\\b(?<!(?<!\\.)\\.)[a-z0-9_]+\\b"
}
]
}
}
}

View file

@ -79,7 +79,7 @@ repository:
-
comment: 'decimal integers and floats'
name: constant.numeric.decimal.zokrates
match: '\b\d[\d_]*(?:u128|u16|u32|u64|u8|f)?\b'
match: '\b\d[\d_]*(?:u16|u32|u64|u8|f)?\b'
-
comment: 'hexadecimal integers'
name: constant.numeric.hex.zokrates
@ -202,7 +202,7 @@ repository:
-
comment: 'control flow keywords'
name: keyword.control.zokrates
match: \b(for|in|do|endfor|if|then|else|fi|return|assert)\b
match: \b(for|in|if|else|return|assert|log)\b
-
comment: 'storage keywords'
name: storage.type.zokrates
@ -227,6 +227,10 @@ repository:
comment: 'logical operators'
name: keyword.operator.logical.zokrates
match: '(\^|\||\|\||&|&&|<<|>>|!)(?!=)'
-
comment: 'mut'
name: "storage.modifier.mut.zokrates"
match: \b(mut)\b
-
comment: 'single equal'
name: keyword.operator.assignment.equal.zokrates
@ -270,7 +274,7 @@ repository:
patterns:
-
comment: 'numeric types'
match: '(?<![A-Za-z])(u128|u16|u32|u64|u8|field)\b'
match: '(?<![A-Za-z])(u16|u32|u64|u8|field)\b'
captures:
'1': {name: entity.name.type.numeric.zokrates}
-
@ -309,10 +313,18 @@ repository:
comment: comma
name: punctuation.comma.zokrates
match: ','
-
comment: 'curly braces'
name: punctuation.brackets.curly.zokrates
match: '[{}]'
-
comment: 'parentheses, round brackets'
name: punctuation.brackets.round.zokrates
match: '[()]'
-
comment: 'semicolon'
name: punctuation.semi.zokrates
match: ';'
-
comment: 'square brackets'
name: punctuation.brackets.square.zokrates

View file

@ -180,6 +180,6 @@ COMMENT = _{ ("/*" ~ (!"*/" ~ ANY)* ~ "*/") | ("//" ~ (!NEWLINE ~ ANY)*) }
// the ordering of reserved keywords matters: if "as" is before "assert", then "assert" gets parsed as (as)(sert) and incorrectly
// accepted
keyword = @{
"log"|"assert"|"as"|"bool"|"const"|"def"|"else"|"false"|"field"|"for"|"if"|"then"|"fi"|"import"|"from"|
"in"|"mut"|"private"|"public"|"return"|"struct"|"true"|"u8"|"u16"|"u32"|"u64"
"log"|"assert"|"as"|"bool"|"const"|"def"|"else"|"false"|"field"|"for"|"if"|"import"|"from"|
"in"|"mut"|"private"|"public"|"return"|"struct"|"true"|"type"|"u8"|"u16"|"u32"|"u64"
}