Issue with using ANTLR4 from Julia via PyCall

I’m attempting to integrate ANTLR4 libraries into my Julia project using the PyCall library.
I encounter an error when running my code:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>akhil@KHUSHI:~/FortranStructureExtractor$ julia FSEFortran90.jl TestProgram/TestProgram.f90 TestProgram/TestProgramStructureJulia.DOT
An unexpected error occurred:PyError ($(Expr(:escape, :(ccall(#= /home/akhil/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:43 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class 'AttributeError'>
AttributeError("'PyCall.jlwrap' object has no attribute 'enterEveryRule'")
File "/usr/local/lib/python3.10/dist-packages/antlr4/tree/Tree.py", line 158, in walk
self.enterRule(listener, t)
File "/usr/local/lib/python3.10/dist-packages/antlr4/tree/Tree.py", line 177, in enterRule
listener.enterEveryRule(ctx)
ERROR: LoadError: PyError ($(Expr(:escape, :(ccall(#= /home/akhil/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:43 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class 'AttributeError'>
AttributeError("'PyCall.jlwrap' object has no attribute 'enterEveryRule'")
File "/usr/local/lib/python3.10/dist-packages/antlr4/tree/Tree.py", line 158, in walk
self.enterRule(listener, t)
File "/usr/local/lib/python3.10/dist-packages/antlr4/tree/Tree.py", line 177, in enterRule
listener.enterEveryRule(ctx)
Stacktrace:
[1] pyerr_check
@ ~/.julia/packages/PyCall/1gn3u/src/exception.jl:75 [inlined]
[2] pyerr_check
@ ~/.julia/packages/PyCall/1gn3u/src/exception.jl:79 [inlined]
[3] _handle_error(msg::String)
@ PyCall ~/.julia/packages/PyCall/1gn3u/src/exception.jl:96
[4] macro expansion
@ ~/.julia/packages/PyCall/1gn3u/src/exception.jl:110 [inlined]
[5] #107
@ ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:43 [inlined]
[6] disable_sigint
@ ./c.jl:473 [inlined]
[7] __pycall!
@ ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:42 [inlined]
[8] _pycall!(ret::PyObject, o::PyObject, args::Tuple{FSEFortran90Listener, PyObject}, nargs::Int64, kw::Ptr{Nothing})
@ PyCall ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:29
[9] _pycall!(ret::PyObject, o::PyObject, args::Tuple{FSEFortran90Listener, PyObject}, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ PyCall ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:11
[10] (::PyObject)(::FSEFortran90Listener, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ PyCall ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:86
[11] (::PyObject)(::FSEFortran90Listener, ::Vararg{Any})
@ PyCall ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:86
[12] process_source_file(filePath::String, listener::FSEFortran90Listener)
@ Main ~/FortranStructureExtractor/FSEFortran90.jl:161
[13] main()
@ Main ~/FortranStructureExtractor/FSEFortran90.jl:144
[14] top-level scope
@ ~/FortranStructureExtractor/FSEFortran90.jl:170
in expression starting at /home/akhil/FortranStructureExtractor/FSEFortran90.jl:170
</code>
<code>akhil@KHUSHI:~/FortranStructureExtractor$ julia FSEFortran90.jl TestProgram/TestProgram.f90 TestProgram/TestProgramStructureJulia.DOT An unexpected error occurred:PyError ($(Expr(:escape, :(ccall(#= /home/akhil/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:43 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class 'AttributeError'> AttributeError("'PyCall.jlwrap' object has no attribute 'enterEveryRule'") File "/usr/local/lib/python3.10/dist-packages/antlr4/tree/Tree.py", line 158, in walk self.enterRule(listener, t) File "/usr/local/lib/python3.10/dist-packages/antlr4/tree/Tree.py", line 177, in enterRule listener.enterEveryRule(ctx) ERROR: LoadError: PyError ($(Expr(:escape, :(ccall(#= /home/akhil/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:43 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class 'AttributeError'> AttributeError("'PyCall.jlwrap' object has no attribute 'enterEveryRule'") File "/usr/local/lib/python3.10/dist-packages/antlr4/tree/Tree.py", line 158, in walk self.enterRule(listener, t) File "/usr/local/lib/python3.10/dist-packages/antlr4/tree/Tree.py", line 177, in enterRule listener.enterEveryRule(ctx) Stacktrace: [1] pyerr_check @ ~/.julia/packages/PyCall/1gn3u/src/exception.jl:75 [inlined] [2] pyerr_check @ ~/.julia/packages/PyCall/1gn3u/src/exception.jl:79 [inlined] [3] _handle_error(msg::String) @ PyCall ~/.julia/packages/PyCall/1gn3u/src/exception.jl:96 [4] macro expansion @ ~/.julia/packages/PyCall/1gn3u/src/exception.jl:110 [inlined] [5] #107 @ ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:43 [inlined] [6] disable_sigint @ ./c.jl:473 [inlined] [7] __pycall! @ ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:42 [inlined] [8] _pycall!(ret::PyObject, o::PyObject, args::Tuple{FSEFortran90Listener, PyObject}, nargs::Int64, kw::Ptr{Nothing}) @ PyCall ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:29 [9] _pycall!(ret::PyObject, o::PyObject, args::Tuple{FSEFortran90Listener, PyObject}, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ PyCall ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:11 [10] (::PyObject)(::FSEFortran90Listener, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ PyCall ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:86 [11] (::PyObject)(::FSEFortran90Listener, ::Vararg{Any}) @ PyCall ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:86 [12] process_source_file(filePath::String, listener::FSEFortran90Listener) @ Main ~/FortranStructureExtractor/FSEFortran90.jl:161 [13] main() @ Main ~/FortranStructureExtractor/FSEFortran90.jl:144 [14] top-level scope @ ~/FortranStructureExtractor/FSEFortran90.jl:170 in expression starting at /home/akhil/FortranStructureExtractor/FSEFortran90.jl:170 </code>
akhil@KHUSHI:~/FortranStructureExtractor$ julia FSEFortran90.jl TestProgram/TestProgram.f90 TestProgram/TestProgramStructureJulia.DOT 
An unexpected error occurred:PyError ($(Expr(:escape, :(ccall(#= /home/akhil/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:43 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class 'AttributeError'>
AttributeError("'PyCall.jlwrap' object has no attribute 'enterEveryRule'")
  File "/usr/local/lib/python3.10/dist-packages/antlr4/tree/Tree.py", line 158, in walk
    self.enterRule(listener, t)
  File "/usr/local/lib/python3.10/dist-packages/antlr4/tree/Tree.py", line 177, in enterRule
    listener.enterEveryRule(ctx)
ERROR: LoadError: PyError ($(Expr(:escape, :(ccall(#= /home/akhil/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:43 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class 'AttributeError'>
AttributeError("'PyCall.jlwrap' object has no attribute 'enterEveryRule'")
  File "/usr/local/lib/python3.10/dist-packages/antlr4/tree/Tree.py", line 158, in walk
    self.enterRule(listener, t)
  File "/usr/local/lib/python3.10/dist-packages/antlr4/tree/Tree.py", line 177, in enterRule
    listener.enterEveryRule(ctx)
Stacktrace:
  [1] pyerr_check
    @ ~/.julia/packages/PyCall/1gn3u/src/exception.jl:75 [inlined]
  [2] pyerr_check
    @ ~/.julia/packages/PyCall/1gn3u/src/exception.jl:79 [inlined]
  [3] _handle_error(msg::String)
    @ PyCall ~/.julia/packages/PyCall/1gn3u/src/exception.jl:96
  [4] macro expansion
    @ ~/.julia/packages/PyCall/1gn3u/src/exception.jl:110 [inlined]
  [5] #107
    @ ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:43 [inlined]
  [6] disable_sigint
    @ ./c.jl:473 [inlined]
  [7] __pycall!
    @ ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:42 [inlined]
  [8] _pycall!(ret::PyObject, o::PyObject, args::Tuple{FSEFortran90Listener, PyObject}, nargs::Int64, kw::Ptr{Nothing})
    @ PyCall ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:29
  [9] _pycall!(ret::PyObject, o::PyObject, args::Tuple{FSEFortran90Listener, PyObject}, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ PyCall ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:11
 [10] (::PyObject)(::FSEFortran90Listener, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ PyCall ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:86
 [11] (::PyObject)(::FSEFortran90Listener, ::Vararg{Any})
    @ PyCall ~/.julia/packages/PyCall/1gn3u/src/pyfncall.jl:86
 [12] process_source_file(filePath::String, listener::FSEFortran90Listener)
    @ Main ~/FortranStructureExtractor/FSEFortran90.jl:161
 [13] main()
    @ Main ~/FortranStructureExtractor/FSEFortran90.jl:144
 [14] top-level scope
    @ ~/FortranStructureExtractor/FSEFortran90.jl:170
in expression starting at /home/akhil/FortranStructureExtractor/FSEFortran90.jl:170

My Julia Code (FSEFortran90.jl):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>include("ProgramNode/ProgramNode.jl")
import .ProgramNodeMod: ProgramNode, ProgramNodeType, addChild, toDOT
using PyCall
antlr4 = pyimport("antlr4")
const ParseTreeWalker = antlr4.ParseTreeWalker
pushfirst!(PyVector(pyimport("sys")."path"), pwd())
Fortran90ParserListener = pyimport("Fortran90ParserListener")
mutable struct FSEFortran90Listener
root::ProgramNode
parentStack::Vector{ProgramNode}
end
function FSEFortran90Listener(root::ProgramNode)
parentStack = Vector{ProgramNode}()
push!(parentStack, root)
return FSEFortran90Listener(root, parentStack)
end
function enterMainProgram(listener::FSEFortran90Listener, ctx)
programStmtContext = ctx.programStmt()
if programStmtContext !== nothing
programNameNode = programStmtContext.NAME()
programName = programNameNode.getText()
programNode = ProgramNode(programName, ProgramNodeType("Program"))
currentParent = last(listener.parentStack)
addChild(currentParent, programNode)
push!(listener.parentStack, programNode)
end
end
function exitMainProgram(listener::FSEFortran90Listener, ctx)
pop!(listener.parentStack)
end
function enterModule(listener::FSEFortran90Listener, ctx)
moduleStmtContext = ctx.moduleStmt()
if moduleStmtContext !== nothing
moduleNameNode = moduleStmtContext.moduleName().ident().NAME()
moduleName = moduleNameNode.getText()
moduleNode = ProgramNode(moduleName, ProgramNodeType("Module"))
currentParent = last(listener.parentStack)
addChild(currentParent, moduleNode)
push!(listener.parentStack, moduleNode)
end
end
function exitModule(listener::FSEFortran90Listener, ctx)
pop!(listener.parentStack)
end
function enterFunctionSubprogram(listener::FSEFortran90Listener, ctx)
functionNameNode = ctx.functionName().NAME()
functionName = functionNameNode.getText()
functionNode = ProgramNode(functionName, ProgramNodeType("Function"))
currentParent = last(listener.parentStack)
addChild(currentParent, functionNode)
push!(listener.parentStack, functionNode)
end
function exitFunctionSubprogram(listener::FSEFortran90Listener, ctx)
pop!(listener.parentStack)
end
function enterSubroutineSubprogram(listener::FSEFortran90Listener, ctx)
subroutineNameNode = ctx.subroutineName().NAME()
subroutineName = subroutineNameNode.getText()
subroutineNode = ProgramNode(subroutineName, ProgramNodeType("Subroutine"))
currentParent = last(listener.parentStack)
addChild(currentParent, subroutineNode)
push!(listener.parentStack, subroutineNode)
end
function exitSubroutineSubprogram(listener::FSEFortran90Listener, ctx)
pop!(listener.parentStack)
end
function enterFunctionInterfaceBody(listener::FSEFortran90Listener, ctx)
currentParent = last(listener.parentStack)
functionNameNode = ctx.NAME()
functionName = functionNameNode.getText()
functionNode = ProgramNode(functionName, ProgramNodeType("FunctionInterface"))
addChild(currentParent, functionNode)
push!(listener.parentStack, functionNode)
end
function exitFunctionInterfaceBody(listener::FSEFortran90Listener, ctx)
pop!(listener.parentStack)
end
function enterSubroutineInterfaceBody(listener::FSEFortran90Listener, ctx)
currentParent = last(listener.parentStack)
subroutineNameNode = ctx.NAME()
subroutineName = subroutineNameNode.getText()
subroutineNode = ProgramNode(subroutineName, ProgramNodeType("SubroutineInterface"))
addChild(currentParent, subroutineNode)
push!(listener.parentStack, subroutineNode)
end
function exitSubroutineInterfaceBody(listener::FSEFortran90Listener, ctx)
pop!(listener.parentStack)
end
using ArgParse
# Import necessary modules from the local Python files
#FSEFortran90Listener = pyimport("FSEFortran90Listener")
Fortran90Lexer = pyimport("Fortran90Lexer")
Fortran90Parser = pyimport("Fortran90Parser")
# Importing necessary Python packages
const FileStream = antlr4.FileStream
const CommonTokenStream = antlr4.CommonTokenStream
function parse_arguments()
s = ArgParseSettings()
@add_arg_table! s begin
"inputFilePath"
help = "Path to the input file (.f90)"
required = true
"outputFilePath"
help = "Path to the output file (.dot)"
required = true
end
return parse_args(s)
end
function main()
parsed_args = parse_arguments()
inputFilePath = parsed_args["inputFilePath"]
outputFilePath = parsed_args["outputFilePath"]
fileName = basename(inputFilePath)
root = ProgramNode(fileName, ProgramNodeType("File"))
listener = FSEFortran90Listener(root)
try
process_source_file(inputFilePath, listener)
dotRepresentation = toDOT(root)
write_to_file(dotRepresentation, outputFilePath)
println("DOT representation written to file successfully.")
catch e
println("An unexpected error occurred:", e)
rethrow()
end
end
function process_source_file(filePath, listener)
input = FileStream(filePath)
lexer = Fortran90Lexer.Fortran90Lexer(input)
tokens = CommonTokenStream(lexer)
parser = Fortran90Parser.Fortran90Parser(tokens)
tree = parser.program()
walker = ParseTreeWalker()
walker.walk(listener, tree)
end
function write_to_file(content, filePath)
open(filePath, "w") do f
write(f, content)
end
end
main()
</code>
<code>include("ProgramNode/ProgramNode.jl") import .ProgramNodeMod: ProgramNode, ProgramNodeType, addChild, toDOT using PyCall antlr4 = pyimport("antlr4") const ParseTreeWalker = antlr4.ParseTreeWalker pushfirst!(PyVector(pyimport("sys")."path"), pwd()) Fortran90ParserListener = pyimport("Fortran90ParserListener") mutable struct FSEFortran90Listener root::ProgramNode parentStack::Vector{ProgramNode} end function FSEFortran90Listener(root::ProgramNode) parentStack = Vector{ProgramNode}() push!(parentStack, root) return FSEFortran90Listener(root, parentStack) end function enterMainProgram(listener::FSEFortran90Listener, ctx) programStmtContext = ctx.programStmt() if programStmtContext !== nothing programNameNode = programStmtContext.NAME() programName = programNameNode.getText() programNode = ProgramNode(programName, ProgramNodeType("Program")) currentParent = last(listener.parentStack) addChild(currentParent, programNode) push!(listener.parentStack, programNode) end end function exitMainProgram(listener::FSEFortran90Listener, ctx) pop!(listener.parentStack) end function enterModule(listener::FSEFortran90Listener, ctx) moduleStmtContext = ctx.moduleStmt() if moduleStmtContext !== nothing moduleNameNode = moduleStmtContext.moduleName().ident().NAME() moduleName = moduleNameNode.getText() moduleNode = ProgramNode(moduleName, ProgramNodeType("Module")) currentParent = last(listener.parentStack) addChild(currentParent, moduleNode) push!(listener.parentStack, moduleNode) end end function exitModule(listener::FSEFortran90Listener, ctx) pop!(listener.parentStack) end function enterFunctionSubprogram(listener::FSEFortran90Listener, ctx) functionNameNode = ctx.functionName().NAME() functionName = functionNameNode.getText() functionNode = ProgramNode(functionName, ProgramNodeType("Function")) currentParent = last(listener.parentStack) addChild(currentParent, functionNode) push!(listener.parentStack, functionNode) end function exitFunctionSubprogram(listener::FSEFortran90Listener, ctx) pop!(listener.parentStack) end function enterSubroutineSubprogram(listener::FSEFortran90Listener, ctx) subroutineNameNode = ctx.subroutineName().NAME() subroutineName = subroutineNameNode.getText() subroutineNode = ProgramNode(subroutineName, ProgramNodeType("Subroutine")) currentParent = last(listener.parentStack) addChild(currentParent, subroutineNode) push!(listener.parentStack, subroutineNode) end function exitSubroutineSubprogram(listener::FSEFortran90Listener, ctx) pop!(listener.parentStack) end function enterFunctionInterfaceBody(listener::FSEFortran90Listener, ctx) currentParent = last(listener.parentStack) functionNameNode = ctx.NAME() functionName = functionNameNode.getText() functionNode = ProgramNode(functionName, ProgramNodeType("FunctionInterface")) addChild(currentParent, functionNode) push!(listener.parentStack, functionNode) end function exitFunctionInterfaceBody(listener::FSEFortran90Listener, ctx) pop!(listener.parentStack) end function enterSubroutineInterfaceBody(listener::FSEFortran90Listener, ctx) currentParent = last(listener.parentStack) subroutineNameNode = ctx.NAME() subroutineName = subroutineNameNode.getText() subroutineNode = ProgramNode(subroutineName, ProgramNodeType("SubroutineInterface")) addChild(currentParent, subroutineNode) push!(listener.parentStack, subroutineNode) end function exitSubroutineInterfaceBody(listener::FSEFortran90Listener, ctx) pop!(listener.parentStack) end using ArgParse # Import necessary modules from the local Python files #FSEFortran90Listener = pyimport("FSEFortran90Listener") Fortran90Lexer = pyimport("Fortran90Lexer") Fortran90Parser = pyimport("Fortran90Parser") # Importing necessary Python packages const FileStream = antlr4.FileStream const CommonTokenStream = antlr4.CommonTokenStream function parse_arguments() s = ArgParseSettings() @add_arg_table! s begin "inputFilePath" help = "Path to the input file (.f90)" required = true "outputFilePath" help = "Path to the output file (.dot)" required = true end return parse_args(s) end function main() parsed_args = parse_arguments() inputFilePath = parsed_args["inputFilePath"] outputFilePath = parsed_args["outputFilePath"] fileName = basename(inputFilePath) root = ProgramNode(fileName, ProgramNodeType("File")) listener = FSEFortran90Listener(root) try process_source_file(inputFilePath, listener) dotRepresentation = toDOT(root) write_to_file(dotRepresentation, outputFilePath) println("DOT representation written to file successfully.") catch e println("An unexpected error occurred:", e) rethrow() end end function process_source_file(filePath, listener) input = FileStream(filePath) lexer = Fortran90Lexer.Fortran90Lexer(input) tokens = CommonTokenStream(lexer) parser = Fortran90Parser.Fortran90Parser(tokens) tree = parser.program() walker = ParseTreeWalker() walker.walk(listener, tree) end function write_to_file(content, filePath) open(filePath, "w") do f write(f, content) end end main() </code>
include("ProgramNode/ProgramNode.jl")
import .ProgramNodeMod: ProgramNode, ProgramNodeType, addChild, toDOT

using PyCall

antlr4 = pyimport("antlr4")
const ParseTreeWalker = antlr4.ParseTreeWalker

pushfirst!(PyVector(pyimport("sys")."path"), pwd())
Fortran90ParserListener = pyimport("Fortran90ParserListener")

mutable struct FSEFortran90Listener
    root::ProgramNode
    parentStack::Vector{ProgramNode}
end

function FSEFortran90Listener(root::ProgramNode)
    parentStack = Vector{ProgramNode}()
    push!(parentStack, root)
    return FSEFortran90Listener(root, parentStack)
end

function enterMainProgram(listener::FSEFortran90Listener, ctx)
    programStmtContext = ctx.programStmt()
    if programStmtContext !== nothing
        programNameNode = programStmtContext.NAME()
        programName = programNameNode.getText()
        programNode = ProgramNode(programName, ProgramNodeType("Program"))
        currentParent = last(listener.parentStack)
        addChild(currentParent, programNode)
        push!(listener.parentStack, programNode)
    end
end

function exitMainProgram(listener::FSEFortran90Listener, ctx)
    pop!(listener.parentStack)
end

function enterModule(listener::FSEFortran90Listener, ctx)
    moduleStmtContext = ctx.moduleStmt()
    if moduleStmtContext !== nothing
        moduleNameNode = moduleStmtContext.moduleName().ident().NAME()
        moduleName = moduleNameNode.getText()
        moduleNode = ProgramNode(moduleName, ProgramNodeType("Module"))
        currentParent = last(listener.parentStack)
        addChild(currentParent, moduleNode)
        push!(listener.parentStack, moduleNode)
    end
end

function exitModule(listener::FSEFortran90Listener, ctx)
    pop!(listener.parentStack)
end

function enterFunctionSubprogram(listener::FSEFortran90Listener, ctx)
    functionNameNode = ctx.functionName().NAME()
    functionName = functionNameNode.getText()
    functionNode = ProgramNode(functionName, ProgramNodeType("Function"))
    currentParent = last(listener.parentStack)
    addChild(currentParent, functionNode)
    push!(listener.parentStack, functionNode)
end

function exitFunctionSubprogram(listener::FSEFortran90Listener, ctx)
    pop!(listener.parentStack)
end

function enterSubroutineSubprogram(listener::FSEFortran90Listener, ctx)
    subroutineNameNode = ctx.subroutineName().NAME()
    subroutineName = subroutineNameNode.getText()
    subroutineNode = ProgramNode(subroutineName, ProgramNodeType("Subroutine"))
    currentParent = last(listener.parentStack)
    addChild(currentParent, subroutineNode)
    push!(listener.parentStack, subroutineNode)
end

function exitSubroutineSubprogram(listener::FSEFortran90Listener, ctx)
    pop!(listener.parentStack)
end

function enterFunctionInterfaceBody(listener::FSEFortran90Listener, ctx)
    currentParent = last(listener.parentStack)
    functionNameNode = ctx.NAME()
    functionName = functionNameNode.getText()
    functionNode = ProgramNode(functionName, ProgramNodeType("FunctionInterface"))
    addChild(currentParent, functionNode)
    push!(listener.parentStack, functionNode)
end

function exitFunctionInterfaceBody(listener::FSEFortran90Listener, ctx)
    pop!(listener.parentStack)
end

function enterSubroutineInterfaceBody(listener::FSEFortran90Listener, ctx)
    currentParent = last(listener.parentStack)
    subroutineNameNode = ctx.NAME()
    subroutineName = subroutineNameNode.getText()
    subroutineNode = ProgramNode(subroutineName, ProgramNodeType("SubroutineInterface"))
    addChild(currentParent, subroutineNode)
    push!(listener.parentStack, subroutineNode)
end

function exitSubroutineInterfaceBody(listener::FSEFortran90Listener, ctx)
    pop!(listener.parentStack)
end

using ArgParse

# Import necessary modules from the local Python files
#FSEFortran90Listener = pyimport("FSEFortran90Listener")
Fortran90Lexer = pyimport("Fortran90Lexer")
Fortran90Parser = pyimport("Fortran90Parser")

# Importing necessary Python packages
const FileStream = antlr4.FileStream
const CommonTokenStream = antlr4.CommonTokenStream

function parse_arguments()
    s = ArgParseSettings()

    @add_arg_table! s begin
        "inputFilePath"
            help = "Path to the input file (.f90)"
            required = true
        "outputFilePath"
            help = "Path to the output file (.dot)"
            required = true
    end

    return parse_args(s)
end

function main()
    parsed_args = parse_arguments()

    inputFilePath = parsed_args["inputFilePath"]
    outputFilePath = parsed_args["outputFilePath"]

    fileName = basename(inputFilePath)
    root = ProgramNode(fileName, ProgramNodeType("File"))
    listener = FSEFortran90Listener(root)

    try
        process_source_file(inputFilePath, listener)
        dotRepresentation = toDOT(root)
        write_to_file(dotRepresentation, outputFilePath)
        println("DOT representation written to file successfully.")
    catch e
        println("An unexpected error occurred:", e)
        rethrow()
    end
end

function process_source_file(filePath, listener)
    input = FileStream(filePath)
    lexer = Fortran90Lexer.Fortran90Lexer(input)
    tokens = CommonTokenStream(lexer)
    parser = Fortran90Parser.Fortran90Parser(tokens)
    tree = parser.program()
    walker = ParseTreeWalker()
    walker.walk(listener, tree)
end

function write_to_file(content, filePath)
    open(filePath, "w") do f
        write(f, content)
    end
end

main()

I tried integrating the ANTLR4 libraries into my Julia project using the PyCall library. Specifically, I imported the necessary Python modules, set up the listener, and attempted to parse a Fortran 90 source file to generate a DOT representation.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật