Comments (28)
let me show an example :
This is a custom colorization I made manually in one of my slides.
What should be done:
- Choose a color for namespace names
- Choose a color for token names
- Choose a color for token values
- Choose a color for rules
- Use those color in the token sequence (
-s
) output - Use those color in the dump visitor (
-v dump
) output - Use those color in the trace (
-t
) output
from compiler.
Why not using automatic color for the namespace and for tokens?
from compiler.
@Hywan what do you mean by "automatic color" ?
from compiler.
@jubianchi Automatic color selection, in a palette. Each token or namespace without a color has a color attached automatically, and it remains attached. This way, this is easy to track the token by its color instead of its name.
from compiler.
@jubianchi For instance, regarding your example, T_NUMBER
will be blue, T_OP_PLUS
will be orange, T_VAR
will be red, but T_OP_EQUAL
will not be orange but pink instead. All token value will have the color associated to its token name. Same for namespace.
from compiler.
@Hywan good idea! let me try something when I get some time ;)
from compiler.
Moreover, I would like something like highlight_code
for a beautiful display ;)
from compiler.
I experimented with some algorithms to colorize the output and it seems hard to do it automatically:
- we have to generate random color with reasonable distance, or
- we have to hardcode a color palette which is large enough to deal with with huge grammars, but
- we would have to take care of user's terminal background (color cannot be the same on light and dark backgrounds)
If we choose to generate random color on-the-fly, we will have to add too much code (IMHO) to compute random colors, deal with distances between them, etc.
If we choose to hardcode a palette, we would have to hardcode two palettes: one for light backgrounds and one for dark ones. Or we have to find a palette working with both backgrounds.
from compiler.
example palette (80 colors):
from compiler.
Can we specify in an other file, which color to join for each token.
Perhaps a %filename%.pp-lut relative to %filename%.pp
from compiler.
Or shall we think about a "check style" tool?
An extra file setup the coding style and the token style (text color, line break, spacing, etc)
Perhaps there is the same thought.
from compiler.
@1e1 I don't understand what you're talking about. We are talking about colorizing the output of some compiler:pp
command, not to colorize a PP grammar.
@jubianchi Let me ask some colleague designers. Having a pre-defined palette sounds good for me. Else we would have to start a Hoa\Color
library and we don't have time for this right now. Your proposed palette seems excellent. What is the source?
from compiler.
@Hywan I randomly generateed 256 colors and manually removed those not fitting in both backgrounds
from compiler.
@Hywan
I thought it is to highlight a rule written from a PP file.
from compiler.
@jubianchi Good work.
from compiler.
@ghn points me this https://github.com/mbostock/d3/wiki/Ordinal-Scales#categorical-colors. These palettes have not been designed to work on both light and black backgrounds, but we can maybe find some inspiration there.
from compiler.
Example output with the 80 colors palette:
For each new token we shift a color from the palette and use it.
from compiler.
How do you choose colors in your palette? Are colors already ordered by distance (in which space?)? Do you choose colors by the maximum distance each time?
from compiler.
How do you choose colors in your palette?
For each new token we shift a color from the palette and use it.
Are colors already ordered by distance (in which space?)?
No.
Do you choose colors by the maximum distance each time?
No.
from compiler.
And here is an example trace output:
from compiler.
Sounds good. Colors are a little bit too “agressive”, thoughts?
from compiler.
@Hywan yes the colors are not optimal :/
from compiler.
But this is an excellent start! I am going to ask for a “““palette flatter”””
from compiler.
@ghn provides me this other resource: http://kentor.me/posts/generating-pastel-colors-for-css/. @jubianchi, it can help you a lot I guess.
from compiler.
And so this: https://randomcolor.llllll.li/ (a PHP port exists, for inspiration).
from compiler.
@Hywan I searched yesterday for libraries doing good colors randomization and I found https://randomcolor.llllll.li/ was really promising but to do things well, we should port it.
from compiler.
@jubianchi Isn't it possible to develop a very minimal algorithm?
from compiler.
@jubianchi do you want to post your code in a github repository somewhere? Maybe some people can take it as a starting point and continue your work if you don't longer want it.
from compiler.
Related Issues (20)
- Multiple start-symbols support
- Parsing tree is just the first token HOT 1
- Dependabot can't resolve your PHP dependency files
- Backtrack issue when rules overlap HOT 1
- PHP 7.4 deprecation warning in Bin/Pp.php
- Future of Compiler package HOT 4
- Enhance context output of UnrecognizedToken exception
- Enhance context output of UnexpectedToken exception
- Unexpected namespace assignment for PCRE containing colon
- Dependabot can't resolve your PHP dependency files
- Dependabot can't resolve your PHP dependency files
- mbstring problem
- Debug grammar tooling problems
- Bug when saving parser class
- Question: how to access/traverse nodes of grammar HOT 5
- Inlining code of the Parser and license HOT 2
- Madness with exceptions HOT 5
- Remove dependency to `ext/ctype` HOT 4
- Broken visualization of invalid input token in multiline input HOT 7
- Unrecognized Token in Lexer always reports Line 1? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from compiler.