Skip to content

Commit

Permalink
fix comment after string
Browse files Browse the repository at this point in the history
metelkin committed Sep 18, 2024
1 parent ba08d6d commit 30d1b33
Showing 3 changed files with 51 additions and 142 deletions.
167 changes: 30 additions & 137 deletions src/index.js

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

7 changes: 4 additions & 3 deletions src/pegjs/heta.pegjs
Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@ Dict "Dict" = "{" (Break/Space/Comment)* item: DictPair* (Break/Space/Comment)*
return res;
}

DictPair = (Break/Space)* key: KeyName (Break/Space)* ":" (Break/Space)* value: ValueTypes ","? Comment?
DictPair = (Break/Space)* key: KeyName (Break/Space)* ":" (Break/Space)* value: ValueTypes ","? Comment*
{
return [key, value];
}
@@ -227,9 +227,10 @@ KeyName = symbol: $([A-Za-z_][A-Za-z0-9_]*)
return symbol;
}

String "String" = (Break/Space)* s: $([^,[\]{};] !"//" !"/*")+ Comment?
//String "String" = (Break/Space)* s: $([^,[\]{};] !"//" !"/*")+ (Comment)*
String "String" = (Break/Space)* s: (Comment/[^,[\]{};])+
{
let str = s.trim()
let str = s.join('').trim()

if (str === 'null') {
res = null;
19 changes: 17 additions & 2 deletions test/syntax/index.js
Original file line number Diff line number Diff line change
@@ -537,11 +537,26 @@ let to_test = [
source: '{aux: a,//b\n};',
expectation: [{action: 'upsert', aux: 'a'}]
},
/*{
{
description: 'complex strings with // as comment',
source: '{aux: a//comment\n};',
expectation: [{action: 'upsert', aux: 'a'}]
}*/
},
{
descrition: 'complex strings with /* */as comment',
source: '{aux: a/*b*/};',
expectation: [{action: 'upsert', aux: 'a'}]
},
{
description: 'no strings with /* */ as comment',
source: '{aux: /*b */a};',
expectation: [{action: 'upsert', aux: 'a'}]
},
{
description: 'no strings with /* */ as comment',
source: '{aux: /*b */};',
expectation: [{action: 'upsert', aux: ''}]
}
];

describe('Single object parsing.', () => {

0 comments on commit 30d1b33

Please sign in to comment.