1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: parse_file(path)

This commit is contained in:
Alexander Medvednikov 2020-01-01 10:15:05 +01:00
parent 87cff0386c
commit 96d02849aa
4 changed files with 16 additions and 8 deletions

View File

@ -98,14 +98,14 @@ pub fn create(path string) ?File {
$if linux {
//$if linux_or_macos {
mut fd := 0
println('creat SYS')
//println('creat SYS')
$if macos {
fd = C.syscall(sys_open_nocancel, path.str, 0x601, 0x1b6)
}
$else {
fd = C.syscall(sys_creat, path.str, 511)
}
println('fd=$fd')
//println('fd=$fd')
if fd == -1 {
return error('failed to create file "$path"')
}

View File

@ -17,14 +17,12 @@ fn test_c_files() {
vexe := os.getenv('VEXE')
vroot := filepath.dir(vexe)
for i in 1 .. nr_tests + 1 {
text := os.read_file('$vroot/vlib/v/gen/tests/${i}.vv') or {
panic(err)
}
path := '$vroot/vlib/v/gen/tests/${i}.vv'
ctext := os.read_file('$vroot/vlib/v/gen/tests/${i}.c') or {
panic(err)
}
table := &table.Table{}
program := parser.parse_file(text, table)
program := parser.parse_file(path, table)
res := gen.cgen([program])
if compare_texts(res, ctext) {
eprintln('${i}... ' + term.green('OK'))

View File

@ -4,7 +4,9 @@ fn function1() int {
return 0
}
fn foo(a int) {}
fn foo(a int) {
end()
}
struct User {
name string
@ -57,5 +59,9 @@ fn init_array() {
}
fn end() {
}
fn main() {
}

View File

@ -62,11 +62,15 @@ pub fn (p mut Parser) get_type() types.Type {
}
}
pub fn parse_file(text string, table &table.Table) ast.File {
pub fn parse_file(path string, table &table.Table) ast.File {
text := os.read_file(path) or {
panic(err)
}
mut stmts := []ast.Stmt
mut p := Parser{
scanner: scanner.new_scanner(text)
table: table
file_name: path
}
p.read_first_token()
for {