mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-09-17 10:48:12 +00:00
Compare commits
8 Commits
main
...
8eb8b8cb48
Author | SHA1 | Date | |
---|---|---|---|
8eb8b8cb48 | |||
1252376663 | |||
2aa8b235ee | |||
dcfd960107 | |||
5af09edc5f | |||
fc53344649 | |||
6766eb14f3 | |||
61899cfe83 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,3 +9,4 @@ shard.lock
|
||||
.vscode/
|
||||
.crystal/
|
||||
venv/
|
||||
.croupier
|
||||
|
3
.md.rb
Normal file
3
.md.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
exclude_rule 'MD033' # Inline HTML
|
||||
exclude_rule 'MD005' # 3-space indent for lists
|
||||
exclude_rule 'MD024' # Repeated headings
|
19
CHANGELOG.md
19
CHANGELOG.md
@@ -2,12 +2,29 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [unreleased]
|
||||
## [0.6.4] - 2024-08-28
|
||||
|
||||
### 🐛 Bug Fixes
|
||||
|
||||
- Ameba
|
||||
|
||||
### 📚 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
|
||||
|
||||
## [0.6.1] - 2024-08-25
|
||||
|
||||
|
115
Hacefile.yml
Normal file
115
Hacefile.yml
Normal file
@@ -0,0 +1,115 @@
|
||||
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
|
21
Makefile
21
Makefile
@@ -1,21 +0,0 @@
|
||||
all: build
|
||||
|
||||
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
|
||||
|
||||
|
||||
clean:
|
||||
rm -rf bin lib shard.lock
|
||||
|
||||
test:
|
||||
crystal spec
|
||||
|
||||
lint:
|
||||
ameba --fix src spec
|
||||
|
||||
.PHONY: clean all test bin lint
|
@@ -7,10 +7,10 @@ docker run --rm --privileged \
|
||||
|
||||
# Build for AMD64
|
||||
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 && make static"
|
||||
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"
|
||||
mv bin/tartrazine bin/tartrazine-static-linux-amd64
|
||||
|
||||
# Build for ARM64
|
||||
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 && make static"
|
||||
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"
|
||||
mv bin/tartrazine bin/tartrazine-static-linux-arm64
|
||||
|
15
do_release.sh
Executable file
15
do_release.sh
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/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)"
|
@@ -1,5 +1,5 @@
|
||||
name: tartrazine
|
||||
version: 0.6.3
|
||||
version: 0.6.4
|
||||
|
||||
authors:
|
||||
- Roberto Alsina <roberto.alsina@gmail.com>
|
||||
|
@@ -12,7 +12,7 @@ module Tartrazine
|
||||
|
||||
def format(text : String, lexer : BaseLexer, io : IO) : Nil
|
||||
tokenizer = lexer.tokenizer(text)
|
||||
io << Tartrazine::Lexer.collapse_tokens(tokenizer.to_a).to_json
|
||||
io << Tartrazine::RegexLexer.collapse_tokens(tokenizer.to_a).to_json
|
||||
end
|
||||
end
|
||||
end
|
||||
|
21
src/lexer.cr
21
src/lexer.cr
@@ -1,5 +1,6 @@
|
||||
require "baked_file_system"
|
||||
require "./constants/lexers"
|
||||
require "./heuristics"
|
||||
require "baked_file_system"
|
||||
|
||||
module Tartrazine
|
||||
class LexerFiles
|
||||
@@ -14,14 +15,14 @@ module Tartrazine
|
||||
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)
|
||||
RegexLexer.from_xml(LexerFiles.get("/#{LEXERS_BY_NAME["plaintext"]}.xml").gets_to_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)
|
||||
RegexLexer.from_xml(LexerFiles.get("/#{lexer_file_name}.xml").gets_to_end)
|
||||
end
|
||||
|
||||
private def self.lexer_by_name(name : String) : BaseLexer
|
||||
@@ -29,7 +30,7 @@ module Tartrazine
|
||||
return create_delegating_lexer(name) if lexer_file_name.nil? && name.includes? "+"
|
||||
raise Exception.new("Unknown lexer: #{name}") if lexer_file_name.nil?
|
||||
|
||||
Lexer.from_xml(LexerFiles.get("/#{lexer_file_name}.xml").gets_to_end)
|
||||
RegexLexer.from_xml(LexerFiles.get("/#{lexer_file_name}.xml").gets_to_end)
|
||||
end
|
||||
|
||||
private def self.lexer_by_filename(filename : String) : BaseLexer
|
||||
@@ -52,7 +53,7 @@ module Tartrazine
|
||||
end
|
||||
end
|
||||
|
||||
Lexer.from_xml(LexerFiles.get("/#{lexer_file_name}.xml").gets_to_end)
|
||||
RegexLexer.from_xml(LexerFiles.get("/#{lexer_file_name}.xml").gets_to_end)
|
||||
end
|
||||
|
||||
private def self.lexer_by_content(fname : String) : String?
|
||||
@@ -152,7 +153,9 @@ module Tartrazine
|
||||
end
|
||||
end
|
||||
|
||||
abstract class BaseLexer
|
||||
alias BaseLexer = Lexer
|
||||
|
||||
abstract class Lexer
|
||||
property config = {
|
||||
name: "",
|
||||
priority: 0.0,
|
||||
@@ -174,7 +177,7 @@ module Tartrazine
|
||||
# For explanations on what actions and states do
|
||||
# the Pygments documentation is a good place to start.
|
||||
# https://pygments.org/docs/lexerdevelopment/
|
||||
class Lexer < BaseLexer
|
||||
class RegexLexer < BaseLexer
|
||||
# Collapse consecutive tokens of the same type for easier comparison
|
||||
# and smaller output
|
||||
def self.collapse_tokens(tokens : Array(Tartrazine::Token)) : Array(Tartrazine::Token)
|
||||
@@ -198,7 +201,7 @@ module Tartrazine
|
||||
end
|
||||
|
||||
def self.from_xml(xml : String) : Lexer
|
||||
l = Lexer.new
|
||||
l = RegexLexer.new
|
||||
lexer = XML.parse(xml).first_element_child
|
||||
if lexer
|
||||
config = lexer.children.find { |node|
|
||||
@@ -263,7 +266,7 @@ module Tartrazine
|
||||
#
|
||||
# This is useful for things like template languages, where
|
||||
# you have Jinja + HTML or Jinja + CSS and so on.
|
||||
class DelegatingLexer < BaseLexer
|
||||
class DelegatingLexer < Lexer
|
||||
property language_lexer : BaseLexer
|
||||
property root_lexer : BaseLexer
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
require "docopt"
|
||||
require "./**"
|
||||
require "./tartrazine"
|
||||
|
||||
HELP = <<-HELP
|
||||
tartrazine: a syntax highlighting tool
|
||||
|
1
src/run_tests.cr
Normal file
1
src/run_tests.cr
Normal file
@@ -0,0 +1 @@
|
||||
require "../spec/**"
|
@@ -1,5 +1,6 @@
|
||||
require "./actions"
|
||||
require "./formatter"
|
||||
require "./formatters/**"
|
||||
require "./rules"
|
||||
require "./styles"
|
||||
require "./tartrazine"
|
||||
|
Reference in New Issue
Block a user