Commit Graph

13 Commits

Author SHA1 Message Date
Bob Nystrom
ffc9ec950c feat: add trim, trimEnd, trimStart methods with optional chars argument to String class
Implement six new trimming methods on String: trim(), trim(chars), trimEnd(), trimEnd(chars), trimStart(), trimStart(chars). The core logic uses a private trim_ helper that accepts a chars string, converts it to code points, and iterates from the start and/or end of the string to remove matching characters. Default whitespace set is tab, carriage return, newline, and space. Includes comprehensive test coverage for default and custom character trimming, edge cases (empty strings, all-trimmed strings, 8-bit clean data), and runtime error when chars argument is not a string.
2018-07-15 17:48:56 +00:00
Bob Nystrom
dad494093e feat: add validation to skip/take and rename split parameter for clarity
Add type and range checks to Sequence.skip() and Sequence.take() methods, aborting with "Count must be a non-negative integer." when count is not a non-negative integer. Rename split() parameter from 'delim' to 'delimiter' and update its error message from "Argument must be a non-empty string." to "Delimiter must be a non-empty string." for consistency. Remove old behavior allowing negative counts and add new test files for skip/take validation errors.
2017-03-15 14:22:44 +00:00
Bob Nystrom
38b92435bf feat: add lazy skip and take methods to Sequence with SkipSequence and TakeSequence classes
Implement `skip(count)` and `take(count)` on the Sequence class, backed by new SkipSequence and TakeSequence wrapper classes that lazily skip or limit iteration. Includes documentation in the sequence module markdown, core source definitions, and unit tests for edge cases (zero, negative, and overflow counts).
2017-03-15 14:15:00 +00:00
Andew Jones
6fa769beeb feat: add split and replace methods to String class with tests and docs 2017-03-08 02:12:03 +00:00
Bob Nystrom
4d1215697e feat: add MapEntry class and make Map a Sequence for direct iteration
Add MapEntry class to expose key-value pairs during map iteration, and make Map extend Sequence so maps can be directly iterated with `for` loops. Rename the internal `iterate_` primitive to `iterate` and update error messages for invalid map iterators.
2016-07-06 14:17:07 +00:00
Bob Nystrom
b301e9f119 feat: implement eager * operator for String and List to repeat content by integer count
Add `*(count)` method to both String and List classes in wren_core.wren, enabling eager repetition of string characters or list elements. The operator validates that count is a non-negative integer, aborting with a clear error message otherwise. For strings, concatenates the original string count times; for lists, builds a new list by adding all elements count times. Includes comprehensive test cases for normal, zero, and edge-case inputs, plus error tests for negative, non-integer, and non-numeric counts. Also refactors existing list plus tests to use inline expressions and adds a plus_not_iterable error test.
2016-02-24 15:48:03 +00:00
Bob Nystrom
58d4dfc2db refactor: eagerly evaluate interpolated expressions in string compilation
Remove the deferred function compilation for interpolation parts and instead evaluate them directly during string parsing. This simplifies the compiler by eliminating the need for String.interpolate_() and the associated closure creation, replacing it with a direct list construction and join() call.
2015-11-23 15:08:14 +00:00
Bob Nystrom
920b3e2a32 feat: implement string interpolation with %(expr) syntax in compiler and core library
Add lexer support for `TOKEN_INTERPOLATION` to split string literals at interpolation points, introduce `MAX_INTERPOLATION_NESTING` limit of 8, and compile interpolated strings by emitting calls to `String.interpolate_()`. Optimize list and map literal construction with new `addCore_` primitives to reduce stack churn. Update `String`, `List`, and `Map` `toString` methods in core library to use interpolation syntax, and migrate all benchmark and test files from explicit concatenation to interpolated strings.
2015-11-11 15:55:48 +00:00
Bob Nystrom
c03d86c28b chore: move core.wren source from builtin/ to src/vm/ and update build paths
- Remove builtin/README.md explaining the .wren to .wren.inc conversion process
- Update src/README.md to document new aux/ directory for optional modules
- Fix generated file headers in wren_core.wren.inc and wren_aux_random.wren.inc to point to new source locations
- Update Makefile pattern rule to look for .wren sources in src/vm/ instead of builtin/
- Adjust wren_to_c_string.py to strip both "aux_" and "wren_" prefixes when deriving module names
2015-10-18 05:17:10 +00:00
Bob Nystrom
e0984a5012 fix: require parentheses for zero-argument join() method on Sequence
The zero-argument overload of `join` on `Sequence` was previously defined as a
getter-style method without parentheses. This change makes it a regular method
that requires explicit parentheses, consistent with the one-argument `join(sep)`
variant and standard Wren method syntax. The implementation now reads
`join() { join("") }` instead of `join { join("") }`.

All call sites in tests and documentation are updated accordingly.
2015-09-16 14:15:48 +00:00
Bob Nystrom
aa72900a9e feat: replace IO class with System class and remove separate IO module
- Delete wren_io.c, wren_io.h, and io.wren source files
- Remove multi-arity print overloads and IO.read/IO.time methods
- Add System class with print, printAll, write, writeAll methods to core.wren
- Update all documentation examples and README to use System.print instead of IO.print
2015-09-15 14:46:09 +00:00
Bob Nystrom
95626bb136 feat: replace inline C string literals with auto-generated .wren.inc includes
Replace the manually embedded C string constants for builtin Wren modules with
a new build system that automatically generates `.wren.inc` header files from
`.wren` source files. The old `script/generate_builtins.py` is removed and
replaced by `script/wren_to_c_string.py`, which produces standalone include
files with a `PREAMBLE` containing the module name and source path. The Makefile
gains pattern rules to rebuild these `.wren.inc` files whenever the
corresponding `.wren` source changes, and the `builtin` phony target is removed
since the generation is now automatic. The `wren.mk` wildcard lists are updated
to include the new `.wren.inc` files as dependencies. The `timer.c` and
`wren_core.c` source files now `#include` their respective `.wren.inc` headers
instead of defining the string literals inline, and the `timer.wren` trailing
newline is removed.
2015-09-13 17:03:02 +00:00
Thorbjørn Lindeijer
4555a47465 feat: add lazy Sequence.skip and Sequence.take methods with SkipSequence and TakeSequence classes
Implement SkipSequence and TakeSequence as lazy iterator-producing wrappers in the core Sequence class. SkipSequence advances past the first count elements on initial iteration, while TakeSequence tracks taken count via _taken field and returns null when exceeded. Include documentation in sequence.markdown, update wren_core.wren.inc, and add test files for both methods covering edge cases (zero, negative, overflow counts).
2015-04-06 15:54:04 +00:00