Skip to content

Commit 82dabbe

Browse files
committed
Parse expressions that follows the % character
1 parent db2e375 commit 82dabbe

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const parseLine = (() => {
7272
const re3 = new RegExp(/\s+/g);
7373
return (line => line.replace(re1, '').replace(re2, '').replace(re3, ''));
7474
})();
75-
const re = /(%[a-zA-Z][a-zA-Z0-9_]*)|([a-zA-Z][0-9\+\-\.]*)|(\*[0-9]+)|((?:\$\$)|(?:\$[a-zA-Z0-9#]*))/igm;
75+
const re = /(%.*)|((?:\$\$)|(?:\$[a-zA-Z0-9#]*))|([a-zA-Z][0-9\+\-\.]*)|(\*[0-9]+)/igm;
7676

7777
return (line, options) => {
7878
options = options || {};

test/index.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,39 @@ describe('gcode-parser', () => {
6464
});
6565

6666
describe('Commands', () => {
67-
it('should parse $ commands for Grbl.', (done) => {
67+
it('should be able to parse $ command (e.g. Grbl).', (done) => {
6868
const data = parseLine('$H $C');
6969
expect(data).to.be.an('object');
7070
expect(data.line).to.be.an('string');
7171
expect(data.words).to.be.empty;
7272
expect(data.cmds).to.deep.equal(['$H', '$C']);
7373
done();
7474
});
75-
it('should parse % commands for bCNC and CNCjs.', (done) => {
76-
const data = parseLine('%wait');
77-
expect(data).to.be.an('object');
78-
expect(data.line).to.be.an('string');
79-
expect(data.words).to.be.empty;
80-
expect(data.cmds).to.deep.equal(['%wait']);
75+
it('should be able to parse % command (e.g. bCNC, CNCjs).', (done) => {
76+
{ // %wait
77+
const data = parseLine('%wait');
78+
expect(data).to.be.an('object');
79+
expect(data.line).to.be.an('string');
80+
expect(data.words).to.be.empty;
81+
expect(data.cmds).to.deep.equal(['%wait']);
82+
}
83+
84+
{ // %zsafe=10
85+
const data = parseLine('%zsafe=10');
86+
expect(data).to.be.an('object');
87+
expect(data.line).to.be.an('string');
88+
expect(data.words).to.be.empty;
89+
expect(data.cmds).to.deep.equal(['%zsafe=10']);
90+
}
91+
92+
{ // %x0=posx,y0=posy,z0=posz
93+
const data = parseLine('%x0=posx,y0=posy,z0=posz');
94+
expect(data).to.be.an('object');
95+
expect(data.line).to.be.an('string');
96+
expect(data.words).to.be.empty;
97+
expect(data.cmds).to.deep.equal(['%x0=posx,y0=posy,z0=posz']);
98+
}
99+
81100
done();
82101
});
83102
});

0 commit comments

Comments
 (0)