Commit graph

37 commits

Author SHA1 Message Date
leaysgur
5a73a663dc refactor(regular_expression)!: Simplify public APIs (#6262)
This PR makes 2 changes to improve the existing API that are not very useful.

- Remove `(Literal)Parser` and `FlagsParser` and their ASTs
- Add `with_flags(flags_text)` helper to `ParserOptions`

Here are the details.

> Remove `(Literal)Parser` and `FlagsParser` and their ASTs

Previously, the `oxc_regular_expression` crate exposed 3 parsers.

- `(Literal)Parser`: assumes `/pattern/flags` format
- `PatternParser`: assumes `pattern` part only
- `FlagsParser`: assumes `flags` part only

However, it turns out that in actual usecases, only the `PatternParser` is actually sufficient, as the pattern and flags are validated and sliced in advance on the `oxc_parser` side.

The current usecase for `(Literal)Parser` is mostly for internal testing.

There were also some misuses of `(Literal)Parser` that restore `format!("/{pattern}/{flags}")` back and use `(Literal)Parser`.

Therefore, only `PatternParser` is now published, and unnecessary ASTs have been removed.
(This also obsoletes #5592 .)

> Added `with_flags(flags_text)` helper to `ParserOptions`

Strictly speaking, there was a subtle difference between the "flag" strings that users were aware of and the "mode" recognised by the parser.

Therefore, it was a common mistake to forget to enable `unicode_mode` when using the `v` flag.

With this helper, crate users no longer need to distinguish between flags and modes.
2024-10-03 02:47:08 +00:00
DonIsaac
3120c6c5ba docs(parser): add module and struct level documentation (#5831) 2024-09-18 06:27:24 +00:00
Boshen
4abfa7682a
refactor(parser): add --ast and --comments to example 2024-09-14 09:02:23 +08:00
Boshen
e8bf30a125 feat(ast): add Comment::real_span (#5764) 2024-09-13 15:28:34 +00:00
rzvxa
59abf27d95 feat(ast, parser): add oxc_regular_expression types to the parser and AST. (#5256)
closes #5060
2024-09-03 02:36:37 +00:00
Boshen
5e27798dc3
chore(parser): parse regular expression in example 2024-08-28 19:32:44 +08:00
Boshen
dd3ad4d68e
chore(regular_expression): remove circular dependency
Error: Circular dependency detected: oxc_parser -> oxc_regular_expression
2024-08-23 16:16:10 +08:00
Boshen
4c989d0fda
chore(parser): remove multi-thread example
because `ouroboros` has a few heavy dependencies, including an older
version of itertools.
2024-08-16 22:57:10 +08:00
overlookmotel
2c7bb9f6c8 refactor(ast): pass final ScopeFlags into visit_function (#4283)
We have a strange workaround for `visit_function` where we pass in `ScopeFlags`, to support creating the scope inside `Function`, but setting different flags for `MethodDefinition`s.

Previously `visit_function` took `Option<ScopeFlags>` and then did `flags.unwrap_or(ScopeFlags::empty()) | ScopeFlags::Function` to it. Personally, I found this confusing. When I was looking at `MethodDefinition`, I was wondering "It's a function, why doesn't it set Function flag too?"

This changes makes it more explicit and clear what `ScopeFlags` everything has.
2024-07-16 07:22:07 +00:00
Boshen
a71787572e
chore: remove unsafe_code = "warn" rust lint
Feels too verbose as we already have unsafe comment turned on
2024-07-15 10:39:08 +08:00
Luca Bruno
5731e3957f
refactor(ast)!: store span details inside comment struct (#4132)
This tweaks `Comment` definition in order to internally store the start
and end position of its span.

Closes: https://github.com/oxc-project/oxc/issues/4069
2024-07-09 23:23:43 +08:00
Boshen
051ceb6539
chore: improve some format by running cargo +nightly fmt 2024-06-19 00:48:30 +08:00
Boshen
982e6f08df chore: make println and eprintln opt-in (#3712)
I noticed accidental `println` can be merged, which isn't really nice.
2024-06-17 10:40:34 +00:00
Boshen
e818fba21c refactor(parser): improve parse_simple_arrow_function_expression (#3349) 2024-05-19 06:05:39 +00:00
Boshen
9ced605487
refactor(parser): start porting arrow function parsing from tsc (#3340)
relates #3320
2024-05-18 22:35:29 +08:00
branchseer
f159f60084
Make ast types covariant over the allocator lifetime. (#2943)
## Why

Due to the usage of `&'alloc mut T` in `oxc_allocator::Box`, and
`bumpalo::collections::Vec` in `oxc_allocator::Vec`, ast types are
currently invariant over their allocator lifetime `'a`. This prevents
`ouroboros` from generating `borrow_*` on ast type fields, leading to
the unfriendly `with_*` api:
c250b288ef/crates/oxc_parser/examples/multi-thread.rs (L82-L84)

## How

- For `oxc_allocator::Vec`, switch to `allocator_api2::vec::Vec`, which
has a covariant relationship with the allocator lifetime.
- For `oxc_allocator::Box`, use `std::ptr::NonNull` which is
specifically designed to be covariant. I don't use
`allocator_api2::boxed::Box` because it holds the allocator for
dropping, so the size is bigger.

## Downside

Now that `oxc_allocator::Box` uses the unsafe `NonNull`. It has to be a
private field to be safe. This make it impossible to do `Box(....)`
pattern matching.
2024-04-12 18:12:18 +08:00
Boshen
59748199da
refactor(ast): clean up the ts type visit methods 2024-04-11 15:26:24 +08:00
Boshen
fb2ebf462e
chore: fix clippy on unsafe comment 2024-04-03 19:57:21 +08:00
Boshen
feb3c90098
chore(parser): allow unsafe in examples 2024-04-03 19:40:02 +08:00
Ali Rezvani
fc3878350f
refactor(ast): add walk_mut functions (#2776)
* move `visit` and `visit_mut` modules to a super module called `visit`
* add `walk_mut` module containing walk functions
* update `enter_node` and `leave_node` events to not pass a reference in the `VisitMut` trait
* add `AstType`, a non-referencing version of `AstKind` to use with `VisitMut` trait
* update the `VisitMut` trait's usages.
2024-03-25 20:40:13 +03:30
Ali Rezvani
198eea0bce
refactor(ast): add walk functions to Visit trait. (#2791)
closes #2442
2024-03-25 10:44:29 +08:00
Boshen
ef1108a749
chore: Rust v1.77.0 (#2781) 2024-03-21 17:21:57 +00:00
Boshen
0f86333437
refactor(ast): refactor Trivias API - have less noise around it (#2692) 2024-03-12 20:16:36 +08:00
Boshen
cda9c93436
fix(parser): improve lexing of jsx identifier to fix duplicated comments after jsx name (#2687) 2024-03-12 15:51:51 +08:00
Boshen
351a0572be
chore(parser): print both AST and errors in examples/parser 2024-02-26 23:20:46 +08:00
Boshen
a2c173de57
refactor: remove panic! from examples (#2454)
relates #2308
2024-02-20 16:18:39 +08:00
Boshen
6849c047ef
chore(parser): add visitor example (#2271)
closes #2256
2024-02-02 17:08:00 +08:00
Boshen
4886d408eb
chore(clippy): enable undocumented_unsafe_blocks 2023-10-16 15:18:14 +08:00
Boshen
8ae345bde0
chore(parser): add an AST Send example (#712)
relates #709

The allocator and lifetime gets in the way if we want to parse in
parallel but process them in a single thread.

This example uses `ouroboros` to provide a safe API for working with
this unsafe behavior.
2023-08-10 15:56:31 +08:00
Boshen
14720e7c69
refactor: move SourceType from oxc_ast to oxc_span (#351)
related #350
2023-05-12 23:16:14 +08:00
Shannon Rothe
df78044c87 lint 2023-03-01 20:47:52 -08:00
Shannon Rothe
4d894e7db1 parser: prevent JSX expressions using comma operator 2023-03-01 20:47:52 -08:00
Boshen
3b887dbeaf feat(parser): print json in parser example 2023-02-28 00:05:54 +08:00
Boshen
4684118c9e
fix: change example names so their binary names don't collide with each other 2023-02-23 21:46:39 +08:00
Boshen
7a44a657e1 feat: add miette fancy report to examples 2023-02-22 19:23:01 +08:00
Boshen
d8fd23524a
feat(oxc_parser): allow filename as option in examples/simple.rs 2023-02-12 15:57:40 +08:00
Boshen
3daf5bcea9
chore(example): add an example for testing purposes 2023-02-12 11:11:35 +08:00