Skip to content

Commit

Permalink
Remove extra logs
Browse files Browse the repository at this point in the history
  • Loading branch information
kmturley committed Feb 18, 2024
1 parent 7d6ccbc commit 6578d98
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/parse.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import { apiText } from './api';
import {
ParseHeader,
ParseHeaderNames,
ParseOpcode,
ParseOpcodeObj,
ParseVariables,
} from './types/parse';
import { log, pathJoin } from './utils';
import { ParseHeader, ParseHeaderNames, ParseOpcode, ParseOpcodeObj, ParseVariables } from './types/parse';
import { pathJoin } from './utils';

const DEBUG = false;
const variables: any = {};
let fileReadString: any = apiText;

function parseDefines(contents: string) {
const defines: string[] | null = contents.match(/(?<=#define ).+(?=\r|\n)/g);
if (!defines) return contents;
for (const define of defines) {
log(define);
if (DEBUG) console.log(define);
const val: string[] = define.split(' ');
variables[val[0]] = val[1];
}
Expand Down Expand Up @@ -110,8 +105,7 @@ function parseSanitize(contents: string) {

function parseSegment(segment: string) {
if (segment.includes('"')) segment = segment.replace(/"/g, '');
if (segment.includes('$')) console.log(segment);
segment = parseVariables(segment, variables);
if (segment.includes('$')) segment = parseVariables(segment, variables);
return segment;
}

Expand All @@ -128,11 +122,11 @@ async function parseSfz(contents: string, prefix = '') {
for (let i: number = 0; i < segments.length; i++) {
const segment: string = parseSegment(segments[i]);
if (segment.charAt(0) === '/') {
log('comment:', segment);
if (DEBUG) console.log('comment:', segment);
} else if (segment === '#define') {
const key: string = segments[i + 1];
const val: string = segments[i + 2];
log('define:', key, val);
if (DEBUG) console.log('define:', key, val);
variables[key] = val;
i += 2;
} else if (segment.charAt(0) === '<') {
Expand All @@ -141,12 +135,12 @@ async function parseSfz(contents: string, prefix = '') {
name: parseHeader(segment) as ParseHeaderNames,
elements: [],
};
log('header:', element.name);
if (DEBUG) console.log('header:', element.name);
elements.push(element);
} else {
if (!element.elements) element.elements = [];
const opcode: string[] = segment.split('=');
log('opcode:', opcode);
if (DEBUG) console.log('opcode:', opcode);
// If orphaned string, add on to previous opcode value.
if (opcode.length === 1 && element.elements.length && opcode[0] !== '') {
element.elements[element.elements.length - 1].attributes.value += ' ' + opcode[0];
Expand Down

0 comments on commit 6578d98

Please sign in to comment.