(spec)
| 26 | } |
| 27 | |
| 28 | function extractValue (spec) { |
| 29 | // First check for a leading keyword: |
| 30 | const words = spec.split(' ') |
| 31 | // If the last word end in 'i' and the value is not labeled as complex, |
| 32 | // label it for the comment writer: |
| 33 | if (words[words.length - 1].substr(-1) === 'i' && words[0] !== 'Complex') { |
| 34 | words.unshift('Complex') |
| 35 | } |
| 36 | // Collapse 'Dense Matrix' into 'DenseMatrix' |
| 37 | if (words[0] === 'Dense' && words[1] === 'Matrix') { |
| 38 | words.shift() |
| 39 | words[0] = 'DenseMatrix' |
| 40 | } |
| 41 | // Collapse 'Complex Matrix' into 'ComplexMatrix', similarly for 'Array' |
| 42 | if (words[0] === 'Complex') { |
| 43 | if (words[1] === 'Matrix') { |
| 44 | words.shift() |
| 45 | words[0] = 'ComplexMatrix' |
| 46 | } else if (words[1] === 'Array') { |
| 47 | words.shift() |
| 48 | words[0] = 'ComplexArray' |
| 49 | } else if (words[1].startsWith('[')) { |
| 50 | words[0] = 'ComplexArray' |
| 51 | } |
| 52 | } |
| 53 | const keywords = { |
| 54 | number: 'Number(_)', |
| 55 | BigNumber: 'math.bignumber(_)', |
| 56 | Fraction: 'math.fraction(_)', |
| 57 | Complex: "math.complex('_')", |
| 58 | Unit: "math.unit('_')", |
| 59 | Array: '_', |
| 60 | Matrix: 'math.matrix(_)', |
| 61 | DenseMatrix: "math.matrix(_, 'dense')", |
| 62 | ComplexArray: 'math.complex(_)', |
| 63 | ComplexMatrix: 'math.complex(math.matrix(_))', |
| 64 | string: '_', |
| 65 | Node: 'math.parse(_)', |
| 66 | value: 'math._', |
| 67 | throws: "'_'" |
| 68 | } |
| 69 | if (words[0] in keywords) { |
| 70 | const template = keywords[words[0]] |
| 71 | const spot = template.indexOf('_') |
| 72 | let filler = words.slice(1).join(' ') |
| 73 | if (words[0] === 'Complex') { // a bit of a hack here :( |
| 74 | filler = words.slice(1).join('') |
| 75 | } |
| 76 | spec = template.substring(0, spot) + filler + template.substr(spot + 1) |
| 77 | } |
| 78 | if (spec.substring(0, 7) === 'matrix(') { |
| 79 | spec = 'math.' + spec // More hackery :( |
| 80 | } |
| 81 | let value |
| 82 | try { |
| 83 | value = eval(spec) // eslint-disable-line no-eval |
| 84 | } catch (err) { |
| 85 | if (spec[0] === '[') { |
no test coverage detected
searching dependent graphs…