Skip to content

Commit

Permalink
syntax-rules identifiers #43 + improve Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Apr 26, 2020
1 parent 39274d8 commit 680d6cf
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 20 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SPEC_CHECKSUM=`md5sum spec/lips.spec.js | cut -d' ' -f 1`
COMMIT=`git rev-parse HEAD`
URL=`git config --get remote.origin.url`

MAKE=make
GIT=git
CD=cd
SED=sed
Expand Down Expand Up @@ -67,6 +68,12 @@ jest-test: dist/lips.js
test: dist/lips.js
@$(NPM) run test

watch-test:
@inotifywait -m -e close_write src/lips.js tests/*.scm | while read even; do $(MAKE) --no-print-directory test; done

watch-lint:
@inotifywait -m -e close_write src/lips.js | while read even; do $(MAKE) --no-print-directory lint; done

coveralls:
$(NPM) run coverage

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# [LIPS is Pretty Simple](https://jcubic.github.io/lips/) - Scheme based Powerful LISP

[![npm](https://img.shields.io/badge/npm-DEV-blue.svg)](https://www.npmjs.com/package/@jcubic/lips)
[![travis](https://travis-ci.org/jcubic/lips.svg?branch=devel&9f77320ab7e76c7fb82b35f89195537e8eb30782)](https://travis-ci.org/jcubic/lips)
[![travis](https://travis-ci.org/jcubic/lips.svg?branch=devel&39274d8b2e4afdfdd7e03c6d5a84a9dbc4900d7e)](https://travis-ci.org/jcubic/lips)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&cc91fde7195a8236554da603afbfdd15)](https://coveralls.io/github/jcubic/lips?branch=devel)


Expand Down
38 changes: 27 additions & 11 deletions dist/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* Copyright (c) 2014-present, Facebook, Inc.
* released under MIT license
*
* build: Sun, 26 Apr 2020 12:36:28 +0000
* build: Sun, 26 Apr 2020 14:18:40 +0000
*/
(function () {
'use strict';
Expand Down Expand Up @@ -3369,6 +3369,10 @@

var _name3 = pattern.valueOf();

if (symbols.includes(_name3)) {
return true;
}

log({
name: _name3
}); //console.log(code.toString());
Expand Down Expand Up @@ -6775,6 +6779,24 @@
var dynamic_scope = options.dynamic_scope,
error = options.error;
var env = this;

function get_identifiers(node) {
var symbols = [];

while (node !== nil) {
var x = node.car;

if (!(x instanceof LSymbol)) {
throw new Error('syntax: wrong identifier');
}

symbols.push(x.valueOf());
node = node.cdr;
}

return symbols;
}

return new Syntax(function (code, _ref17) {
var macro_expand = _ref17.macro_expand;
var scope = env.inherit('syntax');
Expand All @@ -6790,13 +6812,7 @@
dynamic_scope: dynamic_scope,
error: error
};
var symbols = macro.car.toArray().map(function (x) {
if (!(x instanceof LSymbol)) {
throw new Error('syntax: wrong identifier');
}

return x.valueOf();
});
var symbols = get_identifiers(macro.car);

while (rules !== nil) {
var rule = rules.car.car;
Expand Down Expand Up @@ -8696,10 +8712,10 @@

var banner = function () {
// Rollup tree-shaking is removing the variable if it's normal string because
// obviously 'Sun, 26 Apr 2020 12:36:28 +0000' == '{{' + 'DATE}}'; can be removed
// obviously 'Sun, 26 Apr 2020 14:18:40 +0000' == '{{' + 'DATE}}'; can be removed
// but disablig Tree-shaking is adding lot of not used code so we use this
// hack instead
var date = LString('Sun, 26 Apr 2020 12:36:28 +0000').valueOf();
var date = LString('Sun, 26 Apr 2020 14:18:40 +0000').valueOf();

var _date = date === '{{' + 'DATE}}' ? new Date() : new Date(date);

Expand Down Expand Up @@ -8732,7 +8748,7 @@
var lips = {
version: 'DEV',
banner: banner,
date: 'Sun, 26 Apr 2020 12:36:28 +0000',
date: 'Sun, 26 Apr 2020 14:18:40 +0000',
exec: exec,
parse: parse,
tokenize: tokenize,
Expand Down
4 changes: 2 additions & 2 deletions dist/lips.min.js

Large diffs are not rendered by default.

22 changes: 16 additions & 6 deletions src/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -1901,6 +1901,9 @@
}
log('>> 11');
const name = pattern.valueOf();
if (symbols.includes(name)) {
return true;
}
log({ name });
//console.log(code.toString());
if (ellipsis) {
Expand Down Expand Up @@ -4725,6 +4728,18 @@
'syntax-rules': new Macro('syntax-rules', function(macro, options) {
var { dynamic_scope, error } = options;
var env = this;
function get_identifiers(node) {
let symbols = [];
while (node !== nil) {
const x = node.car;
if (!(x instanceof LSymbol)) {
throw new Error('syntax: wrong identifier');
}
symbols.push(x.valueOf());
node = node.cdr;
}
return symbols;
}
return new Syntax(function(code, { macro_expand }) {
var scope = env.inherit('syntax');
if (dynamic_scope) {
Expand All @@ -4733,12 +4748,7 @@
var rules = macro.cdr;
var var_scope = this;
var eval_args = { env: scope, dynamic_scope, error };
var symbols = macro.car.toArray().map(x => {
if (!(x instanceof LSymbol)) {
throw new Error('syntax: wrong identifier');
}
return x.valueOf();
});
const symbols = get_identifiers(macro.car);
while (rules !== nil) {
var rule = rules.car.car;
var expr = rules.car.cdr.car;
Expand Down
7 changes: 7 additions & 0 deletions templates/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SPEC_CHECKSUM=`md5sum spec/lips.spec.js | cut -d' ' -f 1`
COMMIT=`git rev-parse HEAD`
URL=`git config --get remote.origin.url`

MAKE=make
GIT=git
CD=cd
SED=sed
Expand Down Expand Up @@ -67,6 +68,12 @@ jest-test: dist/lips.js
test: dist/lips.js
@$(NPM) run test

watch-test:
@inotifywait -m -e close_write src/lips.js tests/*.scm | while read even; do $(MAKE) --no-print-directory test; done

watch-lint:
@inotifywait -m -e close_write src/lips.js | while read even; do $(MAKE) --no-print-directory lint; done

coveralls:
$(NPM) run coverage

Expand Down
13 changes: 13 additions & 0 deletions tests/syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,16 @@
(t.is (merge (1 2 3)) '(1 2 3))
(t.is (merge (1 2 3) (4 5 6)) '(1 2 3 4 5 6))
(t.is (merge (1 2 3) (4 5 6) (7 8 9)) '(1 2 3 4 5 6 7 8 9))))

(test "syntax-rules: identifiers"
(lambda (t)
(define-syntax let+
(syntax-rules (==>)
((_ ((a ==> b) ...) . body)
(let ((a b) ...) . body))))

(t.is (let ((==> (lambda (x) (* x x))))
(let+ ((a ==> 1)
(b ==> 2))
(==> (+ a b))))
9)))

0 comments on commit 680d6cf

Please sign in to comment.