From a91226c376dc257c03956a8fc2ac7fe4d2e27044 Mon Sep 17 00:00:00 2001 From: David 'Epper' Marshall Date: Sat, 7 May 2022 13:18:42 -0400 Subject: [PATCH] docs: cleanup (#14327) --- CONTRIBUTING.md | 18 +++++++++--------- vlib/builtin/string.v | 18 +++++++++--------- vlib/datatypes/README.md | 1 + vlib/regex/regex_util.v | 9 ++++++++- vlib/strings/builder.c.v | 2 +- 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9a3ec65dc..eda847aec 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -35,35 +35,35 @@ The main files are: - Creates a parser object for each file and runs `parse()` on them. - The correct backend is called (C, JS, native), and a binary is compiled. -2. `v/scanner` The scanner's job is to parse a list of characters and convert +2. `vlib/v/scanner` The scanner's job is to parse a list of characters and convert them to tokens. -3. `v/token` This is simply a list of all tokens, their string values, and a +3. `vlib/v/token` This is simply a list of all tokens, their string values, and a couple of helper functions. -4. `v/parser` The parser. It converts a list of tokens into an AST. +4. `vlib/v/parser` The parser. It converts a list of tokens into an AST. In V, objects can be used before declaration, so unknown types are marked as unresolved. They are resolved later in the type checker. -5. `v/table` V creates one table object that is shared by all parsers. It +5. `vlib/v/table` V creates one table object that is shared by all parsers. It contains all types, consts, and functions, as well as several helpers to search for objects by name, register new objects, modify types' fields, etc. -6. `v/checker` Type checker and resolver. It processes the AST and makes sure +6. `vlib/v/checker` Type checker and resolver. It processes the AST and makes sure the types are correct. Unresolved types are resolved, type information is added to the AST. -7. `v/gen/c` C backend. It simply walks the AST and generates C code that can be +7. `vlib/v/gen/c` C backend. It simply walks the AST and generates C code that can be compiled with Clang, GCC, Visual Studio, and TCC. -8. `v/gen/js` JavaScript backend. It simply walks the AST and generates JS code that can be +8. `vlib/v/gen/js` JavaScript backend. It simply walks the AST and generates JS code that can be executed on the browser or in NodeJS/Deno. -9. `v/gen/c/json.v` defines the json code generation. This file will be removed once V +9. `vlib/v/gen/c/json.v` defines the json code generation. This file will be removed once V supports comptime code generation, and it will be possible to do this using the language's tools. -10. `v/gen/native` is the directory with all the machine code generation logic. It +10. `vlib/v/gen/native` is the directory with all the machine code generation logic. It defines a set of functions that translate assembly instructions to machine code and build the binary from scratch byte by byte. It manually builds all headers, segments, sections, symtable, relocations, etc. Right now it only has basic diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index 54cfbc3a5..08de6da1f 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -550,6 +550,15 @@ pub fn (s string) u64() u64 { return strconv.common_parse_uint(s, 0, 64, false, false) or { 0 } } +// parse_uint is like `parse_int` but for unsigned numbers +// +// This method directly exposes the `parse_int` function from `strconv` +// as a method on `string`. For more advanced features, +// consider calling `strconv.common_parse_int` directly. +pub fn (s string) parse_uint(_base int, _bit_size int) ?u64 { + return strconv.parse_uint(s, _base, _bit_size) +} + // parse_int interprets a string s in the given base (0, 2 to 36) and // bit size (0 to 64) and returns the corresponding value i. // @@ -566,15 +575,6 @@ pub fn (s string) u64() u64 { // This method directly exposes the `parse_uint` function from `strconv` // as a method on `string`. For more advanced features, // consider calling `strconv.common_parse_uint` directly. -pub fn (s string) parse_uint(_base int, _bit_size int) ?u64 { - return strconv.parse_uint(s, _base, _bit_size) -} - -// parse_uint is like `parse_int` but for unsigned numbers -// -// This method directly exposes the `parse_int` function from `strconv` -// as a method on `string`. For more advanced features, -// consider calling `strconv.common_parse_int` directly. pub fn (s string) parse_int(_base int, _bit_size int) ?i64 { return strconv.parse_int(s, _base, _bit_size) } diff --git a/vlib/datatypes/README.md b/vlib/datatypes/README.md index 8e9dbdf62..e595c7f3b 100644 --- a/vlib/datatypes/README.md +++ b/vlib/datatypes/README.md @@ -26,4 +26,5 @@ println(stack) - [x] Stack (LIFO) - [x] Queue (FIFO) - [x] Min heap (priority queue) +- [ ] Set - [ ] ... diff --git a/vlib/regex/regex_util.v b/vlib/regex/regex_util.v index 8bece48f5..6b6056d21 100644 --- a/vlib/regex/regex_util.v +++ b/vlib/regex/regex_util.v @@ -249,7 +249,14 @@ pub fn (mut re RE) find_from(in_txt string, start int) (int, int) { return -1, -1 } -// find_all find all the non overlapping occurrences of the match pattern +// find_all find all the non overlapping occurrences of the match pattern and return the start and end index of the match +// +// Usage: +// ```v +// blurb := 'foobar boo steelbar toolbox foot tooooot' +// mut re := regex.regex_opt('f|t[eo]+')? +// res := re.find_all(blurb) // [0, 3, 12, 15, 20, 23, 28, 31, 33, 39] +// ``` [direct_array_access] pub fn (mut re RE) find_all(in_txt string) []int { // old_flag := re.flag diff --git a/vlib/strings/builder.c.v b/vlib/strings/builder.c.v index a32a961f9..70b262f34 100644 --- a/vlib/strings/builder.c.v +++ b/vlib/strings/builder.c.v @@ -57,7 +57,7 @@ pub fn (mut b Builder) write_b(data u8) { b << data } -// write_byte appends a single `data` byte to the accumulated buffer +// write_u8 appends a single `data` byte to the accumulated buffer pub fn (mut b Builder) write_u8(data u8) { b << data } -- 2.30.2