Skip to content

strings.textscanner, examples: add TextScanner .skip_whitespace/0, .peek_u8/0, .peek_n_u8/0, add mini_calculator_recursive_descent.v#23001

Merged
spytheman merged 1 commit intovlang:masterfrom
spytheman:feature/add/Textscanner.skip_whitespace
Nov 28, 2024
Merged

Conversation

@spytheman
Copy link
Copy Markdown
Contributor

@spytheman spytheman commented Nov 28, 2024

Here is a sample run of the new example, compared to bc:

#0 21:02:23 ^ feature/add/Textscanner.skip_whitespace ~/code/v>v run examples/mini_calculator_recursive_descent.v
Please enter the expression you want to calculate, e.g. `2 * (5-1)` .
Enter 'exit' or 'EXIT' to quit.
[1] 2 * (5-1)
8.0
[2] (((2+2)*3)+10)
22.0
[3] exit
#0 21:02:57 ^ feature/add/Textscanner.skip_whitespace ~/code/v>bc
2 * (5-1)
8
(((2+2)*3)+10)
22
#0 21:03:09 ^ feature/add/Textscanner.skip_whitespace ~/code/v>

Huly®: V_0.6-21442

…eek_u8/0, .peek_n_u8/0, add examples/mini_calculator_recursive_descent.v
@spytheman spytheman changed the title strings.textscanner, examples: add TextScanner .skip_whitespace/0, .peek_u8/0, .peek_n_u8/0, add examples/mini_calculator_recursive_descent.v strings.textscanner, examples: add TextScanner .skip_whitespace/0, .peek_u8/0, .peek_n_u8/0, add mini_calculator_recursive_descent.v Nov 28, 2024
@spytheman
Copy link
Copy Markdown
Contributor Author

Note: unlike examples/mini_calculator.v, examples/mini_calculator_recursive_descent.v can handle/skip whitespace, instead of erroring.

It is also shorter (since it reuses strings.textscanner for the trivial parts), and clearer to read/maintain (because of it using the recursive descent technique, instead of an explicit stack/array).

@spytheman spytheman merged commit c7ee45f into vlang:master Nov 28, 2024
@spytheman spytheman deleted the feature/add/Textscanner.skip_whitespace branch November 28, 2024 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant