mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
couple more tweaks to lexer.coffee
This commit is contained in:
parent
29ece0e6ba
commit
cd6dd5abfd
2 changed files with 12 additions and 11 deletions
10
lib/lexer.js
10
lib/lexer.js
|
@ -7,7 +7,7 @@
|
||||||
//
|
//
|
||||||
// [tag, value, line_number]
|
// [tag, value, line_number]
|
||||||
//
|
//
|
||||||
// Which is a format that can be fed directly into Jison.
|
// Which is a format that can be fed directly into [Jison](http://github.com/zaach/jison).
|
||||||
// Set up the Lexer for both Node.js and the browser, depending on where we are.
|
// Set up the Lexer for both Node.js and the browser, depending on where we are.
|
||||||
if ((typeof process !== "undefined" && process !== null)) {
|
if ((typeof process !== "undefined" && process !== null)) {
|
||||||
Rewriter = require('./rewriter').Rewriter;
|
Rewriter = require('./rewriter').Rewriter;
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
}
|
}
|
||||||
// Constants
|
// Constants
|
||||||
// ---------
|
// ---------
|
||||||
// Keywords that CoffeScript shares in common with JS.
|
// Keywords that CoffeeScript shares in common with JavaScript.
|
||||||
JS_KEYWORDS = ["if", "else", "true", "false", "new", "return", "try", "catch", "finally", "throw", "break", "continue", "for", "in", "while", "delete", "instanceof", "typeof", "switch", "super", "extends", "class"];
|
JS_KEYWORDS = ["if", "else", "true", "false", "new", "return", "try", "catch", "finally", "throw", "break", "continue", "for", "in", "while", "delete", "instanceof", "typeof", "switch", "super", "extends", "class"];
|
||||||
// CoffeeScript-only keywords, which we're more relaxed about allowing. They can't
|
// CoffeeScript-only keywords, which we're more relaxed about allowing. They can't
|
||||||
// be used standalone, but you can reference them as an attached property.
|
// be used standalone, but you can reference them as an attached property.
|
||||||
|
@ -68,7 +68,7 @@
|
||||||
// Tokens that indicate an access -- keywords immediately following will be
|
// Tokens that indicate an access -- keywords immediately following will be
|
||||||
// treated as identifiers.
|
// treated as identifiers.
|
||||||
ACCESSORS = ['PROPERTY_ACCESS', 'PROTOTYPE_ACCESS', 'SOAK_ACCESS', '@'];
|
ACCESSORS = ['PROPERTY_ACCESS', 'PROTOTYPE_ACCESS', 'SOAK_ACCESS', '@'];
|
||||||
// Tokens that, when immediately preceding a 'WHEN', indicate that the 'WHEN'
|
// Tokens that, when immediately preceding a `WHEN`, indicate that the `WHEN`
|
||||||
// occurs at the start of a line. We disambiguate these from trailing whens to
|
// occurs at the start of a line. We disambiguate these from trailing whens to
|
||||||
// avoid an ambiguity in the grammar.
|
// avoid an ambiguity in the grammar.
|
||||||
BEFORE_WHEN = ['INDENT', 'OUTDENT', 'TERMINATOR'];
|
BEFORE_WHEN = ['INDENT', 'OUTDENT', 'TERMINATOR'];
|
||||||
|
@ -298,7 +298,7 @@
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
// We treat all other single characters as a token. Eg.: `( ) , . !`
|
// We treat all other single characters as a token. Eg.: `( ) , . !`
|
||||||
// Multi-character operators are also literal tokens, so that Racc can assign
|
// Multi-character operators are also literal tokens, so that Jison can assign
|
||||||
// the proper order of operations.
|
// the proper order of operations.
|
||||||
Lexer.prototype.literal_token = function literal_token() {
|
Lexer.prototype.literal_token = function literal_token() {
|
||||||
var match, not_spaced, tag, value;
|
var match, not_spaced, tag, value;
|
||||||
|
@ -338,7 +338,7 @@
|
||||||
};
|
};
|
||||||
// Token Manipulators
|
// Token Manipulators
|
||||||
// ------------------
|
// ------------------
|
||||||
// As we consume a new IDENTIFIER, look at the previous token to determine
|
// As we consume a new `IDENTIFIER`, look at the previous token to determine
|
||||||
// if it's a special kind of accessor.
|
// if it's a special kind of accessor.
|
||||||
Lexer.prototype.name_access_type = function name_access_type() {
|
Lexer.prototype.name_access_type = function name_access_type() {
|
||||||
if (this.value() === '::') {
|
if (this.value() === '::') {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#
|
#
|
||||||
# [tag, value, line_number]
|
# [tag, value, line_number]
|
||||||
#
|
#
|
||||||
# Which is a format that can be fed directly into Jison.
|
# Which is a format that can be fed directly into [Jison](http://github.com/zaach/jison).
|
||||||
|
|
||||||
# Set up the Lexer for both Node.js and the browser, depending on where we are.
|
# Set up the Lexer for both Node.js and the browser, depending on where we are.
|
||||||
if process?
|
if process?
|
||||||
|
@ -17,7 +17,7 @@ else
|
||||||
# Constants
|
# Constants
|
||||||
# ---------
|
# ---------
|
||||||
|
|
||||||
# Keywords that CoffeScript shares in common with JS.
|
# Keywords that CoffeeScript shares in common with JavaScript.
|
||||||
JS_KEYWORDS: [
|
JS_KEYWORDS: [
|
||||||
"if", "else",
|
"if", "else",
|
||||||
"true", "false",
|
"true", "false",
|
||||||
|
@ -98,7 +98,7 @@ CALLABLE: ['IDENTIFIER', 'SUPER', ')', ']', '}', 'STRING', '@']
|
||||||
# treated as identifiers.
|
# treated as identifiers.
|
||||||
ACCESSORS: ['PROPERTY_ACCESS', 'PROTOTYPE_ACCESS', 'SOAK_ACCESS', '@']
|
ACCESSORS: ['PROPERTY_ACCESS', 'PROTOTYPE_ACCESS', 'SOAK_ACCESS', '@']
|
||||||
|
|
||||||
# Tokens that, when immediately preceding a 'WHEN', indicate that the 'WHEN'
|
# Tokens that, when immediately preceding a `WHEN`, indicate that the `WHEN`
|
||||||
# occurs at the start of a line. We disambiguate these from trailing whens to
|
# occurs at the start of a line. We disambiguate these from trailing whens to
|
||||||
# avoid an ambiguity in the grammar.
|
# avoid an ambiguity in the grammar.
|
||||||
BEFORE_WHEN: ['INDENT', 'OUTDENT', 'TERMINATOR']
|
BEFORE_WHEN: ['INDENT', 'OUTDENT', 'TERMINATOR']
|
||||||
|
@ -258,7 +258,7 @@ exports.Lexer: class Lexer
|
||||||
true
|
true
|
||||||
|
|
||||||
# We treat all other single characters as a token. Eg.: `( ) , . !`
|
# We treat all other single characters as a token. Eg.: `( ) , . !`
|
||||||
# Multi-character operators are also literal tokens, so that Racc can assign
|
# Multi-character operators are also literal tokens, so that Jison can assign
|
||||||
# the proper order of operations.
|
# the proper order of operations.
|
||||||
literal_token: ->
|
literal_token: ->
|
||||||
match: @chunk.match(OPERATOR)
|
match: @chunk.match(OPERATOR)
|
||||||
|
@ -289,7 +289,7 @@ exports.Lexer: class Lexer
|
||||||
# Token Manipulators
|
# Token Manipulators
|
||||||
# ------------------
|
# ------------------
|
||||||
|
|
||||||
# As we consume a new IDENTIFIER, look at the previous token to determine
|
# As we consume a new `IDENTIFIER`, look at the previous token to determine
|
||||||
# if it's a special kind of accessor.
|
# if it's a special kind of accessor.
|
||||||
name_access_type: ->
|
name_access_type: ->
|
||||||
@tag(1, 'PROTOTYPE_ACCESS') if @value() is '::'
|
@tag(1, 'PROTOTYPE_ACCESS') if @value() is '::'
|
||||||
|
@ -372,7 +372,8 @@ exports.Lexer: class Lexer
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|
||||||
# Does a list include a value?
|
# Does a list include a value?
|
||||||
include: (list, value) -> list.indexOf(value) >= 0
|
include: (list, value) ->
|
||||||
|
list.indexOf(value) >= 0
|
||||||
|
|
||||||
# Count the number of occurences of a character in a string.
|
# Count the number of occurences of a character in a string.
|
||||||
count: (string, letter) ->
|
count: (string, letter) ->
|
||||||
|
|
Loading…
Add table
Reference in a new issue