/*
	?- range('1..10').
	range(1,10,inclusive)
	
	?- range('-100...10').
	range(-100,10,exclusive)

*/

range(range(From,To,Type)) --> number(From), dots(Type), number(To).

number(Number) --> sign(Sign), digits(Digits),
    {atom_number(Digits,N), Number is Sign * N}.

sign(1) --> [].
sign(-1) --> [-].

digit(Digit, [Digit|Left],Left) :- atom_chars('0123456789', Digits),
    member(Digit, Digits).

digits(Digit) --> digit(Digit).
digits(Digits) --> digit(First), digits(More),
    { concat_atom([First,More], Digits) }.

dots(inclusive) --> [.,.].
dots(exclusive) --> [.,.,.].

range(Spec) :-
    atom_chars(Spec,Chars), range(Range,Chars,[]),
    Range = range(From,To,Type), writeln(Range), ck_range(From,To,Type), !.
range(_) :- writeln('Invalid range').

ck_range(From,To,inclusive) :- From > To, writeln('Warning: Range is empty'),!.
ck_range(From,To,exclusive) :- From >= To, writeln('Warning: Range is empty'),!.
ck_range(_,_,_).

