Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ilonachan committed Oct 1, 2024
1 parent ca84de1 commit 01809b2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
4 changes: 2 additions & 2 deletions formats/gds/cmddef.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

from typing import Optional, List, Union, Set
from typing import Optional, List, Union, Set, Any, Mapping
import os
from dataclasses import dataclass, field

Expand Down Expand Up @@ -395,4 +395,4 @@ def init_commands(root: str = None):
pprint.pp(COMMANDS_BYID)
pprint.pp(COMMANDS_BYNAME)
else:
init_commands()
init_commands()
42 changes: 37 additions & 5 deletions formats/gds/gda.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from typing import Optional, List
from dataclasses import dataclass


from utils import round_perfect
from .cmddef import GDSCommand
from .model import (
GDSProgram,
GDSElement,
Expand All @@ -18,8 +21,6 @@
GDSConditionToken
)

from utils import round_perfect

def read_gda(data: str, path: Optional[str] = None) -> GDSProgram:
pass

Expand All @@ -36,9 +37,10 @@ def nl(self):
self.result += '\n' + ' '*self.indent
def insert_comment(self, comment: str):
self.result, latest_line = self.result.rsplit("\n", 1)
self.nl()
self.write(f"# {comment}\n")
self.write(latest_line)
for line in comment.splitlines():
self.nl()
self.write(f"# {line}")
self.write("\n"+latest_line)


def write_gda(prog: GDSProgram, filename: Optional[str] = None) -> str:
Expand Down Expand Up @@ -185,3 +187,33 @@ def write_while(ctx: WriterContext, cmd: GDSLoopInvocation):
"repeatN": write_repeatN,
"while": write_while,
}



def format_comment(comment: str, filename: str, args: List[GDSValue], cmd: GDSCommand):
from parsy import forward_declaration, regex, seq, string, alt

str_part = regex(r'[^$]')
str_part_fvar = regex(r'[^$}:]')
str_part_expr = regex(r'[^$)]')
fvar_esc = string(r'}}') | string(r'::')
expr_esc = string(r'))')

format_args = regex(r"0\d+")
fvar = forward_declaration()
expr = forward_declaration()
str_var = string('$') >> (
string('{') >> fvar << string('}')
| string('(') >> expr << string(')')
)

varname = regex(r"\w+")

fvar_expr = (str_part_fvar | fvar_esc | str_var).many().concat()
fvar.become( seq ( (varname) , string(":") >> format_args | None ) )
expr.become( (str_part_expr | expr_esc | str_var).many().concat() )

str_ = (str_part | str_var).many().concat()

# TODO: parse variables like $TEST or ${1:03} and $(filepath)
pass

0 comments on commit 01809b2

Please sign in to comment.