fix indent
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
|
||||
:- initialization(main).
|
||||
|
||||
:- dynamic val/2, item/2, last_node/2.
|
||||
:- dynamic val/2, item/2, last_node/2, indent/1.
|
||||
|
||||
get_arg( Inp, Out ) :-
|
||||
unix( argv( [Inp, Out] ) ), !.
|
||||
@@ -34,6 +34,7 @@ scan_file( Inp ) :-
|
||||
repeat,
|
||||
line_count( S, Lines ),
|
||||
read_line_to_string(S, Line0),
|
||||
%( Lines = 416 %string(Line0),sub_string( Line0,_,_,_, "\secref{unicodesyntax}") -> trace ; true ),
|
||||
assert_static( source( Inp, Lines, Line0 ) ),
|
||||
( Line0 == end_of_file ->
|
||||
!,
|
||||
@@ -119,12 +120,13 @@ scan_file( Inp ) :-
|
||||
)
|
||||
).
|
||||
|
||||
|
||||
out( _S ) :-
|
||||
% init
|
||||
nb_setval(old_line, "here I go"),
|
||||
nb_setval(level, 0),
|
||||
nb_setval(item, indent(0,0)),
|
||||
retractall( stack(_, _) ),
|
||||
assert( indent( 0 ) ),
|
||||
nb_setval(do_buffer, true),
|
||||
nb_setval( min, 0 ),
|
||||
fail.
|
||||
@@ -139,8 +141,12 @@ out( S ) :-
|
||||
;
|
||||
NewLine == ""
|
||||
->
|
||||
nb_getval( old_line, OldLine ),
|
||||
OldLine \= "",
|
||||
% nb_getval( old_line, OldLine ),
|
||||
% OldLine \= "",
|
||||
format(string(SN), '~n', [])
|
||||
;
|
||||
NewLine == force
|
||||
->
|
||||
format(string(SN), '~n', [])
|
||||
;
|
||||
( speek( list, it(_Env, _, Level, _) ),
|
||||
@@ -164,7 +170,8 @@ separating_line( First ) :-
|
||||
|
||||
singleton_line(L) :- string_concat("@item",_,L),
|
||||
\+ speek(list,it("@table",_,_,_)), !.
|
||||
singleton_line(L) :- string_concat("@noindent",_,L), !.
|
||||
singleton_line(L) :- string_concat("@c",_,L), !.
|
||||
singleton_line(L) :- string_concat("@comment",_,L), !.
|
||||
singleton_line(L) :- string_concat("@findex",_,L), !.
|
||||
singleton_line(L) :- string_concat("@cindex",_,L), !.
|
||||
singleton_line(L) :- string_concat("@cnindex",_,L), !.
|
||||
@@ -250,61 +257,40 @@ command( Line, Word, Rest ) :-
|
||||
process("@item", Line, Rest, NewLine , FilePos) :-
|
||||
pop( list, it(Env, Item, Pos, Numb)), !,
|
||||
NNumb is Numb+1,
|
||||
item_type(Item, Numb, Type ),
|
||||
run( Text, Rest ),
|
||||
/* ( Env = "@table",
|
||||
atom_string( A, Line )
|
||||
->
|
||||
push( list, it(Env, Item, 0, NNumb)),
|
||||
nb_getval( level, N1 ),
|
||||
push( indent, done ),
|
||||
title(N1, Title),
|
||||
( pred( _Pred, Key, A, FilePos )
|
||||
->
|
||||
format(string(NewLine), '~*c ~a {#~a}', [ N1, 0'#, Text, Key]) %'
|
||||
% format(string(NewLine), '@paragraph ~a ~a', [ Key, Text]) %'
|
||||
;
|
||||
first_word(Text, Id, _),
|
||||
format(string(NewLine), '~*c ~a ', [ N1, 0'#, Text]) %'
|
||||
% format(string(NewLine), '@paragraph ~ss ~s', [ Id, Text]) %'
|
||||
)
|
||||
;
|
||||
( Pos == 0,
|
||||
format( user_error, 'Non-predicate after predicate, line ~d ~s~n', [FilePos, Line] ),
|
||||
fail
|
||||
;
|
||||
*/
|
||||
(
|
||||
Env = "@table",
|
||||
atom_string( A, Line ),
|
||||
pred( _Pred, Key, A, FilePos )
|
||||
->
|
||||
format(string(NewLine), '~t~s ~*|~s @anchor ~a', [Type, Pos, Text, Key])
|
||||
;
|
||||
format(string(NewLine), '~t~s ~*|~s', [Type, Pos, Text])
|
||||
),
|
||||
push( list, it(Env, Item, Pos, NNumb) ),
|
||||
push( indent, done ).
|
||||
jmp_blanks( Rest, First ),
|
||||
item_type(Item, Numb, Marker ),
|
||||
(
|
||||
Env = "table",
|
||||
atom_string( A, Line ),
|
||||
pred( _Pred, Key, A, FilePos )
|
||||
->
|
||||
push( list, it(Env, Item, Pos, NNumb) ),
|
||||
(
|
||||
% sendout the comand
|
||||
format(string(NewLine), '~t~s ~*|~s @anchor ~a', [Marker, Pos, First, Key]),
|
||||
push( indent, done )
|
||||
;
|
||||
NewLine = force
|
||||
)
|
||||
;
|
||||
format(string(NewLine), '~t~s ~*|~s', [ Marker, Pos, First]),
|
||||
push( list, it(Env, Item, Pos, NNumb) ),
|
||||
push( indent, done )
|
||||
).
|
||||
process("@end", _Line, Rest, NewLine , _Pos) :-
|
||||
speek(list,it(Env,_,_LL,_)),
|
||||
sub_string( Env, 1, _, 0, Env1 ),
|
||||
sub_string( Rest, _, _, _, Env1), !, % check
|
||||
pop( list, it(Env, _, _, _) ),
|
||||
(
|
||||
Env1 == "table"
|
||||
->
|
||||
nb_getval( level, N1 ),
|
||||
N is N1-1,
|
||||
nb_setval( level, N ),
|
||||
NewLine = ""
|
||||
;
|
||||
NewLine = ""
|
||||
).
|
||||
NewLine = "".
|
||||
process("@end", Line, _Rest, NewLine , _Pos) :-
|
||||
sub_string(Line, _, _, 0, "ifnottex"), !, % check
|
||||
NewLine = "\\endhtmlonly".
|
||||
process("@end", _Line, Rest, "" , _Pos) :-
|
||||
sub_string(Rest, _, _, _, "cartouche"), !. % check
|
||||
process("@end", _Line, Rest, "" , _Pos) :-
|
||||
sub_string(Rest, _, _, _, "format"), !. % check
|
||||
process("@end", _Line, Rest, "" , _Pos ) :-
|
||||
sub_string(Rest, _, _, _, "group"), !. % check
|
||||
process("@end", Line, _Rest, NewLine , _Pos ) :-
|
||||
@@ -318,6 +304,7 @@ process("@end", Line, _Rest, NewLine , _Pos) :-
|
||||
process("@author", _Line, Rest, NewLine , _Pos) :- !,
|
||||
jmp_blanks( Rest, Firs ),
|
||||
format( string( NewLine), '\\author ~s', [ Firs ] ).
|
||||
process("@*", _Line, _Rest, ¨¨ , _Pos) :- !.
|
||||
process("@c", _Line, Rest, NewLine , _Pos) :- !,
|
||||
gen_comment( Rest, NewLine ).
|
||||
process("@comment", _Line, Rest, NewLine , _Pos) :- !,
|
||||
@@ -333,7 +320,7 @@ process("@chapter", _Line, Rest, NewLine, _Pos ) :- !,
|
||||
run( Title, Firs ),
|
||||
nb_setval( level, 1 ),
|
||||
title_from_words(Firs, Id, _Pos),
|
||||
format(string(NewLine), '@page ~s ~s', [Id,Title]).
|
||||
format(string(NewLine), '@section ~s ~s', [Id,Title]).
|
||||
% ( format( string(NewLine), '~s', [Title] ) ; NewLine = "======" ).
|
||||
process("@cindex", _Line, _Rest, no , _Pos) :- !.
|
||||
process("@caindex", _Line, _Rest, no, _Pos ) :- !.
|
||||
@@ -349,7 +336,7 @@ process("@documentencoding", _Line, _Rest, "" , _Pos) :- !.
|
||||
process("@end", Line, _Rest, NewLine , _Pos) :- !,
|
||||
gen_comment( Line, NewLine ).
|
||||
process("@enumerate", _Line, _Rest, NewLine , _Pos) :-
|
||||
list( "@enumerate", "@enumerate", NewLine).
|
||||
list( "@enumerate", "@enumerate", NewLine, _Pos).
|
||||
process("@example", _Line, _Rest, "" , _Pos).
|
||||
process("@example", _Line, _Rest, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" , _Pos) :- !,
|
||||
push( skip, verbatim).
|
||||
@@ -362,7 +349,7 @@ process("@findexx", _Line, _Rest, "" , _Pos) :- !.
|
||||
process("@ifnottex", _Line, _Rest, "\\htmlonly" , _Pos) :- !.
|
||||
process("@itemize", _Line, Rest, NewLine , _Pos) :- !,
|
||||
jmp_blanks( Rest, First ),
|
||||
list( "@itemize", First, NewLine).
|
||||
list( "@itemize", First, NewLine, _Pos).
|
||||
process("@menu", _Line, _Rest, "" , _Pos) :- !,
|
||||
push(skip, "menu" ).
|
||||
process("@node", Line, Rest, NewLine, Pos ) :- !,
|
||||
@@ -387,7 +374,7 @@ process("@section", _Line, Rest, NewLine, Pos ) :- !,
|
||||
nb_setval( level, 2 ),
|
||||
% format(string(NewLine), '# ~s #', [NewTitle]).
|
||||
title_from_words(NewTitle, Id, Pos),
|
||||
format(string(NewLine), '@section ~s ~s', [Id,NewTitle]).
|
||||
format(string(NewLine), '@subsection ~s ~s', [Id,NewTitle]).
|
||||
% format(string(NewLine), '# ~s #', [NewTitle]).
|
||||
process("@appendix", _Line, Rest, NewLine, _Pos ) :- !,
|
||||
jmp_blanks( Rest, Title ),
|
||||
@@ -398,7 +385,7 @@ process("@subsection", _Line, Rest, NewLine, _Pos ) :- !,
|
||||
run( NewTitle, Title ),
|
||||
nb_setval( level, 3 ),
|
||||
title_from_words(NewTitle, Id, _Pos),
|
||||
format(string(NewLine), '@subsection ~s ~s', [Id,NewTitle]).
|
||||
format(string(NewLine), '@subsubsection ~s ~s', [Id,NewTitle]).
|
||||
% format(string(NewLine), '## ~s ##', [NewTitle]).
|
||||
process("@unnumberedsubsubsec", _Line, Rest, NewLine, _Pos ) :- !,
|
||||
nb_setval( level, 4 ),
|
||||
@@ -408,7 +395,7 @@ process("@subsubsection", _Line, Rest, NewLine, _Pos ) :- !,
|
||||
jmp_blanks( Rest, Title ),
|
||||
run( NewTitle, Title ),
|
||||
title_from_words(NewTitle, Id, _Pos),
|
||||
format(string(NewLine), '@subsubsection ~s ~s', [Id,NewTitle]).
|
||||
format(string(NewLine), '@paragraph ~s ~s', [Id,NewTitle]).
|
||||
% format(string(NewLine), '### ~s ###', [NewTitle]).
|
||||
process("@set", _Line, Rest, NewLine , _Pos) :- !,
|
||||
first_word( Rest, V, SecC),
|
||||
@@ -446,7 +433,7 @@ process("@table", _Line, Rest, NewLine , _Pos) :- !,
|
||||
nb_getval( level, N1 ),
|
||||
N is N1+1,
|
||||
nb_setval( level, N ),
|
||||
list( "@table", First, NewLine).
|
||||
list( "@table", First, NewLine, _Pos).
|
||||
process("@title", _Line, _Rest, "" , _Pos) :- !.
|
||||
process("@titlepage", _Line, _Rest, "", _Pos ) :- !.
|
||||
process("@top", _Line, _Rest, "" , _Pos) :- !.
|
||||
@@ -473,24 +460,22 @@ get_second( Rest, Title ) :-
|
||||
%
|
||||
% clear the buffer first.
|
||||
%
|
||||
list( Env, Line, New) :-
|
||||
list( Env, Line, New, _Pos) :-
|
||||
writeln(_Pos),
|
||||
first_word( Line, V, Rest),
|
||||
jmp_blanks( Rest, End ),
|
||||
(
|
||||
speek( list, it(_, _,Pos, _) ) ->
|
||||
(
|
||||
Pos1 is Pos + 4
|
||||
)
|
||||
Pos1 is Pos + 6
|
||||
;
|
||||
(
|
||||
Pos1 = 4
|
||||
)
|
||||
Pos1 = 6
|
||||
),
|
||||
push( list, it( Env, V, Pos1, 1 ) ),
|
||||
% b_getval( pos, _Pos ),
|
||||
% writeln(add:_Pos:Env:Pos1:End),
|
||||
% listing(stack),
|
||||
run( New, End).
|
||||
|
||||
|
||||
item_type("@bullet", _, "-" ).
|
||||
item_type("@code", _, "-" ).
|
||||
@@ -766,8 +751,16 @@ run( L) --> "@uref{",
|
||||
argument(AL, 0'{, 0'}), !, %
|
||||
{ format( codes(L, R), '<~s>' ,[AL]) },
|
||||
run(R).
|
||||
run([0' ,0'*|L]) --> "@emph{" , !, text(L, 0'}, [ 0' , 0'* |R]), run(R).
|
||||
run(NL) --> "@cite{" , !, { NL = [0'\\, 0'c, 0'i, 0't, 0'e, 0' | L] }, text(L, 0'}, [ 0' |R]), run(R).
|
||||
run(L) --> "@emph{" ,
|
||||
argument(AL, 0'{, 0'}), !, %
|
||||
!,
|
||||
{ format( codes(L, R), '<em>~s</em>' ,[AL]) },
|
||||
run(R).
|
||||
run(L) --> "@cite{" ,
|
||||
!,
|
||||
argument(AL, 0'{, 0'}), !,
|
||||
{ format( codes(L, R), '@cite ~s ' ,[AL]) },
|
||||
run(R).
|
||||
run([0'©|L]) --> "@copyright{" , !, spaces, "}", run(L). %'
|
||||
run([0'\\,C|L]) --> [C], %'
|
||||
{ md_escaped(C) }, !,
|
||||
|
Reference in New Issue
Block a user