@@ -8,21 +8,22 @@ const Parser = require('./Parser');
88const Lexer = require ( './Lexer' ) ;
99
1010// credit: http://stackoverflow.com/a/3886106/124861
11- function isFloat ( n ) {
11+ function isFloat ( n ) {
1212 return Number ( n ) === n && n % 1 !== 0 ;
1313}
1414
1515function floatEqual ( a , b , epsilon = Number . EPSILON ) {
16- if ( a === b ) {
17- return true ;
18- }
16+ if ( a === b ) {
17+ return true ;
18+ }
1919
20- if ( isNaN ( a ) || isNaN ( b ) || ! isFinite ( a ) || ! isFinite ( b ) ) {
21- return false ;
22- }
20+ if ( isNaN ( a ) || isNaN ( b ) || ! isFinite ( a ) || ! isFinite ( b ) ) {
21+ return false ;
22+ }
23+
24+ const diff = Math . abs ( a - b ) ;
2325
24- const diff = Math . abs ( a - b ) ;
25- return diff < epsilon ? true : diff <= Math . max ( Math . abs ( a ) , Math . abs ( b ) ) * epsilon ;
26+ return diff < epsilon ? true : diff <= Math . max ( Math . abs ( a ) , Math . abs ( b ) ) * epsilon ;
2627}
2728
2829const {
@@ -66,6 +67,7 @@ class Runner {
6667
6768 for ( const value of sources ) {
6869 const path = value . type === PARSER_TYPE_VARIABLE ? this . getValueFromVariable ( value . name ) : value . value ;
70+
6971 tasks [ path ] = fs . readFile . bind ( fs , path ) ;
7072 }
7173
@@ -96,10 +98,17 @@ class Runner {
9698 }
9799
98100 invokeInclude ( statement ) {
101+ let path ;
99102
100- if ( )
101-
102- this . invoke ( ast ) ;
103+ if ( statement . value . type === PARSER_TYPE_VARIABLE ) {
104+ path = this . getValueFromVariable ( statement . value . name ) ;
105+ }
106+ else {
107+ path = statement . value . value ;
108+ }
109+ if ( this . astCache [ path ] ) {
110+ this . invokeStatements ( this . astCache [ path ] . statements ) ;
111+ }
103112 }
104113
105114 invokeBranch ( statement ) {
@@ -108,6 +117,8 @@ class Runner {
108117 return this . invokeStatements ( branch . consequent . statements ) ;
109118 }
110119 }
120+ // no branch executed
121+ return null ;
111122 }
112123
113124 evaluateExpression ( expression ) {
@@ -123,6 +134,7 @@ class Runner {
123134 else if ( expression . type === PARSER_TYPE_VARIABLE ) {
124135 return this . getValueFromVariable ( expression . name ) ;
125136 }
137+ throw new RuntimeError ( `Unknown expression type: ${ expression . type } ` ) ;
126138 }
127139
128140 evaluateBinaryExpression ( expression ) {
@@ -176,7 +188,7 @@ class Runner {
176188 if ( isFloat ( leftValue ) && isFloat ( rightValue ) ) {
177189 return floatEqual ( leftValue , rightValue ) ;
178190 }
179-
191+ // eslint-disable-next-line eqeqeq
180192 return strict ? leftValue === rightValue : leftValue == rightValue ;
181193 }
182194
@@ -189,7 +201,7 @@ class Runner {
189201 }
190202
191203 getValueFromVariable ( name ) {
192- if ( ! name in this . input ) {
204+ if ( ! ( name in this . input ) ) {
193205 throw new RuntimeError ( `Unset variable: ${ name } ` ) ;
194206 }
195207 return this . input [ name ] ;
0 commit comments