Skip to content

Commit

Permalink
Separate parsers into individual files
Browse files Browse the repository at this point in the history
  • Loading branch information
Akianonymus committed Feb 27, 2023
1 parent b0e08be commit dde3084
Show file tree
Hide file tree
Showing 22 changed files with 1,288 additions and 668 deletions.
231 changes: 148 additions & 83 deletions doc/colorizer.txt
Original file line number Diff line number Diff line change
Expand Up @@ -412,34 +412,124 @@ default_namespace *colorizer.buffer.default_namespace*
==============================================================================
COLOR *colorizer.color-introduction*

Helper functions to parse different colour formats
Helper color functions


==============================================================================
LUA API *colorizer.color-lua-api*

Functions: ~
|argb_hex_parser| - parse for 0xaarrggbb and return rgb hex.

|hsl_to_rgb| - Converts an HSL color value to RGB.

|hsl_function_parser| - Parse for hsl() hsla() css function and return rgb
hex.

|hue_to_rgb| - Convert hsl colour values to rgb.

|is_bright| - Determine whether to use black or white text.

|name_parser| - Grab all the colour values from `vim.api.nvim_get_color_map`
and create a lookup table.

|rgb_function_parser| - Parse for rgb() rgba() css function and return rgb
hex.
hsl_to_rgb({h}, {s}, {l}) *colorizer.color.hsl_to_rgb*
Converts an HSL color value to RGB.

Parameters: ~
{h} - number: Hue
{s} - number: Saturation
{l} - number: Lightness

returns:~
number or nil,number or nil,number or nil



hue_to_rgb({p}, {q}, {t}) *colorizer.color.hue_to_rgb*
Convert hsl colour values to rgb.

Source: https://gist.github.com/mjackson/5311256


Parameters: ~
{p} - number
{q} - number
{t} - number

returns:~
number



is_bright({r}, {g}, {b}) *colorizer.color.is_bright*
Determine whether to use black or white text.


ref: https://stackoverflow.com/a/1855903/837964
https://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color


Parameters: ~
{r} - number: Red
{g} - number: Green
{b} - number: Blue



==============================================================================
MATCHER *colorizer.matcher-introduction*

Helper functions for colorizer to enable required parsers


==============================================================================
LUA API *colorizer.matcher-lua-api*

Functions: ~
|compile| - Form a trie stuct with the given prefixes

|make| - Parse the given options and return a function with enabled parsers.


compile({matchers}, {matchers_trie}) *colorizer.matcher.compile*
Form a trie stuct with the given prefixes

Parameters: ~
{matchers} - table: List of prefixes, {"rgb", "hsl"}
{matchers_trie} - table: Table containing information regarding
non-trie based parsers

returns:~
function: function which will just parse the line for enabled parsers



make({options}) *colorizer.matcher.make*
Parse the given options and return a function with enabled parsers.

if no parsers enabled then return false
Do not try make the function again if it is present in the cache

|rgba_hex_parser| - parse for #rrggbbaa and return rgb hex.

Parameters: ~
{options} - table: options created in `colorizer.setup`

argb_hex_parser({line}, {i}) *colorizer.color.argb_hex_parser*
returns:~
function or boolean: function which will just parse the line for enabled
parsers



==============================================================================
ARGB_HEX *colorizer.parser.argb_hex-introduction*

Helper function to parse argb


==============================================================================
LUA API *colorizer.parser.argb_hex-lua-api*

Functions: ~
|parser.argb_hex_parser| - parse for 0xaarrggbb and return rgb hex.



*colorizer.parser.argb_hex.parser.argb_hex_parser*
parser.argb_hex_parser({line}, {i})
parse for 0xaarrggbb and return rgb hex.

a format used in android apps
Expand All @@ -455,20 +545,23 @@ argb_hex_parser({line}, {i}) *colorizer.color.argb_hex_parser*



hsl_to_rgb({h}, {s}, {l}) *colorizer.color.hsl_to_rgb*
Converts an HSL color value to RGB.
==============================================================================
HSL *colorizer.parser.hsl-introduction*

Parameters: ~
{h} - number: Hue
{s} - number: Saturation
{l} - number: Lightness
Helper function to parse argb

returns:~
number or nil,number or nil,number or nil

