* @desc Parses the abstract syntax tree for *literal value* * * @param {Object} ast - the AST object to parse * @param {Array} retArr - return array string * * @returns {Array} the append retArr
(ast, retArr)
| 215 | * @returns {Array} the append retArr |
| 216 | */ |
| 217 | astLiteral(ast, retArr) { |
| 218 | // Reject non numeric literals |
| 219 | if (isNaN(ast.value)) { |
| 220 | throw this.astErrorOutput( |
| 221 | 'Non-numeric literal not supported : ' + ast.value, |
| 222 | ast |
| 223 | ); |
| 224 | } |
| 225 | |
| 226 | const key = this.astKey(ast); |
| 227 | if (Number.isInteger(ast.value)) { |
| 228 | if (this.isState('casting-to-integer') || this.isState('building-integer')) { |
| 229 | this.literalTypes[key] = 'Integer'; |
| 230 | retArr.push(`${ast.value}`); |
| 231 | } else if (this.isState('casting-to-float') || this.isState('building-float')) { |
| 232 | this.literalTypes[key] = 'Number'; |
| 233 | retArr.push(`${ast.value}.0`); |
| 234 | } else { |
| 235 | this.literalTypes[key] = 'Number'; |
| 236 | retArr.push(`${ast.value}.0`); |
| 237 | } |
| 238 | } else if (this.isState('casting-to-integer') || this.isState('building-integer')) { |
| 239 | this.literalTypes[key] = 'Integer'; |
| 240 | retArr.push(Math.round(ast.value)); |
| 241 | } else { |
| 242 | this.literalTypes[key] = 'Number'; |
| 243 | retArr.push(`${ast.value}`); |
| 244 | } |
| 245 | return retArr; |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * @desc Parses the abstract syntax tree for *binary* expression |
nothing calls this directly
no test coverage detected