-
Notifications
You must be signed in to change notification settings - Fork 0
/
parsing.jl
28 lines (25 loc) · 982 Bytes
/
parsing.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#######################################################################
# Utilities for parsing Julia files
#######################################################################
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Parsing Julia files
#
# Based on
# https://discourse.julialang.org/t/parsing-a-julia-file/32622
#
#=
parsefile(file) = parse(join(["quote", readstring(file), "end"], ";"))
parsecode(code::String)::Vector =
# https://discourse.julialang.org/t/parsing-a-julia-file/32622
filter(x->!(x isa LineNumberNode),
Meta.parse(join(["quote", code, "end"], ";")).args[1].args)
=#
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# String → AST
# Parses `text` as Julia code
parseJuliaCode(text :: AbstractString) =
Meta.parse(join(["quote", text, "end"], "\n"))
# String → AST
# Parses file `filePath` as Julia code
parseJuliaFile(filePath :: AbstractString) =
parseJuliaCode(read(filePath, String))