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 google-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 google-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 google-code-prettify.
Related Issues (20)
- Perl syntax highlighting does not recognize POD and highlights quotes in comments
- Bash "$#" treated as comment HOT 1
- Integration for Presentation
- Patch for /trunk/src/lang-css.js
- "><img src=x onerror=prompt(1);> HOT 2
- Feature request: AspectJ syntax highlighting.
- gzip disabled
- Patch for /trunk/js-modules/run_prettify.js
- Patch for /trunk/src/lang-vb.js
- Line numbers carry over in clipboard using IE 11.
- Patch for /trunk/src/awkirin.css
- Problem with backslash in VB
- FLOW_CONTROL_KEYWORDS should not contain `do`
- Syntax Highlighting for Rebol (and Red) programming languages
- Patch for /trunk/styles/sons-of-obsidian.css
- Syntax highlight for Robot Framework syntax
- Patch for /trunk/src/prettify.css HOT 1
- Inconsist TCL Syntax higlighter
- Patch for /trunk/src/lang-sql.js
- Patch for /trunk/styles/sons-of-obsidian.css
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 google-code-prettify.