From 3396dce2bbbe2dbd2eb29cc257279997b2dd83a9 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Mon, 8 Mar 2010 20:57:28 -0500 Subject: [PATCH] waypoint -- going to try to clean up regex_token --- Cakefile | 4 ++-- lib/lexer.js | 14 +++++++------- src/lexer.coffee | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Cakefile b/Cakefile index dc436688..1bd9240e 100644 --- a/Cakefile +++ b/Cakefile @@ -28,8 +28,8 @@ task 'build', 'build the CoffeeScript language from source', -> run ['-c', '-o', 'lib'].concat(files) -task 'build:full', 'checkout /lib, rebuild the source twice, and run the tests', -> - exec 'git checkout lib && bin/cake build && bin/cake build && bin/cake test', (err, stdout, stderr) -> +task 'build:full', 'rebuild the source twice, and run the tests', -> + exec 'bin/cake build && bin/cake build && bin/cake test', (err, stdout, stderr) -> print stdout if stdout print stderr if stderr throw err if err diff --git a/lib/lexer.js b/lib/lexer.js index bef8b616..ee349cce 100644 --- a/lib/lexer.js +++ b/lib/lexer.js @@ -175,13 +175,13 @@ if (!(starts(this.chunk, '/'))) { return false; } + if (include(NOT_REGEX, this.tag())) { + return false; + } if (!((regex = this.balanced_token(['/', '/'])))) { return false; } - if (regex.length < 3 || regex.match(/^\/\s+|\n/)) { - return false; - } - if (include(NOT_REGEX, this.tag())) { + if (regex.length < 3 || regex.match(/^\/\s+/m)) { return false; } flags = ['i', 'm', 'g', 'y']; @@ -462,10 +462,10 @@ i += 1; } if (levels.length) { - if (!(delimited[0][0] === '/')) { - throw new Error("SyntaxError: Unterminated " + (levels.pop()[0]) + " starting on line " + (this.line + 1)); + if (delimited[0][0] === '/') { + return false; } - return false; + throw new Error("SyntaxError: Unterminated " + (levels.pop()[0]) + " starting on line " + (this.line + 1)); } if (i === 0) { return false; diff --git a/src/lexer.coffee b/src/lexer.coffee index 27957c85..9e71baf3 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -127,9 +127,9 @@ exports.Lexer: class Lexer # JavaScript and Ruby. regex_token: -> return false unless starts @chunk, '/' - return false unless regex: @balanced_token ['/', '/'] - return false if regex.length < 3 or regex.match /^\/\s+|\n/ return false if include NOT_REGEX, @tag() + return false unless regex: @balanced_token ['/', '/'] + return false if regex.length < 3 or regex.match /^\/\s+/m flags: ['i', 'm', 'g', 'y'] while (index: flags.indexOf @chunk.substr regex.length, 1) >= 0 regex += flags[index] @@ -337,8 +337,8 @@ exports.Lexer: class Lexer break unless levels.length i += 1 if levels.length - throw new Error "SyntaxError: Unterminated ${levels.pop()[0]} starting on line ${@line + 1}" unless delimited[0][0] is '/' - return false + return false if delimited[0][0] is '/' + throw new Error "SyntaxError: Unterminated ${levels.pop()[0]} starting on line ${@line + 1}" return false if i is 0 return str.substring(0, i)