Berry syntax highlighter for multiline f-strings (#24155)

This commit is contained in:
s-hadinger 2025-11-23 23:03:42 +01:00 committed by GitHub
parent dc2ae5078c
commit 73fd0aa377
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 199 additions and 236 deletions

View File

@ -1,153 +0,0 @@
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "Berry",
"patterns": [
{
"include": "#controls"
},
{
"include": "#strings"
},
{
"include": "#comment-block"
},
{
"include": "#comments"
},
{
"include": "#keywords"
},
{
"include": "#function"
},
{
"include": "#member"
},
{
"include": "#identifier"
},
{
"include": "#number"
},
{
"include": "#operator"
}
],
"repository": {
"controls": {
"patterns": [{
"name": "keyword.control.berry",
"match": "\\b(if|elif|else|for|while|do|end|break|continue|return|try|except|raise)\\b"
}]
},
"strings": {
"patterns": [
{
"name": "string.quoted.double.berry",
"begin": "(\"|')",
"end": "\\1",
"patterns": [
{
"name": "constant.character.escape.berry",
"match": "(\\\\x[\\h]{2})|(\\\\[0-7]{3})|(\\\\\\\\)|(\\\\\")|(\\\\')|(\\\\a)|(\\\\b)|(\\\\f)|(\\\\n)|(\\\\r)|(\\\\t)|(\\\\v)"
}
]
},
{
"name": "string.quoted.other.berry",
"begin": "f(\"|')",
"end": "\\1",
"patterns": [
{
"name": "constant.character.escape.berry",
"match": "(\\\\x[\\h]{2})|(\\\\[0-7]{3})|(\\\\\\\\)|(\\\\\")|(\\\\')|(\\\\a)|(\\\\b)|(\\\\f)|(\\\\n)|(\\\\r)|(\\\\t)|(\\\\v)"
},
{
"name": "string.quoted.other.berry",
"match": "\\{\\{[^\\}]*\\}\\}"
},
{
"name": "keyword.other.unit.berry",
"begin": "\\{",
"end": "\\}",
"patterns": [
{
"include": "#keywords"
},
{
"include": "#numbers"
},
{
"include": "#identifier"
},
{
"include": "#operator"
},
{
"include": "#member"
},
{
"include": "#function"
}
]
}
]
}
]
},
"comment-block": {
"name": "comment.berry",
"begin": "\\#\\-",
"end": "\\-#",
"patterns": [{}]
},
"comments": {
"name": "comment.line.berry",
"begin": "\\#",
"end": "\\n",
"patterns": [{}]
},
"keywords": {
"patterns": [{
"name": "keyword.berry",
"match": "\\b(var|static|def|class|true|false|nil|self|super|import|as|_class)\\b"
}]
},
"identifier": {
"patterns": [{
"name": "identifier.berry",
"match": "\\b[_A-Za-z]\\w+\\b"
}]
},
"number": {
"patterns": [{
"name": "constant.numeric.berry",
"match": "0x[a-fA-F0-9]+|\\d+|(\\d+\\.?|\\.\\d)\\d*([eE][+-]?\\d+)?"
}]
},
"operator": {
"patterns": [{
"name": "keyword.operator.berry",
"match": "\\(|\\)|\\[|\\]|\\.|-|\\!|~|\\*|/|%|\\+|&|\\^|\\||<|>|=|:"
}]
},
"member": {
"patterns": [{
"match": "\\.([a-zA-Z_][a-zA-Z0-9_]*)",
"captures": {
"0": {
"name": "entity.other.attribute-name.berry"
}
}
}]
},
"function": {
"patterns": [{
"name": "entity.name.function.berry",
"match": "\\b([a-zA-Z_][a-zA-Z0-9_]*(?=\\s*\\())"
}]
}
},
"scopeName": "source.berry"
}

View File

