# Path: src/SigasiProjectCreator/DotF/parseFile.py
# def parse_dotf(filename):
#     print('\nParsing file: ' + filename)
#     input_stream = FileStream(filename)
#     lexer = DotFLexer(input_stream)
#     stream = CommonTokenStream(lexer)
#     parser = DotFParser(stream)
#     tree = parser.cmd_options()
#     extractor = DotFextractListener()
#     extractor.options = []
#     walker = ParseTreeWalker()
#     walker.walk(extractor, tree)
#     return extractor.options
# 
# Path: src/SigasiProjectCreator/convertDotFtoCsv.py
# def rebase_file(filename, dotfdir):
#     hdlpath = os.path.expandvars(filename)
#     if not os.path.isabs(hdlpath):
#         hdlpath = os.path.join(dotfdir, hdlpath)
#     hdlpath = os.path.normpath(hdlpath)
#     return hdlpath


import os
import sys
import glob
from .parseFile import parse_dotf
from ..convertDotFtoCsv import rebase_file
                elif option[0] == "+incdir":
                    for fn in option[1:]:
                        self.includes.add(rebase_file(fn[1:], self.dotfdir))
                elif option[0] == "+define":
                    for df in option[1:]:
                        self.defines.append(df[1:].strip())
                else:
                    print('Unknown multiline option (ignored) : ' + option[0])
            else:
                bare_option = str(option).strip('"')
                if bare_option.startswith("-endlib"):
                    pass
                elif bare_option.startswith("-f "):
                    # Parse included .f file
                    subfile = os.path.expandvars(bare_option.split()[1])
                    if not os.path.isabs(subfile):
                        subfile = os.path.join(self.dotfdir, subfile)
                    subparser = DotFfileParser(subfile)
                    self.library_mapping.update(subparser.library_mapping)
                    self.includes |= subparser.includes
                    self.defines.extend(subparser.defines)
                elif bare_option.startswith("+") or bare_option.startswith("-"):
                    print("Unknown option (ignored) : " + bare_option)
                else:
                    # Design file: add to library mapping
                    if "*" in bare_option:
                        expanded_option = glob.glob(rebase_file(bare_option, self.dotfdir), recursive=True)
                        for f in expanded_option:
                            self.library_mapping[f] = 'work'
                    else:

# Path: src/SigasiProjectCreator/DotF/parseFile.py
# def parse_dotf(filename):
#     print('\nParsing file: ' + filename)
#     input_stream = FileStream(filename)
#     lexer = DotFLexer(input_stream)
#     stream = CommonTokenStream(lexer)
#     parser = DotFParser(stream)
#     tree = parser.cmd_options()
#     extractor = DotFextractListener()
#     extractor.options = []
#     walker = ParseTreeWalker()
#     walker.walk(extractor, tree)
#     return extractor.options
# 
# Path: src/SigasiProjectCreator/convertDotFtoCsv.py
# def rebase_file(filename, dotfdir):
#     hdlpath = os.path.expandvars(filename)
#     if not os.path.isabs(hdlpath):
#         hdlpath = os.path.join(dotfdir, hdlpath)
#     hdlpath = os.path.normpath(hdlpath)
#     return hdlpath


# Path: src/SigasiProjectCreator/DotF/DotFfileParser.py
import os
import sys
import glob
from .parseFile import parse_dotf
from ..convertDotFtoCsv import rebase_file

                elif option[0] == "+incdir":
                    for fn in option[1:]:
                        self.includes.add(rebase_file(fn[1:], self.dotfdir))
                elif option[0] == "+define":
                    for df in option[1:]:
                        self.defines.append(df[1:].strip())
                else:
                    print('Unknown multiline option (ignored) : ' + option[0])
            else:
                bare_option = str(option).strip('"')
                if bare_option.startswith("-endlib"):
                    pass
                elif bare_option.startswith("-f "):
                    # Parse included .f file
                    subfile = os.path.expandvars(bare_option.split()[1])
                    if not os.path.isabs(subfile):
                        subfile = os.path.join(self.dotfdir, subfile)
                    subparser = DotFfileParser(subfile)
                    self.library_mapping.update(subparser.library_mapping)
                    self.includes |= subparser.includes
                    self.defines.extend(subparser.defines)
                elif bare_option.startswith("+") or bare_option.startswith("-"):
                    print("Unknown option (ignored) : " + bare_option)
                else:
                    # Design file: add to library mapping
                    if "*" in bare_option:
                        expanded_option = glob.glob(rebase_file(bare_option, self.dotfdir), recursive=True)
                        for f in expanded_option:
                            self.library_mapping[f] = 'work'
                    else:

                        self.library_mapping[rebase_file(bare_option, self.dotfdir)] = 'work'