parser: change the new_parser() signature
parent
624a932420
commit
0589decc43
|
@ -110,13 +110,13 @@ fn (p mut Parser) comp_time() {
|
|||
// Parse the function and embed resulting C code in current function so that
|
||||
// all variables are available.
|
||||
pos := p.cgen.lines.len - 1
|
||||
mut pp := p.v.new_parser('.vwebtmpl.v', Pass.main)
|
||||
mut pp := p.v.new_parser('.vwebtmpl.v')
|
||||
if !p.pref.is_debug {
|
||||
os.rm('.vwebtmpl.v')
|
||||
}
|
||||
pp.is_vweb = true
|
||||
pp.cur_fn = p.cur_fn // give access too all variables in current function
|
||||
pp.parse()
|
||||
pp.parse(.main)
|
||||
tmpl_fn_body := p.cgen.lines.slice(pos + 2, p.cgen.lines.len).join('\n').clone()
|
||||
end_pos := tmpl_fn_body.last_index('Builder_str( sb )') + 19 // TODO
|
||||
p.cgen.lines = p.cgen.lines.left(pos)
|
||||
|
|
|
@ -67,6 +67,7 @@ mut:
|
|||
out_name string // "program.exe"
|
||||
vroot string
|
||||
mod string // module being built with -lib
|
||||
//parsers []Parser
|
||||
}
|
||||
|
||||
struct Preferences {
|
||||
|
@ -222,6 +223,10 @@ fn (v mut V) compile() {
|
|||
|
||||
mut cgen := v.cgen
|
||||
cgen.genln('// Generated by V')
|
||||
// Add builtin parsers
|
||||
for i, file in v.files {
|
||||
// v.parsers << v.new_parser(file)
|
||||
}
|
||||
v.add_v_files_to_compile()
|
||||
if v.pref.is_verbose {
|
||||
println('all .v files:')
|
||||
|
@ -229,8 +234,8 @@ fn (v mut V) compile() {
|
|||
}
|
||||
// First pass (declarations)
|
||||
for file in v.files {
|
||||
mut p := v.new_parser(file, Pass.decl)
|
||||
p.parse()
|
||||
mut p := v.new_parser(file)
|
||||
p.parse(.decl)
|
||||
}
|
||||
// Main pass
|
||||
cgen.pass = Pass.main
|
||||
|
@ -282,8 +287,8 @@ fn (v mut V) compile() {
|
|||
cgen.genln('this line will be replaced with definitions')
|
||||
defs_pos := cgen.lines.len - 1
|
||||
for file in v.files {
|
||||
mut p := v.new_parser(file, Pass.main)
|
||||
p.parse()
|
||||
mut p := v.new_parser(file)
|
||||
p.parse(.main)
|
||||
// p.g.gen_x64()
|
||||
// Format all files (don't format automatically generated vlib headers)
|
||||
if !v.pref.nofmt && !file.contains('/vlib/') {
|
||||
|
@ -522,13 +527,13 @@ fn (v mut V) add_v_files_to_compile() {
|
|||
}
|
||||
// Parse builtin imports
|
||||
for file in v.files {
|
||||
mut p := v.new_parser(file, Pass.imports)
|
||||
p.parse()
|
||||
mut p := v.new_parser(file)
|
||||
p.parse(.imports)
|
||||
}
|
||||
// Parse user imports
|
||||
for file in user_files {
|
||||
mut p := v.new_parser(file, Pass.imports)
|
||||
p.parse()
|
||||
mut p := v.new_parser(file)
|
||||
p.parse(.imports)
|
||||
}
|
||||
// Parse lib imports
|
||||
/*
|
||||
|
@ -563,8 +568,8 @@ fn (v mut V) add_v_files_to_compile() {
|
|||
}
|
||||
// Add all imports referenced by these libs
|
||||
for file in vfiles {
|
||||
mut p := v.new_parser(file, Pass.imports)
|
||||
p.parse()
|
||||
mut p := v.new_parser(file)
|
||||
p.parse(.imports)
|
||||
}
|
||||
}
|
||||
if v.pref.is_verbose {
|
||||
|
|
|
@ -98,10 +98,8 @@ const (
|
|||
MaxModuleDepth = 4
|
||||
)
|
||||
|
||||
fn (v mut V) new_parser(path string, pass Pass) Parser {
|
||||
v.log('new_parser("$path")')
|
||||
v.cgen.pass = pass
|
||||
|
||||
fn (v mut V) new_parser(path string) Parser {
|
||||
//println('new_parser("$path")')
|
||||
mut path_pcguard := ''
|
||||
mut path_platform := '.v'
|
||||
for path_ending in ['_lin.v', '_mac.v', '_win.v', '_nix.v'] {
|
||||
|
@ -126,7 +124,6 @@ fn (v mut V) new_parser(path string, pass Pass) Parser {
|
|||
is_script: (v.pref.is_script && path == v.dir)
|
||||
pref: v.pref
|
||||
os: v.os
|
||||
pass: pass
|
||||
vroot: v.vroot
|
||||
building_v: !v.pref.is_repl && (path.contains('compiler/') ||
|
||||
path.contains('v/vlib'))
|
||||
|
@ -159,7 +156,8 @@ fn (p &Parser) log(s string) {
|
|||
*/
|
||||
}
|
||||
|
||||
fn (p mut Parser) parse() {
|
||||
fn (p mut Parser) parse(pass Pass) {
|
||||
p.pass = pass
|
||||
p.log('\nparse() run=$p.pass file=$p.file_name tok=${p.strtok()}')// , "script_file=", script_file)
|
||||
// `module main` is not required if it's a single file program
|
||||
if p.is_script || p.pref.is_test {
|
||||
|
@ -3528,13 +3526,6 @@ fn (p mut Parser) js_decode() string {
|
|||
return ''
|
||||
}
|
||||
|
||||
/*
|
||||
fn (p &Parser) building_v() bool {
|
||||
cur_dir := os.getwd()
|
||||
return p.file_path.contains('v/compiler') || cur_dir.contains('v/compiler')
|
||||
}
|
||||
*/
|
||||
|
||||
fn (p mut Parser) attribute() {
|
||||
p.check(.lsbr)
|
||||
if p.tok == .key_interface {
|
||||
|
|
Loading…
Reference in New Issue