Applied style rules to genocide all \t characters
This commit is contained in:
@@ -2,23 +2,23 @@ import resolve, { traverse, toString, map } from '../resolve';
|
||||
import error from './error';
|
||||
|
||||
const indexNode = {
|
||||
create({array, index}) {
|
||||
return {
|
||||
create({ array, index }) {
|
||||
return {
|
||||
parseType: 'index',
|
||||
array,
|
||||
index,
|
||||
}
|
||||
},
|
||||
resolve(fn, node, scope, context){
|
||||
let {result: index} = resolve(fn, node.index, scope, context);
|
||||
let {result: array} = resolve(fn, node.array, scope, context);
|
||||
resolve(fn, node, scope, context) {
|
||||
let { result: index } = resolve(fn, node.index, scope, context);
|
||||
let { result: array } = resolve(fn, node.array, scope, context);
|
||||
|
||||
if (
|
||||
index.valueType === 'number' &&
|
||||
Number.isInteger(index.value) &&
|
||||
array.parseType === 'array'
|
||||
){
|
||||
if (index.value < 1 || index.value > array.values.length){
|
||||
) {
|
||||
if (index.value < 1 || index.value > array.values.length) {
|
||||
context.error({
|
||||
type: 'warning',
|
||||
message: `Index of ${index.value} is out of range for an array` +
|
||||
@@ -26,11 +26,11 @@ const indexNode = {
|
||||
});
|
||||
}
|
||||
let selection = array.values[index.value - 1];
|
||||
if (selection){
|
||||
if (selection) {
|
||||
return resolve(fn, selection, scope, context);
|
||||
}
|
||||
} else if (fn === 'reduce'){
|
||||
if (array.parseType !== 'array'){
|
||||
} else if (fn === 'reduce') {
|
||||
if (array.parseType !== 'array') {
|
||||
const message = `Can not get the index of a non-array node: ${toString(node.array)} = ${toString(array)}`
|
||||
context.error(message);
|
||||
return {
|
||||
@@ -40,7 +40,7 @@ const indexNode = {
|
||||
}),
|
||||
context,
|
||||
};
|
||||
} else if (!index.isInteger){
|
||||
} else if (!index.isInteger) {
|
||||
const message = `${toString(array)} is not an integer index of the array`
|
||||
context.error(message);
|
||||
return {
|
||||
@@ -60,17 +60,17 @@ const indexNode = {
|
||||
context,
|
||||
};
|
||||
},
|
||||
toString(node){
|
||||
toString(node) {
|
||||
return `${toString(node.array)}[${toString(node.index)}]`;
|
||||
},
|
||||
traverse(node, fn){
|
||||
traverse(node, fn) {
|
||||
fn(node);
|
||||
traverse(node.array, fn);
|
||||
traverse(node.index, fn);
|
||||
},
|
||||
map(node, fn){
|
||||
map(node, fn) {
|
||||
const resultingNode = fn(node);
|
||||
if (resultingNode === node){
|
||||
if (resultingNode === node) {
|
||||
node.array = map(node.array, fn);
|
||||
node.index = map(node.index, fn);
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
import constant from './constant.js';
|
||||
|
||||
const rollArray = {
|
||||
create({values, diceSize, diceNum}) {
|
||||
return {
|
||||
create({ values, diceSize, diceNum }) {
|
||||
return {
|
||||
parseType: 'rollArray',
|
||||
values,
|
||||
diceSize,
|
||||
diceNum,
|
||||
};
|
||||
},
|
||||
compile(node, scope, context){
|
||||
compile(node, scope, context) {
|
||||
return {
|
||||
result: node,
|
||||
context
|
||||
};
|
||||
},
|
||||
toString(node){
|
||||
toString(node) {
|
||||
return `${node.diceNum || ''}d${node.diceSize} [ ${node.values.join(', ')} ]`;
|
||||
},
|
||||
reduce(node, scope, context){
|
||||
reduce(node, scope, context) {
|
||||
const total = node.values.reduce((a, b) => a + b, 0);
|
||||
return {
|
||||
result: constant.create({
|
||||
|
||||
Reference in New Issue
Block a user