@ -1,58 +0,0 @@
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "Berry",
"patterns": [
{
"include": "#comments"
},
{
"include": "#keywords"
},
{
"include": "#number"
},
{
"include": "#operator"
},
{
"include": "#entity"
}
],
"repository": {
"comments": {
"name": "comment.line.berry.bytecode",
"begin": "\\--",
"end": "\\n",
"patterns": [{}]
},
"keywords": {
"patterns": [{
"name": "keyword.berry.bytecode",
"match": "or"
}]
},
"number": {
"patterns": [{
"name": "constant.numeric.berry.bytecode",
"match": "\\b((0x)?[0-9]+)\\b"
}]
},
"operator": {
"patterns": [
{
"name": "keyword.operator.berry.bytecode",
"match": "\\(|\\)|:|\\[|\\]|\\||->"
}
]
},
"entity": {
"patterns": [
{
"name": "entity.name.function.berry",
"match": "^\\s*\\w+(?=\\s*(:|->))"
}
]
}
},
"scopeName": "source.berry.bytecode"
}

View File

@ -11,17 +11,8 @@
<Properties> <Properties>
<Property Id="Microsoft.VisualStudio.Code.Engine" Value="^1.15.1" /> <Property Id="Microsoft.VisualStudio.Code.Engine" Value="^1.15.1" />
<Property Id="Microsoft.VisualStudio.Code.ExtensionDependencies" Value="" /> <Property Id="Microsoft.VisualStudio.Code.ExtensionDependencies" Value="" />
<Property Id="Microsoft.VisualStudio.Services.GitHubFlavoredMarkdown" Value="true" /> <Property Id="Microsoft.VisualStudio.Services.GitHubFlavoredMarkdown" Value="true" />
</Properties> </Properties>
</Metadata> </Metadata>
<Installation> <Installation>
<InstallationTarget Id="Microsoft.VisualStudio.Code"/> <InstallationTarget Id="Microsoft.VisualStudio.Code"/>

View File

@ -6,3 +6,5 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
## [Unreleased] ## [Unreleased]
- Initial release - Initial release
- add support for f-strings, `_class` and indent on `do` - add support for f-strings, `_class` and indent on `do`
- add support for multiline f-strings
- remove bytecode

View File

@ -2,7 +2,8 @@
"name": "berry", "name": "berry",
"displayName": "Berry Script Language", "displayName": "Berry Script Language",
"description": "A small embedded script language.", "description": "A small embedded script language.",
"version": "1.1.0", "version": "1.2.0",
"icon": "berry-icon.png",
"publisher": "skiars", "publisher": "skiars",
"engines": { "engines": {
"vscode": "^1.15.1" "vscode": "^1.15.1"
@ -22,16 +23,6 @@
".be" ".be"
], ],
"configuration": "./berry-configuration.json" "configuration": "./berry-configuration.json"
},
{
"id": "berry-bytecode",
"aliases": [
"Berry Bytecode",
"berry bytecode"
],
"extensions": [
"berry.bytecode"
]
} }
], ],
"grammars": [ "grammars": [
@ -39,11 +30,6 @@
"language": "berry", "language": "berry",
"scopeName": "source.berry", "scopeName": "source.berry",
"path": "./syntaxes/berry.json" "path": "./syntaxes/berry.json"
},
{
"language": "berry-bytecode",
"scopeName": "source.berry.bytecode",
"path": "./syntaxes/bytecode.json"
} }
] ]
}, },

View File

