Skip to content

Commit

Permalink
fix syntax-rules #43
Browse files Browse the repository at this point in the history
Fix case when there is list and first item in user code is nil
When the user code is in ellipsis processing and there is next item
There is need to be list where first item need to be nil.
  • Loading branch information
jcubic committed Nov 27, 2020
1 parent a8e249c commit 28926ae
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![LIPS - Scheme Based Powerful Lisp Language](https://github.com/jcubic/lips/blob/devel/assets/lips.svg?raw=true)

[![npm](https://img.shields.io/badge/npm-1.0.0%E2%80%93beta.9-blue.svg)](https://www.npmjs.com/package/@jcubic/lips)
[![travis](https://travis-ci.org/jcubic/lips.svg?branch=devel&23602f723c664a70302e09a348ec54c1c281f9fb)](https://travis-ci.org/jcubic/lips)
[![travis](https://travis-ci.org/jcubic/lips.svg?branch=devel&a8e249c78f5091179b503edb78246d1f21a5dbbb)](https://travis-ci.org/jcubic/lips)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&f6ff9bc2f84ef7b55e3e590fe6bc423b)](https://coveralls.io/github/jcubic/lips?branch=devel)
[![Join Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jcubic/lips)
[![GitHub license](https://img.shields.io/github/license/jcubic/lips.svg)](https://github.com/jcubic/lips/blob/master/LICENSE)
Expand Down
20 changes: 14 additions & 6 deletions dist/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* Copyright (c) 2014-present, Facebook, Inc.
* released under MIT license
*
* build: Thu, 26 Nov 2020 11:32:25 +0000
* build: Fri, 27 Nov 2020 14:30:09 +0000
*/
(function () {
'use strict';
Expand Down Expand Up @@ -4791,7 +4791,14 @@
if (ellipsis) {
if (bindings['...'].symbols[_name3]) {
var node = bindings['...'].symbols[_name3];
bindings['...'].symbols[_name3] = node.append(new Pair(code, nil));

if (node === nil) {
node = new Pair(nil, new Pair(code, nil));
} else {
node = node.append(new Pair(code, nil));
}

bindings['...'].symbols[_name3] = node;
} else {
bindings['...'].symbols[_name3] = new Pair(code, nil);
}
Expand Down Expand Up @@ -5133,7 +5140,7 @@
function transform_ellipsis_expr(expr, bindings, state) {
var next = arguments.length > 3 && arguments[3] !== undefined$1 ? arguments[3] : function () {};
var nested = state.nested;
log(' ==> ' + expr.toString());
log(' ==> ' + expr.toString(true));
log(bindings);

if (expr instanceof LSymbol) {
Expand Down Expand Up @@ -5179,6 +5186,7 @@

var item = bindings[_name7];
log({
expr: expr.toString(true),
name: _name7,
bindings: bindings,
item: item
Expand Down Expand Up @@ -11792,10 +11800,10 @@

var banner = function () {
// Rollup tree-shaking is removing the variable if it's normal string because
// obviously 'Thu, 26 Nov 2020 11:32:25 +0000' == '{{' + 'DATE}}'; can be removed
// obviously 'Fri, 27 Nov 2020 14:30:09 +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('Thu, 26 Nov 2020 11:32:25 +0000').valueOf();
var date = LString('Fri, 27 Nov 2020 14:30:09 +0000').valueOf();

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

Expand Down Expand Up @@ -11832,7 +11840,7 @@
var lips = {
version: 'DEV',
banner: banner,
date: 'Thu, 26 Nov 2020 11:32:25 +0000',
date: 'Fri, 27 Nov 2020 14:30:09 +0000',
exec: exec,
// unwrap async generator into Promise<Array>
parse: compose(uniterate_async, parse),
Expand Down
4 changes: 2 additions & 2 deletions dist/lips.min.js

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions src/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -2647,10 +2647,13 @@
log('>> 3 ' + ellipsis);
if (ellipsis) {
if (bindings['...'].symbols[name]) {
const node = bindings['...'].symbols[name];
bindings['...'].symbols[name] = node.append(
new Pair(code, nil)
);
let node = bindings['...'].symbols[name];
if (node === nil) {
node = new Pair(nil, new Pair(code, nil));
} else {
node = node.append(new Pair(code, nil));
}
bindings['...'].symbols[name] = node;
} else {
bindings['...'].symbols[name] = new Pair(code, nil);
}
Expand Down Expand Up @@ -2949,7 +2952,7 @@
}
function transform_ellipsis_expr(expr, bindings, state, next = () => {}) {
const { nested } = state;
log(' ==> ' + expr.toString());
log(' ==> ' + expr.toString(true));
log(bindings);
if (expr instanceof LSymbol) {
const name = expr.valueOf();
Expand Down Expand Up @@ -2982,7 +2985,7 @@
log('[t 2');
const name = expr.car.valueOf();
const item = bindings[name];
log({ name, bindings, item });
log({ expr: expr.toString(true), name, bindings, item });
if (item === null) {
return;
} else if (item) {
Expand Down
2 changes: 1 addition & 1 deletion tests/syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@
(t.is result '(((bar 1) (bar 2)) ((baz 3) (baz 4))))))


(test_ "syntax-rules: R6RS do macro"
(test "syntax-rules: R6RS do macro"
(lambda (t)
(define-syntax do
(syntax-rules ()
Expand Down

0 comments on commit 28926ae

Please sign in to comment.