Skip to content

Commit

Permalink
(feat): add test extensio
Browse files Browse the repository at this point in the history
  • Loading branch information
danielogen committed Sep 6, 2024
1 parent c4dc4b4 commit a5aaf3e
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/PyReprism/languages/nasm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import re
from PyReprism.utils import extension


class Nasm:
def __init__() -> None:
pass

@staticmethod
def file_extension() -> str:
return extension.nasm

@staticmethod
def keywords() -> list:
keyword = ''.split('|')
return keyword

@staticmethod
def comment_regex() -> re.Pattern:
pattern = re.compile(r'(?P<comment>/\*[\s\S]*?\*/|/\*.*?$|^.*?\*/)|(?P<noncomment>[^/*]*[^\n]*)', re.DOTALL | re.MULTILINE)
return pattern

@staticmethod
def number_regex() -> re.Pattern:
pattern = re.compile(r'')
return pattern

@staticmethod
def operator_regex() -> re.Pattern:
pattern = re.compile(r'')
return pattern

@staticmethod
def keywords_regex() -> re.Pattern:
return re.compile(r'\b(' + '|'.join(Nasm.keywords()) + r')\b')

@staticmethod
def remove_comments(source_code: str, isList: bool = False) -> str:
result = []
for match in Nasm.comment_regex().finditer(source_code):
if match.group('noncomment'):
result.append(match.group('noncomment'))
if isList:
return result
return ''.join(result)

@staticmethod
def remove_keywords(source: str) -> str:
return re.sub(re.compile(Nasm.keywords_regex()), '', source)
54 changes: 54 additions & 0 deletions src/PyReprism/languages/nix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import re
from PyReprism.utils import extension


class Nix:
def __init__() -> None:
pass

@staticmethod
def file_extension() -> str:
return extension.nix

@staticmethod
def keywords() -> list:
keyword = 'assert|builtins|else|if|in|inherit|let|null|or|then|with'.split('|')
return keyword

@staticmethod
def comment_regex() -> re.Pattern:
pattern = re.compile(r'(?P<comment>/\*[\s\S]*?\*/|/\*.*?$|^.*?\*/)|(?P<noncomment>[^/*]*[^\n]*)', re.DOTALL | re.MULTILINE)
return pattern

@staticmethod
def number_regex() -> re.Pattern:
pattern = re.compile(r'')
return pattern

@staticmethod
def operator_regex() -> re.Pattern:
pattern = re.compile(r'[=!<>]=?|\+\+?|\|\||&&|\/\/|->?|[?@]')
return pattern

@staticmethod
def keywords_regex() -> re.Pattern:
return re.compile(r'\b(' + '|'.join(Nix.keywords()) + r')\b')

@staticmethod
def delimiters_regex() -> re.Pattern:
return re.compile(r'[{}()[\].,:;]')

@staticmethod
def remove_comments(source_code: str, isList: bool = False) -> str:
return Nix.comment_regex().sub(lambda match: match.group('noncomment') if match.group('noncomment') else '', source_code).strip()
result = []
for match in Nix.comment_regex().finditer(source_code):
if match.group('noncomment'):
result.append(match.group('noncomment'))
if isList:
return result
return ''.join(result)

@staticmethod
def remove_keywords(source: str) -> str:
return re.sub(re.compile(Nix.keywords_regex()), '', source)
1 change: 1 addition & 0 deletions src/tests/utils/test_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def test_extension():
assert extension.smalltalk == '.st'
assert extension.smarty == '.tpl'
assert extension.soy == '.soy'
assert extension.sql == '.sql'
assert extension.stylus == '.styl'
assert extension.swift == '.swift'
assert extension.tcl == '.tcl'
Expand Down

0 comments on commit a5aaf3e

Please sign in to comment.