==============================================================================
LUA API *colorizer.parser.hsl-lua-api*

Functions: ~
|parser.hsl_function_parser| - Parse for hsl() hsla() css function and
return rgb hex.



hsl_function_parser({line}, {i}, {opts}) *colorizer.color.hsl_function_parser*
*colorizer.parser.hsl.parser.hsl_function_parser*
parser.hsl_function_parser({line}, {i}, {opts})
Parse for hsl() hsla() css function and return rgb hex.

For more info:
Expand All @@ -486,38 +579,23 @@ hsl_function_parser({line}, {i}, {opts}) *colorizer.color.hsl_function_parser*



hue_to_rgb({p}, {q}, {t}) *colorizer.color.hue_to_rgb*
Convert hsl colour values to rgb.

Source: https://gist.github.com/mjackson/5311256


Parameters: ~
{p} - number
{q} - number
{t} - number

returns:~
number



is_bright({r}, {g}, {b}) *colorizer.color.is_bright*
Determine whether to use black or white text.
==============================================================================
NAMES *colorizer.parser.names-introduction*

Helper function to parse argb

ref: https://stackoverflow.com/a/1855903/837964
https://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color

==============================================================================
LUA API *colorizer.parser.names-lua-api*

Parameters: ~
{r} - number: Red
{g} - number: Green
{b} - number: Blue
Functions: ~
|parser.name_parser| - Grab all the colour values from
`vim.api.nvim_get_color_map` and create a lookup table.



name_parser({line}, {i}, {opts}) *colorizer.color.name_parser*
*colorizer.parser.names.parser.name_parser*
parser.name_parser({line}, {i}, {opts})
Grab all the colour values from `vim.api.nvim_get_color_map` and create a
lookup table.

Expand All @@ -531,25 +609,22 @@ name_parser({line}, {i}, {opts}) *colorizer.color.name_parser*



rgb_function_parser({line}, {i}, {opts}) *colorizer.color.rgb_function_parser*
Parse for rgb() rgba() css function and return rgb hex.
==============================================================================
RGBA_HEX *colorizer.parser.rgba_hex-introduction*

For more info:
https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/rgb
Helper function to parse argb


Parameters: ~
{line} - string: Line to parse
{i} - number: Index of line from where to start parsing
{opts} - table: Values passed from matchers like prefix
==============================================================================
LUA API *colorizer.parser.rgba_hex-lua-api*

returns:~
number or nil: Index of line where the rgb/rgba function ended
string or nil: rgb hex value
Functions: ~
|parser.rgba_hex_parser| - parse for #rrggbbaa and return rgb hex.



rgba_hex_parser({line}, {i}, {opts}) *colorizer.color.rgba_hex_parser*
*colorizer.parser.rgba_hex.parser.rgba_hex_parser*
parser.rgba_hex_parser({line}, {i}, {opts})
parse for #rrggbbaa and return rgb hex.

a format used in android apps
Expand All @@ -567,46 +642,36 @@ rgba_hex_parser({line}, {i}, {opts}) *colorizer.color.rgba_hex_parser*


==============================================================================
MATCHER *colorizer.matcher-introduction*
RGB *colorizer.parser.rgb-introduction*

Helper functions for colorizer to enable required parsers
Helper function to parse argb


==============================================================================
LUA API *colorizer.matcher-lua-api*
LUA API *colorizer.parser.rgb-lua-api*

Functions: ~
|compile| - Form a trie stuct with the given prefixes
|parser.rgb_function_parser| - Parse for rgb() rgba() css function and
return rgb hex.

|make| - Parse the given options and return a function with enabled parsers.


compile({matchers}, {matchers_trie}) *colorizer.matcher.compile*
Form a trie stuct with the given prefixes

Parameters: ~
{matchers} - table: List of prefixes, {"rgb", "hsl"}
{matchers_trie} - table: Table containing information regarding
non-trie based parsers

returns:~
function: function which will just parse the line for enabled parsers



make({options}) *colorizer.matcher.make*
Parse the given options and return a function with enabled parsers.
*colorizer.parser.rgb.parser.rgb_function_parser*
parser.rgb_function_parser({line}, {i}, {opts})
Parse for rgb() rgba() css function and return rgb hex.

