Exemplo n.º 1
0
    def _getParser(self, log_level):

        ## The relative path the the pushdown grammar parser file from the current file
        grammar_file_path = get_relative_path( "grammars_grammar.pushdown", __file__ )

        ## The parser used to build the Abstract Syntax Tree and parse the input text
        with open( grammar_file_path, "r", encoding='utf-8' ) as file:
            my_parser = pushdown.Lark( file.read(), start='language_syntax', parser='lalr', lexer='contextual', debug=log_level)
            return my_parser
Exemplo n.º 2
0
    def _getBackend(self, example_grammar, example_program, example_settings):
        function_file = get_relative_path( "examples/%s.html" % getCallerName(), __file__ )
        # log( 1, "function_file: %s", function_file )

        tree = self._getError( example_grammar, True )
        backend = code_formatter.Backend( code_formatter.SingleSpaceFormatter, tree, example_program, example_settings )
        generated_html = backend.generated_html()

        with open( function_file, 'w', newline='\n', encoding='utf-8' ) as output_file:
            output_file.write( generated_html )
            output_file.write("\n")

        return generated_html
Exemplo n.º 3
0
def getLogger(debug_level=127, logger_name=None, **kwargs):
    global log
    global line

    if kwargs.pop('create_test_file', False):
        kwargs['file'] = utilities.get_relative_path('main_unit_tests.txt',
                                                     __file__)

    log = debug_tools.logger.getLogger(debug_level, logger_name, **kwargs)
    _stderr.clear(log)
    _stdout.clear(log)

    frameinfo = inspect.getframeinfo(sys._getframe(1))
    line = frameinfo.lineno
Exemplo n.º 4
0
    def test_createStdoutHandler(self):
        std_replacement_path = utilities.get_relative_path(
            'stdout_replacement.py', utilities.__file__)

        with io.open(std_replacement_path, "r") as model_file:
            model_text = model_file.read()

        utilities._create_stdout_handler()

        with io.open(std_replacement_path, "r") as model_file:
            updated_model_text = model_file.read()

        self.assertEqual(updated_model_text, model_text)

        with io.open(std_replacement_path, "w", newline='\n') as model_file:
            model_file.write(model_text)
Exemplo n.º 5
0
    def setup_main_window(self):
        """
            How to remember last geometry of PyQt application?
            https://stackoverflow.com/questions/33869721/how-to-remember-last-geometry-of-pyqt-application
        """
        self.setWindowTitle(
            "Chomsky Grammar Tools for Context Free Grammars (CFG)")
        self.settings = QSettings(
            'Open Source GPL v3 Application',
            'Chomsky Grammar Tools for Context Free Grammars (CFG)')
        self.largestFirstCollumn = 0

        # Initial window size/pos last saved. Use default values for first time
        windowScreenGeometry = self.settings.value("mainWindowScreenGeometry")
        windowScreenState = self.settings.value("mainWindowScreenState")

        if windowScreenGeometry:
            self.restoreGeometry(windowScreenGeometry)

        else:
            self.resize(800, 600)
            # self.move( get_screen_center( self ) )

        if windowScreenState:
            self.restoreState(windowScreenState)

        # https://github.com/GNOME/adwaita-icon-theme
        # https://code.google.com/archive/p/faenza-icon-theme/
        self.mainApplicationIcon = QtGui.QIcon(
            get_relative_path("../login.png", __file__))

        # PyQt4 set windows taskbar icon
        # https://stackoverflow.com/questions/12432637/pyqt4-set-windows-taskbar-icon
        # https://stackoverflow.com/questions/44161669/how-to-set-a-python-qt4-window-icon
        self.setWindowIcon(self.mainApplicationIcon)

        # QWidget::setLayout: Attempting to set QLayout “” on ProgramWindow “”, which already has a layout
        # https://stackoverflow.com/questions/50176661/qwidgetsetlayout-attempting-to-set-qlayout-on-programwindow-which-alre
        self.centralwidget = QWidget()
        self.setCentralWidget(self.centralwidget)
Exemplo n.º 6
0
def generate_image(tree, tree_name):
    log.clean("Generating '%s'...", tree_name)
    make_png(tree, get_relative_path(tree_name, __file__), debug=0, dpi=300)
Exemplo n.º 7
0
program_name = "main_highlighter"
log = getLogger(__name__)


def assert_path(module):
    if module not in sys.path:
        sys.path.append(module)


assert_path(os.path.realpath(__file__))
from utilities import make_png
from debug_tools.utilities import get_relative_path

## The relative path the the pushdown grammar parser file from the current file
metagrammar_path = get_relative_path("grammars_grammar.pushdown", __file__)

## The parser used to build the syntax tree and parse the input text
with open(metagrammar_path, "r", encoding='utf-8') as file:
    my_parser = Lark(file.read(),
                     start='language_syntax',
                     parser='lalr',
                     lexer='contextual')

example_grammar = wrap_text(r"""
    scope: source.sma
    name: Abstract Machine Language
    contexts: {
        match: // {
            scope: comment.start.sma
            push: {
    def assert_path(module):

        if module not in sys.path:
            sys.path.append(module)

    # Import the debug tools
    assert_path(
        os.path.join(
            os.path.dirname(
                os.path.dirname(os.path.dirname(os.path.realpath(__file__)))),
            'all'))

# Import and reload the debugger
import imp
import debug_tools.logger
imp.reload(debug_tools.logger)

from debug_tools.logger import getLogger
from debug_tools.utilities import get_relative_path

log = getLogger(127,
                __name__,
                file=get_relative_path('file_handler_manual_tests.txt',
                                       __file__),
                stdout=True)
print('I am working!')

# Unlock the file
log.removeHandlers()