Skip to content

Commit

Permalink
Handle new INI version, change API (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
karniv00l authored Jan 16, 2022
1 parent 143566c commit bb89b94
Show file tree
Hide file tree
Showing 20 changed files with 347,366 additions and 280 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ yarn-error.log*

.eslintcache

# temp test data
/test/data/tmp/*
!/test/data/tmp/.keep
# # temp test data
# /test/data/tmp/*
# !/test/data/tmp/.keep
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"typescript": "^4.5.3"
},
"dependencies": {
"@speedy-tuner/types": "^0.2.1",
"@speedy-tuner/types": "^0.3.0",
"js-yaml": "^4.1.0",
"parsimmon": "^1.18.1"
}
Expand Down
25 changes: 14 additions & 11 deletions src/ini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import {
Config as ConfigType,
Constant,
} from '@speedy-tuner/types';
import { ParserInterface } from './parserInterface';

export class INI {
export class INI implements ParserInterface {
space: P.Parser<any>;

expression: P.Parser<any>;
Expand Down Expand Up @@ -49,11 +50,11 @@ export class INI {

result: ConfigType;

constructor(buffer: string) {
constructor(buffer: ArrayBuffer) {
this.space = P.optWhitespace;
this.expression = P.regexp(/{.+?}/);
this.expression = P.regexp(/{.+?}|(([a-z])([A-z\d]+))/);
this.numbers = P.regexp(/[0-9.-]*/);
this.name = P.regexp(/[0-9a-z_]*/i);
this.name = P.regexp(/[0-9a-z_\\-]*/i);
this.equal = P.string('=');
this.quote = P.string('"');
this.quotes = [this.quote, this.quote];
Expand All @@ -65,7 +66,7 @@ export class INI {
this.inQuotes = this.notQuote.trim(this.space).wrap(...this.quotes);
this.values = P.regexp(/[^,;]*/).trim(this.space).sepBy(this.comma);

this.lines = buffer.toString().split('\n');
this.lines = (new TextDecoder()).decode(buffer).split('\n');

this.currentPage = undefined;
this.currentDialog = undefined;
Expand Down Expand Up @@ -99,8 +100,13 @@ export class INI {
};
}

parse() {
parse(): this {
this.parseSections();

return this;
}

getResults(): ConfigType {
return this.result;
}

Expand Down Expand Up @@ -1055,10 +1061,7 @@ export class INI {
};

const scalarShortRest: any = [
['units', P.alt(
this.expression,
this.inQuotes,
)],
['units', P.alt(this.expression, this.inQuotes)],
...this.delimiter,
['scale', P.alt(this.expression, this.numbers)],
...this.delimiter,
Expand All @@ -1072,7 +1075,7 @@ export class INI {
...this.delimiter,
['max', P.alt(this.expression, this.numbers)],
...this.delimiter,
['digits', P.digits],
['digits', P.alt(this.expression, P.digits)],
P.all,
];

Expand Down
7 changes: 7 additions & 0 deletions src/parserInterface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface ParserInterface {
parse(): this;
}

export interface ParserConstructor {
new(buffer: ArrayBuffer): ParserInterface;
}
173 changes: 80 additions & 93 deletions test/data/ini/202109-dev.ini → test/data/ini/202108.ini

Large diffs are not rendered by default.

5,331 changes: 5,331 additions & 0 deletions test/data/ini/202202.ini

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

Loading

0 comments on commit bb89b94

Please sign in to comment.