MCPcopy Index your code
hub / github.com/Moddable-OpenSource/moddable / DTSParser

Class DTSParser

tools/mcdevicetree.js:1016–1496  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1014initCharTable();
1015
1016class DTSParser {
1017 constructor() {
1018 this.content = '';
1019 this.pos = 0;
1020 this.length = 0;
1021 }
1022
1023 /**
1024 * Parse DTS content
1025 */
1026 parse(content) {
1027 this.content = content;
1028 this.contentS = new String(content); // to avoid temporary instances
1029 this.pos = 0;
1030 this.length = content.length;
1031
1032 const result = {
1033 version: null,
1034 nodes: {},
1035 includes: [],
1036 comments: []
1037 };
1038
1039 // Extract version quickly
1040 const versionIndex = content.indexOf('/dts-v1/');
1041 if (versionIndex !== -1) {
1042 result.version = 'v1';
1043 }
1044
1045 // Skip to root node
1046 this.skipToRoot();
1047
1048 if (this.pos < this.length && this.content.charCodeAt(this.pos) === SLASH) {
1049 const nextCode = this.pos + 1 < this.length ? this.content.charCodeAt(this.pos + 1) : 0;
1050 if (nextCode !== 42) { // not '/*'
1051 const rootNode = this.parseNode();
1052 if (rootNode) {
1053 result.nodes[rootNode.name] = rootNode;
1054 }
1055 }
1056 }
1057
1058 return result;
1059 }
1060
1061 isWhitespace(code) {
1062 return CHAR_TABLE[code] & WHITESPACE;
1063 }
1064 isDigit(code) {
1065 return CHAR_TABLE[code] & DIGIT;
1066 }
1067 isHexDigit(code) {
1068 return CHAR_TABLE[code] & HEX_DIGIT;
1069 }
1070 isIdentifierStart(code) {
1071 return CHAR_TABLE[code] & IDENTIFIER_START;
1072 }
1073 isIdentifierChar(code) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected