Comments (3)
Thanks for the bug report.
From http://www.mozilla.org/js/language/js20/rationale/syntax.html
"To support error recovery, JavaScript 2.0's lexical grammar must be
made independent of its syntactic grammar. To make the lexical grammar
independent of the syntactic grammar, JavaScript 2.0 determines whether
a / starts a regular expression or is a division (or /=) operator solely
based on the previous token."
That page then lists the tokens that can precede a Regex literal, and says:
"Regardless of the previous token, // is interpreted as the beginning
of a comment."
Original comment by [email protected]
on 8 May 2007 at 6:19
from code-prettify.
I'm going to assume that "the previous token" does not consider either comment
or
whitespace tokens.
I'm further going to assume that the list of preceding tokens
"!", "!=", "!==", "#", "%", "%=", "&", "&&", "&&=", "&=", "(", "*",
"*=", "+", "+=", ",", "-", "-=", "->", ".", "..", "...", "/", "/=", ":",
"::", ";", "<", "<<", "<<=", "<=", "=", "==", "===", ">", ">=", ">>",
">>=", ">>>", ">>>=", "?", "@", "[", "^", "^=", "^^", "^^=", "{", "|",
"|=", "||", "||=", "~", "abstract", "break", "case", "catch", "class",
"const", "continue", "debugger", "default", "delete", "do", "else",
"enum", "export", "extends", "field", "final", "finally", "for",
"function", "goto", "if", "implements", "import", "in", "instanceof",
"is", "namespace", "native", "new", "package", "return", "static",
"switch", "synchronized", "throw", "throws", "transient", "try",
"typeof", "use", "var", "volatile", "while", "with",
So I'll need to check that the '.' is not the tail of a number.
Also, since I'm trying to come up with a lexical scheme that supports reasonably
readable code in a variety of languages I think I'll skip the keywords in this
list
that are not keywords in most languages -- `debugger`, `function`, and `field`
come
to mind, and `in` and `with` might cause problems as well. `with` in js has to
be
followed by an open paren, but `in` might present problems.
Removing the set of keywords, that in javascript cannot legally be followed by a
regexp literal according to the grammar yields
"!", "!=", "!==", "#", "%", "%=", "&", "&&", "&&=", "&=", "(", "*",
"*=", "+", "+=", ",", "-", "-=", "->", ".", "..", "...", "/", "/=", ":",
"::", ";", "<", "<<", "<<=", "<=", "=", "==", "===", ">", ">=", ">>",
">>=", ">>>", ">>>=", "?", "@", "[", "^", "^=", "^^", "^^=", "{", "|",
"|=", "||", "||=", "~", "break", "case", "catch",
"continue", "delete", "do", "else", "finally",
"in", "instanceof", "is", "return", "throw", "try", "typeof",
"is" and "in" are problematic, and are recently introduced language features.
I'm
inclined to skip them too.
Original comment by [email protected]
on 8 May 2007 at 6:35
- Changed title: *Lexer does not handle Javascript regular expression literals *
- Changed state: Accepted
from code-prettify.
Fixed: implemented lexing of regular expression literals using
an approach based on javascripts lexical grammar to decide when a /
begins a regexp literal.
See testcase at
http://google-code-prettify.googlecode.com/svn/trunk/tests/prettify_test.html#is
sue12
This is more conservative than javascript since I don't attempt to handle
lexically valid but syntactically invalid javascript.
There is one case where a regexp literal in a syntactically valid javascript
will not be recognized
for (var fieldName in /foo/) {
...
}
I have never seen this in practice. Someone might iterate over a regexp to
iterate out parenthetical matches, but they would have to assign the regexp
to a variable first, since javascript does not allow pooling of regexp
literals.
Original comment by [email protected]
on 23 May 2007 at 4:09
- Changed state: Fixed
from code-prettify.
Related Issues (20)
- Add support for Chapel? HOT 2
- [Feature Request] Add diff / patch highlighting support for StackExchange websites. HOT 1
- Add support for Idris
- No GitHub wiki
- Add support for Perl6 HOT 1
- How to use `Google Code Prettifier` to VBA macro in Microsoft Excel ?
- Add support for AppleScript HOT 1
- White space indentation added on Firefox when using linenums class
- Performance problem with "Hit Test" in Chrome HOT 1
- Wrong highlighting on stackoverflow.com vba if default is used HOT 1
- Extra white-space appears on the first line HOT 1
- XSS risks?
- Request: terraform / hcl language support HOT 2
- Golang run-on string when backticks appear to be escaped
- Makefile: is it really supported?
- Request support of ChoiceScript language
- Added 'record' among Java keywords
- How auto justify codes?
- Request support for DigitalMicrograph Scripting language (DM-script)
- Add support to MiniZinc
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 code-prettify.