Skip to content

Commit

Permalink
Merge 04979a0 into 4314ab7
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurélien Ooms committed Oct 17, 2018
2 parents 4314ab7 + 04979a0 commit 6ab4811
Show file tree
Hide file tree
Showing 8 changed files with 242 additions and 178 deletions.
9 changes: 7 additions & 2 deletions src/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,16 @@ const productions = {
"renewenvironment" : [ '=renewenvironment' , "&environment-definition" ] ,
"\n" : [ '=\n' ] ,
" " : [ '= ' ] ,
"arg" : [ '=arg' ] , // 1.12
"digit" : [ '=digit' ] ,
"argument" : [ '=#' , '&argument-subject' ] , // 1.12
"$" : [ '=$' ] ,
"math" : [ '=\\(' , '&anything' , '=\\)' ] ,
"mathenv" : [ '=\\[' , '&anything' , '=\\]' ] ,
} ,
"argument-subject" : {
"#" : [ "=#" ] ,
"digit" : [ "=digit" ] ,
} ,
"endif" : { // endif : 2
"elsefi" : [ '=else' , "&anything" , '=fi' ] , // 2.0
"fi" : [ '=fi' ] , // 2.1
Expand All @@ -85,7 +90,7 @@ const productions = {
"*{envname}[nargs][default]{begin}{end}" : [ '=*' , '={' , '=text' , '=}' , "&definition-parameters" , '={' , "&anything" , '=}' , '={' , "&anything" , '=}' ] ,
} ,
"definition-parameters" : {
"yes" : [ '=[' , '=text' , '=]' , '&default-argument-for-definition' , "&ignore" ] ,
"yes" : [ '=[' , '=digit' , '=]' , '&default-argument-for-definition' , "&ignore" ] ,
"no" : [ ] ,
} ,
"default-argument-for-definition" : {
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import Position from './Position' ;
import grammar from './grammar' ;
import shaker from './shaker' ;
import shakestream from './shakestream' ;
import shakestring from './shakestring' ;
import shaketape from './shaketape' ;
import tokens from './tokens' ;
import transform from './transform' ;

export default {
Position ,
grammar ,
shaker ,
shakestream ,
shakestring ,
shaketape ,
tokens ,
transform ,
} ;

export {
Position ,
grammar ,
shaker ,
shakestream ,
shakestring ,
shaketape ,
tokens ,
transform ,
} ;
4 changes: 2 additions & 2 deletions src/shaketape.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import tape from '@aureooms/js-tape' ;

import tokens from './tokens' ;
import grammar from './grammar' ;
import shaker from './shaker' ;
import shaker from './transform/shaker' ;

export default async function shaketape ( inputTape , outputStream ) {

Expand All @@ -25,8 +25,8 @@ export default async function shaketape ( inputTape , outputStream ) {

const ctx = {
env : [ ] ,
args : [ ] ,
variables ,
parser ,
} ;

const transformed = await ast.transform( tree , shaker , ctx ) ;
Expand Down
34 changes: 16 additions & 18 deletions src/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,27 +86,25 @@ async function* _tokens ( tape ) {
}

}
else if ( c === '#' ) {
yield* flush();

// read arg number
let arg = '#' ;
while ( true ) {
const d = await tape.read();
if ( d === tape.eof ) break ;
else if ( d >= '0' && d <= '9' ) arg += d;
else {
tape.unread(d);
break;
}
}
if ( arg === '#' ) throw new Error('Incomplete #') ;
yield [ 'arg' , arg , new Position(line, position) ] ;
position += arg.length;
}
else {
switch ( c ) {

case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
yield* flush();
yield [ 'digit' , c , new Position(line, position) ] ;
++position;
break;

case '#':
case '{':
case '}':
case '[':
Expand Down
12 changes: 12 additions & 0 deletions src/transform/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import shaker from './shaker' ;
import visitor from './visitor' ;

export default {
shaker ,
visitor ,
} ;

export {
shaker ,
visitor ,
} ;

0 comments on commit 6ab4811

Please sign in to comment.