if no parsers enabled then return false
Do not try make the function again if it is present in the cache
For more info:
https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/rgb


Parameters: ~
{options} - table: options created in `colorizer.setup`
{line} - string: Line to parse
{i} - number: Index of line from where to start parsing
{opts} - table: Values passed from matchers like prefix

returns:~
function or boolean: function which will just parse the line for enabled
parsers
number or nil: Index of line where the rgb/rgba function ended
string or nil: rgb hex value



Expand Down
27 changes: 26 additions & 1 deletion doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ <h2>Modules</h2>
<li><a href="modules/colorizer.buffer.html">buffer</a></li>
<li><a href="modules/colorizer.color.html">color</a></li>
<li><a href="modules/colorizer.matcher.html">matcher</a></li>
<li><a href="modules/colorizer.parser.argb_hex.html">parser.argb_hex</a></li>
<li><a href="modules/colorizer.parser.hsl.html">parser.hsl</a></li>
<li><a href="modules/colorizer.parser.names.html">parser.names</a></li>
<li><a href="modules/colorizer.parser.rgb.html">parser.rgb</a></li>
<li><a href="modules/colorizer.parser.rgba_hex.html">parser.rgba_hex</a></li>
<li><a href="modules/colorizer.sass.html">sass</a></li>
<li><a href="modules/colorizer.tailwind.html">tailwind</a></li>
<li><a href="modules/colorizer.trie.html">trie</a></li>
Expand All @@ -59,12 +64,32 @@ <h2>Modules</h2>
</tr>
<tr>
<td class="name" nowrap><a href="modules/colorizer.color.html">colorizer.color</a></td>
<td class="summary">Helper functions to parse different colour formats</td>
<td class="summary">Helper color functions</td>
</tr>
<tr>
<td class="name" nowrap><a href="modules/colorizer.matcher.html">colorizer.matcher</a></td>
<td class="summary">Helper functions for colorizer to enable required parsers</td>
</tr>
<tr>
<td class="name" nowrap><a href="modules/colorizer.parser.argb_hex.html">colorizer.parser.argb_hex</a></td>
<td class="summary">Helper function to parse argb</td>
</tr>
<tr>
<td class="name" nowrap><a href="modules/colorizer.parser.hsl.html">colorizer.parser.hsl</a></td>
<td class="summary">Helper function to parse argb</td>
</tr>
<tr>
<td class="name" nowrap><a href="modules/colorizer.parser.names.html">colorizer.parser.names</a></td>
<td class="summary">Helper function to parse argb</td>
</tr>
<tr>
<td class="name" nowrap><a href="modules/colorizer.parser.rgb.html">colorizer.parser.rgb</a></td>
<td class="summary">Helper function to parse argb</td>
</tr>
<tr>
<td class="name" nowrap><a href="modules/colorizer.parser.rgba_hex.html">colorizer.parser.rgba_hex</a></td>
<td class="summary">Helper function to parse argb</td>
</tr>
<tr>
<td class="name" nowrap><a href="modules/colorizer.sass.html">colorizer.sass</a></td>
<td class="summary">Helper functions to parse sass color variables</td>
Expand Down
5 changes: 5 additions & 0 deletions doc/modules/colorizer.buffer.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ <h2>Modules</h2>
<li><strong>buffer</strong></li>
<li><a href="../modules/colorizer.color.html">color</a></li>
<li><a href="../modules/colorizer.matcher.html">matcher</a></li>
<li><a href="../modules/colorizer.parser.argb_hex.html">parser.argb_hex</a></li>
<li><a href="../modules/colorizer.parser.hsl.html">parser.hsl</a></li>
<li><a href="../modules/colorizer.parser.names.html">parser.names</a></li>
<li><a href="../modules/colorizer.parser.rgb.html">parser.rgb</a></li>
<li><a href="../modules/colorizer.parser.rgba_hex.html">parser.rgba_hex</a></li>
<li><a href="../modules/colorizer.sass.html">sass</a></li>
<li><a href="../modules/colorizer.tailwind.html">tailwind</a></li>
<li><a href="../modules/colorizer.trie.html">trie</a></li>
Expand Down
Loading

0 comments on commit dde3084

Please sign in to comment.