Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@ jobs:
working-directory: tool
run: npm ci && npm run generate
- name: Check for differences
run: git diff --exit-code -- packages/syntax/lib packages/syntax/NOTICE
run: git diff --exit-code -- packages/syntax_core/lib packages/syntax_core/NOTICE
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ theme.

| Package | What it is |
|---|---|
| [`packages/syntax`](packages/syntax) | Pure Dart, zero dependencies. Contains the tokenizer, themes, HTML/ANSI rendering, diff tools (patch parsing, line diffs, word-level changes), and the renderer-neutral pieces other renderers build on. It runs on the VM, AOT, the web and inside Flutter. |
| [`packages/syntax_core`](packages/syntax_core) | Pure Dart, zero dependencies. Contains the tokenizer, themes, HTML/ANSI rendering, diff tools (patch parsing, line diffs, word-level changes), and the renderer-neutral pieces other renderers build on. It runs on the VM, AOT, the web and inside Flutter. |
| [`packages/syntax_flutter`](packages/syntax_flutter) | Contains `HighlightedCode` (read-only highlighted code), `PatchView` (a highlighted diff or patch, unified or split) and `HighlighterScope`. |
| [`packages/syntax_flutter/example`](packages/syntax_flutter/example) | A read-only code, diff and patch preview with a picker for every bundled language and theme. |
| [`packages/syntax_noir`](packages/syntax_noir) | Terminal widgets on [noir](https://github.com/btwld/noir): a `CodeHighlighter` for noir's `CodeView` and a `PatchView`. Needs Dart 3.10, so it sits outside the workspace. |

Install [`syntax`](https://pub.dev/packages/syntax),
Install [`syntax_core`](https://pub.dev/packages/syntax_core),
[`syntax_flutter`](https://pub.dev/packages/syntax_flutter), and
[`syntax_noir`](https://pub.dev/packages/syntax_noir) from pub.dev (0.0.1).
Renderers paint what the core lays out.
Expand Down Expand Up @@ -64,7 +64,7 @@ grammar.json ──► RuleFactory ──► Grammar.tokenizeLine(line, state)

Shiki, with its Oniguruma WASM engine, is the oracle.

- **Bundled grammars:** `packages/syntax/test/conformance_test.dart` checks
- **Bundled grammars:** `packages/syntax_core/test/conformance_test.dart` checks
18 bundled grammars on 21 samples. Every token's scopes match Shiki
exactly, as does every character's color and font style under three
themes: 84 of 84 checks pass.
Expand Down Expand Up @@ -111,11 +111,11 @@ default, as in VS Code; set `Highlighter.maxLineLength` to change it.
Reproduce with the same input for each:

```bash
dart run packages/syntax/benchmark/tokenize.dart path/to/file.dart
dart run packages/syntax_core/benchmark/tokenize.dart path/to/file.dart
```

```bash
dart compile js -O4 packages/syntax/benchmark/web_bench.dart -o /tmp/syntax_bench.js && node /tmp/syntax_bench.js path/to/file.dart
dart compile js -O4 packages/syntax_core/benchmark/web_bench.dart -o /tmp/syntax_bench.js && node /tmp/syntax_bench.js path/to/file.dart
```

```bash
Expand All @@ -125,7 +125,7 @@ cd tool && npm run bench -- path/to/file.dart
The long-line numbers come from:

```bash
dart run packages/syntax/benchmark/long_line.dart
dart run packages/syntax_core/benchmark/long_line.dart
```

## Development
Expand All @@ -138,7 +138,7 @@ The workspace is `syntax` and `syntax_flutter`, so it resolves with the
Flutter SDK.

```bash
cd packages/syntax && dart test
cd packages/syntax_core && dart test
```

```bash
Expand Down Expand Up @@ -168,11 +168,11 @@ cd tool && npm ci && npm run generate && npm run samples && npm run golden
These tools are for checking regex and tokenizer changes against every
Shiki grammar:

- `packages/syntax/tool/coverage.dart` translates and compiles every
- `packages/syntax_core/tool/coverage.dart` translates and compiles every
pattern in a directory of grammars.
- `packages/syntax/tool/stress.dart`, with `tool/stress.mjs`, compares
- `packages/syntax_core/tool/stress.dart`, with `tool/stress.mjs`, compares
tokens with Shiki for every grammar that has an upstream sample.
- `packages/syntax/tool/git_compare.dart` checks `parsePatch` and
- `packages/syntax_core/tool/git_compare.dart` checks `parsePatch` and
`diffTexts` against `git diff` on random edits.

## Not done yet
Expand All @@ -185,4 +185,4 @@ Shiki grammar:
## License

BSD 3-Clause, see [LICENSE](LICENSE). The bundled grammars and themes keep
their own licenses, listed in [packages/syntax/NOTICE](packages/syntax/NOTICE).
their own licenses, listed in [packages/syntax_core/NOTICE](packages/syntax_core/NOTICE).
3 changes: 0 additions & 3 deletions packages/syntax/CHANGELOG.md

This file was deleted.

File renamed without changes.
3 changes: 3 additions & 0 deletions packages/syntax_core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

See https://github.com/btwld/syntax-dart/releases/tag/syntax_core-v0.0.1
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions packages/syntax/README.md → packages/syntax_core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ web and Flutter.
## Usage

```dart
import 'package:syntax/syntax.dart';
import 'package:syntax/langs/dart.dart';
import 'package:syntax/themes/github_dark.dart';
import 'package:syntax_core/syntax.dart';
import 'package:syntax_core/langs/dart.dart';
import 'package:syntax_core/themes/github_dark.dart';

final highlighter = Highlighter(languages: [dartLanguage]);

Expand Down Expand Up @@ -56,18 +56,18 @@ in one call.

Each grammar and theme is its own library, so unused ones are tree-shaken:

- `package:syntax/langs/<name>.dart`. The bundled languages are:
- `package:syntax_core/langs/<name>.dart`. The bundled languages are:
- css, dart, diff, go, html, javascript, json, jsonc, kotlin, markdown,
python, rust, shellscript, sql, swift, typescript, xml and yaml.
- Markdown highlights fenced code blocks for any of these languages
that you register.
- `package:syntax/themes/<name>.dart`. The bundled themes are:
- `package:syntax_core/themes/<name>.dart`. The bundled themes are:
- github-dark and github-light;
- dark-plus and light-plus;
- one-dark-pro, dracula, nord, monokai and tokyo-night;
- catppuccin (latte and mocha) and vitesse (dark and light);
- min-light and solarized-light.
- `package:syntax/langs/all.dart` and `package:syntax/themes/all.dart` contain
- `package:syntax_core/langs/all.dart` and `package:syntax_core/themes/all.dart` contain
everything.

### Your own grammars and themes
Expand Down Expand Up @@ -136,7 +136,7 @@ Renderers keep their own interaction state and wording; for example,

Names such as `Token`, `Language` and `Grammar` are common. If they
clash with your own, import with a prefix:
`import 'package:syntax/syntax.dart' as syntax;`.
`import 'package:syntax_core/syntax.dart' as syntax;`.

## Regex engine

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Each line repeats a snippet a whole number of times, so every length
// ends the same way: some JavaScript patterns look ahead to the line end.
// dart run benchmark/long_line.dart [lengths...]
import 'package:syntax/langs/javascript.dart';
import 'package:syntax/langs/json.dart';
import 'package:syntax/syntax.dart';
import 'package:syntax_core/langs/javascript.dart';
import 'package:syntax_core/langs/json.dart';
import 'package:syntax_core/syntax.dart';

// Minified JavaScript: functions, arrows, classes, template and regex
// literals, object literals and numbers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// dart compile exe benchmark/tokenize.dart -o /tmp/bench && /tmp/bench <file>
import 'dart:io';

import 'package:syntax/syntax.dart';
import 'package:syntax/langs/dart.dart';
import 'package:syntax/themes/github_dark.dart';
import 'package:syntax_core/syntax.dart';
import 'package:syntax_core/langs/dart.dart';
import 'package:syntax_core/themes/github_dark.dart';

void main(List<String> args) {
final code = File(args.single).readAsStringSync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
// node /tmp/syntax_bench.js path/to/file.dart
import 'dart:js_interop';

import 'package:syntax/langs/dart.dart';
import 'package:syntax/syntax.dart';
import 'package:syntax/themes/github_dark.dart';
import 'package:syntax_core/langs/dart.dart';
import 'package:syntax_core/syntax.dart';
import 'package:syntax_core/themes/github_dark.dart';

@JS('process.argv')
external JSArray<JSString> get _argv;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:syntax/langs/dart.dart';
import 'package:syntax/syntax.dart';
import 'package:syntax/themes/github_dark.dart';
import 'package:syntax_core/langs/dart.dart';
import 'package:syntax_core/syntax.dart';
import 'package:syntax_core/themes/github_dark.dart';

const code = '''
void main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Importing this library pulls in every bundled entry. Import
// individual files instead to keep app size down.
import 'package:syntax/syntax.dart' show Language;
import 'package:syntax_core/syntax.dart' show Language;

import 'css.dart';
import 'dart.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Source: https://github.com/microsoft/vscode/blob/af600487b1e94374d9f48f57cbf2cad24656b07f/extensions/css/syntaxes/css.tmLanguage.json
// License: MIT
// ignore_for_file: prefer_single_quotes, lines_longer_than_80_chars
import 'package:syntax/syntax.dart' show Language;
import 'package:syntax_core/syntax.dart' show Language;

/// CSS (`source.css`).
const cssLanguage = Language(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Source: https://github.com/microsoft/vscode/blob/af600487b1e94374d9f48f57cbf2cad24656b07f/extensions/dart/syntaxes/dart.tmLanguage.json
// License: MIT
// ignore_for_file: prefer_single_quotes, lines_longer_than_80_chars
import 'package:syntax/syntax.dart' show Language;
import 'package:syntax_core/syntax.dart' show Language;

/// Dart (`source.dart`).
const dartLanguage = Language(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Source: https://github.com/microsoft/vscode/blob/4549bd26c7b799284e0ebd8dc1e0310e6a8707a1/extensions/diff/syntaxes/diff.tmLanguage.json
// License: MIT
// ignore_for_file: prefer_single_quotes, lines_longer_than_80_chars
import 'package:syntax/syntax.dart' show Language;
import 'package:syntax_core/syntax.dart' show Language;

/// Diff (`source.diff`).
const diffLanguage = Language(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Source: https://github.com/microsoft/vscode/blob/091ef378baaa141c8bc4bbe9775d4cb3bd655a80/extensions/go/syntaxes/go.tmLanguage.json
// License: MIT
// ignore_for_file: prefer_single_quotes, lines_longer_than_80_chars
import 'package:syntax/syntax.dart' show Language;
import 'package:syntax_core/syntax.dart' show Language;

/// Go (`source.go`).
const goLanguage = Language(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Source: https://github.com/microsoft/vscode/blob/45324363153075dab0482312ae24d8c068d81e4f/extensions/html/syntaxes/html.tmLanguage.json
// License: MIT
// ignore_for_file: prefer_single_quotes, lines_longer_than_80_chars
import 'package:syntax/syntax.dart' show Language;
import 'package:syntax_core/syntax.dart' show Language;

/// HTML (`text.html.basic`).
const htmlLanguage = Language(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Source: https://github.com/microsoft/vscode/blob/210541906e5a96ab39f9c753f921b1bd35f4138b/extensions/javascript/syntaxes/JavaScript.tmLanguage.json
// License: MIT
// ignore_for_file: prefer_single_quotes, lines_longer_than_80_chars
import 'package:syntax/syntax.dart' show Language;
import 'package:syntax_core/syntax.dart' show Language;

/// JavaScript (`source.js`).
const javascriptLanguage = Language(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Source: https://github.com/microsoft/vscode/blob/d6af4893ed9a3545163a4cb748fa5548bd1e51a5/extensions/json/syntaxes/JSON.tmLanguage.json
// License: MIT
// ignore_for_file: prefer_single_quotes, lines_longer_than_80_chars
import 'package:syntax/syntax.dart' show Language;
import 'package:syntax_core/syntax.dart' show Language;

/// JSON (`source.json`).
const jsonLanguage = Language(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Source: https://github.com/microsoft/vscode/blob/0adddd82816db666c52038e8277312dc55da2756/extensions/json/syntaxes/JSONC.tmLanguage.json
// License: MIT
// ignore_for_file: prefer_single_quotes, lines_longer_than_80_chars
import 'package:syntax/syntax.dart' show Language;
import 'package:syntax_core/syntax.dart' show Language;

/// JSON with Comments (`source.json.comments`).
const jsoncLanguage = Language(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Source: https://github.com/fwcd/vscode-kotlin/blob/626e20d5c51a4379c4c0ee293aa89e58b5232aec/syntaxes/kotlin.tmLanguage.json
// License: MIT
// ignore_for_file: prefer_single_quotes, lines_longer_than_80_chars
import 'package:syntax/syntax.dart' show Language;
import 'package:syntax_core/syntax.dart' show Language;

/// Kotlin (`source.kotlin`).
const kotlinLanguage = Language(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Source: https://github.com/microsoft/vscode/blob/6d8ab9737d58fc5eaf07e2ae6553b38183a5de47/extensions/markdown-basics/syntaxes/markdown.tmLanguage.json
// License: MIT
// ignore_for_file: prefer_single_quotes, lines_longer_than_80_chars
import 'package:syntax/syntax.dart' show Language;
import 'package:syntax_core/syntax.dart' show Language;

/// Markdown (`text.html.markdown`).
const markdownLanguage = Language(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Source: https://github.com/microsoft/vscode/blob/cf4c9e469d521fa5f33353737e8157eb0789ad02/extensions/python/syntaxes/MagicPython.tmLanguage.json
// License: MIT
// ignore_for_file: prefer_single_quotes, lines_longer_than_80_chars
import 'package:syntax/syntax.dart' show Language;
import 'package:syntax_core/syntax.dart' show Language;

/// Python (`source.python`).
const pythonLanguage = Language(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Source: https://github.com/microsoft/vscode/blob/af600487b1e94374d9f48f57cbf2cad24656b07f/extensions/rust/syntaxes/rust.tmLanguage.json
// License: MIT
// ignore_for_file: prefer_single_quotes, lines_longer_than_80_chars
import 'package:syntax/syntax.dart' show Language;
import 'package:syntax_core/syntax.dart' show Language;

/// Rust (`source.rust`).
const rustLanguage = Language(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Source: https://github.com/microsoft/vscode/blob/9473445f7d3dcb5c579f42ece8b6c18c43c63ed3/extensions/shellscript/syntaxes/shell-unix-bash.tmLanguage.json
// License: MIT
// ignore_for_file: prefer_single_quotes, lines_longer_than_80_chars
import 'package:syntax/syntax.dart' show Language;
import 'package:syntax_core/syntax.dart' show Language;

/// Shell (`source.shell`).
const shellscriptLanguage = Language(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Source: https://github.com/microsoft/vscode/blob/af600487b1e94374d9f48f57cbf2cad24656b07f/extensions/sql/syntaxes/sql.tmLanguage.json
// License: MIT
// ignore_for_file: prefer_single_quotes, lines_longer_than_80_chars
import 'package:syntax/syntax.dart' show Language;
import 'package:syntax_core/syntax.dart' show Language;

/// SQL (`source.sql`).
const sqlLanguage = Language(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Source: https://github.com/jtbandes/swift-tmlanguage/blob/2be007b6bc88e54a0edfd3c313ff31276edc923d/Swift.tmLanguage.yaml
// License: MIT
// ignore_for_file: prefer_single_quotes, lines_longer_than_80_chars
import 'package:syntax/syntax.dart' show Language;
import 'package:syntax_core/syntax.dart' show Language;

/// Swift (`source.swift`).
const swiftLanguage = Language(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Source: https://github.com/microsoft/vscode/blob/210541906e5a96ab39f9c753f921b1bd35f4138b/extensions/typescript-basics/syntaxes/TypeScript.tmLanguage.json
// License: MIT
// ignore_for_file: prefer_single_quotes, lines_longer_than_80_chars
import 'package:syntax/syntax.dart' show Language;
import 'package:syntax_core/syntax.dart' show Language;

/// TypeScript (`source.ts`).
const typescriptLanguage = Language(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Source: https://github.com/microsoft/vscode/blob/10a1d2a50a2882f5ae85bdb51eb04d3064fb9de9/extensions/xml/syntaxes/xml.tmLanguage.json
// License: MIT
// ignore_for_file: prefer_single_quotes, lines_longer_than_80_chars
import 'package:syntax/syntax.dart' show Language;
import 'package:syntax_core/syntax.dart' show Language;

/// XML (`text.xml`).
const xmlLanguage = Language(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// GENERATED by tool/generate.mjs. Do not edit.
// Source: https://github.com/textmate/yaml.tmbundle/blob/e54ceae3b719506dba7e481a77cea4a8b576ae46/Syntaxes/YAML.tmLanguage
// ignore_for_file: prefer_single_quotes, lines_longer_than_80_chars
import 'package:syntax/syntax.dart' show Language;
import 'package:syntax_core/syntax.dart' show Language;

/// YAML (`source.yaml`).
const yamlLanguage = Language(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/// TextMate-grammar syntax highlighting in pure Dart.
///
/// ```dart
/// import 'package:syntax/syntax.dart';
/// import 'package:syntax/langs/dart.dart';
/// import 'package:syntax/themes/github_dark.dart';
/// import 'package:syntax_core/syntax.dart';
/// import 'package:syntax_core/langs/dart.dart';
/// import 'package:syntax_core/themes/github_dark.dart';
///
/// final highlighter = Highlighter(languages: [dartLanguage]);
/// print(highlighter.toAnsi(code, language: 'dart', theme: githubDarkTheme));
/// ```
///
/// Bundled grammars live under `package:syntax/langs/` and themes under
/// `package:syntax/themes/`. Import only the ones you need, so the rest are
/// Bundled grammars live under `package:syntax_core/langs/` and themes under
/// `package:syntax_core/themes/`. Import only the ones you need, so the rest are
/// tree-shaken. Any VS Code grammar or theme JSON can also be loaded at
/// runtime with [Language.fromJson] and [SyntaxTheme.fromJson].
library;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Importing this library pulls in every bundled entry. Import
// individual files instead to keep app size down.
import 'package:syntax/syntax.dart' show SyntaxTheme;
import 'package:syntax_core/syntax.dart' show SyntaxTheme;

import 'catppuccin_latte.dart';
import 'catppuccin_mocha.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Source: https://github.com/catppuccin/vscode/blob/befc9e6fc41980f4241408f7049755d47c06ff45/packages/catppuccin-vsc/package.json
// License: MIT
// ignore_for_file: prefer_single_quotes, lines_longer_than_80_chars
import 'package:syntax/syntax.dart' show SyntaxTheme;
import 'package:syntax_core/syntax.dart' show SyntaxTheme;

/// Catppuccin Latte.
const catppuccinLatteTheme = SyntaxTheme(
Expand Down
Loading
Loading