mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-16 10:34:55 -05:00
first bit of equals for symbology ... barely started on lexer.coffee
This commit is contained in:
@@ -8,66 +8,66 @@
|
||||
|
||||
# Set up dependencies correctly for both the server and the browser.
|
||||
if process?
|
||||
path: require 'path'
|
||||
Lexer: require('./lexer').Lexer
|
||||
parser: require('./parser').parser
|
||||
helpers: require('./helpers').helpers
|
||||
path = require 'path'
|
||||
Lexer = require('./lexer').Lexer
|
||||
parser = require('./parser').parser
|
||||
helpers = require('./helpers').helpers
|
||||
helpers.extend global, require './nodes'
|
||||
if require.registerExtension
|
||||
require.registerExtension '.coffee', (content) -> compile content
|
||||
else
|
||||
this.exports: this.CoffeeScript: {}
|
||||
Lexer: this.Lexer
|
||||
parser: this.parser
|
||||
helpers: this.helpers
|
||||
this.exports = this.CoffeeScript = {}
|
||||
Lexer = this.Lexer
|
||||
parser = this.parser
|
||||
helpers = this.helpers
|
||||
|
||||
# The current CoffeeScript version number.
|
||||
exports.VERSION: '0.7.2'
|
||||
exports.VERSION = '0.7.2'
|
||||
|
||||
# Instantiate a Lexer for our use here.
|
||||
lexer: new Lexer
|
||||
lexer = new Lexer
|
||||
|
||||
# Compile a string of CoffeeScript code to JavaScript, using the Coffee/Jison
|
||||
# compiler.
|
||||
exports.compile: compile: (code, options) ->
|
||||
options: or {}
|
||||
exports.compile = compile = (code, options) ->
|
||||
options = or {}
|
||||
try
|
||||
(parser.parse lexer.tokenize code).compile options
|
||||
catch err
|
||||
err.message: "In $options.source, $err.message" if options.source
|
||||
err.message = "In $options.source, $err.message" if options.source
|
||||
throw err
|
||||
|
||||
# Tokenize a string of CoffeeScript code, and return the array of tokens.
|
||||
exports.tokens: (code) ->
|
||||
exports.tokens = (code) ->
|
||||
lexer.tokenize code
|
||||
|
||||
# Tokenize and parse a string of CoffeeScript code, and return the AST. You can
|
||||
# then compile it by calling `.compile()` on the root, or traverse it by using
|
||||
# `.traverse()` with a callback.
|
||||
exports.nodes: (code) ->
|
||||
exports.nodes = (code) ->
|
||||
parser.parse lexer.tokenize code
|
||||
|
||||
# Compile and execute a string of CoffeeScript (on the server), correctly
|
||||
# setting `__filename`, `__dirname`, and relative `require()`.
|
||||
exports.run: ((code, options) ->
|
||||
module.filename: __filename: options.source
|
||||
__dirname: path.dirname(__filename)
|
||||
exports.run = ((code, options) ->
|
||||
module.filename = __filename = options.source
|
||||
__dirname = path.dirname __filename
|
||||
eval exports.compile code, options
|
||||
)
|
||||
|
||||
# The real Lexer produces a generic stream of tokens. This object provides a
|
||||
# thin wrapper around it, compatible with the Jison API. We can then pass it
|
||||
# directly as a "Jison lexer".
|
||||
parser.lexer: {
|
||||
parser.lexer = {
|
||||
lex: ->
|
||||
token: @tokens[@pos] or [""]
|
||||
@pos: + 1
|
||||
this.yylineno: token[2]
|
||||
this.yytext: token[1]
|
||||
token = @tokens[@pos] or [""]
|
||||
@pos = + 1
|
||||
this.yylineno = token[2]
|
||||
this.yytext = token[1]
|
||||
token[0]
|
||||
setInput: (tokens) ->
|
||||
@tokens: tokens
|
||||
@pos: 0
|
||||
@tokens = tokens
|
||||
@pos = 0
|
||||
upcomingInput: -> ""
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ parser.lexer: {
|
||||
# on page load. Unfortunately, the text contents of remote scripts cannot be
|
||||
# accessed from the browser, so only inline script tags will work.
|
||||
if document? and document.getElementsByTagName
|
||||
processScripts: ->
|
||||
processScripts = ->
|
||||
for tag in document.getElementsByTagName('script') when tag.type is 'text/coffeescript'
|
||||
eval exports.compile tag.innerHTML
|
||||
if window.addEventListener
|
||||
|
||||
Reference in New Issue
Block a user