Comments (5)
Thanks for trying this out @yisonPylkita !
Yeah I haven't done any work on regular expressions yet, so it doesn't know how to handle those tokens. I can break it down why this doesn't work.
Lexer
If you look here, the lexer doesn't create any literal regular expression tokens, only divide, single line comments and multi-line comments https://github.com/jasonwilliams/boa/blob/master/src/lib/syntax/lexer.rs#L361-L388
We can prove this by looking at the token output for your source code, we end up with an identifier
between 2 divide
tokens which is clearly wrong
[
Token {
data: Keyword(
Var
),
pos: Position {
column_number: 1,
line_number: 1
}
},
Token {
data: Identifier(
"re2"
),
pos: Position {
column_number: 5,
line_number: 1
}
},
Token {
data: Punctuator(
Assign
),
pos: Position {
column_number: 9,
line_number: 1
}
},
Token {
data: Punctuator(
Div
),
pos: Position {
column_number: 11,
line_number: 1
}
},
Token {
data: Identifier(
"abc"
),
pos: Position {
column_number: 12,
line_number: 1
}
},
Token {
data: Punctuator(
Div
),
pos: Position {
column_number: 15,
line_number: 1
}
},
Token {
data: Punctuator(
Semicolon
),
pos: Position {
column_number: 16,
line_number: 1
}
}
]
We would need to add some additional logic here to check for an expresion between the 2 /
characters and mark that value as a regex token.
I actually think this is pretty dooable.
Parser
If you're interested, the error is being emitted from here:
https://github.com/jasonwilliams/boa/blob/master/src/lib/syntax/parser.rs#L524
There are not expressions currently that begin with a /
so that case isn't covered and it just fails.
We would need to create a new Const::RegExp()
expression here and then return it similar to this https://github.com/jasonwilliams/boa/blob/master/src/lib/syntax/parser.rs#L303
The error message could also be a bit more helpful too.
from boa.
Thanks for a quick replay.
Woow, that is a quite detailed problem description. It will definitely help me with a PR. I will start working on this in coming week.
from boa.
@yisonPylkita how you getting on?
from boa.
@yisonPylkita work has happened on this here:
jasonwilliams#94
from boa.
Milestone has now been created for regular expressions so this can be closed:
https://github.com/jasonwilliams/boa/milestone/3
from boa.
Related Issues (20)
- Intl: Extract implementation into a separate crate
- Intl: Remove hacks to get the supported locales of a service HOT 1
- Add backtraces to errors HOT 2
- Explore other storage methods for our test results HOT 12
- custom `JsValue` for better embed HOT 2
- Restrict Direct Construction of `JsValue` to Ensure Invariants HOT 4
- Function.prototyp.toString only returns a fixed `[native code]` string
- Relative imports in SimpleModuleLoader fail to resolve HOT 4
- `Context::get_active_script_or_module` should return a script or module when using import in a generator HOT 1
- Simplifying Function Binding HOT 4
- Array.prototype.at
- Implement `console.groupCollapsed()` method
- Implement `console.table()` method HOT 2
- Implement `console.profile()` and `console.profileEnd()` methods HOT 1
- Implement `console.trace()` method
- Implement `console.timeStamp()` methods HOT 2
- Add Boa Matrix space to the repo HOT 1
- Bug on set_loop_iteration_limit on ''.repeat
- Access to PropertyMap keys HOT 2
- to_json() on a nested data structure containing undefined should not fail
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from boa.