<commit_before>#!/usr/bin/perl
package main;
use v5.14;

# Adding modules in @INC
use FindBin qw($Bin);
use lib "$Bin/../lib";
use lib "$Bin/../lib/RVM";

# Pragmas
use strict;
use warnings;

# Packages
use Cortex;
use RVM::RVM;

# Function to evaluate if a scalar is a number (or not)
use Scalar::Util qw(looks_like_number); 

# Options
use Getopt::Long;

my $base  = "$Bin/..";
my $src   = "src";
my $help  = undef; 
my $build = "build/classes";

Getopt::Long::Configure('bundling');
GetOptions(
    "b|build-path=s" => \$build,
    "h|help"         => \$help,
    "r|root-path=s"  => \$base,
    "s|src-path=s"   => \$src,
);

# Help/Usage
die << "HELP" if($help);

 parser.pl
 --------------------
 Creates a package in Java for runngin a 
 program in assembly, loaded by Main.java
 
 OPTIONS:
 * -b, --build-path=s
   Path/Directory for .class files.
 * -r, --root-path=s
   Root directory for all the process.
 * -s, --src-path=s
   Path/Directory for .java files.

 AUTHORS
 <NAME>, <NAME>, 
 <NAME>.

HELP

if(scalar @ARGV != 1) { 
    die "USAGE: perl parser.pl program.txt\n";
} 

#######################################################################
##                             PARSING                               ##
#######################################################################

my $file = shift;

# Criando parser e programa
my $positronic_brain = new Cortex;
my @prog = $positronic_brain->parse("$file");

########################################################################
##                             PREPROC                                ##
########################################################################
my %textual;
my %numeric;

for my $line (@prog)
{
    # Split line fields
    my ($func, $arg, $label) = @$line;
    my $n = 0;
    
    # Creating variables
    if(defined $arg)
    {
        if( looks_like_number($arg) ) {
            $line->[1] = "n$arg";
            $numeric{$arg} = "Num n$arg = new Num($arg);";
        }
        else { #elsif( $arg =~ /^["'].*["']$/ ) { 
            $n++; $line->[1] = "msg$n";
            $textual{$arg} = "Text msg$n = new Text(\"$arg\");";
        }
    }
}

########################################################################
##                          PRINTING PARSER                           ##
########################################################################
mkdir "$base/$src/parser"; 
open(my $PARSER, ">", "$base/$src/parser/Parser.java");
select $PARSER;

# Preamble<commit_msg>Correcting bug when generating strings in Parser.java<commit_after>#!/usr/bin/perl
package main;
use v5.14;

# Adding modules in @INC
use FindBin qw($Bin);
use lib "$Bin/../lib";
use lib "$Bin/../lib/RVM";

# Pragmas
use strict;
use warnings;

# Packages
use Cortex;
use RVM::RVM;

# Function to evaluate if a scalar is a number (or not)
use Scalar::Util qw(looks_like_number); 

# Options
use Getopt::Long;

my $base  = "$Bin/..";
my $src   = "src";
my $help  = undef; 
my $build = "build/classes";

Getopt::Long::Configure('bundling');
GetOptions(
    "b|build-path=s" => \$build,
    "h|help"         => \$help,
    "r|root-path=s"  => \$base,
    "s|src-path=s"   => \$src,
);

# Help/Usage
die << "HELP" if($help);

 parser.pl
 --------------------
 Creates a package in Java for runngin a 
 program in assembly, loaded by Main.java
 
 OPTIONS:
 * -b, --build-path=s
   Path/Directory for .class files.
 * -r, --root-path=s
   Root directory for all the process.
 * -s, --src-path=s
   Path/Directory for .java files.

 AUTHORS
 <NAME>, <NAME>, 
 <NAME>.

HELP

if(scalar @ARGV != 1) { 
    die "USAGE: perl parser.pl program.txt\n";
} 

#######################################################################
##                             PARSING                               ##
#######################################################################

my $file = shift;

# Criando parser e programa
my $positronic_brain = new Cortex;
my @prog = $positronic_brain->parse("$file");

########################################################################
##                             PREPROC                                ##
########################################################################
my %textual;
my %numeric;

my $n = 0;
for my $line (@prog)
{
    # Split line fields
    my ($func, $arg, $label) = @$line;
    
    # Creating variables
    if(defined $arg)
    {
        if( looks_like_number($arg) ) {
            $line->[1] = "n$arg";
            $numeric{$arg} = "Num n$arg = new Num($arg);";
        }
        else { #elsif( $arg =~ /^["'].*["']$/ ) { 
            $n++; $line->[1] = "msg$n";
            $textual{$arg} = "Text msg$n = new Text(\"$arg\");";
        }
    }
}

########################################################################
##                          PRINTING PARSER                           ##
########################################################################
mkdir "$base/$src/parser"; 
open(my $PARSER, ">", "$base/$src/parser/Parser.java");
select $PARSER;

# Preamble
{'fraction_non_alphanumeric': 0.3241365621278285, 'fraction_numerical': 0.00277888050813815, 'mean_word_length': 2.5839260312944523, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6834319', 'n_tokens_mistral': 1619, 'n_tokens_neox': 1531, 'n_words': 383}