1- """The module containing the decomposer"""
1+ """The decomposer decomposes the file into tokes and passes them into the tree"""
2+
23from dataclasses import dataclass
34from pathlib import Path
45import re
@@ -15,6 +16,7 @@ class Iterator:
1516 prepend : str = ""
1617 previous_prepend : str = ""
1718
19+
1820class CommentHandling :
1921 """Class to handle the comments in a Nix file"""
2022
@@ -116,12 +118,13 @@ def get_comments_for_attaching(self) -> dict[int, list[tuple[str, bool]]]:
116118
117119 return self .__comments
118120
121+
119122class Decomposer :
120123 """Class to handle the decomposition of the Nix file and addition of tokens to the tree"""
121124
122125 def __init__ (self , file_path : Path , tree : DecomposerTree ) -> None :
123126 """Takes in file path and stores it for the main decomposition function
124-
127+
125128 Args:
126129 file_path: Path - The file path for the Nix configuration file
127130 tree: DecomposerTree - The tree that decomposer should add to
@@ -224,7 +227,7 @@ def __prepare_the_file(self, file: str) -> list[str]:
224227 rest_of_file_split : list = file .split (" " )
225228 i = 0
226229 while True :
227- if i < len (rest_of_file_split ): # Doing it like this because the length changes every time
230+ if i < len (rest_of_file_split ): # Doing it like this because the length changes every time
228231 rest_of_file_split , i = self .__connecting_spaced_lines (rest_of_file_split , i )
229232 i += 1
230233 else :
@@ -268,13 +271,13 @@ def __managing_the_rest_of_the_file(self) -> None:
268271 comment_list : list [tuple [str , bool ]] = comments .pop (equals_locations [iterator .equals_number ][2 ])
269272 comments_attached_to_id .update ({
270273 self .__checking_group (groups , equals_locations [iterator .equals_number ][0 ]) +
271- rest_of_file_split [equals_locations [iterator .equals_number ][1 ] - 1 ] :
274+ rest_of_file_split [equals_locations [iterator .equals_number ][1 ] - 1 ]:
272275 comment_list
273276 })
274277 except KeyError : # If there isn't a comment attached
275278 pass
276279 place_to_check = 1
277- for i in range (1 , len (rest_of_file_split )): # To stop empty portions like [""] being an issue and meaning something was skipped
280+ for i in range (1 , len (rest_of_file_split )): # To stop empty portions like [""] being an issue and meaning something was skipped
278281 if rest_of_file_split [equals_locations [iterator .equals_number ][1 ] + i ] != "" :
279282 place_to_check = i
280283 break
@@ -350,14 +353,14 @@ def __cleaning_the_configuration(self, file: str) -> str:
350353 Returns:
351354 file: str - the file all on one line now cleaned
352355 """
353- file = re .sub (r"[^\S\n]+" , " " , file ) # The [^\S\n] is my form of .*, it just excludes new lines so comment attaching can work as expected
356+ file = re .sub (r"[^\S\n]+" , " " , file ) # The [^\S\n] is my form of .*, it just excludes new lines so comment attaching can work as expected
354357 file = re .sub ("=" , " = " , file )
355358 file = re .sub (r"[^\S\n]}" , " } " , file )
356359 file = re .sub (r"[^\S\n]{" , " { " , file )
357360 file = re .sub (";" , " ; " , file ) # For with clauses
358361 file = re .sub (r"}[^\S\n]*;" , "}; " , file )
359362 file = re .sub (r"][^\S\n]*;" , "]; " , file )
360- file = re .sub (r'\[[^\S\n]*"' , '[ "' , file ) # Looks scary because of escapes for square brackets, is simply removing and adding spaces in lists
363+ file = re .sub (r'\[[^\S\n]*"' , '[ "' , file ) # Looks scary because of escapes for square brackets, is simply removing and adding spaces in lists
361364 file = re .sub (r"\[[^\S\n]*'" , "[ '" , file )
362365 file = re .sub (r"\[[^\S\n]*''" , "[ ''" , file )
363366 file = re .sub (r"(\S*)(];)" , r"\1 \2" , file )
@@ -478,7 +481,7 @@ def replace_normal_speech(match):
478481 char_count += len (line )
479482 return equals_locations
480483
481- def __add_comments_to_nodes (self , node : Node , prepend : str , comments : dict [str , list [tuple [str ,bool ]]]):
484+ def __add_comments_to_nodes (self , node : Node , prepend : str , comments : dict [str , list [tuple [str , bool ]]]):
482485 """Adds the comment lists to their respective nodes
483486
484487 Args:
0 commit comments