Skip to content

Commit

Permalink
feat: parsers with stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
star0202 committed Jun 7, 2023
1 parent be308cd commit 554745f
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 87 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
node_modules
dist
.idea
params.txt
responses.txt
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
"test": "jest",
"build": "rimraf dist && tsc",
"release": "semantic-release",
"prepack": "pnpm build",
"params": "ts-node scripts/paramParser.ts",
"responses": "ts-node scripts/responseParser.ts"
"prepack": "pnpm build"
},
"packageManager": "[email protected]",
"release": {
Expand Down
49 changes: 0 additions & 49 deletions scripts/paramParser.ts

This file was deleted.

44 changes: 44 additions & 0 deletions scripts/parse_param.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from re import match, sub

raw = ""
while i := input():
raw += i
raw += "\n"

items = [
sub(r" +", " ", " ".join(x).replace("\t", ""))
for x in (x.strip().split(" ") for x in raw.split("\n") if x.strip())
]

print(items)

regex = r"^(.*) (.*)\((필수|선택)\) (.*)$"
result = []


def string_to_type(name: str) -> str:
if name == "STRING":
return "string"
elif name == "INTEGER":
return "number"
else:
raise NotImplementedError("not implemented")


for data in items:
matches = match(regex, data)

if not matches:
print("not matched:", data)
continue

name, typeName, required, description = matches.groups()

result.extend(
[
f"/** {description} */",
f'readonly {name}{"" if required == "필수" else "?"}: {string_to_type(typeName)}',
]
)

print("\n".join(result))
30 changes: 30 additions & 0 deletions scripts/parse_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from re import match, sub

raw = ""
while i := input():
raw += i
raw += "\n"

items = [
sub(r" +", " ", " ".join(x).replace("\t", ""))
for x in (x.strip().split(" ") for x in raw.split("\n") if x.strip())
]

print(items)

regex = r"^(\d*) (.*) (.*)$"
result = []

for data in items:
matches = match(regex, data)

if not matches:
print("not matched:", data)
continue

name, description = matches.groups()[1:3]

result.append(f"/** {description} */")
result.append(f"readonly {name}: str")

print("\n".join(result))
33 changes: 0 additions & 33 deletions scripts/responseParser.ts

This file was deleted.

0 comments on commit 554745f

Please sign in to comment.