111 Commits
Author SHA1 Message Date
a60d994e25 Improve Performance of the Type System (#824)
* export the checker and ensure no methods or fields are exported

* make Checker reusable

* add PatchAndCheck method to Checker, and reuse it in visitors

* avoid unnecessary map and consolidate structs

* make all Nature methods use pointer-receiver

* added cache for type and nature information

* optimize type and nature checks

* more aggressively cache some partial results and add cheap checks

* cache reused values

* reduce copying in Nature by breaking down optional fields

* enforce use of cache

* improve ergonomics of FromType and NatureOf

* improve struct method fetching

* make cache private to Nature

* first iteration improving struct reflect caching

* cleaned up struct fields data

* improve caching of functions data

* simplify checker code

* simplify and remove dead code

* add checker benchmarks

* address PR comments and minor improvements

* rename from SetCache to Bind

* make the benchmarks more fair

* fix benchmark option not being applied

* move Cache to be argument instead of field

* merge FuncData into Optional

* rename Optional to TypeData

* simplify struct logic

* cache builtin numeric types

---------

Co-authored-by: Anton Medvedev <[email protected]>
2025-09-18 14:38:27 +02:00
Diego Augusto MolinaandGitHub 98b021a54c Allow backticks to be quoted in string literals (#820)
* allow backticks to be quoted in string literals

* remove redundant empty string
2025-08-28 11:06:51 +02:00
Diego Augusto MolinaandGitHub fefc347053 Improve parser and lexer (#811)
* convert source to a struct and fix minor issue displaying error

* lexer: add byte and char pos

* improve parser to use string instead of []rune

* add lexer benchmarks

* make lexer work as an iterator

* make parser use the new iterator API in lexer

* allow reusing the parser

* cleanup code

* add parser benchmarks
2025-06-30 20:08:46 +02:00
Anton MedvedevandGitHub 452d355706 Make expr.Eval faster (#775)
* Make expr.Eval faster

* Add bench_call_test.go

* Make parser config optional
2025-03-24 14:48:41 +01:00
Anton MedvedevandGitHub d5f9c1bf84 Fix parsing of variable declaration nodes combined with sequence node (#773)
Fixes #772
2025-03-18 10:49:13 +01:00
Anton Medvedev ddbaa171c4 Add more tailing comma tests 2025-03-09 10:48:37 +01:00
18e2e03c5a Allow tailing comma in arguments (#623)
* feat: extract code for compiling equal operator

* feat: support last argument append with comma

---------

Co-authored-by: Anton Medvedev <[email protected]>
2025-03-09 10:45:17 +01:00
Anton Medvedev 41da963d55 Remove pointer accessor check in parser 2025-03-08 17:11:49 +01:00
Anton Medvedev 26eebbe70c Better error message for predicate with sequence 2025-03-08 12:14:13 +01:00
Anton Medvedev 97e061adca Only allow if on precedence == 0 2025-03-08 12:02:09 +01:00
Anton Medvedev 2cff08a4a5 Refactor TestParse_error tests 2025-03-08 09:49:28 +01:00
Anton Medvedev c146c2fc9b Add SequenceNode
Fixes #717
2025-03-08 09:27:09 +01:00
9dd86858e1 feat: add node budget and memory limits (#762)
* feat: add node budget and memory limits

Implement compile-time and runtime safeguards against deeply nested expressions:

- Add MaxNodes limit to track and limit AST node count during parsing
- Move MemoryBudget from VM to Config for better configurability
- Add node creation tracking in parser to enforce node budget
- Refactor node creation to check limits before allocation
- Add RunWithConfig to VM for passing memory budget settings
- Set reasonable defaults in Config (10000 nodes, 1M memory)
- Add comprehensive tests for both node and memory limits

This prevents stack overflows from malicious or poorly written expressions
by failing fast with clear error messages during compilation or runtime.

Signed-off-by: Ville Vesilehto <[email protected]>

* Update parser.go

Signed-off-by: Anton Medvedev <[email protected]>

---------

Signed-off-by: Ville Vesilehto <[email protected]>
Signed-off-by: Anton Medvedev <[email protected]>
Co-authored-by: Anton Medvedev <[email protected]>
2025-03-07 14:09:41 +01:00
5000e417f5 Add if-else conditional (#736)
Co-authored-by: Anton Medvedev <[email protected]>
2025-02-23 14:19:51 +01:00
Anton MedvedevandGitHub c953d0dde1 Refactor types table (#667) 2024-06-04 00:08:01 +02:00
Anton Medvedev c8b0171f3a Return tree on parse errors 2024-05-18 23:41:49 +02:00
Anton MedvedevandGitHub 696844a709 Refactor lexer (#653) 2024-05-17 18:10:26 +02:00
Anton MedvedevandGitHub 68e3148c1f Vendor testify (#642) 2024-05-08 00:24:35 +02:00
Anton Medvedev c5dfe3a811 Make count() predicate optional 2024-04-13 23:38:35 +02:00
Anton MedvedevandGitHub 772eaba1ca Add predicate to sum() builtin (#592)
* Add predicate to sum() builtin

* go mod tidy
2024-04-13 15:37:02 +02:00
Ganesan KaruppasamyandGitHub 650a7f5ac1 Fix -1 not in [] expressions (#590) 2024-03-04 14:40:33 +01:00
SergeyandGitHub 26bfa591a9 Support chzained comparisonc1 < 2 < 3 (#581) 2024-02-27 14:23:49 +01:00
Anton MedvedevandGitHub b1e82de54a Refactor groupBy and sortBy (#562)
* Rearrange opcodes

* Refactor groupBy

* Fix tests

* Super opcodes for GroupBy

* Refactor sortBy builtin

* Fix sortBy bench
2024-02-15 19:53:35 +01:00
SergeyandGitHub 8d2e6b133c Add optional array access like foo?.[42] (#550) 2024-02-08 12:20:20 +01:00
SergeyandGitHub a0e2fe3664 Fix string literal slicing error (#543) 2024-01-31 18:07:26 +01:00
Anton Medvedev d645265cd1 Fix pipeline and call parsing 2024-01-24 23:49:57 +01:00
Anton Medvedev 7d4dd1a708 Improve ast printing for boolean operators 2024-01-17 23:21:11 +01:00
Ganesan KaruppasamyandGitHub 9b73bb722e Remove parents field for optimization (#527) 2024-01-16 12:47:46 +01:00
Anton MedvedevandGitHub e7b1a64b58 Allow to override builtins (#522)
* Allow to override builtins

* Add :: syntax to access builtin in case of override
2024-01-13 15:56:49 +01:00
Anton MedvedevandGitHub 30be4c9f08 Remove redundant fields from CallNode and BinaryNode (#504) 2023-12-29 19:50:08 +01:00
a0db9a6c19 feat: Implement Bitwise and Shift Operator Support (#496)
Co-authored-by: Ganesan Karuppasamy <[email protected]>
2023-12-25 18:25:26 +01:00
Ganesan KaruppasamyandGitHub 57a6bc8f7d Incorporate support for raw string literals (#485) 2023-12-25 18:05:25 +01:00
591e36fc00 Enhance the number parser to include support for parsing hexadecimal, binary, and octal literals. (#483)
* Enhance the number parser to include support for parsing hexadecimal, binary, and octal literals.

* added invalid literal test cases

* Refactoring code as per comment

---------

Co-authored-by: Ganesan Karuppasamy <[email protected]>
2023-12-08 18:33:50 +01:00
Anton Medvedev 551d2a7e0f Use expr-lang/expr 2023-12-03 21:53:01 +01:00
Anton Medvedev 113725207c Fix size check 2023-09-06 09:51:46 +02:00
Anton Medvedev e2c14ca624 Fix if 2023-09-06 09:42:58 +02:00
Anton Medvedev 3c4d579704 Check for an overflow before allocating 2023-09-06 09:42:58 +02:00
Anton Medvedev d78a714f19 Add check for int64->int conversion 2023-09-06 09:42:58 +02:00
Anton Medvedev 6d8d2390cf Remove countBy 2023-08-30 14:55:05 +02:00
Anton Medvedev 5023b3005d Add reduce() 2023-08-30 13:33:16 +02:00
Anton Medvedev 7f85c0551f Add countBy() 2023-08-30 12:07:16 +02:00
Anton Medvedev 32f5fde2eb Replace interface{} with any 2023-08-30 11:25:15 +02:00
Anton Medvedev 3f57b885d4 Add groupBy 2023-08-30 11:14:54 +02:00
Anton Medvedev 2fd03266f6 Add better pointer lexer 2023-08-25 15:50:57 +02:00
Anton Medvedev 4683fbe2bf Add parsing support for pointer names 2023-08-24 15:27:00 +02:00
Anton Medvedev 166d8b8ce9 Add filter()[-1] optimization 2023-08-24 11:15:43 +02:00
Anton Medvedev 2c139ca36a Add find() and findIndex() 2023-08-24 11:15:43 +02:00
Anton Medvedev d237c8ab4e Forbid to redeclare variables, builtins, functions. 2023-08-22 22:30:07 +02:00
Anton Medvedev ed5f9bfbcb Add variables 2023-08-22 22:30:07 +02:00
Anton Medvedev eb023470c8 Refactor lexer_test.go 2023-08-22 14:02:53 +02:00