Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 9 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
{
"label": "Start Development",
"type": "shell",
"command": "npm run dev",
"windows": {
"command": "npm i; npm run dev",
},
"linux": {
"command": "npm i && npm run dev"
},
"osx": {
"command": "npm i && npm run dev"
},
"presentation": {
"reveal": "always",
"panel": "new"
Expand Down
1 change: 1 addition & 0 deletions biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"enabled": true,
"rules": {
"style": {
"useEnumInitializers": "error",
"noInferrableTypes": "off", // we want to be explicit (for transpiler)
"noNonNullAssertion": "off", // we use these assertions often.
"noParameterAssign": "off", // useful for default values
Expand Down
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions packages/alphatab/src/exporter/AlphaTexExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
type AlphaTexPropertyNode,
type AlphaTexScoreNode,
type AlphaTexStringLiteral,
type AlphaTexValueList,
type AlphaTexArgumentList,
type IAlphaTexAstNode
} from '@coderline/alphatab/importer/alphaTex/AlphaTexAst';
import type { IAlphaTexLanguageImportHandler } from '@coderline/alphatab/importer/alphaTex/IAlphaTexLanguageImportHandler';
Expand Down Expand Up @@ -241,19 +241,19 @@ class AlphaTexPrinter {
this._writeValue(m.tag.tag);

let newLineAfterMeta = true;
if (m.propertiesBeforeValues) {
if (m.propertiesBeforeArguments) {
if (m.properties) {
this._writer.write(' ');
this._writeProperties(m.properties, false);
}
if (m.values) {
if (m.arguments) {
this._writer.write(' ');
this._writeValues(m.values);
this._writeValues(m.arguments);
}
} else {
if (m.values) {
if (m.arguments) {
this._writer.write(' ');
this._writeValues(m.values);
this._writeValues(m.arguments);
}

if (m.properties) {
Expand Down Expand Up @@ -322,19 +322,19 @@ class AlphaTexPrinter {
this._writeComments(p.leadingComments);

this._writeValue(p.property);
if (p.values) {
if (p.arguments) {
this._writer.write(' ');
this._writeValues(p.values);
this._writeValues(p.arguments);
}

this._writeComments(p.trailingComments);
}

private _writeValues(values: AlphaTexValueList) {
private _writeValues(values: AlphaTexArgumentList) {
this._writeComments(values.leadingComments);
this._writeToken(values.openParenthesis, false);
let first = true;
for (const v of values.values) {
for (const v of values.arguments) {
if (!first) {
this._writer.write(' ');
}
Expand All @@ -355,8 +355,8 @@ class AlphaTexPrinter {
this._writer.write((v as AlphaTexIdentifier).text);
break;

case AlphaTexNodeType.Values:
this._writeValues(v as AlphaTexValueList);
case AlphaTexNodeType.Arguments:
this._writeValues(v as AlphaTexArgumentList);
break;
case AlphaTexNodeType.Number:
this._writer.write((v as AlphaTexNumberLiteral).value.toString());
Expand Down
23 changes: 17 additions & 6 deletions packages/alphatab/src/importer/AlphaTexImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
type AlphaTexScoreNode,
type AlphaTexTextNode
} from '@coderline/alphatab/importer/alphaTex/AlphaTexAst';
import { AlphaTexParser } from '@coderline/alphatab/importer/alphaTex/AlphaTexParser';
import { AlphaTexParseMode, AlphaTexParser } from '@coderline/alphatab/importer/alphaTex/AlphaTexParser';
import {
AlphaTexAccidentalMode,
type AlphaTexDiagnostic,
Expand Down Expand Up @@ -175,7 +175,7 @@ class AlphaTexImportState implements IAlphaTexImporterState {
* @public
*/
export class AlphaTexImporter extends ScoreImporter implements IAlphaTexImporter {
private _parser!: AlphaTexParser;
private _parser?: AlphaTexParser;
private _handler: IAlphaTexLanguageImportHandler = AlphaTex1LanguageHandler.instance;

private _state = new AlphaTexImportState();
Expand All @@ -193,11 +193,22 @@ export class AlphaTexImporter extends ScoreImporter implements IAlphaTexImporter
}

public get lexerDiagnostics() {
return this._parser.lexerDiagnostics;
return this._parser!.lexerDiagnostics;
}

public get parserDiagnostics() {
return this._parser.parserDiagnostics;
return this._parser!.parserDiagnostics;
}

/**
* The underlying parser used for parsing the AST. Available after initialization of the importer.
*/
public get parser(): AlphaTexParser | undefined {
return this._parser;
}

public get parseMode(): AlphaTexParseMode {
return this._parser!.mode;
}

public logErrors: boolean = false;
Expand Down Expand Up @@ -226,7 +237,7 @@ export class AlphaTexImporter extends ScoreImporter implements IAlphaTexImporter

let scoreNode: AlphaTexScoreNode;
try {
scoreNode = this._parser.read();
scoreNode = this._parser!.read();
this._state.scoreNode = scoreNode;
} catch (e) {
if (this.logErrors) {
Expand All @@ -235,7 +246,7 @@ export class AlphaTexImporter extends ScoreImporter implements IAlphaTexImporter
throw new UnsupportedFormatError('Error parsing alphaTex, check inner error for details', e as Error);
}

if (this._parser.parserDiagnostics.hasErrors || this._parser.lexer.lexerDiagnostics.hasErrors) {
if (this._parser!.parserDiagnostics.hasErrors || this._parser!.lexer.lexerDiagnostics.hasErrors) {
const error = new AlphaTexErrorWithDiagnostics(
'There are errors in the parsed alphaTex, check the diagnostics for details',
this.lexerDiagnostics,
Expand Down
46 changes: 23 additions & 23 deletions packages/alphatab/src/importer/alphaTex/ATNF.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
type AlphaTexPropertiesNode,
type AlphaTexPropertyNode,
type AlphaTexStringLiteral,
type AlphaTexValueList,
type IAlphaTexValueListItem
type AlphaTexArgumentList,
type IAlphaTexArgumentValue
} from '@coderline/alphatab/importer/alphaTex/AlphaTexAst';

/**
Expand All @@ -39,7 +39,7 @@ export class Atnf {

public static meta(
tag: string,
values?: AlphaTexValueList,
args?: AlphaTexArgumentList,
properties?: AlphaTexPropertiesNode
): AlphaTexMetaDataNode {
return {
Expand All @@ -54,9 +54,9 @@ export class Atnf {
text: tag
} as AlphaTexIdentifier
} as AlphaTexMetaDataTagNode,
values,
arguments: args,
properties,
propertiesBeforeValues: false
propertiesBeforeArguments: false
} as AlphaTexMetaDataNode;
}

Expand All @@ -68,16 +68,16 @@ export class Atnf {
return Atnf.meta(tag, Atnf.numberValue(value));
}

public static values(
values: (IAlphaTexValueListItem | undefined)[],
public static args(
args: (IAlphaTexArgumentValue | undefined)[],
parentheses: boolean | undefined = undefined
): AlphaTexValueList | undefined {
): AlphaTexArgumentList | undefined {
const valueList = {
nodeType: AlphaTexNodeType.Values,
values: values.filter(v => v !== undefined)
} as AlphaTexValueList;
nodeType: AlphaTexNodeType.Arguments,
arguments: args.filter(v => v !== undefined)
} as AlphaTexArgumentList;

const addParenthesis: boolean = parentheses === undefined ? valueList.values.length > 1 : parentheses;
const addParenthesis: boolean = parentheses === undefined ? valueList.arguments.length > 1 : parentheses;

if (addParenthesis) {
valueList.openParenthesis = {
Expand All @@ -88,27 +88,27 @@ export class Atnf {
} as AlphaTexParenthesisCloseTokenNode;
}

if (valueList.values.length === 0) {
if (valueList.arguments.length === 0) {
return undefined;
}

return valueList;
}

public static stringValue(text: string): AlphaTexValueList {
return Atnf.values([Atnf.string(text)])!;
public static stringValue(text: string): AlphaTexArgumentList {
return Atnf.args([Atnf.string(text)])!;
}

public static identValue(text: string): AlphaTexValueList {
return Atnf.values([Atnf.ident(text)])!;
public static identValue(text: string): AlphaTexArgumentList {
return Atnf.args([Atnf.ident(text)])!;
}

public static numberValue(value: number): AlphaTexValueList {
return Atnf.values([Atnf.number(value)])!;
public static numberValue(value: number): AlphaTexArgumentList {
return Atnf.args([Atnf.number(value)])!;
}

public static props(
properties: ([string, AlphaTexValueList | undefined] | undefined)[]
properties: ([string, AlphaTexArgumentList | undefined] | undefined)[]
): AlphaTexPropertiesNode {
const node = {
nodeType: AlphaTexNodeType.Props,
Expand All @@ -126,19 +126,19 @@ export class Atnf {
node.properties.push({
nodeType: AlphaTexNodeType.Prop,
property: Atnf.ident(p[0]),
values: p[1]
arguments: p[1]
} as AlphaTexPropertyNode);
}
}

return node;
}

public static prop(properties: AlphaTexPropertyNode[], identifier: string, values?: AlphaTexValueList) {
public static prop(properties: AlphaTexPropertyNode[], identifier: string, args?: AlphaTexArgumentList) {
properties.push({
nodeType: AlphaTexNodeType.Prop,
property: Atnf.ident(identifier),
values
arguments: args
});
}
}
Loading
Loading