Skip to content

Commit

Permalink
Parse unknown as null, open as infinity
Browse files Browse the repository at this point in the history
  • Loading branch information
inukshuk committed May 11, 2016
1 parent 5d95b60 commit ae0d1a6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/bitmask.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Bitmask.XXXX = Bitmask.compute('xxxxmmdd')
/*
* Map each UA symbol position to a mask.
*
* ~YYYY~-2MM3-4DD5
* ~YYYY~-~MM~-~DD~
* 0 1 2 3 4 5
*/
Bitmask.UA = [
Expand Down
11 changes: 6 additions & 5 deletions src/edtf.ne
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@{%
const {
num, zero, nothing, pick, pluck, join, concat, merge, unknown, open,
num, zero, nothing, pick, pluck, join, concat, merge,
interval, list, masked, date, datetime, season, qualify, year
} = require('./util')

Expand Down Expand Up @@ -110,10 +110,11 @@ L1i -> L1i_date "/" L1i_date {% interval(1) %}
| date_time "/" L1i_date {% interval(1) %}
| L1i_date "/" date_time {% interval(1) %}

L1i_date -> null {% unknown %}
L1i_date -> null {% nothing %}
| date_ua {% id %}
| "*" {% open %}
| INFINITY {% id %}

INFINITY -> "*" {% () => Infinity %}

L1X -> d4 "-" md "-XX" {% masked() %}
| d4 "-XX-XX" {% masked() %}
Expand Down Expand Up @@ -191,10 +192,10 @@ L2i -> L2i_date "/" L2i_date {% interval(2) %}
| date_time "/" L2i_date {% interval(2) %}
| L2i_date "/" date_time {% interval(2) %}

L2i_date -> null {% unknown %}
L2i_date -> null {% nothing %}
| ua_date {% id %}
| L2X {% id %}
| "*" {% open %}
| INFINITY {% id %}

L2Y -> exp_year {% id %}
| exp_year significant_digits {% merge(0, 1) %}
Expand Down
11 changes: 6 additions & 5 deletions src/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
function id(x) {return x[0]; }

const {
num, zero, nothing, pick, pluck, join, concat, merge, unknown, open,
num, zero, nothing, pick, pluck, join, concat, merge,
interval, list, masked, date, datetime, season, qualify, year
} = require('./util')

Expand Down Expand Up @@ -87,9 +87,10 @@ var grammar = {
{"name": "L1i", "symbols": ["L1i_date", {"literal":"/"}, "L1i_date"], "postprocess": interval(1)},
{"name": "L1i", "symbols": ["date_time", {"literal":"/"}, "L1i_date"], "postprocess": interval(1)},
{"name": "L1i", "symbols": ["L1i_date", {"literal":"/"}, "date_time"], "postprocess": interval(1)},
{"name": "L1i_date", "symbols": [], "postprocess": unknown},
{"name": "L1i_date", "symbols": [], "postprocess": nothing},
{"name": "L1i_date", "symbols": ["date_ua"], "postprocess": id},
{"name": "L1i_date", "symbols": [{"literal":"*"}], "postprocess": open},
{"name": "L1i_date", "symbols": ["INFINITY"], "postprocess": id},
{"name": "INFINITY", "symbols": [{"literal":"*"}], "postprocess": () => Infinity},
{"name": "L1X$string$1", "symbols": [{"literal":"-"}, {"literal":"X"}, {"literal":"X"}], "postprocess": function joiner(d) {return d.join('');}},
{"name": "L1X", "symbols": ["d4", {"literal":"-"}, "md", "L1X$string$1"], "postprocess": masked()},
{"name": "L1X$string$2", "symbols": [{"literal":"-"}, {"literal":"X"}, {"literal":"X"}, {"literal":"-"}, {"literal":"X"}, {"literal":"X"}], "postprocess": function joiner(d) {return d.join('');}},
Expand Down Expand Up @@ -197,10 +198,10 @@ var grammar = {
{"name": "L2i", "symbols": ["L2i_date", {"literal":"/"}, "L2i_date"], "postprocess": interval(2)},
{"name": "L2i", "symbols": ["date_time", {"literal":"/"}, "L2i_date"], "postprocess": interval(2)},
{"name": "L2i", "symbols": ["L2i_date", {"literal":"/"}, "date_time"], "postprocess": interval(2)},
{"name": "L2i_date", "symbols": [], "postprocess": unknown},
{"name": "L2i_date", "symbols": [], "postprocess": nothing},
{"name": "L2i_date", "symbols": ["ua_date"], "postprocess": id},
{"name": "L2i_date", "symbols": ["L2X"], "postprocess": id},
{"name": "L2i_date", "symbols": [{"literal":"*"}], "postprocess": open},
{"name": "L2i_date", "symbols": ["INFINITY"], "postprocess": id},
{"name": "L2Y", "symbols": ["exp_year"], "postprocess": id},
{"name": "L2Y", "symbols": ["exp_year", "significant_digits"], "postprocess": merge(0, 1)},
{"name": "L2Y", "symbols": ["L1Y", "significant_digits"], "postprocess": merge(0, 1, { level: 2 })},
Expand Down
8 changes: 0 additions & 8 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ const util = {
}
},

unknown() {
return { type: 'Unknown', level: 1, values: [] }
},

open() {
return { type: 'Open', level: 1, values: [] }
},

list(data) {
return assign({ values: data[1], level: 2 }, data[0], data[2])
},
Expand Down

0 comments on commit ae0d1a6

Please sign in to comment.