#!/usr/bin/env raku

# 
# This file has been automatically generated by RaQt_maker V0.0.4.
# To modify and regenerate it, see the source code available here: 
#         https://github.com/yguillemot/RaQt_maker
# 


sub USAGE ()
{
    my $ver = "Qt::QtWidgets version 0.0.4";


    print qq:to/END/; 
            
        {$*PROGRAM-NAME} delivered with $ver
            
        Print the list of "use" instructions related to Qt::Widgets
        needed by the Raku script whose file name is specified.
            
        Usage: {$*PROGRAM-NAME} <file name>
            
        END
        
    exit 1;
}

multi sub MAIN(Str $fileName)
{

    my constant START = "use Qt::QtWidgets::";
    my constant END = ";\n";
    
#     my constant EXCLUDED
#         = set < QtWidgets QtSlot QtSignal QtSigsloty QtObject >;
        
    my constant CLASSES = set (
                "QApplication",
                "QAbstractButton",
                "QAbstractScrollArea",
                "QAction",
                "QBoxLayout",
                "QBrush",
                "QColor",
                "QCoreApplication",
                "QDialog",
                "QEvent",
                "QFileDialog",
                "QFont",
                "QFrame",
                "QGuiApplication",
                "QHBoxLayout",
                "QImage",
                "QInputEvent",
                "QLabel",
                "QLayout",
                "QLayoutItem",
                "QLineEdit",
                "QMenu",
                "QMouseEvent",
                "QPaintDevice",
                "QPaintEvent",
                "QPainter",
                "QPen",
                "QPoint",
                "QPointF",
                "QPushButton",
                "QRect",
                "QRegion",
                "QResizeEvent",
                "QSize",
                "QTextEdit",
                "QTimer",
                "QVBoxLayout",
                "QWidget",
                "Qt",

    );
    
    # Does the file exist and be readable ?
    if $fileName.IO !~~ :f & :r {
        say "Can't read $fileName";
        exit 1;
    }
    
    # Read the file
    my Str $code = slurp $fileName;
    
    # Remove all "use" instructions
    $code ~~ s:g/ 'use ' .+? ';'//;
    
    # Look for all words beginning with "Q"
    $code ~~ m:g/<< 'Q' \w+ >>/;
    
    # Create and print the "use" instructions based on the found words
    say "";
    say "use Qt::QtWidgets;";
    say [~] START <<~>> ((set $/.list>>.Str) (&) CLASSES).keys.sort <<~>> END;
}

