diff --git a/tests/typ/full/coma.typ b/tests/typ/full/coma.typ index 03f6dcc31..4779c2c12 100644 --- a/tests/typ/full/coma.typ +++ b/tests/typ/full/coma.typ @@ -22,7 +22,7 @@ Dr. Max Mustermann \ Ola Nordmann, John Doe ] -#align(right, box([*WiSe 2019/2020* \ Woche 3])) +#align(right, box[*WiSe 2019/2020* \ Woche 3]) // Adds vertical spacing. #v(6mm) diff --git a/tools/support/README.md b/tools/support/README.md new file mode 100644 index 000000000..68a98f96e --- /dev/null +++ b/tools/support/README.md @@ -0,0 +1,4 @@ +# Language support + +This VS Code extension provides language support for Typst. It contains a syntax +definition and a language configuration for comment toggling, autoclosing etc. diff --git a/tools/support/config.json b/tools/support/config.json new file mode 100644 index 000000000..7ad0f437f --- /dev/null +++ b/tools/support/config.json @@ -0,0 +1,29 @@ +{ + "comments": { + "lineComment": "//", + "blockComment": ["/*", "*/"] + }, + "brackets": [ + ["[", "]"], + ["{", "}"], + ["(", ")"] + ], + "autoClosingPairs": [ + { "open": "[", "close": "]" }, + { "open": "{", "close": "}" }, + { "open": "(", "close": ")" }, + { "open": "\"", "close": "\"", "notIn": ["string"] }, + { "open": "$", "close": "$", "notIn": ["string"] } + ], + "autoCloseBefore": "$ \n\t", + "surroundingPairs": [ + ["[", "]"], + ["{", "}"], + ["(", ")"], + ["\"", "\""], + ["*", "*"], + ["_", "_"], + ["`", "`"], + ["$", "$"] + ] +} diff --git a/tools/support/package.json b/tools/support/package.json new file mode 100644 index 000000000..c28b691b3 --- /dev/null +++ b/tools/support/package.json @@ -0,0 +1,29 @@ +{ + "name": "typst", + "displayName": "Typst", + "description": "Typst Language Support.", + "version": "0.0.1", + "engines": { + "vscode": "^1.53.0" + }, + "categories": [ + "Programming Languages" + ], + "contributes": { + "languages": [ + { + "id": "typst", + "aliases": ["Typst", "typst"], + "extensions": [".typ"], + "configuration": "./config.json" + } + ], + "grammars": [ + { + "language": "typst", + "scopeName": "source.typst", + "path": "./typst.tmLanguage.json" + } + ] + } +} diff --git a/tools/support/typst.tmLanguage.json b/tools/support/typst.tmLanguage.json new file mode 100644 index 000000000..1f9a08971 --- /dev/null +++ b/tools/support/typst.tmLanguage.json @@ -0,0 +1,332 @@ +{ + "name": "typst", + "patterns": [ + { "include": "#markup" } + ], + "repository": { + "common": { + "patterns": [ + { + "name": "comment.line.double-slash.typst", + "begin": "//", + "end": "\n", + "beginCaptures": { "0": { "name": "punctuation.definition.comment.typst" } } + }, + { + "name": "comment.block.typst", + "begin": "/\\*", + "end": "\\*/", + "captures": { "0": { "name": "punctuation.definition.comment.typst" } }, + "patterns": [{ "include": "$self" }] + }, + { + "name": "meta.block.typst", + "begin": "{", + "end": "}", + "captures": { "0": { "name": "punctuation.definition.block.typst" } }, + "patterns": [{ "include": "#code" }] + }, + { + "name": "meta.template.typst", + "begin": "\\[", + "end": "\\]", + "captures": { "0": { "name": "punctuation.definition.template.typst" } }, + "patterns": [{ "include": "#markup" }] + } + ] + }, + "markup": { + "patterns": [ + { "include": "#common" }, + { + "name": "constant.character.escape.content.typst", + "match": "\\\\([\\\\/\\[\\]{}#*_=~`$-.]|u\\{[0-9a-zA-Z]*\\}?)" + }, + { + "name": "markup.bold.typst", + "begin": "\\*", + "end": "\\*|(?=\\])", + "captures": { "0": { "name": "punctuation.definition.bold.typst" } }, + "patterns": [{ "include": "#markup" }] + }, + { + "name": "markup.italic.typst", + "begin": "_", + "end": "_|(?=\\])", + "captures": { "0": { "name": "punctuation.definition.italic.typst" } }, + "patterns": [{ "include": "#markup" }] + }, + { + "name": "punctuation.definition.linebreak.typst", + "match": "\\\\" + }, + { + "name": "punctuation.definition.em-dash.typst", + "match": "---" + }, + { + "name": "punctuation.definition.en-dash.typst", + "match": "--" + }, + { + "name": "punctuation.definition.nonbreaking-space.typst", + "match": "~" + }, + { + "name": "markup.heading.typst", + "contentName": "entity.name.section.typst", + "begin": "^\\s*={1,6}", + "end": "\n", + "beginCaptures": { "0": { "name": "punctuation.definition.heading.typst" } }, + "patterns": [{ "include": "#markup" }] + }, + { + "name": "punctuation.definition.list.unnumbered.typst", + "match": "^\\s*-" + }, + { + "name": "punctuation.definition.list.numbered.typst", + "match": "^\\s*[0-9]*\\." + }, + { + "name": "string.other.math.block.typst", + "begin": "\\$\\[", + "end": "\\]\\$", + "captures": { "0": { "name": "punctuation.defintion.string.math.typst" } } + }, + { + "name": "string.other.math.typst", + "begin": "\\$", + "end": "\\$", + "captures": { "0": { "name": "punctuation.defintion.string.math.typst" } } + }, + { + "name": "markup.raw.block.typst", + "begin": "`{3,}", + "end": "\\0", + "captures": { "0": { "name": "punctuation.definition.raw.typst" } } + }, + { + "name": "markup.raw.inline.typst", + "begin": "`", + "end": "`", + "captures": { "0": { "name": "punctuation.definition.raw.typst" } } + }, + { + "name": "keyword.control.typst", + "match": "(#)(break|continue|return)", + "captures": { "1": { "name": "punctuation.definition.keyword.typst" } } + }, + { + "name": "keyword.other.typst", + "match": "(#)from", + "captures": { "1": { "name": "punctuation.definition.keyword.typst" } } + }, + { + "begin": "(#)pub", + "end": "\n|(;)|(?=])|(?<=}|])", + "beginCaptures": { + "0": { "name": "keyword.other.typst" }, + "1": { "name": "punctuation.definition.keyword.typst" } + }, + "endCaptures": { "1": { "name": "punctuation.terminator.statement.typst" } }, + "patterns": [{ "include": "#code" }] + }, + { + "begin": "(#)let", + "end": "\n|;|(?=])|(?<=}|])", + "beginCaptures": { + "0": { "name": "keyword.other.typst" }, + "1": { "name": "punctuation.definition.keyword.typst" } + }, + "endCaptures": { "1": { "name": "punctuation.terminator.statement.typst" } }, + "patterns": [{ "include": "#code" }] + }, + { + "begin": "(#)if", + "end": "\n|(?=])|(?<=}|])", + "beginCaptures": { + "0": { "name": "keyword.control.conditional.typst" }, + "1": { "name": "punctuation.definition.keyword.typst" } + }, + "patterns": [{ "include": "#code" }] + }, + { + "begin": "(#)else", + "end": "\n|(?=])|(?<=}|])", + "beginCaptures": { + "0": { "name": "keyword.control.conditional.typst" }, + "1": { "name": "punctuation.definition.keyword.typst" } + }, + "patterns": [{ "include": "#code" }] + }, + { + "begin": "(#)for", + "end": "\n|(?=])|(?<=}|])", + "beginCaptures": { + "0": { "name": "keyword.control.typst" }, + "1": { "name": "punctuation.definition.keyword.typst" } + }, + "patterns": [{ "include": "#code" }] + }, + { + "begin": "(#)while", + "end": "\n|(?=])|(?<=}|])", + "beginCaptures": { + "0": { "name": "keyword.control.typst" }, + "1": { "name": "punctuation.definition.keyword.typst" } + }, + "patterns": [{ "include": "#code" }] + }, + { + "begin": "(#)import", + "end": "\n|(?=])", + "beginCaptures": { + "0": { "name": "keyword.control.import.typst" }, + "1": { "name": "punctuation.definition.keyword.typst" } + }, + "patterns": [{ "include": "#code" }] + }, + { + "comment": "Function name", + "name": "entity.name.function.typst", + "match": "((#)[[:alpha:]_][[:alnum:]_-]*)(?=\\[|\\()", + "captures": { "2": { "name": "punctuation.definition.function.typst" } } + }, + { + "comment": "Function arguments", + "begin": "(?<=#[[:alpha:]_][[:alnum:]_-]*)\\(", + "end": "\\)", + "captures": { "3": { "name": "punctuation.definition.group.typst" } }, + "patterns": [{ "include": "#arguments" }] + }, + { + "name": "variable.interpolated.typst", + "match": "(#)[[:alpha:]_][[:alnum:]_-]*", + "captures": { "1": { "name": "punctuation.definition.variable.typst" } } + } + ] + }, + "code": { + "patterns": [ + { "include": "#common" }, + { + "name": "meta.group.typst", + "begin": "\\(", + "end": "\\)|(?=;)", + "captures": { "0": { "name": "punctuation.definition.group.typst" } }, + "patterns": [{ "include": "#code" }] + }, + { + "name": "punctuation.separator.colon.typst", + "match": ":" + }, + { + "name": "punctuation.separator.comma.typst", + "match": "," + }, + { + "name": "keyword.operator.typst", + "match": "=>|\\.\\." + }, + { + "name": "keyword.operator.relational.typst", + "match": "==|!=|<=|<|>=|>" + }, + { + "name": "keyword.operator.assignment.typst", + "match": "\\+=|-=|\\*=|/=|=" + }, + { + "name": "keyword.operator.arithmetic.typst", + "match": "\\+|\\*|/|(?