1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-03-17 20:58:08 +02:00

Implement 1S:Enterprise (#545)

This commit is contained in:
Dmitry Titov 2021-09-04 07:20:45 +07:00 committed by GitHub
parent 4436c497ee
commit 02951cec42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 225 additions and 1 deletions

View File

@ -50,7 +50,7 @@ K | Kotlin
L | Lighttpd configuration file, LLVM, Lua
M | Mako, markdown, Mason, Mathematica, Matlab, MiniZinc, MLIR, Modula-2, MonkeyC, MorrowindScript, Myghty, MySQL
N | NASM, Newspeak, Nginx configuration file, Nim, Nix
O | Objective-C, OCaml, Octave, OpenSCAD, Org Mode
O | Objective-C, OCaml, Octave, OnesEnterprise, OpenSCAD, Org Mode
P | PacmanConf, Perl, PHP, PHTML, Pig, PkgConfig, PL/pgSQL, plaintext, Pony, PostgreSQL SQL dialect, PostScript, POVRay, PowerShell, Prolog, PromQL, Protocol Buffer, Puppet, Python 2, Python
Q | QBasic
R | R, Racket, Ragel, Raku, react, ReasonML, reg, reStructuredText, Rexx, Ruby, Rust

View File

@ -0,0 +1,50 @@
package o
import (
. "github.com/alecthomas/chroma" // nolint
"github.com/alecthomas/chroma/lexers/internal"
)
// 1S:Enterprise lexer.
var OnesEnterprise = internal.Register(MustNewLazyLexer(
&Config{
Name: "OnesEnterprise",
Aliases: []string{"ones", "onesenterprise", "1S", "1S:Enterprise"},
Filenames: []string{"*.EPF", "*.epf", "*.ERF", "*.erf"},
MimeTypes: []string{"application/octet-stream"},
CaseInsensitive: true,
},
onesRules,
))
func onesRules() Rules {
return Rules{
"root": {
{`\n`, Text, nil},
{`\s+`, Text, nil},
{`\\\n`, Text, nil},
{`[^\S\n]+`, Text, nil},
{`//(.*?)\n`, Comment, nil},
{`(#область|#region|#конецобласти|#endregion|#если|#if|#иначе|#else|#конецесли|#endif).*`, CommentPreproc, nil},
{`(&наклиенте|&atclient|&насервере|&atserver|&насерверебезконтекста|&atservernocontext|&наклиентенасерверебезконтекста|&atclientatservernocontext).*`, CommentPreproc, nil},
{`(>=|<=|<>|\+|-|=|>|<|\*|/|%)`, Operator, nil},
{`(;|,|\)|\(|\.)`, Punctuation, nil},
{Words(``, `\b`, `истина`, `true`, `ложь`, `false`, `и`, `and`, `или`, `or`, `не`, `not`), Operator, nil},
{Words(``, `\b`, `если`, `if`, `тогда`, `then`, `иначе`, `else`, `иначеесли`, `elsif`, `конецесли`, `endif`), Operator, nil},
{Words(``, `\b`, `для`, `for`, `каждого`, `each`, `из`, `in`, `цикл`, `do`, `пока`, `while`, `конеццикла`, `enddo`, `по`, `to`), Operator, nil},
{Words(``, `\b`, `прервать`, `break`, `продолжить`, `continue`, `возврат`, `return`, `перейти`, `goto`), Operator, nil},
{Words(``, `\b`, `процедура`, `procedure`, `конецпроцедуры`, `endprocedure`, `функция`, `function`, `конецфункции`, `endfunction`), Keyword, nil},
{Words(``, `\b`, `новый`, `new`, `знач`, `val`, `экспорт`, `export`, `перем`, `var`), Keyword, nil},
{Words(``, `\b`, `попытка`, `try`, `исключение`, `except`, `вызватьисключение`, `raise`, `конецпопытки`, `endtry`), Keyword, nil},
{Words(``, `\b`, `выполнить`, `execute`, `вычислить`, `eval`), Keyword, nil},
{`"`, LiteralString, Push("string")},
{`[_а-яА-Я0-9][а-яА-Я0-9]*`, Name, nil},
{`[_\w][\w]*`, Name, nil},
},
"string": {
{`""`, LiteralString, nil},
{`"C?`, LiteralString, Pop(1)},
{`[^"]+`, LiteralString, nil},
},
}
}

26
lexers/testdata/onesenterprise.actual vendored Normal file
View File

@ -0,0 +1,26 @@
#Область СлужебныйПрограммныйИнтерфейс
&НаСервере
Функция Создать(ИмяФайла) Экспорт
//Создает новый архив
Инфо = Новый Файл(ИмяФайла);
Если Инфо.Существует() Тогда
УдалитьФайлы(ИмяФайла);
КонецЕсли;
Архив = Новый Структура;
Архив.Вставить("Поток", ФайловыеПотоки.ОткрытьДляЗаписи(ИмяФайла));
Архив.Вставить("Файлы", Новый Массив);
Архив.Вставить("РазмерКаталога", 0);
Если Архив.РазмерКаталога > 0 Или Архив.Файлы.Количество() <> 0 Тогда
Возврат Неопределено;
КонецЕсли;
Возврат Архив;
КонецФункции
#КонецОбласти

131
lexers/testdata/onesenterprise.expected vendored Normal file
View File

@ -0,0 +1,131 @@
[
{"type":"CommentPreproc","value":"#Область СлужебныйПрограммныйИнтерфейс"},
{"type":"Text","value":"\n\n"},
{"type":"CommentPreproc","value":"\u0026НаСервере"},
{"type":"Text","value":"\n"},
{"type":"Keyword","value":"Функция"},
{"type":"Text","value":" "},
{"type":"Name","value":"Создать"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"ИмяФайла"},
{"type":"Punctuation","value":")"},
{"type":"Text","value":" "},
{"type":"Keyword","value":"Экспорт"},
{"type":"Text","value":"\n\t\n\t"},
{"type":"Comment","value":"//Создает новый архив\n"},
{"type":"Text","value":"\n\t"},
{"type":"Name","value":"Инфо"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Keyword","value":"Новый"},
{"type":"Text","value":" "},
{"type":"Name","value":"Файл"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"ИмяФайла"},
{"type":"Punctuation","value":");"},
{"type":"Text","value":"\n\t"},
{"type":"Operator","value":"Если"},
{"type":"Text","value":" "},
{"type":"Name","value":"Инфо"},
{"type":"Punctuation","value":"."},
{"type":"Name","value":"Существует"},
{"type":"Punctuation","value":"()"},
{"type":"Text","value":" "},
{"type":"Operator","value":"Тогда"},
{"type":"Text","value":"\n\t\t"},
{"type":"Name","value":"УдалитьФайлы"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"ИмяФайла"},
{"type":"Punctuation","value":");"},
{"type":"Text","value":"\n\t"},
{"type":"Operator","value":"КонецЕсли"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n\t\n\t"},
{"type":"Name","value":"Архив"},
{"type":"Text","value":" "},
{"type":"Operator","value":"="},
{"type":"Text","value":" "},
{"type":"Keyword","value":"Новый"},
{"type":"Text","value":" "},
{"type":"Name","value":"Структура"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n\t"},
{"type":"Name","value":"Архив"},
{"type":"Punctuation","value":"."},
{"type":"Name","value":"Вставить"},
{"type":"Punctuation","value":"("},
{"type":"LiteralString","value":"\"Поток\""},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"ФайловыеПотоки"},
{"type":"Punctuation","value":"."},
{"type":"Name","value":"ОткрытьДляЗаписи"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"ИмяФайла"},
{"type":"Punctuation","value":"));"},
{"type":"Text","value":"\n\t"},
{"type":"Name","value":"Архив"},
{"type":"Punctuation","value":"."},
{"type":"Name","value":"Вставить"},
{"type":"Punctuation","value":"("},
{"type":"LiteralString","value":"\"Файлы\""},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Keyword","value":"Новый"},
{"type":"Text","value":" "},
{"type":"Name","value":"Массив"},
{"type":"Punctuation","value":");"},
{"type":"Text","value":"\n\t"},
{"type":"Name","value":"Архив"},
{"type":"Punctuation","value":"."},
{"type":"Name","value":"Вставить"},
{"type":"Punctuation","value":"("},
{"type":"LiteralString","value":"\"РазмерКаталога\""},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"Name","value":"0"},
{"type":"Punctuation","value":");"},
{"type":"Text","value":"\n\n\t"},
{"type":"Operator","value":"Если"},
{"type":"Text","value":" "},
{"type":"Name","value":"Архив"},
{"type":"Punctuation","value":"."},
{"type":"Name","value":"РазмерКаталога"},
{"type":"Text","value":" "},
{"type":"Operator","value":"\u003e"},
{"type":"Text","value":" "},
{"type":"Name","value":"0"},
{"type":"Text","value":" "},
{"type":"Operator","value":"Или"},
{"type":"Text","value":" "},
{"type":"Name","value":"Архив"},
{"type":"Punctuation","value":"."},
{"type":"Name","value":"Файлы"},
{"type":"Punctuation","value":"."},
{"type":"Name","value":"Количество"},
{"type":"Punctuation","value":"()"},
{"type":"Text","value":" "},
{"type":"Operator","value":"\u003c\u003e"},
{"type":"Text","value":" "},
{"type":"Name","value":"0"},
{"type":"Text","value":" "},
{"type":"Operator","value":"Тогда"},
{"type":"Text","value":"\n\t\t"},
{"type":"Operator","value":"Возврат"},
{"type":"Text","value":" "},
{"type":"Name","value":"Неопределено"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n\t"},
{"type":"Operator","value":"КонецЕсли"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n\t\n\t"},
{"type":"Operator","value":"Возврат"},
{"type":"Text","value":" "},
{"type":"Name","value":"Архив"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n\t\n"},
{"type":"Keyword","value":"КонецФункции"},
{"type":"Text","value":"\n\n"},
{"type":"CommentPreproc","value":"#КонецОбласти"}
]

17
styles/onesenterprise.go Normal file
View File

@ -0,0 +1,17 @@
package styles
import (
"github.com/alecthomas/chroma"
)
// 1S:Designer color palette
var OnesEnterprise = Register(chroma.MustNewStyle("onesenterprise", chroma.StyleEntries{
chroma.Text: "#000000",
chroma.Comment: "#008000",
chroma.CommentPreproc: "#963200",
chroma.Operator: "#FF0000",
chroma.Keyword: "#FF0000",
chroma.Punctuation: "#FF0000",
chroma.LiteralString: "#000000",
chroma.Name: "#0000FF",
}))