Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 5 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
View
5 .npmignore
@@ -0,0 +1,5 @@
+*.tmproj
+TODO.txt
+*.loop
+node_modules/*
+!node_modules/uglify-js
View
1 lib/loop/eval.js
@@ -110,6 +110,7 @@ var loopEval = function(syntaxTree) {
case 'string':
case 'number':
case 'comment':
+ case 'regexp':
return syntaxTree;
default:
throw new Error('unknown type of syntaxTree, type: ' + syntaxTree.type);
View
2 lib/loop/grammar.jison
@@ -4,6 +4,7 @@
";".* return "COMMENT";
\"(\\.|[^\\"])*\" return "STRING";
\'(\\.|[^\\'])*\' return "STRING";
+\/(\\.|[^\\/])*\/([a-zA-Z]*) return "REGEXP";
\s+ /* skip whitespace */
\n+ /* skip newlines */
\r+ /* same */
@@ -94,6 +95,7 @@ atom
| float { $$ = $1; }
| INT { $$ = require("./grammar/token-builders").makeNumber($1, @1); }
| STRING { $$ = require("./grammar/token-builders").makeString($1, @1); }
+ | REGEXP { $$ = require("./grammar/token-builders").makeRegexp($1, @1); }
| SYMBOL { $$ = require("./grammar/token-builders").makeSymbol($1, @1); }
;
View
16 lib/loop/grammar/token-builders.js
@@ -47,6 +47,22 @@ tokenBuilders.makeString = function(str, sourceInfo) {
};
};
+tokenBuilders.makeRegexp = function(str, sourceInfo) {
+ str = str.slice(1);
+ var parts = str.split("/");
+ var regexPart = parts[0];
+ var modifiers = parts[1];
+
+ return {
+ type: 'regexp',
+ contents: {
+ regex: regexPart,
+ modifiers: modifiers
+ },
+ sourceInfo: sourceInfo
+ };
+};
+
tokenBuilders.makeObjectLiteral = function(listMembers, sourceInfo) {
if (listMembers) {
var list = [];
View
1 lib/loop/reverse-compiler.js
@@ -548,7 +548,6 @@ createSyntaxTree = function(statement) {
});
break;
-
case 'while':
expr = {
type: 'list',
View
3 lib/loop/uglify.js
@@ -382,6 +382,8 @@ var progn = function(tree) {
return ['name', tree.contents];
case 'string':
return ['string', tree.contents];
+ case 'regexp':
+ return ['regexp', tree.contents.regex, tree.contents.modifiers];
case 'number':
return ['num', tree.contents];
case 'comment':
@@ -397,6 +399,7 @@ processStatementOrExpression = function(statementOrExpression) {
case 'string':
case 'prop-access':
case 'number':
+ case 'regexp':
return stmt(progn(statementOrExpression));
case 'comment':
return progn(statementOrExpression);
View
6 package.json
@@ -1,8 +1,8 @@
{
- "name": "loop",
+ "name": "loop-lang",
"description": "loop programming language",
- "version": "0.0.1",
- "private": true,
+ "version": "0.0.2",
+ "private": false,
"repository": {
"type": "git",
"url": "git://github.com/smtlaissezfaire/loop_js.git"
View
15 spec/integration/regex-spec.js
@@ -0,0 +1,15 @@
+var vows = require("vows");
+var assert = require("assert");
+var loop = require(__dirname + "/../../lib/loop");
+
+vows.describe("macro matching").addBatch({
+ 'it should parse a simple regexp': function() {
+ assert.equal(loop.compile('/foobar/'), '/foobar/');
+ },
+ 'it should parse a regex as a regex': function() {
+ assert.equal(loop.compile('/^WHORU\\:(.*)\\n$/'), '/^WHORU\\:(.*)\\n$/');
+ },
+ 'it should parse a regex as a regex with a modifier': function() {
+ assert.equal(loop.compile('/foobar/i'), '/foobar/i');
+ }
+}).export(module);

No commit comments for this range

Something went wrong with that request. Please try again.