Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
21
Task/Brace-expansion/Prolog/brace-expansion-1.pro
Normal file
21
Task/Brace-expansion/Prolog/brace-expansion-1.pro
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
sym(',', commalist) --> ['\\',','], !.
|
||||
sym(H, Context) --> [H], { not(H = '{'; H = '}'), (Context = commalist -> not(H = ','); true) }.
|
||||
syms([H|T], Context) --> sym(H, Context), !, syms(T, Context).
|
||||
syms([], _) --> [].
|
||||
symbol(Symbol, Context) --> syms(Syms,Context), {atom_chars(Symbol, Syms)}.
|
||||
|
||||
braces(Member) --> ['{'], commalist(List), ['}'], {length(List, Len), Len > 1, member(Member, List)}.
|
||||
|
||||
commalist([H|T]) --> sym_braces(H, commalist), [','], commalist(T).
|
||||
commalist([H]) --> sym_braces(H, commalist).
|
||||
|
||||
sym_braces(String, Context) --> symbol(S1, Context), braces(S2), sym_braces(S3, Context), {atomics_to_string([S1,S2,S3],String)}.
|
||||
sym_braces(String, Context) --> braces(S1), symbol(S2, Context), sym_braces(S3, Context), {atomics_to_string([S1,S2,S3],String)}.
|
||||
sym_braces(String, Context) --> symbol(String, Context).
|
||||
sym_braces(String, _) --> braces(String).
|
||||
sym_braces(String, Context) --> ['{'], sym_braces(S2, Context), {atomics_to_string(['{',S2],String)}.
|
||||
sym_braces(String, Context) --> ['}'], sym_braces(S2, Context), {atomics_to_string(['}',S2],String)}.
|
||||
|
||||
grammar(String) --> sym_braces(String, braces).
|
||||
|
||||
brace_expansion(In, Out) :- atom_chars(In, Chars), findall(Out,grammar(Out, Chars, []), List), list_to_set(List, Out).
|
||||
8
Task/Brace-expansion/Prolog/brace-expansion-2.pro
Normal file
8
Task/Brace-expansion/Prolog/brace-expansion-2.pro
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
?- brace_expansion("~/{Downloads,Pictures}/*.{jpg,gif,png}", Out).
|
||||
Out = ["~/Downloads/*.jpg","~/Downloads/*.gif","~/Downloads/*.png","~/Pictures/*.jpg","~/Pictures/*.gif","~/Pictures/*.png"].
|
||||
|
||||
?- brace_expansion("It{{em,alic}iz,erat}e{d,}, please.", Out).
|
||||
Out = ["Itemized, please.", "Itemize, please.", "Iterated, please.", "Iterate, please.", "Italicized, please.", "Italicize, please."].
|
||||
|
||||
?- brace_expansion("{,{,gotta have{ ,\\, again\\, }}more }cowbell!", Out).
|
||||
Out = ["cowbell!", "more cowbell!", "gotta have more cowbell!", "gotta have, again, more cowbell!"].
|
||||
Loading…
Add table
Add a link
Reference in a new issue