Replaced raw_chars//1 in library(pio) with seq//1 in library(dcgs).
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
:- module(dcgs,
|
:- module(dcgs,
|
||||||
[op(1105, xfy, '|'),
|
[op(1105, xfy, '|'),
|
||||||
phrase/2,
|
phrase/2,
|
||||||
phrase/3]).
|
phrase/3,
|
||||||
|
seq//1,
|
||||||
|
seqq//1]).
|
||||||
|
|
||||||
:- use_module(library(error)).
|
:- use_module(library(error)).
|
||||||
:- use_module(library(lists), [append/3]).
|
:- use_module(library(lists), [append/3]).
|
||||||
@@ -178,3 +180,11 @@ user:term_expansion(Term0, Term) :-
|
|||||||
nonvar(Term0),
|
nonvar(Term0),
|
||||||
dcg_rule(Term0, (Head :- Body)),
|
dcg_rule(Term0, (Head :- Body)),
|
||||||
Term = (Head :- Body).
|
Term = (Head :- Body).
|
||||||
|
|
||||||
|
% Describes a sequence
|
||||||
|
seq([]) --> [].
|
||||||
|
seq([E|Es]) --> [E], seq(Es).
|
||||||
|
|
||||||
|
% Describes a sequence of sequences
|
||||||
|
seqq([]) --> [].
|
||||||
|
seqq([Es|Ess]) --> seq(Es), seqq(Ess).
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
:- module(pio, [phrase_from_file/2,
|
:- module(pio, [phrase_from_file/2,
|
||||||
phrase_from_file/3,
|
phrase_from_file/3]).
|
||||||
raw_chars//1]).
|
|
||||||
|
|
||||||
:- use_module(library(dcgs)).
|
:- use_module(library(dcgs)).
|
||||||
:- use_module(library(error)).
|
:- use_module(library(error)).
|
||||||
@@ -44,15 +43,3 @@ reader_step(Stream, Pos, Xs0) :-
|
|||||||
partial_string(Cs, Xs0, Xs),
|
partial_string(Cs, Xs0, Xs),
|
||||||
stream_to_lazy_list(Stream, Xs)
|
stream_to_lazy_list(Stream, Xs)
|
||||||
).
|
).
|
||||||
|
|
||||||
/* Relate a character list to itself greedily - for reading raw file contents using `phrase_from_file/2`
|
|
||||||
A quick benchmark:
|
|
||||||
Greedy (recurse first):
|
|
||||||
?- time(phrase_from_file(raw_chars(_), '/mnt/544KB.json')).
|
|
||||||
% CPU time: 22.471 seconds
|
|
||||||
Generous (empty list first):
|
|
||||||
?- time(phrase_from_file(raw_chars(_), '/mnt/544KB.json')).
|
|
||||||
% CPU time: 44.119 seconds
|
|
||||||
*/
|
|
||||||
raw_chars([C|Cs]) --> [C], raw_chars(Cs).
|
|
||||||
raw_chars([]) --> [].
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ minify_sample_json :-
|
|||||||
|
|
||||||
test_json_minify :-
|
test_json_minify :-
|
||||||
test_path("pass_everything.min.json", MinPath),
|
test_path("pass_everything.min.json", MinPath),
|
||||||
once(phrase_from_file(raw_chars(RefChars), MinPath)),
|
once(phrase_from_file(seq(RefChars), MinPath)),
|
||||||
name_parse("pass_everything.json", Json),
|
name_parse("pass_everything.json", Json),
|
||||||
time(once(phrase(json_chars(Json), MinChars))),
|
time(once(phrase(json_chars(Json), MinChars))),
|
||||||
RefChars = MinChars.
|
RefChars = MinChars.
|
||||||
|
|||||||
Reference in New Issue
Block a user