Skip to content

Commit

Permalink
Support GroupMenu (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
karniv00l authored Sep 26, 2022
1 parent 54b65e7 commit 86c755a
Show file tree
Hide file tree
Showing 25 changed files with 152,809 additions and 376 deletions.
647 changes: 284 additions & 363 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
"test": "npm run build && node test/test.js"
},
"devDependencies": {
"@hyper-tuner/eslint-config": "^0.1.2",
"@hyper-tuner/eslint-config": "^0.1.6",
"@types/js-yaml": "^4.0.5",
"@types/node": "^18.7.18",
"@types/node": "^18.7.22",
"@types/parsimmon": "^1.10.6",
"eslint-plugin-modules-newline": "^0.0.6",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-prettier": "^4.2.1",
"typescript": "^4.8.3"
},
"dependencies": {
"@hyper-tuner/types": "^0.3.0",
"@hyper-tuner/types": "^0.4.0",
"js-yaml": "^4.1.0",
"parsimmon": "^1.18.1"
}
Expand Down
72 changes: 71 additions & 1 deletion src/ini.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as P from 'parsimmon';
import P from 'parsimmon';
import {
Config as ConfigType,
Constant,
GroupMenu,
} from '@hyper-tuner/types';
import { ParserInterface } from './parserInterface';

Expand Down Expand Up @@ -44,6 +45,8 @@ export class INI implements ParserInterface {

currentMenu?: string;

currentGroupMenu?: string;

currentCurve?: string;

currentTable?: string;
Expand Down Expand Up @@ -801,10 +804,76 @@ export class INI implements ParserInterface {
title: INI.sanitize(title),
subMenus: {},
};

return;
}

if (this.currentMenu) {
// parse groupMenu
// groupMenu = "Engine Protection"
const groupMenuResult = P
.seqObj<any>(
P.string('groupMenu'),
this.space, this.equal, this.space,
['title', this.notQuote.wrap(...this.quotes)],
P.all,
)
.parse(line);

if (groupMenuResult.status) {
const title = INI
.sanitize(groupMenuResult.value.title);
const name = title
.toLowerCase()
.replace(/([^\w]\w)/g, (g) => g[1].toUpperCase()); // camelCase

this.currentGroupMenu = name;
this.result.menus[this.currentMenu].subMenus[name] = {
type: 'groupMenu',
title: INI.sanitize(title),
groupChildMenus: {},
};

return;
}

// parse groupChildMenu
if (this.currentGroupMenu && line.startsWith('groupChildMenu')) {
// groupChildMenu = std_separator
const base: any = [
P.string('groupChildMenu'),
this.space, this.equal, this.space,
['name', this.name],
];

// groupChildMenu = engineProtection, "Common Engine Protection"
const withTitle: any = [
...base,
...this.delimiter,
['title', this.notQuote.wrap(...this.quotes)],
];

// groupChildMenu = revLimiterDialog, "Rev Limiters", { engineProtectType }
const full: any = [
...withTitle,
...this.delimiter,
['condition', this.expression],
P.all,
];

const groupChildMenuResult = P.seqObj<any>(...full, P.all)
.or(P.seqObj<any>(...withTitle, P.all))
.or(P.seqObj<any>(...base, P.all))
.tryParse(line);

(this.result.menus[this.currentMenu].subMenus[this.currentGroupMenu] as GroupMenu).groupChildMenus[groupChildMenuResult.name] = {
title: INI.sanitize(groupChildMenuResult.title),
condition: groupChildMenuResult.condition ? INI.sanitize(groupChildMenuResult.condition) : '',
};

return;
}

// subMenu = std_separator
const base: any = [
P.string('subMenu'),
Expand Down Expand Up @@ -849,6 +918,7 @@ export class INI implements ParserInterface {
.tryParse(line);

this.result.menus[this.currentMenu].subMenus[subMenuResult.name] = {
type: 'subMenu',
title: INI.sanitize(subMenuResult.title),
page: Number(subMenuResult.page || 0),
condition: subMenuResult.condition ? INI.sanitize(subMenuResult.condition) : '',
Expand Down
5,557 changes: 5,557 additions & 0 deletions test/data/ini/202207.ini

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/data/json/202012.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/data/json/202103.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/data/json/202108.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/data/json/202202.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/data/json/202207.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/data/tmp/202012.json

Large diffs are not rendered by default.

Loading

0 comments on commit 86c755a

Please sign in to comment.