This is a project built with marpa.
Flexible syntax highlighter.
Add this to your application's shard.yml
:
dependencies:
syntax:
github: omarroth/syntax.cr
require "syntax"
highlighter = Syntax::Highlighter.new
grammar = <<-'END_BNF'
# Grammar from https://metacpan.org/pod/distribution/Marpa-R2/pod/Semantics.pod
:start ::= Expression
Expression ::= Number
| '(' Expression ')' bgcolor => salmon
|| Expression '**' Expression bgcolor => red
|| Expression '*' Expression bgcolor => yellow color => black
| Expression '/' Expression bgcolor => green color => orange
|| Expression '+' Expression bgcolor => blue color => orange
| Expression '-' Expression bgcolor => cyan color => black
Number ~ [\d]+
:discard ~ whitespace
whitespace ~ [\s]+
END_BNF
input = "10 + (6 - 1 / 3) * 2"
highlighter.highlight(input, grammar)
- Fork it (https://github.com/omarroth/syntax.cr/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- omarroth Omar Roth - creator, maintainer