<commit_before>package com.juliacomputing.jldt.eclipse.internal.parser;

import com.juliacomputing.jldt.eclipse.ast.Operator;
import com.juliacomputing.jldt.eclipse.ast.QualifiedName;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.tree.TerminalNode;
import org.eclipse.dltk.ast.ASTListNode;
import org.eclipse.dltk.ast.ASTNode;
import org.eclipse.dltk.ast.Modifiers;
import org.eclipse.dltk.ast.declarations.Argument;
import org.eclipse.dltk.ast.declarations.MethodDeclaration;
import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
import org.eclipse.dltk.ast.declarations.TypeDeclaration;
import org.eclipse.dltk.ast.expressions.Expression;
import org.eclipse.dltk.ast.references.SimpleReference;
import org.eclipse.dltk.ast.references.TypeReference;
import org.eclipse.dltk.ast.references.VariableReference;
import org.eclipse.dltk.ast.statements.Block;
import org.julia.lang.parser.JuliaParser.*;
import org.julia.lang.parser.JuliaParserBaseVisitor;

import java.util.ArrayList;
import java.util.List;


//todo review start/stop indices

public class JuliaModuleFactory extends JuliaParserBaseVisitor<ASTNode> {

    public ModuleDeclaration create(UnitContext context) {
        return visitUnit(context);
    }

    @Override
    public ModuleDeclaration visitUnit(UnitContext ctx) {
        final ModuleDeclaration moduleDeclaration = new ModuleDeclaration(ctx.getText().length());
        final List<StatementContext> statementContexts = ctx.statement();
        for (StatementContext statementContext : statementContexts) {
            final ASTNode statement = visit(statementContext);
            if (statement == null)
                continue;
            moduleDeclaration.addStatement(statement);
        }
        return moduleDeclaration;
    }

    @Override
    public ASTNode visitAssign(AssignContext ctx) {
        final Expression lhs = (Expression) visit(ctx.exp(0));
        final Expression rhs = (Expression) visit(ctx.exp(1));
        return new Operator("<-", start(ctx), stop(ctx), lhs, rhs);
    }

    @Override
    public ASTNode visitPlus(PlusContext ctx) {
        final Expression lhs = (Expression) visit(ctx.exp(0));
        final Expression rhs = (Expression) visit(ctx.exp(1));
        return new Operator("+", start(ctx), stop(ctx), lhs, rhs);
    }

    @Override
    public ASTNode visitIdentifier(IdentifierContext ctx) {
        final Token identifier = ctx.ID().getSymbol();
        return new VariableReference(start(identifier), stop(identifier), identifier.getText());
    }


    @Override<commit_msg>add named module support (minimal)<commit_after>package com.juliacomputing.jldt.eclipse.internal.parser;

import com.juliacomputing.jldt.eclipse.ast.Operator;
import com.juliacomputing.jldt.eclipse.ast.QualifiedName;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.tree.TerminalNode;
import org.eclipse.dltk.ast.ASTListNode;
import org.eclipse.dltk.ast.ASTNode;
import org.eclipse.dltk.ast.Modifiers;
import org.eclipse.dltk.ast.declarations.Argument;
import org.eclipse.dltk.ast.declarations.MethodDeclaration;
import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
import org.eclipse.dltk.ast.declarations.TypeDeclaration;
import org.eclipse.dltk.ast.expressions.Expression;
import org.eclipse.dltk.ast.references.SimpleReference;
import org.eclipse.dltk.ast.references.TypeReference;
import org.eclipse.dltk.ast.references.VariableReference;
import org.eclipse.dltk.ast.statements.Block;
import org.julia.lang.parser.JuliaParser.*;
import org.julia.lang.parser.JuliaParserBaseVisitor;

import java.util.ArrayList;
import java.util.List;


//todo review start/stop indices

public class JuliaModuleFactory extends JuliaParserBaseVisitor<ASTNode> {

    public ModuleDeclaration create(UnitContext context) {
        return visitUnit(context);
    }

    @Override
    public ModuleDeclaration visitUnit(UnitContext ctx) {
        final ModuleDeclaration moduleDeclaration = new ModuleDeclaration(ctx.getText().length());
        final List<StatementContext> statementContexts = ctx.statement();
        for (StatementContext statementContext : statementContexts) {
            final ASTNode statement = visit(statementContext);
            if (statement == null)
                continue;
            moduleDeclaration.addStatement(statement);
        }
        return moduleDeclaration;
    }

    @Override
    public ASTNode visitModuleDeclaration(ModuleDeclarationContext ctx) {
        ASTListNode statements = new ASTListNode();
        final List<StatementContext> statementContexts = ctx.statement();
        for (StatementContext statementContext : statementContexts) {
            final ASTNode statement = visit(statementContext);
            statements.addNode(statement);
        }
        return statements;
    }

    @Override
    public ASTNode visitAssign(AssignContext ctx) {
        final Expression lhs = (Expression) visit(ctx.exp(0));
        final Expression rhs = (Expression) visit(ctx.exp(1));
        return new Operator("<-", start(ctx), stop(ctx), lhs, rhs);
    }

    @Override
    public ASTNode visitPlus(PlusContext ctx) {
        final Expression lhs = (Expression) visit(ctx.exp(0));
        final Expression rhs = (Expression) visit(ctx.exp(1));
        return new Operator("+", start(ctx), stop(ctx), lhs, rhs);
    }

    @Override
    public ASTNode visitIdentifier(IdentifierContext ctx) {
        final Token identifier = ctx.ID().getSymbol();
        return new VariableReference(start(identifier), stop(identifier), identifier.getText());
    }


    @Override
{'fraction_non_alphanumeric': 0.1036360442648867, 'fraction_numerical': 0.002459160372387142, 'mean_word_length': 3.9427083333333335, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 8, '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': '6083765', 'n_tokens_mistral': 1636, 'n_tokens_neox': 1596, 'n_words': 321}