couple more tweaks to lexer.coffee

This commit is contained in:
Jeremy Ashkenas 2010-02-28 21:39:07 -05:00
parent 29ece0e6ba
commit cd6dd5abfd
2 changed files with 12 additions and 11 deletions

View File

@ -7,7 +7,7 @@
//
// [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.
if ((typeof process !== "undefined" && process !== null)) {
Rewriter = require('./rewriter').Rewriter;
@ -17,7 +17,7 @@
}
// 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"];
// 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.
@ -68,7 +68,7 @@
// Tokens that indicate an access -- keywords immediately following will be
// treated as identifiers.
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
// avoid an ambiguity in the grammar.
BEFORE_WHEN = ['INDENT', 'OUTDENT', 'TERMINATOR'];
@ -298,7 +298,7 @@
return true;
};
// 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.
Lexer.prototype.literal_token = function literal_token() {
var match, not_spaced, tag, value;
@ -338,7 +338,7 @@
};
// 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.
Lexer.prototype.name_access_type = function name_access_type() {
if (this.value() === '::') {

View File

@ -5,7 +5,7 @@
#
# [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.
if process?
@ -17,7 +17,7 @@ else
# Constants
# ---------
# Keywords that CoffeScript shares in common with JS.
# Keywords that CoffeeScript shares in common with JavaScript.
JS_KEYWORDS: [
"if", "else",
"true", "false",
@ -98,7 +98,7 @@ CALLABLE: ['IDENTIFIER', 'SUPER', ')', ']', '}', 'STRING', '@']
# treated as identifiers.
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
# avoid an ambiguity in the grammar.
BEFORE_WHEN: ['INDENT', 'OUTDENT', 'TERMINATOR']
@ -258,7 +258,7 @@ exports.Lexer: class Lexer
true
# 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.
literal_token: ->
match: @chunk.match(OPERATOR)
@ -289,7 +289,7 @@ exports.Lexer: class Lexer
# 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.
name_access_type: ->
@tag(1, 'PROTOTYPE_ACCESS') if @value() is '::'
@ -372,7 +372,8 @@ exports.Lexer: class Lexer
# -----------------
# 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: (string, letter) ->