Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 194x 194x 1x 1x 1x 1x 1x 1x 152x 152x 152x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 661x 661x 34x 34x 661x 126x 126x 661x 86x 86x 661x 415x 415x 661x 661x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 88x 88x 88x 88x 88x 88x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 427x 427x 419x 395x 395x 419x 427x 427x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 21x 19x 19x 3x 2x 1x 1x 3x 1x 1x 3x 3x 19x 13x 2x 13x 11x 11x 13x 13x 19x 19x 21x 1x 1x | /**
* Copyright © 2020 2021 2022 7thCode.(http://seventh-code.com/)
* This software is released under the MIT License.
* opensource.org/licenses/mit-license.php
*/
"use strict";
import {isContainer} from "./base";
import {TokenType} from "./parser";
/**
* BaseHandler
*
* @remarks
*
*/
export abstract class BaseHandler {
abstract token(type: TokenType, word: string, term: boolean): void;
}
/**
* ValueHandler
*
* actually traverse the object.
*
* @remarks
*
*/
export class ValueHandler extends BaseHandler {
protected current_value: any = null;
/**
* value
*
* Data
*/
public get value(): any {
return this.current_value;
}
/**
*
* @remarks
*/
constructor(root_value: any) {
super();
this.current_value = root_value;
}
/**
* Symbol Handler
*
* @remarks
* Executed when Parser recognizes Token.
*
* @param type - Symbol Type
* @param word
* @param term
* @returns void
*
*/
public token(type: TokenType, word: string, term: boolean): void {
switch (type) {
case TokenType.operator:
// console.log("operator " + word);
break;
case TokenType.number:
// console.log("number " + word);
break;
case TokenType.index:
this.current_value = ValueHandler.sibling(this.current_value, word);
break;
case TokenType.name:
this.current_value = ValueHandler.child(this.current_value, word);
break;
}
}
/**
* Sibling
*
* @remarks
* Extract array elements from index
*
* @param array - Array
* @param index - Index
* @returns Array member
*
*/
protected static sibling(array: any[], index: string): any {
let result: any = undefined;
if (Array.isArray(array)) {
result = array[Number(index)];
}
return result;
}
/**
* child
*
* @remarks
* Returns an object member.
*
* @param obj - Object
* @param attr - Attribute Name
* @returns Object member
*
*/
protected static child(obj: any, attr: string): any {
let result: any = undefined;
if (isContainer(obj)) {
if (attr in obj) {
result = obj[attr];
}
}
return result;
}
}
/**
* Updater
*
* It actually traverses and updates objects.
*
* @remarks
*
*/
export class Updater extends ValueHandler {
private readonly new_value: any;
/**
*
* @remarks
*/
constructor(root_value: any, new_value: any) {
super(root_value);
this.new_value = new_value;
}
/**
* Symbol Handler
*
* @remarks
* Executed when Parser recognizes Token.
*
* @param type - Symbol Type
* @param word
* @param term
* @returns void
*
*/
public token(type: TokenType, word: string, term: boolean): void {
if (this.current_value) {
switch (type) {
case TokenType.index: {
if (term) {
if (this.current_value.length > word) {
this.current_value[word] = this.new_value;
}
} else {
this.current_value = Updater.sibling(this.current_value, word);
}
}
break;
case TokenType.name: {
if (term) {
this.current_value[word] = this.new_value;
} else {
this.current_value = Updater.child(this.current_value, word);
}
}
break;
}
}
}
}
|