-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from Aman-Codes/scss_branch
feat(scss): added support for scss Reviewed-by: [email protected] Tested-by: [email protected]
- Loading branch information
Showing
8 changed files
with
226 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ The Languages we support till now: | |
- Ruby | ||
- Rust | ||
- Scala | ||
- Scss | ||
- Shell | ||
- Swift | ||
- TypeScript | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__all__ = ["c", "c_sharp", "cpp", "css", "dart", "go", "haskell", "html", "java", "javascript", "kotlin", "matlab", "perl", "php", "python", "r", "ruby", "rust", "scala", "shell", "swift", "text", "typescript"] | ||
__all__ = ["c", "c_sharp", "cpp", "css", "dart", "go", "haskell", "html", "java", "javascript", "kotlin", "matlab", "perl", "php", "python", "r", "ruby", "rust", "scala", "scss", "shell", "swift", "text", "typescript"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
''' | ||
Copyright (C) 2020 Aman Dwivedi ([email protected]) | ||
SPDX-License-Identifier: LGPL-2.1 | ||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
This library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
''' | ||
|
||
from nirjas.binder import * | ||
|
||
def scssExtractor(file): | ||
result = CommentSyntax() | ||
result1 = result.doubleNotTripleSlash(file) | ||
result2 = result.slashStar(file) | ||
result3 = result.tripleSlash(file) | ||
result4 = contSingleLines(result1) | ||
result5 = contSingleLines(result3) | ||
file = file.split("/") | ||
output = { | ||
"metadata": [{ | ||
"filename": file[-1], | ||
"lang": "Scss", | ||
"total_lines": result1[1], | ||
"total_lines_of_comments": result1[3]+result2[3]+result3[3], | ||
"blank_lines": result1[2], | ||
"sloc": result1[1]-(result1[3]+result2[3]+result3[3]+result1[2]) | ||
}], | ||
"single_line_comment": [], | ||
"cont_single_line_comment": [], | ||
"multi_line_comment": [] | ||
} | ||
|
||
if result4: | ||
result1 = result4[0] | ||
|
||
if result5: | ||
result3 = result5[0] | ||
|
||
if result1: | ||
for i in result1[0]: | ||
output['single_line_comment'].append({"line_number" :i[0],"comment": i[1]}) | ||
|
||
if result3: | ||
for i in result3[0]: | ||
output['single_line_comment'].append({"line_number" :i[0],"comment": i[1]}) | ||
|
||
if result4: | ||
for idx,i in enumerate(result4[1]): | ||
output['cont_single_line_comment'].append({"start_line": result4[1][idx], "end_line": result4[2][idx], "comment": result4[3][idx]}) | ||
|
||
if result5: | ||
for idx,i in enumerate(result5[1]): | ||
output['cont_single_line_comment'].append({"start_line": result5[1][idx], "end_line": result5[2][idx], "comment": result5[3][idx]}) | ||
|
||
if result2: | ||
try: | ||
for idx,i in enumerate(result2[0]): | ||
output['multi_line_comment'].append({"start_line": result2[0][idx], "end_line": result2[1][idx], "comment": result2[2][idx]}) | ||
except: | ||
pass | ||
|
||
return output | ||
|
||
def scssSource(file, newFile: str): | ||
closingCount = 0 | ||
copy = True | ||
with open(newFile, 'w+') as f1: | ||
with open(file) as f: | ||
for lineNumber, line in enumerate(f, start=1): | ||
if line.strip() == '/*': | ||
closingCount+=1 | ||
copy = False | ||
if closingCount%2 == 0: | ||
copy = True | ||
|
||
if line.strip() == '*/': | ||
closingCount+=1 | ||
copy = False | ||
if closingCount%2 == 0: | ||
copy = True | ||
|
||
if copy: | ||
if line.strip() != '/*' and line.strip() != '*/': | ||
Templine = line.replace(" ","") | ||
if Templine[0:3] != "///": # Syntax for single line documentation comment | ||
f1.write(line) | ||
elif Templine[0:2] != "//": # Syntax for single line comment | ||
f1.write(line) | ||
|
||
f.close() | ||
f1.close() | ||
return newFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
''' | ||
Copyright (C) 2020 Aman Dwivedi ([email protected]) | ||
SPDX-License-Identifier: LGPL-2.1 | ||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
This library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
''' | ||
|
||
import unittest | ||
import os | ||
from nirjas.languages import scss | ||
from nirjas.binder import readSingleLine,readMultiLineDiff | ||
|
||
class ScssTest(unittest.TestCase): | ||
testfile = os.path.join(os.path.abspath(os.path.dirname(__file__)), "TestFiles/textcomment.scss") | ||
|
||
def test_output(self): | ||
regex1 = r'''((?<!\/)\/\/(?!\/)\s*[\w #\.()@+-_*\d]*)''' | ||
regex2 = r'''(\/\/\/\s*[\w #\.()@+-_*\d]*)''' | ||
self.syntax_start = "/*" | ||
self.syntax_end ='*/' | ||
sign1 = '//' | ||
sign2 = '///' | ||
comment_single_doubleSlash = scss.readSingleLine(self.testfile,regex1,sign1) | ||
comment_single_tripleSlash = scss.readSingleLine(self.testfile,regex2,sign2) | ||
comment_multiline = scss.readMultiLineDiff(self.testfile,self.syntax_start,self.syntax_end) | ||
comment_contSingleline1 = scss.contSingleLines(comment_single_doubleSlash) | ||
comment_contSingleline2 = scss.contSingleLines(comment_single_tripleSlash) | ||
self.assertTrue(comment_single_doubleSlash) | ||
self.assertTrue(comment_single_tripleSlash) | ||
self.assertTrue(comment_multiline) | ||
self.assertTrue(comment_contSingleline1) | ||
self.assertTrue(comment_contSingleline2) | ||
|
||
|
||
def test_outputFormat(self): | ||
regex1 = r'''((?<!\/)\/\/(?!\/)\s*[\w #\.()@+-_*\d]*)''' | ||
regex2 = r'''(\/\/\/\s*[\w #\.()@+-_*\d]*)''' | ||
self.syntax_start = "/*" | ||
self.syntax_end ='*/' | ||
sign1 = '//' | ||
sign2 = '///' | ||
expected = scss.scssExtractor(self.testfile) | ||
comment_single_doubleSlash = scss.readSingleLine(self.testfile,regex1,sign1) | ||
comment_single_tripleSlash = scss.readSingleLine(self.testfile,regex2,sign2) | ||
comment_multiline = scss.readMultiLineDiff(self.testfile,self.syntax_start,self.syntax_end) | ||
comment_contSingleline1 = scss.contSingleLines(comment_single_doubleSlash) | ||
comment_contSingleline2 = scss.contSingleLines(comment_single_tripleSlash) | ||
file = self.testfile.split("/") | ||
output = { | ||
"metadata": [{ | ||
"filename": file[-1], | ||
"lang": "Scss", | ||
"total_lines": comment_single_doubleSlash[1], | ||
"total_lines_of_comments": comment_single_doubleSlash[3]+comment_single_tripleSlash[3]+comment_multiline[3], | ||
"blank_lines": comment_single_doubleSlash[2], | ||
"sloc": comment_single_doubleSlash[1]-(comment_single_doubleSlash[3]+comment_single_tripleSlash[3]+comment_multiline[3]+comment_single_doubleSlash[2]) | ||
}], | ||
"single_line_comment": [], | ||
"cont_single_line_comment": [], | ||
"multi_line_comment": [] | ||
} | ||
|
||
if comment_contSingleline1: | ||
comment_single_doubleSlash = comment_contSingleline1[0] | ||
|
||
if comment_contSingleline2: | ||
comment_single_tripleSlash = comment_contSingleline2[0] | ||
|
||
if comment_single_doubleSlash: | ||
for i in comment_single_doubleSlash[0]: | ||
output['single_line_comment'].append({"line_number" :i[0],"comment": i[1]}) | ||
|
||
if comment_single_tripleSlash: | ||
for i in comment_single_tripleSlash[0]: | ||
output['single_line_comment'].append({"line_number" :i[0],"comment": i[1]}) | ||
|
||
if comment_contSingleline1: | ||
for idx,i in enumerate(comment_contSingleline1[1]): | ||
output['cont_single_line_comment'].append({"start_line": comment_contSingleline1[1][idx], "end_line": comment_contSingleline1[2][idx], "comment": comment_contSingleline1[3][idx]}) | ||
|
||
if comment_contSingleline2: | ||
for idx,i in enumerate(comment_contSingleline2[1]): | ||
output['cont_single_line_comment'].append({"start_line": comment_contSingleline2[1][idx], "end_line": comment_contSingleline2[2][idx], "comment": comment_contSingleline2[3][idx]}) | ||
|
||
if comment_multiline: | ||
try: | ||
for idx,i in enumerate(comment_multiline[0]): | ||
output['multi_line_comment'].append({"start_line": comment_multiline[0][idx], "end_line": comment_multiline[1][idx], "comment": comment_multiline[2][idx]}) | ||
except: | ||
pass | ||
|
||
self.assertEqual(output,expected) | ||
|
||
def test_Source(self): | ||
name = "source.txt" | ||
newfile = scss.scssSource(self.testfile,name) | ||
|
||
self.assertTrue(newfile) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters