Skip to content

Commit 568afe5

Browse files
fix: line breaks between entries break the parser. fixes #57
1 parent f2b5952 commit 568afe5

File tree

7 files changed

+128
-4
lines changed

7 files changed

+128
-4
lines changed

src/grammar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ var grammar = {
8585
, value: processRP(value)}) },
8686
{"name": "otherEntry$ebnf$1", "symbols": ["value"]},
8787
{"name": "otherEntry$ebnf$1", "symbols": ["otherEntry$ebnf$1", "value"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
88-
{"name": "otherEntry", "symbols": [(lexer.has("tag") ? {type: "tag"} : tag), (lexer.has("sep") ? {type: "sep"} : sep), "otherEntry$ebnf$1"], "postprocess": ([{value: key},,value]) => ({key, value: value.join(' ')})},
88+
{"name": "otherEntry", "symbols": [(lexer.has("tag") ? {type: "tag"} : tag), (lexer.has("sep") ? {type: "sep"} : sep), "otherEntry$ebnf$1"], "postprocess": ([{value: key},,value]) => ({key, value: value.join('\n')})},
8989
{"name": "value", "symbols": [(lexer.has("value") ? {type: "value"} : value), (lexer.has("newline") ? {type: "newline"} : newline)], "postprocess": ([{value}]) => value}
9090
]
9191
, ParserStart: "ris"

src/grammar.ne

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ reprintEntry ->
9696

9797
otherEntry ->
9898
%tag %sep value:+
99-
{% ([{value: key},,value]) => ({key, value: value.join(' ')}) %}
99+
{% ([{value: key},,value]) => ({key, value: value.join('\n')}) %}
100100

101101
value ->
102102
%value %newline

src/lexer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const moo = require('moo');
66

77
const lexer =
88
moo.compile
9-
( { newline: {match: /\n/, lineBreaks: true}
9+
( { newline: {match: /\n+/, lineBreaks: true}
1010
, sep: " - "
1111
, type: /TY(?= - )/
1212
, person: /(?:AU|A1|A2|A3|A4|TA)(?= - )/

test/features/integration.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ Scenario Outline:
77
Examples:
88
| sample |
99
| 01 |
10+
| 02 |

test/samples/01.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"PLANETS: SPECTRA"
4343
],
4444
"N2": [
45-
"The zeroth, first, and second spectral moments of the rototranslational collision-induced absorption (RT CIA) spectra of hydrogen-helium mixtures are calculated from the fundamental theory, for temperatures from 40 to 3000 K. With the help of simple analytical functions of three parameters and the information given, the RT CIA spectra of H2-He pairs can be generated on computers of small capacity, with rms deviations from exact quantum profiles of not more than a few percent. Such representations of the CIA spectra are of interest for work related to the atmospheres of the outer planets and cool stars. The theoretical spectra are in close agreement with existing laboratory measurements at various temperatures from about 77 to 3000 K."
45+
"The zeroth, first, and second spectral moments of the rototranslational\ncollision-induced absorption (RT CIA) spectra of hydrogen-helium\nmixtures are calculated from the fundamental theory, for temperatures\nfrom 40 to 3000 K. With the help of simple analytical functions of three\nparameters and the information given, the RT CIA spectra of H2-He pairs\ncan be generated on computers of small capacity, with rms deviations\nfrom exact quantum profiles of not more than a few percent. Such\nrepresentations of the CIA spectra are of interest for work related to\nthe atmospheres of the outer planets and cool stars. The theoretical\nspectra are in close agreement with existing laboratory measurements at\nvarious temperatures from about 77 to 3000 K."
4646
],
4747
"SN": [
4848
"0004-637X"

test/samples/02.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[
2+
{
3+
"TY": [
4+
"MUSIC"
5+
],
6+
"TI": [
7+
"Wonderwall"
8+
],
9+
"AB": [
10+
"Today is gonna be the day that they're gonna throw it back to you\nBy now you should've somehow realised what you gotta do\nI don't believe that anybody feels the way I do about you now\nBackbeat, the word is on the street that the fire in your heart is out\nI'm sure you've heard it all before, but you never really had a doubt\nI don't believe that anybody feels the way I do about you now\nAnd all the roads we have to walk are winding\nAnd all the lights that lead us there are blinding\nThere are many things that I would like to say to you\nBut I don't know how\nBecause maybe\nYou're gonna be the one that saves me\nAnd after all\nYou're my wonderwall\nToday was gonna be the day, but they'll never throw it back to you\nBy now you should've somehow realised what you're not to do\nI don't believe that anybody feels the way I do about you now\nAnd all the roads that lead you there were winding\nAnd all the lights that light the way are blinding\nThere are many things that I would like to say to you\nBut I don't know how\nI said maybe\nYou're gonna be the one that saves me\nAnd after all\nYou're my wonderwall\nI said maybe (I said maybe)\nYou're gonna be the one that saves me\nAnd after all\nYou're my wonderwall\nI said maybe (I said maybe)\nYou're gonna be the one that saves me (saves me)\nYou're gonna be the one that saves me (saves me)\nYou're gonna be the one that saves me (saves me)"
11+
],
12+
"AU": [
13+
{
14+
"last_name": "Gallagher",
15+
"first_name": "Noel",
16+
"suffix": "",
17+
"initials": ""
18+
}
19+
]
20+
},
21+
{
22+
"TY": [
23+
"MUSIC"
24+
],
25+
"TI": [
26+
"Wonderwall"
27+
],
28+
"AB": [
29+
"Today is gonna be the day that they're gonna throw it back to you\nBy now you should've somehow realised what you gotta do\nI don't believe that anybody feels the way I do about you now\nBackbeat, the word is on the street that the fire in your heart is out\nI'm sure you've heard it all before, but you never really had a doubt\nI don't believe that anybody feels the way I do about you now\nAnd all the roads we have to walk are winding\nAnd all the lights that lead us there are blinding\nThere are many things that I would like to say to you\nBut I don't know how\nBecause maybe\nYou're gonna be the one that saves me\nAnd after all\nYou're my wonderwall\nToday was gonna be the day, but they'll never throw it back to you\nBy now you should've somehow realised what you're not to do\nI don't believe that anybody feels the way I do about you now\nAnd all the roads that lead you there were winding\nAnd all the lights that light the way are blinding\nThere are many things that I would like to say to you\nBut I don't know how\nI said maybe\nYou're gonna be the one that saves me\nAnd after all\nYou're my wonderwall\nI said maybe (I said maybe)\nYou're gonna be the one that saves me\nAnd after all\nYou're my wonderwall\nI said maybe (I said maybe)\nYou're gonna be the one that saves me (saves me)\nYou're gonna be the one that saves me (saves me)\nYou're gonna be the one that saves me (saves me)"
30+
],
31+
"AU": [
32+
{
33+
"last_name": "Gallagher",
34+
"first_name": "Noel",
35+
"suffix": "",
36+
"initials": ""
37+
}
38+
]
39+
}
40+
]

test/samples/02.ris

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
TY - MUSIC
2+
3+
TI - Wonderwall
4+
5+
AB - Today is gonna be the day that they're gonna throw it back to you
6+
By now you should've somehow realised what you gotta do
7+
I don't believe that anybody feels the way I do about you now
8+
Backbeat, the word is on the street that the fire in your heart is out
9+
I'm sure you've heard it all before, but you never really had a doubt
10+
I don't believe that anybody feels the way I do about you now
11+
And all the roads we have to walk are winding
12+
And all the lights that lead us there are blinding
13+
There are many things that I would like to say to you
14+
But I don't know how
15+
Because maybe
16+
You're gonna be the one that saves me
17+
And after all
18+
You're my wonderwall
19+
Today was gonna be the day, but they'll never throw it back to you
20+
By now you should've somehow realised what you're not to do
21+
I don't believe that anybody feels the way I do about you now
22+
And all the roads that lead you there were winding
23+
And all the lights that light the way are blinding
24+
There are many things that I would like to say to you
25+
But I don't know how
26+
I said maybe
27+
You're gonna be the one that saves me
28+
And after all
29+
You're my wonderwall
30+
I said maybe (I said maybe)
31+
You're gonna be the one that saves me
32+
And after all
33+
You're my wonderwall
34+
I said maybe (I said maybe)
35+
You're gonna be the one that saves me (saves me)
36+
You're gonna be the one that saves me (saves me)
37+
You're gonna be the one that saves me (saves me)
38+
39+
AU - Gallagher, Noel
40+
41+
ER -
42+
43+
TY - MUSIC
44+
45+
TI - Wonderwall
46+
47+
AB - Today is gonna be the day that they're gonna throw it back to you
48+
By now you should've somehow realised what you gotta do
49+
I don't believe that anybody feels the way I do about you now
50+
Backbeat, the word is on the street that the fire in your heart is out
51+
I'm sure you've heard it all before, but you never really had a doubt
52+
I don't believe that anybody feels the way I do about you now
53+
And all the roads we have to walk are winding
54+
And all the lights that lead us there are blinding
55+
There are many things that I would like to say to you
56+
But I don't know how
57+
Because maybe
58+
You're gonna be the one that saves me
59+
And after all
60+
You're my wonderwall
61+
Today was gonna be the day, but they'll never throw it back to you
62+
By now you should've somehow realised what you're not to do
63+
I don't believe that anybody feels the way I do about you now
64+
And all the roads that lead you there were winding
65+
And all the lights that light the way are blinding
66+
There are many things that I would like to say to you
67+
But I don't know how
68+
I said maybe
69+
You're gonna be the one that saves me
70+
And after all
71+
You're my wonderwall
72+
I said maybe (I said maybe)
73+
You're gonna be the one that saves me
74+
And after all
75+
You're my wonderwall
76+
I said maybe (I said maybe)
77+
You're gonna be the one that saves me (saves me)
78+
You're gonna be the one that saves me (saves me)
79+
You're gonna be the one that saves me (saves me)
80+
81+
AU - Gallagher, Noel
82+
83+
ER -

0 commit comments

Comments
 (0)