Skip to content

Commit

Permalink
Broken
Browse files Browse the repository at this point in the history
  • Loading branch information
reemo3dp committed Mar 2, 2024
1 parent 05c7eb0 commit 1342503
Show file tree
Hide file tree
Showing 24 changed files with 29,936 additions and 7 deletions.
2 changes: 2 additions & 0 deletions packages/layer_parser/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
../led_effect/src/layer_parser_lark.py: src/layer_parser.lark
poetry run python -m lark.tools.standalone -s line -o $@ $<
118 changes: 118 additions & 0 deletions packages/layer_parser/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions packages/layer_parser/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[tool.poetry]
package-mode = false
name = "layer_parser"
version = "0.1.0"
description = ""
authors = ["Julian Schill <[email protected]>", "reemo3dp <[email protected]>"]
license = "GPL3"
readme = "README.md"

[tool.poetry.dependencies]
python = ">=3.8,<3.12"

[tool.poetry.group.dev.dependencies]
lark = "^1.1.9"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
25 changes: 25 additions & 0 deletions packages/layer_parser/src/layer_parser.lark
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
line: legacy_line | parameterized_line

legacy_line: LAYER_NAME RATE CUTOFF BLEND palette
LAYER_NAME: WORD
RATE: NUMBER
CUTOFF: NUMBER
BLEND: WORD

parameterized_line: LAYER_NAME "(" parameters ")" BLEND palette
parameters: (parameter ("," parameter)*)?
parameter: CNAME "=" (NUMBER | string)
NUMBER: (FLOAT | INT)

palette: palette_entry ("," palette_entry)*
palette_entry: "(" (NUMBER) "," (NUMBER) "," (NUMBER) ["," (NUMBER)] ")"
?string: CNAME | ESCAPED_STRING

%import common.CNAME
%import common.WORD
%import common.FLOAT
%import common.INT
%import common.WS
%import common.ESCAPED_STRING

%ignore WS
18 changes: 15 additions & 3 deletions packages/led_effect/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/led_effect/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.poetry]
name = "led-effect"
name = "led_effect"
version = "0.1.0"
authors = ["Julian Schill <[email protected]>"]
description = ""
Expand Down
44 changes: 44 additions & 0 deletions packages/led_effect/src/layer_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from . import layer_parser_lark



class TermTransformer(layer_parser_lark.Transformer):
NUMBER = float
RATE = float
CUTOFF = float
BLEND = str
LAYER_NAME = str
WORD = str
CNAME = str

@layer_parser_lark.v_args(inline=True)
def ESCAPED_STRING(self, s):
return s[1:-1].replace('\\"', '"')


layer_line_parser = layer_parser_lark.Lark_StandAlone()


def parse(line):
tree = TermTransformer().transform(layer_line_parser.parse(line))

if tree.children[0].data == "legacy_line":
effect, rate, cutoff, blend, palette = tree.children[0].children
palette = [tuple([color for color in entry.children if color != None])
for entry in palette.children]
return {
"effect": effect, "parameters": {"effectRate": rate, "effectCutoff": cutoff},
"blend": blend, "palette": palette
}
elif tree.children[0].data == "parameterized_line":
effect, parameters, blend, palette = tree.children[0].children

params = {k: v for k, v in [
(param.children[0], param.children[1]) for param in parameters.children]}

palette = [tuple([color for color in entry.children if color != None])
for entry in palette.children]
return {
"effect": effect, "blend": blend, "palette": palette, "parameters": params
}
return None
Loading

0 comments on commit 1342503

Please sign in to comment.