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