Skip to content

Commit a5aaf3e

Browse files
committed
(feat): add test extensio
1 parent c4dc4b4 commit a5aaf3e

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

src/PyReprism/languages/nasm.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import re
2+
from PyReprism.utils import extension
3+
4+
5+
class Nasm:
6+
def __init__() -> None:
7+
pass
8+
9+
@staticmethod
10+
def file_extension() -> str:
11+
return extension.nasm
12+
13+
@staticmethod
14+
def keywords() -> list:
15+
keyword = ''.split('|')
16+
return keyword
17+
18+
@staticmethod
19+
def comment_regex() -> re.Pattern:
20+
pattern = re.compile(r'(?P<comment>/\*[\s\S]*?\*/|/\*.*?$|^.*?\*/)|(?P<noncomment>[^/*]*[^\n]*)', re.DOTALL | re.MULTILINE)
21+
return pattern
22+
23+
@staticmethod
24+
def number_regex() -> re.Pattern:
25+
pattern = re.compile(r'')
26+
return pattern
27+
28+
@staticmethod
29+
def operator_regex() -> re.Pattern:
30+
pattern = re.compile(r'')
31+
return pattern
32+
33+
@staticmethod
34+
def keywords_regex() -> re.Pattern:
35+
return re.compile(r'\b(' + '|'.join(Nasm.keywords()) + r')\b')
36+
37+
@staticmethod
38+
def remove_comments(source_code: str, isList: bool = False) -> str:
39+
result = []
40+
for match in Nasm.comment_regex().finditer(source_code):
41+
if match.group('noncomment'):
42+
result.append(match.group('noncomment'))
43+
if isList:
44+
return result
45+
return ''.join(result)
46+
47+
@staticmethod
48+
def remove_keywords(source: str) -> str:
49+
return re.sub(re.compile(Nasm.keywords_regex()), '', source)

src/PyReprism/languages/nix.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import re
2+
from PyReprism.utils import extension
3+
4+
5+
class Nix:
6+
def __init__() -> None:
7+
pass
8+
9+
@staticmethod
10+
def file_extension() -> str:
11+
return extension.nix
12+
13+
@staticmethod
14+
def keywords() -> list:
15+
keyword = 'assert|builtins|else|if|in|inherit|let|null|or|then|with'.split('|')
16+
return keyword
17+
18+
@staticmethod
19+
def comment_regex() -> re.Pattern:
20+
pattern = re.compile(r'(?P<comment>/\*[\s\S]*?\*/|/\*.*?$|^.*?\*/)|(?P<noncomment>[^/*]*[^\n]*)', re.DOTALL | re.MULTILINE)
21+
return pattern
22+
23+
@staticmethod
24+
def number_regex() -> re.Pattern:
25+
pattern = re.compile(r'')
26+
return pattern
27+
28+
@staticmethod
29+
def operator_regex() -> re.Pattern:
30+
pattern = re.compile(r'[=!<>]=?|\+\+?|\|\||&&|\/\/|->?|[?@]')
31+
return pattern
32+
33+
@staticmethod
34+
def keywords_regex() -> re.Pattern:
35+
return re.compile(r'\b(' + '|'.join(Nix.keywords()) + r')\b')
36+
37+
@staticmethod
38+
def delimiters_regex() -> re.Pattern:
39+
return re.compile(r'[{}()[\].,:;]')
40+
41+
@staticmethod
42+
def remove_comments(source_code: str, isList: bool = False) -> str:
43+
return Nix.comment_regex().sub(lambda match: match.group('noncomment') if match.group('noncomment') else '', source_code).strip()
44+
result = []
45+
for match in Nix.comment_regex().finditer(source_code):
46+
if match.group('noncomment'):
47+
result.append(match.group('noncomment'))
48+
if isList:
49+
return result
50+
return ''.join(result)
51+
52+
@staticmethod
53+
def remove_keywords(source: str) -> str:
54+
return re.sub(re.compile(Nix.keywords_regex()), '', source)

src/tests/utils/test_extensions.py

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def test_extension():
134134
assert extension.smalltalk == '.st'
135135
assert extension.smarty == '.tpl'
136136
assert extension.soy == '.soy'
137+
assert extension.sql == '.sql'
137138
assert extension.stylus == '.styl'
138139
assert extension.swift == '.swift'
139140
assert extension.tcl == '.tcl'

0 commit comments

Comments
 (0)