mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-07-05 07:42:29 +00:00
Compare commits
1 Commits
v0.6.4
...
heuristics
Author | SHA1 | Date | |
---|---|---|---|
72afec773e |
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,4 +9,3 @@ shard.lock
|
|||||||
.vscode/
|
.vscode/
|
||||||
.crystal/
|
.crystal/
|
||||||
venv/
|
venv/
|
||||||
.croupier
|
|
||||||
|
3
.md.rb
3
.md.rb
@ -1,3 +0,0 @@
|
|||||||
exclude_rule 'MD033' # Inline HTML
|
|
||||||
exclude_rule 'MD005' # 3-space indent for lists
|
|
||||||
exclude_rule 'MD024' # Repeated headings
|
|
@ -1,35 +0,0 @@
|
|||||||
# See https://pre-commit.com for more information
|
|
||||||
# See https://pre-commit.com/hooks.html for more hooks
|
|
||||||
|
|
||||||
repos:
|
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
||||||
rev: v4.6.0
|
|
||||||
hooks:
|
|
||||||
- id: trailing-whitespace
|
|
||||||
- id: end-of-file-fixer
|
|
||||||
- id: check-yaml
|
|
||||||
- id: check-added-large-files
|
|
||||||
- id: check-merge-conflict
|
|
||||||
- repo: https://github.com/jumanjihouse/pre-commit-hooks
|
|
||||||
rev: 3.0.0
|
|
||||||
hooks:
|
|
||||||
- id: shellcheck
|
|
||||||
- id: markdownlint
|
|
||||||
exclude: '^content'
|
|
||||||
- repo: https://github.com/mrtazz/checkmake
|
|
||||||
rev: 0.2.2
|
|
||||||
hooks:
|
|
||||||
- id: checkmake
|
|
||||||
exclude: lexers/makefile.xml
|
|
||||||
- repo: https://github.com/python-jsonschema/check-jsonschema
|
|
||||||
rev: 0.29.2
|
|
||||||
hooks:
|
|
||||||
- id: check-github-workflows
|
|
||||||
- repo: https://github.com/commitizen-tools/commitizen
|
|
||||||
rev: v3.29.0 # automatically updated by Commitizen
|
|
||||||
hooks:
|
|
||||||
- id: commitizen
|
|
||||||
- id: commitizen-branch
|
|
||||||
stages:
|
|
||||||
- post-commit
|
|
||||||
- push
|
|
41
CHANGELOG.md
41
CHANGELOG.md
@ -1,41 +0,0 @@
|
|||||||
# Changelog
|
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
|
||||||
|
|
||||||
## [0.6.4] - 2024-08-28
|
|
||||||
|
|
||||||
### 🐛 Bug Fixes
|
|
||||||
|
|
||||||
- Ameba
|
|
||||||
- Variable bame in Hacefile
|
|
||||||
|
|
||||||
### 📚 Documentation
|
|
||||||
|
|
||||||
- Mention AUR package
|
|
||||||
|
|
||||||
### ⚙️ Miscellaneous Tasks
|
|
||||||
|
|
||||||
- Pre-commit hooks
|
|
||||||
- Git-cliff config
|
|
||||||
- Started changelog
|
|
||||||
- Force conventional commit messages
|
|
||||||
- Force conventional commit messages
|
|
||||||
- Updated pre-commit
|
|
||||||
|
|
||||||
### Build
|
|
||||||
|
|
||||||
- Switch from Makefile to Hacefile
|
|
||||||
- Added do_release script
|
|
||||||
- Fix markdown check
|
|
||||||
|
|
||||||
### Bump
|
|
||||||
|
|
||||||
- Release v0.6.4
|
|
||||||
|
|
||||||
## [0.6.1] - 2024-08-25
|
|
||||||
|
|
||||||
### 📚 Documentation
|
|
||||||
|
|
||||||
- Improve readme and help message
|
|
||||||
|
|
||||||
<!-- generated by git-cliff -->
|
|
115
Hacefile.yml
115
Hacefile.yml
@ -1,115 +0,0 @@
|
|||||||
variables:
|
|
||||||
FLAGS: "-d --error-trace"
|
|
||||||
NAME: "tartrazine"
|
|
||||||
|
|
||||||
tasks:
|
|
||||||
build:
|
|
||||||
default: true
|
|
||||||
dependencies:
|
|
||||||
- src
|
|
||||||
- shard.lock
|
|
||||||
- shard.yml
|
|
||||||
- Hacefile.yml
|
|
||||||
- lexers/*xml
|
|
||||||
- styles/*xml
|
|
||||||
outputs:
|
|
||||||
- bin/{{NAME}}
|
|
||||||
commands: |
|
|
||||||
shards build {{FLAGS}}
|
|
||||||
|
|
||||||
get-deps:
|
|
||||||
dependencies:
|
|
||||||
- shard.yml
|
|
||||||
outputs:
|
|
||||||
- shard.lock
|
|
||||||
commands: |
|
|
||||||
shards install
|
|
||||||
|
|
||||||
build-release:
|
|
||||||
phony: true
|
|
||||||
always_run: true
|
|
||||||
commands: |
|
|
||||||
hace build FLAGS="--release"
|
|
||||||
|
|
||||||
install:
|
|
||||||
phony: true
|
|
||||||
always_run: true
|
|
||||||
dependencies:
|
|
||||||
- bin/hace
|
|
||||||
commands: |
|
|
||||||
rm ${HOME}/.local/bin/{{NAME}}
|
|
||||||
cp bin/hace ${HOME}/.local/bin/{{NAME}}
|
|
||||||
|
|
||||||
static:
|
|
||||||
outputs:
|
|
||||||
- bin/{{NAME}}-static-linux-amd64
|
|
||||||
- bin/{{NAME}}-static-linux-arm64
|
|
||||||
commands: |
|
|
||||||
hace clean
|
|
||||||
./build_static.sh
|
|
||||||
|
|
||||||
test:
|
|
||||||
dependencies:
|
|
||||||
- src
|
|
||||||
- spec
|
|
||||||
- shard.lock
|
|
||||||
- shard.yml
|
|
||||||
commands: |
|
|
||||||
crystal spec -v --error-trace
|
|
||||||
phony: true
|
|
||||||
always_run: true
|
|
||||||
|
|
||||||
lint:
|
|
||||||
dependencies:
|
|
||||||
- src
|
|
||||||
- spec
|
|
||||||
- shard.lock
|
|
||||||
- shard.yml
|
|
||||||
commands: |
|
|
||||||
crystal tool format src/*.cr spec/*.cr
|
|
||||||
ameba --fix
|
|
||||||
always_run: true
|
|
||||||
phony: true
|
|
||||||
|
|
||||||
docs:
|
|
||||||
dependencies:
|
|
||||||
- src
|
|
||||||
- shard.lock
|
|
||||||
- shard.yml
|
|
||||||
- README.md
|
|
||||||
commands: |
|
|
||||||
crystal docs
|
|
||||||
outputs:
|
|
||||||
- docs/index.html
|
|
||||||
|
|
||||||
pre-commit:
|
|
||||||
default: true
|
|
||||||
outputs:
|
|
||||||
- .git/hooks/commit-msg
|
|
||||||
- .git/hooks/pre-commit
|
|
||||||
dependencies:
|
|
||||||
- .pre-commit-config.yaml
|
|
||||||
commands: |
|
|
||||||
pre-commit install --hook-type commit-msg
|
|
||||||
pre-commit install
|
|
||||||
|
|
||||||
clean:
|
|
||||||
phony: true
|
|
||||||
always_run: true
|
|
||||||
commands: |
|
|
||||||
rm -rf shard.lock bin lib
|
|
||||||
|
|
||||||
coverage:
|
|
||||||
dependencies:
|
|
||||||
- src
|
|
||||||
- spec
|
|
||||||
- shard.lock
|
|
||||||
- shard.yml
|
|
||||||
commands: |
|
|
||||||
shards install
|
|
||||||
crystal build -o bin/run_tests src/run_tests.cr
|
|
||||||
rm -rf coverage/
|
|
||||||
mkdir coverage
|
|
||||||
kcov --clean --include-path=./src ${PWD}/coverage ./bin/run_tests
|
|
||||||
outputs:
|
|
||||||
- coverage/index.html
|
|
7
Makefile
Normal file
7
Makefile
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
build: $(wildcard src/**/*.cr) $(wildcard lexers/*xml) $(wildcard styles/*xml) shard.yml
|
||||||
|
shards build -Dstrict_multi_assign -Dno_number_autocast -d --error-trace
|
||||||
|
release: $(wildcard src/**/*.cr) $(wildcard lexers/*xml) $(wildcard styles/*xml) shard.yml
|
||||||
|
shards build --release
|
||||||
|
static: $(wildcard src/**/*.cr) $(wildcard lexers/*xml) $(wildcard styles/*xml) shard.yml
|
||||||
|
shards build --release --static
|
||||||
|
strip bin/tartrazine
|
69
README.md
69
README.md
@ -2,22 +2,44 @@
|
|||||||
|
|
||||||
Tartrazine is a library to syntax-highlight code. It is
|
Tartrazine is a library to syntax-highlight code. It is
|
||||||
a port of [Pygments](https://pygments.org/) to
|
a port of [Pygments](https://pygments.org/) to
|
||||||
[Crystal](https://crystal-lang.org/).
|
[Crystal](https://crystal-lang.org/). Kind of.
|
||||||
|
|
||||||
It also provides a CLI tool which can be used to highlight many things in many styles.
|
The CLI tool can be used to highlight many things in many styles.
|
||||||
|
|
||||||
Currently Tartrazine supports 247 languages and has 331 themes (63 from Chroma,
|
# A port of what? Why "kind of"?
|
||||||
the rest are base16 themes via [Sixteen](https://github.com/ralsina/sixteen)
|
|
||||||
|
Pygments is a staple of the Python ecosystem, and it's great.
|
||||||
|
It lets you highlight code in many languages, and it has many
|
||||||
|
themes. Chroma is "Pygments for Go", it's actually a port of
|
||||||
|
Pygments to Go, and it's great too.
|
||||||
|
|
||||||
|
I wanted that in Crystal, so I started this project. But I did
|
||||||
|
not read much of the Pygments code. Or much of Chroma's.
|
||||||
|
|
||||||
|
Chroma has taken most of the Pygments lexers and turned them into
|
||||||
|
XML descriptions. What I did was take those XML files from Chroma
|
||||||
|
and a pile of test cases from Pygments, and I slapped them together
|
||||||
|
until the tests passed and my code produced the same output as
|
||||||
|
Chroma. Think of it as *extreme TDD*.
|
||||||
|
|
||||||
|
Currently the pass rate for tests in the supported languages
|
||||||
|
is `96.8%`, which is *not bad for a couple days hacking*.
|
||||||
|
|
||||||
|
This only covers the RegexLexers, which are the most common ones,
|
||||||
|
but it means the supported languages are a subset of Chroma's, which
|
||||||
|
is a subset of Pygments'.
|
||||||
|
|
||||||
|
Currently Tartrazine supports ... 248 languages.
|
||||||
|
|
||||||
|
It has 331 themes (63 from Chroma, the rest are base16 themes via
|
||||||
|
[Sixteen](https://github.com/ralsina/sixteen)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
If you are using Arch: Use yay or your favourite AUR helper, package name is `tartrazine`.
|
|
||||||
|
|
||||||
From prebuilt binaries:
|
From prebuilt binaries:
|
||||||
|
|
||||||
Each release provides statically-linked binaries that should
|
Each release provides statically-linked binaries that should
|
||||||
work on any Linux. Get them from the [releases page](https://github.com/ralsina/tartrazine/releases)
|
work on any Linux. Get them from the [releases page](https://github.com/ralsina/tartrazine/releases) and put them in your PATH.
|
||||||
and put them in your PATH.
|
|
||||||
|
|
||||||
To build from source:
|
To build from source:
|
||||||
|
|
||||||
@ -30,13 +52,13 @@ To build from source:
|
|||||||
Show a syntax highlighted version of a C source file in your terminal:
|
Show a syntax highlighted version of a C source file in your terminal:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
tartrazine whatever.c -l c -t catppuccin-macchiato --line-numbers -f terminal
|
$ tartrazine whatever.c -l c -t catppuccin-macchiato --line-numbers -f terminal
|
||||||
```
|
```
|
||||||
|
|
||||||
Generate a standalone HTML file from a C source file with the syntax highlighted:
|
Generate a standalone HTML file from a C source file with the syntax highlighted:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
$ tartrazine whatever.c -t catppuccin-macchiato --line-numbers \
|
$ tartrazine whatever.c -l c -t catppuccin-macchiato --line-numbers \
|
||||||
--standalone -f html -o whatever.html
|
--standalone -f html -o whatever.html
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -65,30 +87,3 @@ puts formatter.format(File.read(ARGV[0]), lexer)
|
|||||||
## Contributors
|
## Contributors
|
||||||
|
|
||||||
- [Roberto Alsina](https://github.com/ralsina) - creator and maintainer
|
- [Roberto Alsina](https://github.com/ralsina) - creator and maintainer
|
||||||
|
|
||||||
## A port of what, and why "kind of"
|
|
||||||
|
|
||||||
Pygments is a staple of the Python ecosystem, and it's great.
|
|
||||||
It lets you highlight code in many languages, and it has many
|
|
||||||
themes. Chroma is "Pygments for Go", it's actually a port of
|
|
||||||
Pygments to Go, and it's great too.
|
|
||||||
|
|
||||||
I wanted that in Crystal, so I started this project. But I did
|
|
||||||
not read much of the Pygments code. Or much of Chroma's.
|
|
||||||
|
|
||||||
Chroma has taken most of the Pygments lexers and turned them into
|
|
||||||
XML descriptions. What I did was take those XML files from Chroma
|
|
||||||
and a pile of test cases from Pygments, and I slapped them together
|
|
||||||
until the tests passed and my code produced the same output as
|
|
||||||
Chroma. Think of it as [*extreme TDD*](https://ralsina.me/weblog/posts/tartrazine-reimplementing-pygments.html)
|
|
||||||
|
|
||||||
Currently the pass rate for tests in the supported languages
|
|
||||||
is `96.8%`, which is *not bad for a couple days hacking*.
|
|
||||||
|
|
||||||
This only covers the RegexLexers, which are the most common ones,
|
|
||||||
but it means the supported languages are a subset of Chroma's, which
|
|
||||||
is a subset of Pygments' and DelegatingLexers (useful for things like template languages)
|
|
||||||
|
|
||||||
Then performance was bad, so I hacked and hacked and made it significantly
|
|
||||||
[faster than chroma](https://ralsina.me/weblog/posts/a-tale-of-optimization.html)
|
|
||||||
which is fun.
|
|
||||||
|
4
TODO.md
4
TODO.md
@ -8,8 +8,8 @@
|
|||||||
* ✅ Implement lexer loader that respects aliases
|
* ✅ Implement lexer loader that respects aliases
|
||||||
* ✅ Implement lexer loader by file extension
|
* ✅ Implement lexer loader by file extension
|
||||||
* ✅ Add --line-numbers to terminal formatter
|
* ✅ Add --line-numbers to terminal formatter
|
||||||
* ✅ Implement lexer loader by mime type
|
* Implement lexer loader by mime type
|
||||||
* ✅ Implement Delegating lexers
|
* ✅ Implement Delegating lexers
|
||||||
* ✅ Add RstLexer
|
* ✅ Add RstLexer
|
||||||
* Add Mako template lexer
|
* Add Mako template lexer
|
||||||
* ✅ Implement heuristic lexer detection
|
* Implement heuristic lexer detection
|
||||||
|
@ -7,10 +7,10 @@ docker run --rm --privileged \
|
|||||||
|
|
||||||
# Build for AMD64
|
# Build for AMD64
|
||||||
docker build . -f Dockerfile.static -t tartrazine-builder
|
docker build . -f Dockerfile.static -t tartrazine-builder
|
||||||
docker run -ti --rm -v "$PWD":/app --user="$UID" tartrazine-builder /bin/sh -c "cd /app && rm -rf lib shard.lock && shards build --static --release"
|
docker run -ti --rm -v "$PWD":/app --user="$UID" tartrazine-builder /bin/sh -c "cd /app && rm -rf lib shard.lock && make static"
|
||||||
mv bin/tartrazine bin/tartrazine-static-linux-amd64
|
mv bin/tartrazine bin/tartrazine-static-linux-amd64
|
||||||
|
|
||||||
# Build for ARM64
|
# Build for ARM64
|
||||||
docker build . -f Dockerfile.static --platform linux/arm64 -t tartrazine-builder
|
docker build . -f Dockerfile.static --platform linux/arm64 -t tartrazine-builder
|
||||||
docker run -ti --rm -v "$PWD":/app --platform linux/arm64 --user="$UID" tartrazine-builder /bin/sh -c "cd /app && rm -rf lib shard.lock && shards build --static --release"
|
docker run -ti --rm -v "$PWD":/app --platform linux/arm64 --user="$UID" tartrazine-builder /bin/sh -c "cd /app && rm -rf lib shard.lock && make static"
|
||||||
mv bin/tartrazine bin/tartrazine-static-linux-arm64
|
mv bin/tartrazine bin/tartrazine-static-linux-arm64
|
||||||
|
79
cliff.toml
79
cliff.toml
@ -1,79 +0,0 @@
|
|||||||
# git-cliff ~ default configuration file
|
|
||||||
# https://git-cliff.org/docs/configuration
|
|
||||||
#
|
|
||||||
# Lines starting with "#" are comments.
|
|
||||||
# Configuration options are organized into tables and keys.
|
|
||||||
# See documentation for more information on available options.
|
|
||||||
|
|
||||||
[changelog]
|
|
||||||
# template for the changelog header
|
|
||||||
header = """
|
|
||||||
# Changelog\n
|
|
||||||
All notable changes to this project will be documented in this file.\n
|
|
||||||
"""
|
|
||||||
# template for the changelog body
|
|
||||||
# https://keats.github.io/tera/docs/#introduction
|
|
||||||
body = """
|
|
||||||
{% if version %}\
|
|
||||||
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
|
|
||||||
{% else %}\
|
|
||||||
## [unreleased]
|
|
||||||
{% endif %}\
|
|
||||||
{% for group, commits in commits | group_by(attribute="group") %}
|
|
||||||
### {{ group | striptags | trim | upper_first }}
|
|
||||||
{% for commit in commits %}
|
|
||||||
- {% if commit.scope %}*({{ commit.scope }})* {% endif %}\
|
|
||||||
{% if commit.breaking %}[**breaking**] {% endif %}\
|
|
||||||
{{ commit.message | upper_first }}\
|
|
||||||
{% endfor %}
|
|
||||||
{% endfor %}\n
|
|
||||||
"""
|
|
||||||
# template for the changelog footer
|
|
||||||
footer = """
|
|
||||||
<!-- generated by git-cliff -->
|
|
||||||
"""
|
|
||||||
# remove the leading and trailing s
|
|
||||||
trim = true
|
|
||||||
# postprocessors
|
|
||||||
postprocessors = [
|
|
||||||
# { pattern = '<REPO>', replace = "https://github.com/orhun/git-cliff" }, # replace repository URL
|
|
||||||
]
|
|
||||||
|
|
||||||
[git]
|
|
||||||
# parse the commits based on https://www.conventionalcommits.org
|
|
||||||
conventional_commits = true
|
|
||||||
# filter out the commits that are not conventional
|
|
||||||
filter_unconventional = true
|
|
||||||
# process each line of a commit as an individual commit
|
|
||||||
split_commits = false
|
|
||||||
# regex for preprocessing the commit messages
|
|
||||||
commit_preprocessors = [
|
|
||||||
# Replace issue numbers
|
|
||||||
#{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](<REPO>/issues/${2}))"},
|
|
||||||
# Check spelling of the commit with https://github.com/crate-ci/typos
|
|
||||||
# If the spelling is incorrect, it will be automatically fixed.
|
|
||||||
#{ pattern = '.*', replace_command = 'typos --write-changes -' },
|
|
||||||
]
|
|
||||||
# regex for parsing and grouping commits
|
|
||||||
commit_parsers = [
|
|
||||||
{ message = "^feat", group = "<!-- 0 -->🚀 Features" },
|
|
||||||
{ message = "^fix", group = "<!-- 1 -->🐛 Bug Fixes" },
|
|
||||||
{ message = "^doc", group = "<!-- 3 -->📚 Documentation" },
|
|
||||||
{ message = "^perf", group = "<!-- 4 -->⚡ Performance" },
|
|
||||||
{ message = "^refactor", group = "<!-- 2 -->🚜 Refactor" },
|
|
||||||
{ message = "^style", group = "<!-- 5 -->🎨 Styling" },
|
|
||||||
{ message = "^test", group = "<!-- 6 -->🧪 Testing" },
|
|
||||||
{ message = "^chore\\(release\\): prepare for", skip = true },
|
|
||||||
{ message = "^chore\\(deps.*\\)", skip = true },
|
|
||||||
{ message = "^chore\\(pr\\)", skip = true },
|
|
||||||
{ message = "^chore\\(pull\\)", skip = true },
|
|
||||||
{ message = "^chore|^ci", group = "<!-- 7 -->⚙️ Miscellaneous Tasks" },
|
|
||||||
{ body = ".*security", group = "<!-- 8 -->🛡️ Security" },
|
|
||||||
{ message = "^revert", group = "<!-- 9 -->◀️ Revert" },
|
|
||||||
]
|
|
||||||
# filter out the commits that are not matched by commit parsers
|
|
||||||
filter_commits = false
|
|
||||||
# sort the tags topologically
|
|
||||||
topo_order = false
|
|
||||||
# sort the commits inside sections by oldest/newest order
|
|
||||||
sort_commits = "oldest"
|
|
@ -1,15 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
set e
|
|
||||||
|
|
||||||
PKGNAME=$(basename "$PWD")
|
|
||||||
VERSION=$(git cliff --bumped-version |cut -dv -f2)
|
|
||||||
|
|
||||||
sed "s/^version:.*$/version: $VERSION/g" -i shard.yml
|
|
||||||
git add shard.yml
|
|
||||||
hace lint test
|
|
||||||
git cliff --bump -o
|
|
||||||
git commit -a -m "bump: Release v$VERSION"
|
|
||||||
git tag "v$VERSION"
|
|
||||||
git push --tags
|
|
||||||
hace static
|
|
||||||
gh release create "v$VERSION" "bin/$PKGNAME-static-linux-amd64" "bin/$PKGNAME-static-linux-arm64" --title "Release v$VERSION" --notes "$(git cliff -l -s all)"
|
|
@ -127,3 +127,4 @@
|
|||||||
</state>
|
</state>
|
||||||
</rules>
|
</rules>
|
||||||
</lexer>
|
</lexer>
|
||||||
|
|
||||||
|
@ -52,3 +52,4 @@
|
|||||||
</state>
|
</state>
|
||||||
</rules>
|
</rules>
|
||||||
</lexer>
|
</lexer>
|
||||||
|
|
||||||
|
@ -63,3 +63,4 @@
|
|||||||
</state>
|
</state>
|
||||||
</rules>
|
</rules>
|
||||||
</lexer>
|
</lexer>
|
||||||
|
|
||||||
|
@ -55,3 +55,4 @@
|
|||||||
</state>
|
</state>
|
||||||
</rules>
|
</rules>
|
||||||
</lexer>
|
</lexer>
|
||||||
|
|
||||||
|
@ -75,3 +75,4 @@
|
|||||||
</state>
|
</state>
|
||||||
</rules>
|
</rules>
|
||||||
</lexer>
|
</lexer>
|
||||||
|
|
||||||
|
@ -67,3 +67,4 @@
|
|||||||
</state>
|
</state>
|
||||||
</rules>
|
</rules>
|
||||||
</lexer>
|
</lexer>
|
||||||
|
|
||||||
|
@ -19,3 +19,4 @@
|
|||||||
</state>
|
</state>
|
||||||
</rules>
|
</rules>
|
||||||
</lexer>
|
</lexer>
|
||||||
|
|
||||||
|
@ -53,3 +53,4 @@
|
|||||||
</state>
|
</state>
|
||||||
</rules>
|
</rules>
|
||||||
</lexer>
|
</lexer>
|
||||||
|
|
||||||
|
@ -31,3 +31,4 @@
|
|||||||
</state>
|
</state>
|
||||||
</rules>
|
</rules>
|
||||||
</lexer>
|
</lexer>
|
||||||
|
|
||||||
|
@ -55,3 +55,4 @@
|
|||||||
</state>
|
</state>
|
||||||
</rules>
|
</rules>
|
||||||
</lexer>
|
</lexer>
|
||||||
|
|
||||||
|
@ -73,3 +73,4 @@
|
|||||||
</state>
|
</state>
|
||||||
</rules>
|
</rules>
|
||||||
</lexer>
|
</lexer>
|
||||||
|
|
||||||
|
@ -70,3 +70,4 @@
|
|||||||
</state>
|
</state>
|
||||||
</rules>
|
</rules>
|
||||||
</lexer>
|
</lexer>
|
||||||
|
|
||||||
|
@ -40,3 +40,4 @@
|
|||||||
</state>
|
</state>
|
||||||
</rules>
|
</rules>
|
||||||
</lexer>
|
</lexer>
|
||||||
|
|
||||||
|
@ -52,6 +52,6 @@ with open("src/constants/lexers.cr", "w") as f:
|
|||||||
f.write(" LEXERS_BY_FILENAME = {\n")
|
f.write(" LEXERS_BY_FILENAME = {\n")
|
||||||
for k in sorted(lexer_by_filename.keys()):
|
for k in sorted(lexer_by_filename.keys()):
|
||||||
v = lexer_by_filename[k]
|
v = lexer_by_filename[k]
|
||||||
f.write(f'"{k}" => {str(sorted(list(v))).replace("'", "\"")}, \n')
|
f.write(f'"{k}" => {str(list(v)).replace("'", "\"")}, \n')
|
||||||
f.write("}\n")
|
f.write("}\n")
|
||||||
f.write("end\n")
|
f.write("end\n")
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name: tartrazine
|
name: tartrazine
|
||||||
version: 0.6.4
|
version: 0.6.0
|
||||||
|
|
||||||
authors:
|
authors:
|
||||||
- Roberto Alsina <roberto.alsina@gmail.com>
|
- Roberto Alsina <roberto.alsina@gmail.com>
|
||||||
@ -10,8 +10,7 @@ targets:
|
|||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
baked_file_system:
|
baked_file_system:
|
||||||
github: ralsina/baked_file_system
|
github: schovi/baked_file_system
|
||||||
branch: master
|
|
||||||
base58:
|
base58:
|
||||||
github: crystal-china/base58.cr
|
github: crystal-china/base58.cr
|
||||||
sixteen:
|
sixteen:
|
||||||
|
@ -731,8 +731,8 @@ module Tartrazine
|
|||||||
"*.applescript" => ["applescript"],
|
"*.applescript" => ["applescript"],
|
||||||
"*.aql" => ["arangodb_aql"],
|
"*.aql" => ["arangodb_aql"],
|
||||||
"*.arexx" => ["rexx"],
|
"*.arexx" => ["rexx"],
|
||||||
"*.as" => ["actionscript", "actionscript_3"],
|
"*.as" => ["actionscript_3", "actionscript"],
|
||||||
"*.asm" => ["nasm", "tasm", "z80_assembly"],
|
"*.asm" => ["nasm", "z80_assembly", "tasm"],
|
||||||
"*.au3" => ["autoit"],
|
"*.au3" => ["autoit"],
|
||||||
"*.automount" => ["systemd"],
|
"*.automount" => ["systemd"],
|
||||||
"*.aux" => ["tex"],
|
"*.aux" => ["tex"],
|
||||||
@ -740,7 +740,7 @@ module Tartrazine
|
|||||||
"*.awk" => ["awk"],
|
"*.awk" => ["awk"],
|
||||||
"*.b" => ["brainfuck"],
|
"*.b" => ["brainfuck"],
|
||||||
"*.bal" => ["ballerina"],
|
"*.bal" => ["ballerina"],
|
||||||
"*.bas" => ["qbasic", "vb_net"],
|
"*.bas" => ["vb_net", "qbasic"],
|
||||||
"*.bash" => ["bash"],
|
"*.bash" => ["bash"],
|
||||||
"*.bat" => ["batchfile"],
|
"*.bat" => ["batchfile"],
|
||||||
"*.batch" => ["psl"],
|
"*.batch" => ["psl"],
|
||||||
@ -850,7 +850,7 @@ module Tartrazine
|
|||||||
"*.graphql" => ["graphql"],
|
"*.graphql" => ["graphql"],
|
||||||
"*.graphqls" => ["graphql"],
|
"*.graphqls" => ["graphql"],
|
||||||
"*.groovy" => ["groovy"],
|
"*.groovy" => ["groovy"],
|
||||||
"*.h" => ["c", "c++", "objective-c"],
|
"*.h" => ["objective-c", "c", "c++"],
|
||||||
"*.h++" => ["c++"],
|
"*.h++" => ["c++"],
|
||||||
"*.ha" => ["hare"],
|
"*.ha" => ["hare"],
|
||||||
"*.handlebars" => ["handlebars"],
|
"*.handlebars" => ["handlebars"],
|
||||||
@ -873,7 +873,7 @@ module Tartrazine
|
|||||||
"*.idc" => ["c"],
|
"*.idc" => ["c"],
|
||||||
"*.idr" => ["idris"],
|
"*.idr" => ["idris"],
|
||||||
"*.ijs" => ["j"],
|
"*.ijs" => ["j"],
|
||||||
"*.inc" => ["objectpascal", "php", "povray", "sourcepawn"],
|
"*.inc" => ["php", "objectpascal", "povray", "sourcepawn"],
|
||||||
"*.inf" => ["ini"],
|
"*.inf" => ["ini"],
|
||||||
"*.ini" => ["ini"],
|
"*.ini" => ["ini"],
|
||||||
"*.ino" => ["arduino"],
|
"*.ino" => ["arduino"],
|
||||||
@ -899,7 +899,7 @@ module Tartrazine
|
|||||||
"*.lpk" => ["objectpascal"],
|
"*.lpk" => ["objectpascal"],
|
||||||
"*.lpr" => ["objectpascal"],
|
"*.lpr" => ["objectpascal"],
|
||||||
"*.lua" => ["lua"],
|
"*.lua" => ["lua"],
|
||||||
"*.m" => ["mason", "mathematica", "matlab", "objective-c", "octave"],
|
"*.m" => ["mathematica", "mason", "octave", "objective-c", "matlab"],
|
||||||
"*.ma" => ["mathematica"],
|
"*.ma" => ["mathematica"],
|
||||||
"*.mak" => ["makefile"],
|
"*.mak" => ["makefile"],
|
||||||
"*.man" => ["groff"],
|
"*.man" => ["groff"],
|
||||||
@ -954,7 +954,7 @@ module Tartrazine
|
|||||||
"*.php" => ["php"],
|
"*.php" => ["php"],
|
||||||
"*.php[345]" => ["php"],
|
"*.php[345]" => ["php"],
|
||||||
"*.pig" => ["pig"],
|
"*.pig" => ["pig"],
|
||||||
"*.pl" => ["perl", "prolog"],
|
"*.pl" => ["prolog", "perl"],
|
||||||
"*.plc" => ["plutus_core"],
|
"*.plc" => ["plutus_core"],
|
||||||
"*.plot" => ["gnuplot"],
|
"*.plot" => ["gnuplot"],
|
||||||
"*.plt" => ["gnuplot"],
|
"*.plt" => ["gnuplot"],
|
||||||
@ -962,7 +962,7 @@ module Tartrazine
|
|||||||
"*.pml" => ["promela"],
|
"*.pml" => ["promela"],
|
||||||
"*.pony" => ["pony"],
|
"*.pony" => ["pony"],
|
||||||
"*.pov" => ["povray"],
|
"*.pov" => ["povray"],
|
||||||
"*.pp" => ["objectpascal", "puppet"],
|
"*.pp" => ["puppet", "objectpascal"],
|
||||||
"*.pq" => ["powerquery"],
|
"*.pq" => ["powerquery"],
|
||||||
"*.pr" => ["promela"],
|
"*.pr" => ["promela"],
|
||||||
"*.prm" => ["promela"],
|
"*.prm" => ["promela"],
|
||||||
@ -1011,7 +1011,7 @@ module Tartrazine
|
|||||||
"*.rst" => ["rst"],
|
"*.rst" => ["rst"],
|
||||||
"*.rvt" => ["tcl"],
|
"*.rvt" => ["tcl"],
|
||||||
"*.rx" => ["rexx"],
|
"*.rx" => ["rexx"],
|
||||||
"*.s" => ["armasm", "gas", "r"],
|
"*.s" => ["armasm", "r", "gas"],
|
||||||
"*.sage" => ["python"],
|
"*.sage" => ["python"],
|
||||||
"*.sas" => ["sas"],
|
"*.sas" => ["sas"],
|
||||||
"*.sass" => ["sass"],
|
"*.sass" => ["sass"],
|
||||||
@ -1024,7 +1024,7 @@ module Tartrazine
|
|||||||
"*.scope" => ["systemd"],
|
"*.scope" => ["systemd"],
|
||||||
"*.scss" => ["scss"],
|
"*.scss" => ["scss"],
|
||||||
"*.sed" => ["sed"],
|
"*.sed" => ["sed"],
|
||||||
"*.service" => ["ini", "systemd"],
|
"*.service" => ["systemd", "ini"],
|
||||||
"*.sh" => ["bash"],
|
"*.sh" => ["bash"],
|
||||||
"*.sh-session" => ["bash_session"],
|
"*.sh-session" => ["bash_session"],
|
||||||
"*.sieve" => ["sieve"],
|
"*.sieve" => ["sieve"],
|
||||||
@ -1034,13 +1034,13 @@ module Tartrazine
|
|||||||
"*.smali" => ["smali"],
|
"*.smali" => ["smali"],
|
||||||
"*.sml" => ["standard_ml"],
|
"*.sml" => ["standard_ml"],
|
||||||
"*.snobol" => ["snobol"],
|
"*.snobol" => ["snobol"],
|
||||||
"*.socket" => ["ini", "systemd"],
|
"*.socket" => ["systemd", "ini"],
|
||||||
"*.sol" => ["solidity"],
|
"*.sol" => ["solidity"],
|
||||||
"*.sp" => ["sourcepawn"],
|
"*.sp" => ["sourcepawn"],
|
||||||
"*.sparql" => ["sparql"],
|
"*.sparql" => ["sparql"],
|
||||||
"*.spec" => ["rpm_spec"],
|
"*.spec" => ["rpm_spec"],
|
||||||
"*.spt" => ["cheetah"],
|
"*.spt" => ["cheetah"],
|
||||||
"*.sql" => ["mysql", "sql"],
|
"*.sql" => ["sql", "mysql"],
|
||||||
"*.ss" => ["scheme"],
|
"*.ss" => ["scheme"],
|
||||||
"*.st" => ["smalltalk"],
|
"*.st" => ["smalltalk"],
|
||||||
"*.stas" => ["stas"],
|
"*.stas" => ["stas"],
|
||||||
@ -1069,7 +1069,7 @@ module Tartrazine
|
|||||||
"*.tpl" => ["smarty"],
|
"*.tpl" => ["smarty"],
|
||||||
"*.tpp" => ["c++"],
|
"*.tpp" => ["c++"],
|
||||||
"*.trig" => ["psl"],
|
"*.trig" => ["psl"],
|
||||||
"*.ts" => ["typescript", "typoscript"],
|
"*.ts" => ["typoscript", "typescript"],
|
||||||
"*.tst" => ["scilab"],
|
"*.tst" => ["scilab"],
|
||||||
"*.tsx" => ["typescript"],
|
"*.tsx" => ["typescript"],
|
||||||
"*.ttl" => ["turtle"],
|
"*.ttl" => ["turtle"],
|
||||||
@ -1079,7 +1079,7 @@ module Tartrazine
|
|||||||
"*.twig" => ["twig"],
|
"*.twig" => ["twig"],
|
||||||
"*.txt" => ["plaintext"],
|
"*.txt" => ["plaintext"],
|
||||||
"*.uc" => ["ucode"],
|
"*.uc" => ["ucode"],
|
||||||
"*.v" => ["coq", "v", "verilog"],
|
"*.v" => ["verilog", "v", "coq"],
|
||||||
"*.vala" => ["vala"],
|
"*.vala" => ["vala"],
|
||||||
"*.vapi" => ["vala"],
|
"*.vapi" => ["vala"],
|
||||||
"*.vb" => ["vb_net"],
|
"*.vb" => ["vb_net"],
|
||||||
|
@ -11,7 +11,7 @@ module Tartrazine
|
|||||||
"#{i + 1}".rjust(4).ljust(5)
|
"#{i + 1}".rjust(4).ljust(5)
|
||||||
end
|
end
|
||||||
|
|
||||||
def format(text : String, lexer : BaseLexer) : String
|
def format(text : String, lexer : Lexer) : String
|
||||||
outp = String::Builder.new("")
|
outp = String::Builder.new("")
|
||||||
format(text, lexer, outp)
|
format(text, lexer, outp)
|
||||||
outp.to_s
|
outp.to_s
|
||||||
|
10
src/lexer.cr
10
src/lexer.cr
@ -9,21 +9,13 @@ module Tartrazine
|
|||||||
|
|
||||||
# Get the lexer object for a language name
|
# Get the lexer object for a language name
|
||||||
# FIXME: support mimetypes
|
# FIXME: support mimetypes
|
||||||
def self.lexer(name : String? = nil, filename : String? = nil, mimetype : String? = nil) : BaseLexer
|
def self.lexer(name : String? = nil, filename : String? = nil) : BaseLexer
|
||||||
return lexer_by_name(name) if name && name != "autodetect"
|
return lexer_by_name(name) if name && name != "autodetect"
|
||||||
return lexer_by_filename(filename) if filename
|
return lexer_by_filename(filename) if filename
|
||||||
return lexer_by_mimetype(mimetype) if mimetype
|
|
||||||
|
|
||||||
Lexer.from_xml(LexerFiles.get("/#{LEXERS_BY_NAME["plaintext"]}.xml").gets_to_end)
|
Lexer.from_xml(LexerFiles.get("/#{LEXERS_BY_NAME["plaintext"]}.xml").gets_to_end)
|
||||||
end
|
end
|
||||||
|
|
||||||
private def self.lexer_by_mimetype(mimetype : String) : BaseLexer
|
|
||||||
lexer_file_name = LEXERS_BY_MIMETYPE.fetch(mimetype, nil)
|
|
||||||
raise Exception.new("Unknown mimetype: #{mimetype}") if lexer_file_name.nil?
|
|
||||||
|
|
||||||
Lexer.from_xml(LexerFiles.get("/#{lexer_file_name}.xml").gets_to_end)
|
|
||||||
end
|
|
||||||
|
|
||||||
private def self.lexer_by_name(name : String) : BaseLexer
|
private def self.lexer_by_name(name : String) : BaseLexer
|
||||||
lexer_file_name = LEXERS_BY_NAME.fetch(name.downcase, nil)
|
lexer_file_name = LEXERS_BY_NAME.fetch(name.downcase, nil)
|
||||||
return create_delegating_lexer(name) if lexer_file_name.nil? && name.includes? "+"
|
return create_delegating_lexer(name) if lexer_file_name.nil? && name.includes? "+"
|
||||||
|
@ -1 +0,0 @@
|
|||||||
require "../spec/**"
|
|
Reference in New Issue
Block a user