Skip to content

Commit

Permalink
Add non-standard level 3
Browse files Browse the repository at this point in the history
Add parser support for seasons in intervals

See #12
  • Loading branch information
inukshuk committed Jan 11, 2018
1 parent 1583a1d commit 244bbfb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/edtf.ne
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
edtf -> L0 {% id %}
| L1 {% id %}
| L2 {% id %}
| L3 {% id %}


# --- EDTF Level 0 / ISO 8601-1 ---
Expand Down Expand Up @@ -253,6 +254,21 @@ consecutives
| year ".." year {% d => [date([d[0]]), date([d[2]])] %}


# --- Level 3 / Non-Standard Features ---

L3 -> L3i {% id %}

L3i -> L3S "/" L3S {% interval(3) %}
| L3S "/" L3i_date {% interval(3) %}
| L3i_date "/" L3S {% interval(3) %}

L3i_date -> date_time {% id %}
| L2i_date {% id %}

L3S -> L1S {% id %}
| L2S {% id %}


# --- Base Definitions ---

digit -> positive_digit {% id %}
Expand Down
9 changes: 9 additions & 0 deletions src/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var grammar = {
{"name": "edtf", "symbols": ["L0"], "postprocess": id},
{"name": "edtf", "symbols": ["L1"], "postprocess": id},
{"name": "edtf", "symbols": ["L2"], "postprocess": id},
{"name": "edtf", "symbols": ["L3"], "postprocess": id},
{"name": "L0", "symbols": ["date_time"], "postprocess": id},
{"name": "L0", "symbols": ["century"], "postprocess": id},
{"name": "L0", "symbols": ["L0i"], "postprocess": id},
Expand Down Expand Up @@ -248,6 +249,14 @@ var grammar = {
{"name": "consecutives", "symbols": ["year_month", "consecutives$string$2", "year_month"], "postprocess": d => [date(d[0]), date(d[2])]},
{"name": "consecutives$string$3", "symbols": [{"literal":"."}, {"literal":"."}], "postprocess": function joiner(d) {return d.join('');}},
{"name": "consecutives", "symbols": ["year", "consecutives$string$3", "year"], "postprocess": d => [date([d[0]]), date([d[2]])]},
{"name": "L3", "symbols": ["L3i"], "postprocess": id},
{"name": "L3i", "symbols": ["L1S", {"literal":"/"}, "L1S"], "postprocess": interval(3)},
{"name": "L3i", "symbols": ["L3S", {"literal":"/"}, "L3i_date"], "postprocess": interval(3)},
{"name": "L3i", "symbols": ["L3i_date", {"literal":"/"}, "L3S"], "postprocess": interval(3)},
{"name": "L3i_date", "symbols": ["date_time"], "postprocess": id},
{"name": "L3i_date", "symbols": ["L2i_date"], "postprocess": id},
{"name": "L3S", "symbols": ["L1S"], "postprocess": id},
{"name": "L3S", "symbols": ["L2S"], "postprocess": id},
{"name": "digit", "symbols": ["positive_digit"], "postprocess": id},
{"name": "digit", "symbols": [{"literal":"0"}], "postprocess": id},
{"name": "digits", "symbols": ["digit"], "postprocess": id},
Expand Down
10 changes: 9 additions & 1 deletion test/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,13 @@ describe('parser', () => {
expect(() => p('{1760..}')).to.be.rejected)
})

describe('Level 3 (Non-Standard)', () => {
it.only('YYYY-SS/YYYY-SS', () =>
expect(p('2018-21/2018-23', { level: 3 }))
.to.be.an.interval.through([2018, 23]).at.level(3))

})

describe('constrain', () => {
it('by type', () => {
expect(p('[1760..]', { types: ['List', 'Set'] }))
Expand All @@ -552,7 +559,8 @@ describe('parser', () => {
expect(p('1800/1X01', { level: 2, types: ['Interval'] }))
.to.be.an.interval.at.level(2)

expect(() => p('1800/1X01', { level: 2, types: ['Date'] })).to.be.rejected
expect(() => p('1800/1X01', { level: 2, types: ['Date'] }))
.to.be.rejected
expect(() => p('1800/1X01', { level: 1, types: ['Interval'] }))
.to.be.rejected
})
Expand Down

0 comments on commit 244bbfb

Please sign in to comment.