@ -0,0 +1,195 @@
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "Berry",
"patterns": [
{
"include": "#controls"
},
{
"include": "#strings"
},
{
"include": "#comment-block"
},
{
"include": "#comments"
},
{
"include": "#keywords"
},
{
"include": "#function"
},
{
"include": "#member"
},
{
"include": "#identifier"
},
{
"include": "#number"
},
{
"include": "#operator"
}
],
"repository": {
"controls": {
"patterns": [{
"name": "keyword.control.berry",
"match": "\\b(if|elif|else|for|while|do|end|break|continue|return|try|except|raise)\\b"
}]
},
"strings": {
"patterns": [
{
"begin": "f(?=[\"'])",
"while": "\\G|^[ \\t]*(?=[\"'])",
"patterns": [{
"name": "string.quoted.other.berry",
"begin": "\"",
"end": "\"",
"patterns": [
{
"name": "constant.character.escape.berry",
"match": "(\\\\x[\\h]{2})|(\\\\[0-7]{3})|(\\\\\\\\)|(\\\\\")|(\\\\')|(\\\\a)|(\\\\b)|(\\\\f)|(\\\\n)|(\\\\r)|(\\\\t)|(\\\\v)"
},
{
"name": "string.quoted.other.berry",
"match": "\\{\\{[^\\}]*\\}\\}"
},
{
"name": "keyword.other.unit.berry",
"begin": "\\{",
"end": "\\}",
"patterns": [
{
"include": "#keywords"
},
{
"include": "#numbers"
},
{
"include": "#identifier"
},
{
"include": "#operator"
},
{
"include": "#member"
},
{
"include": "#function"
}
]
}
]
},
{
"name": "string.quoted.other.berry",
"begin": "'",
"end": "'",
"patterns": [
{
"name": "constant.character.escape.berry",
"match": "(\\\\x[\\h]{2})|(\\\\[0-7]{3})|(\\\\\\\\)|(\\\\\")|(\\\\')|(\\\\a)|(\\\\b)|(\\\\f)|(\\\\n)|(\\\\r)|(\\\\t)|(\\\\v)"
},
{
"name": "string.quoted.other.berry",
"match": "\\{\\{[^\\}]*\\}\\}"
},
{
"name": "keyword.other.unit.berry",
"begin": "\\{",
"end": "\\}",
"patterns": [
{
"include": "#keywords"
},
{
"include": "#numbers"
},
{
"include": "#identifier"
},
{
"include": "#operator"
},
{
"include": "#member"
},
{
"include": "#function"
}
]
}
]
}
]
},
{
"name": "string.quoted.double.berry",
"begin": "(\"|')",
"end": "\\1",
"patterns": [{
"name": "constant.character.escape.berry",
"match": "(\\\\x[\\h]{2})|(\\\\[0-7]{3})|(\\\\\\\\)|(\\\\\")|(\\\\')|(\\\\a)|(\\\\b)|(\\\\f)|(\\\\n)|(\\\\r)|(\\\\t)|(\\\\v)"
}]
}
]
},
"comment-block": {
"name": "comment.berry",
"begin": "\\#\\-",
"end": "\\-#",
"patterns": [{}]
},
"comments": {
"name": "comment.line.berry",
"begin": "\\#",
"end": "\\n",
"patterns": [{}]
},
"keywords": {
"patterns": [{
"name": "keyword.berry",
"match": "\\b(var|static|def|class|true|false|nil|self|super|import|as|_class)\\b"
}]
},
"identifier": {
"patterns": [{
"name": "identifier.berry",
"match": "\\b[_A-Za-z]\\w+\\b"
}]
},
"number": {
"patterns": [{
"name": "constant.numeric.berry",
"match": "0x[a-fA-F0-9]+|\\d+|(\\d+\\.?|\\.\\d)\\d*([eE][+-]?\\d+)?"
}]
},
"operator": {
"patterns": [{
"name": "keyword.operator.berry",
"match": "\\(|\\)|\\[|\\]|\\.|-|\\!|~|\\*|/|%|\\+|&|\\^|\\||<|>|=|:"
}]
},
"member": {
"patterns": [{
"match": "\\.([a-zA-Z_][a-zA-Z0-9_]*)",
"captures": {
"0": {
"name": "entity.other.attribute-name.berry"
}
}
}]
},
"function": {
"patterns": [{
"name": "entity.name.function.berry",
"match": "\\b([a-zA-Z_][a-zA-Z0-9_]*(?=\\s*\\())"
}]
}
},
"scopeName": "source.berry"
}