Skip to content

Commit

Permalink
support display command
Browse files Browse the repository at this point in the history
  • Loading branch information
SiriusAshling committed Nov 9, 2021
1 parent 174e1ef commit a0ef18c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "header-language",
"displayName": "Ori WotW Header Language",
"description": "Support for the .wotwrh language",
"version": "0.3.1",
"version": "0.3.2",
"publisher": "orirando",
"license": "MIT",
"repository": {
Expand Down
8 changes: 7 additions & 1 deletion src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export enum CommandVariant {
add,
remove,
name,
display,
price,
icon,
parameter,
Expand Down Expand Up @@ -41,6 +42,11 @@ export interface NameCommand {
item: Item,
name: string,
}
export interface DisplayCommand {
id: CommandVariant.display,
item: Item,
display: string,
}
export interface PriceCommand {
id: CommandVariant.price,
item: Item,
Expand Down Expand Up @@ -80,4 +86,4 @@ export interface EndIfCommand {
id: CommandVariant.endif,
}

export type Command = IncludeCommand | ExcludeCommand | AddCommand | RemoveCommand | NameCommand | PriceCommand | IconCommand | ParameterCommand | PoolCommand | AddPoolCommand | FlushCommand | SetCommand | IfCommand | EndIfCommand;
export type Command = IncludeCommand | ExcludeCommand | AddCommand | RemoveCommand | NameCommand | DisplayCommand | PriceCommand | IconCommand | ParameterCommand | PoolCommand | AddPoolCommand | FlushCommand | SetCommand | IfCommand | EndIfCommand;
3 changes: 3 additions & 0 deletions src/description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ function describeCommand(command: Command): string {
} case CommandVariant.name: {
const itemDescription = describeItem(command.item);
return `Set the name of this item to "${command.name}":\n\n${itemDescription}`;
} case CommandVariant.display: {
const itemDescription = describeItem(command.item);
return `Set the display name of this item to "${command.display}":\n\n${itemDescription}`;
} case CommandVariant.price: {
const itemDescription = describeItem(command.item);
return `Set the price of this item to "${command.price}":\n\n${itemDescription}`;
Expand Down
19 changes: 19 additions & 0 deletions src/parser/parseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ function parseNameCommand(string: string): ParseCommandSuccess | ParseFailure {

return succeed(command, string);
}
function parseDisplayCommand(string: string): ParseCommandSuccess | ParseFailure {
const itemResult = parseItem(string);
if (!itemResult.success) { return itemResult; }
string = itemResult.remaining;
const item = itemResult.result;

const separatorResult = eat(string, " ");
if (separatorResult === null) { return fail(" ", string, { id: CompletionVariant.command }); }
string = separatorResult;

const command: Command = {
id: CommandVariant.display,
item,
display: string,
};

return succeed(command, string);
}
function parsePriceCommand(string: string): ParseCommandSuccess | ParseFailure {
const itemResult = parseItem(string);
if (!itemResult.success) { return itemResult; }
Expand Down Expand Up @@ -239,6 +257,7 @@ export function parseCommand(string: string): ParseCommandSuccess | ParseFailure
case "add": return parseChangeItemPool(string, CommandVariant.add);
case "remove": return parseChangeItemPool(string, CommandVariant.remove);
case "name": return parseNameCommand(string);
case "display": return parseDisplayCommand(string);
case "price": return parsePriceCommand(string);
case "icon": return parseIconCommand(string);
case "parameter": return parseParameterCommand(string);
Expand Down
12 changes: 12 additions & 0 deletions syntaxes/ori-wotw-header.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@
{ "include": "#includeCommand" },
{ "include": "#addCommand" },
{ "include": "#nameCommand" },
{ "include": "#displayCommand" },
{ "include": "#priceCommand" },
{ "include": "#iconCommand" },
{ "include": "#parameterCommand" },
Expand Down Expand Up @@ -560,6 +561,17 @@
{ "include": "#messageString" }
]
},
"displayCommand": {
"begin": "^!!display ",
"end": "$|(?=//)",
"beginCaptures": {
"0": { "name": "keyword" }
},
"patterns": [
{ "include": "#item" },
{ "include": "#messageString" }
]
},
"priceCommand": {
"begin": "^!!price ",
"end": "$|(?=//)",
Expand Down

0 comments on commit a0ef18c

Please sign in to comment.