All files / parser/nodes literal.js

83.33% Statements 5/6
100% Branches 0/0
66.67% Functions 2/3
83.33% Lines 5/6
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                                                154x     154x     154x     154x                   20x      
import Node from './node';
 
/**
 * This matches any simple literal.
 * 
 * This excludes more complex literal types such as lambdas and switches.
 * If it can be expressed in a single string this class will wrap it, else
 *  consider a more complex class. 
 * 
 * The primary classes using this are:
 *  - String
 *  - Number
 *  - Boolean?
 */
export default class Literal extends Node {
    
    /**
     * Creates a wrapper for literals
     * 
     * @param {string} literal the literal string value of the literal
     * @param {number} type The literal type as from a TokenType
     * @param {Object} position a position from nearley
     */
    constructor (literal: string, type: number, position: Object) {
        super(position);
        
        /** @type {string} */
        this.literal = literal;
        
        /** @type {VSLTokenType} */
        this.type = type;
 
        /** @type {ScopeItem[]} */
        this.typeCandidates = [];
    }
    
    /** @override */
    get children() {
        return null;
    }
    
    /** @override */
    toString() {
        return this.literal;
    }
}