Skip to content

Commit

Permalink
Add special case for MIParser to parse 'objects' with values but no k…
Browse files Browse the repository at this point in the history
…eys (#313)
  • Loading branch information
XingMicrochip authored Nov 3, 2023
1 parent 1df3376 commit 71a4f46
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/MIParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,27 @@ export class MIParser {
const result: any = {};
if (c === '{') {
c = this.next();
while (c !== '}') {
if (c !== ',') {
this.back();
if (c !== '"') {
// oject contains name-value pairs
while (c !== '}') {
if (c !== ',') {
this.back();
}
const name = this.handleString();
if (this.next() === '=') {
result[name] = this.handleValue();
}
c = this.next();
}
const name = this.handleString();
if (this.next() === '=') {
result[name] = this.handleValue();
} else {
// "object" contains just values
this.back();
let key = 0;
while (c !== '}') {
let value = this.handleCString();
if (value) result[key++] = value;
c = this.next();
}
c = this.next();
}
}

Expand Down
19 changes: 19 additions & 0 deletions src/integration-tests/miparser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,23 @@ describe('MI Parser Test Suite', function () {
'stdout'
);
});

it('structure that starts with a curly bracket and contains values but not keys', async function () {
parser.parseLine(
'+message,bkpt={number="1",type="breakpoint",thread-groups=["i1"],script={"p }123","p 321","p 789"}}'
);
sinon.assert.calledOnceWithExactly(
gdbBackendMock.emit as sinon.SinonStub,
'statusAsync',
'message',
{
bkpt: {
number: '1',
type: 'breakpoint',
'thread-groups': ['i1'],
script: { '0': 'p }123', '1': 'p 321', '2': 'p 789' },
},
}
);
});
});

0 comments on commit 71a4f46

Please sign in to comment.