1if (!velato) var velato = {}; 2 3/* 4 * A velato.token is the basic parsing unit of the language 5 * 6 * From a series of these tokens, one should be able to determine: 7 * * the entire program as a series of notes 8 * * the entire program as js commands 9 */ 10velato.token = function(lex) { 11 12 this._lexicon = lex; 13 14 this.notes = []; // set of velato.notes for the token -- the actual lexeme 15 16 this.sequence = []; // notes, as strings, for the note sequence -- populated first 17 18 this._print = ""; // print before children 19 20 this._print_staff = ""; // print for vextab 21 22 this.lexpath = undefined; // this will hold the path to the definition of the token 23 24 this.children = []; // child nodes of any type except Cmds (Tone, Exp etc) 25 26 this.resolved = false; 27 28 this.indent = 0; // how many blocks it is in 29 30 31 this.setlexpath = function(l) { 32 this.lexpath = l; // the node in lexicon.json that this token is identified as 33 34 let val = l.reduce((o, n) => o[n], this._lexicon); 35 this.is_defined = true; 36 37 this.type = val.token_type; 38 39 this.name = val.name; 40 this.desc = val.desc; 41 this._print = val.print; 42 this._print_staff = val.print_staff; 43 this.notedesc = val.notedesc; 44 this.childCmds = val.childCmds; 45 46 if (this.type == "Cmd") { 47 this.resolved = true; 48 } 49 50 // we should store the expected children here, to then fill with subsequent notes 51 if (val.children !== undefined) { 52 for (let i = 0; i < val.children.length; i++) { 53 let new_child = new velato.token(this._lexicon); 54 55 // build out the lexpath as the current node's lexpath plus what is needed to match 56 // where the child node falls in the lexicon 57 // e.g. ["Cmds", "Tone"] becomes ["Cmds", "Tone", "children", "0"] 58 child_lexpath = this.lexpath.map((x) => x); 59 child_lexpath.push("children"); 60 child_lexpath.push(i); 61 62 new_child.setlexpath(child_lexpath); 63 this.children.push(new_child); 64 } 65 } 66 } 67 68 this.add_note = function(note) { 69 this.notes.push(note); 70 } 71 72 const escapeHtml = unsafe => { 73 return unsafe 74 .replaceAll("&", "&") 75 .replaceAll("<", "<") 76 .replaceAll(">", ">") 77 .replaceAll('"', """) 78 .replaceAll("'", "'") 79 .replaceAll("\n","String.fromCharCode(10)"); 80 // FIXME: all control codes should be escaped 81 }; 82 83 this.print = function(staff) { 84 let printStr = (staff ? 85 this._print_staff || "" : 86 this._print || ""); 87 88 if (this.type == "Cmd" && !staff) 89 for(let i = 0; i < this.indent;i++) 90 printStr += "\t"; 91 92 for (let i = 0; i < this.children.length; i++) { 93 let child = this.children[i]; 94 printStr = printStr.replace(`{exp}`, child.print(staff)); 95 } 96 if (this.notes.length > 0 && this.notes[0].name) 97 printStr = printStr.replace("{notename}", this.notes[0].name); 98 printStr = printStr.replace("{varname}", this.sequence[0]); 99 if (this.sequence.length == 0) { 100 printStr = printStr.replace("{seq_int}", 0); 101 printStr = printStr.replace("{seq_char}", ''); 102 } else { 103 printStr = printStr.replace("{seq_int}", parseInt(this.sequence.join(""), 10).toString()); 104 printStr = printStr.replace("{seq_char}", escapeHtml(String.fromCharCode(parseInt(this.sequence.join(""), 10)))); 105 106 } 107 108 return printStr; 109 } 110} 111 112if (typeof module !== 'undefined' && module.exports) { 113 module.exports = velato.token; 114}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.