Skip to content

Instantly share code, notes, and snippets.

@fstiffo
Created March 10, 2018 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fstiffo/3a6c9b105c1a9a56e14a384831b16a14 to your computer and use it in GitHub Desktop.
Save fstiffo/3a6c9b105c1a9a56e14a384831b16a14 to your computer and use it in GitHub Desktop.
#Match the results of sommas clause
@builtin "number.ne" # `int`, `decimal`, and `percentage` number primitives
@{%
var sommasObject = function (a,b,c) {
return function (d) {
return {"short_abstr": d[a], "rethorical_typology": d[b], "extabst": d[c]};
};
};
var appendItem = function (a, b) { return function (d) { return d[a].concat(d[b]); } };
var toArray = function (d) { return [d[0]]; };
var uppercase = function (d) { return d[0].toUpperCase(); };
var appendItemChar = function (a, b) { return function (d) { return d[a].concat(d[b]); } };
%}
SOMMAS -> "[" SHORT_ABSTR "," RETHORICAL_TYPOLOGY "," EXTABST "]" {% sommasObject(1,3,5) %}
SHORT_ABSTR -> "short_abstr(" SENTENCE_LIST ")" {% function (d) { return d[1]; } %}
SENTENCE_LIST -> "[" SENTENCES "]" {% function (d) { return d[1]; } %}
SENTENCES -> SENTENCE {% toArray %}
| SENTENCES "," SENTENCE {% appendItem(0,2) %}
RETHORICAL_TYPOLOGY -> "'type%%" TYPE "'" {% function (d) { return d[1]; } %}
TYPE -> "doxastico_scien" {% uppercase %}
| "doxastico_divulg" {% uppercase %}
| "doxastico_scien_divulg" {% uppercase %}
| "retorico_polit" {% uppercase %}
| "retor_polits" {% uppercase %}
| "cronaca_nera_politica" {% uppercase %}
| "cronaca_nera_rosa" {% uppercase %}
| "cronaca_finanz" {% uppercase %}
| "cronaca_sport" {% uppercase %}
| "biography" {% uppercase %}
EXTABST -> "extabst(" SENTENCE_LIST ")" {% function (d) { return d[1]; } %}
SENTENCE_LIST -> "[" SENTENCES "]" {% function (d) { return d[1]; } %}
SENTENCES -> SENTENCE {% toArray %}
| SENTENCES "," SENTENCE {% appendItem(0,2) %}
SENTENCE -> "'" SENTENCE_ID "%%" QUOTED_STRING "'" {% function (d) { return {"id": d[1], "text": d[3]}; } %}
SENTENCE_ID -> unsigned_int {% id %}
QUOTED_STRING -> QUOTED_CHAR {% id %}
| QUOTED_STRING QUOTED_CHAR {% appendItemChar(0,1) %}
QUOTED_CHAR -> [^'] {% id %}
| "''" {% function (d) { return "'"; } %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment