mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-17 19:11:22 -05:00
waypoint -- it's beginning to parser
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
(function(){
|
||||
var ASSIGNMENT, CALLABLE, CODE, COMMENT, COMMENT_CLEANER, HEREDOC, HEREDOC_INDENT, IDENTIFIER, JS, JS_CLEANER, KEYWORDS, LAST_DENT, LAST_DENTS, MULTILINER, MULTI_DENT, NOT_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX, Rewriter, STRING, STRING_NEWLINES, WHITESPACE, lex, sys;
|
||||
sys = require('sys');
|
||||
var ASSIGNMENT, CALLABLE, CODE, COMMENT, COMMENT_CLEANER, HEREDOC, HEREDOC_INDENT, IDENTIFIER, JS, JS_CLEANER, KEYWORDS, LAST_DENT, LAST_DENTS, MULTILINER, MULTI_DENT, NOT_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX, Rewriter, STRING, STRING_NEWLINES, WHITESPACE, lex;
|
||||
Rewriter = require('./rewriter').Rewriter;
|
||||
// The lexer reads a stream of CoffeeScript and divvys it up into tagged
|
||||
// tokens. A minor bit of the ambiguity in the grammar has been avoided by
|
||||
@@ -57,7 +56,6 @@
|
||||
this.chunk = this.code.slice(this.i);
|
||||
this.extract_next_token();
|
||||
}
|
||||
// sys.puts "original stream: " + this.tokens if process.ENV['VERBOSE']
|
||||
this.close_indentation();
|
||||
return (new Rewriter()).rewrite(this.tokens);
|
||||
};
|
||||
@@ -188,7 +186,7 @@
|
||||
}
|
||||
this.line += comment.match(MULTILINER).length;
|
||||
this.token('COMMENT', comment.replace(COMMENT_CLEANER, '').split(MULTILINER));
|
||||
this.token("\n", "\n");
|
||||
this.token('TERMINATOR', "\n");
|
||||
this.i += comment.length;
|
||||
return true;
|
||||
};
|
||||
@@ -228,7 +226,7 @@
|
||||
this.token('OUTDENT', last_indent);
|
||||
move_out -= last_indent;
|
||||
}
|
||||
this.token("\n", "\n");
|
||||
this.token('TERMINATOR', "\n");
|
||||
return true;
|
||||
};
|
||||
// Matches and consumes non-meaningful whitespace.
|
||||
@@ -245,7 +243,7 @@
|
||||
// Use a trailing \ to escape newlines.
|
||||
lex.prototype.newline_token = function newline_token(newlines) {
|
||||
if (!(this.value() === "\n")) {
|
||||
this.token("\n", "\n");
|
||||
this.token('TERMINATOR', "\n");
|
||||
}
|
||||
return true;
|
||||
};
|
||||
@@ -268,6 +266,9 @@
|
||||
}
|
||||
value = value || this.chunk.substr(0, 1);
|
||||
tag = value.match(ASSIGNMENT) ? 'ASSIGN' : value;
|
||||
if (value === ';') {
|
||||
tag = 'TERMINATOR';
|
||||
}
|
||||
if (this.value() !== this.spaced && CALLABLE.indexOf(this.tag()) >= 0) {
|
||||
if (value === '(') {
|
||||
tag = 'CALL_START';
|
||||
@@ -309,13 +310,13 @@
|
||||
return tok[1];
|
||||
};
|
||||
// Count the occurences of a character in a string.
|
||||
lex.prototype.count = function count(string, char) {
|
||||
lex.prototype.count = function count(string, letter) {
|
||||
var num, pos;
|
||||
num = 0;
|
||||
pos = string.indexOf(char);
|
||||
pos = string.indexOf(letter);
|
||||
while (pos !== -1) {
|
||||
count += 1;
|
||||
pos = string.indexOf(char, pos + 1);
|
||||
pos = string.indexOf(letter, pos + 1);
|
||||
}
|
||||
return count;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user