From dea0da340bfedd169f655639aaebe52c1487836b Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 15 Apr 2026 04:37:02 +0300 Subject: [PATCH] doc: fix invalid instructions in vlib/v/README.md (fixes #23702) --- vlib/v/README.md | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/vlib/v/README.md b/vlib/v/README.md index 3e849b076..9805c9854 100644 --- a/vlib/v/README.md +++ b/vlib/v/README.md @@ -32,11 +32,11 @@ Skips the following file types: or `Preferences.compile_defines_all` **if any file is defined**. ## Parsing files -To parse something a new template is created as the first step: +To parse something, a new table is created as the first step: ```v import v.ast -table := ast.new_table() +mut table := ast.new_table() ``` a new preference is created: @@ -46,15 +46,10 @@ import v.pref pref_ := &pref.Preferences{} ``` -and a new scope is created: -```v -import v.ast - -scope := ast.Scope{ - parent: unsafe { nil } -} -``` -after that, you can parse your files. +After that, you can parse your files. +The parser creates the file scope internally and attaches it to the +returned `ast.File` in `parsed_file.scope`. +`ast.Table` also keeps a global scope in `table.global_scope`. ## Parse text If you want to parse only text which isn't saved on the disk you can use this function. @@ -62,8 +57,9 @@ If you want to parse only text which isn't saved on the disk you can use this fu import v.parser code := '' -// table, pref and scope needs to be passed as reference -parsed_file := parser.parse_text(code, table, .parse_comments, &pref, &scope) +path := 'example.v' +// table and pref need to be passed as reference +mut parsed_file := parser.parse_text(code, path, mut table, .parse_comments, pref_) ``` ## Parse a single file @@ -73,8 +69,8 @@ The paths are collected one step earlier. import v.parser path := '' -// table, pref and scope needs to be passed as reference -parsed_file := parser.parse_file(path, table, .parse_comments, &pref, &scope) +// table and pref need to be passed as reference +mut parsed_file := parser.parse_file(path, mut table, .parse_comments, pref_) ``` ## Parse a set of files @@ -84,8 +80,8 @@ there is also a function which does all the work. import v.parser paths := [''] -// table, pref and scope needs to be passed as reference -parsed_files := parser.parse_files(paths, table, &pref, &scope) +// table and pref need to be passed as reference +parsed_files := parser.parse_files(paths, mut table, pref_) ``` ## Parse imports @@ -104,14 +100,14 @@ A new checker is created: ```v oksyntax import v.checker -mut checker := checker.new_checker(table, &pref) +mut checker := checker.new_checker(table, pref_) ``` After checking your files in `checker.errors` and `checker.warnings` you can see the results. ### Check `ast.File` ```v oksyntax -checker.check(parsed_file) +checker.check(mut parsed_file) ``` ### Check a list of `ast.File` @@ -124,5 +120,5 @@ Generating C code works just as this: ```v oksyntax import v.gen.c -res := c.gen(parsed_files, table, &pref) +res := c.gen(parsed_files, mut table, pref_) ``` -- 2.39.5