Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add a hacky Erlang VM printer#207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Vagabond wants to merge1 commit intokatef:main
base:main
Choose a base branch
Loading
fromVagabond:adt/erl-print

Conversation

@Vagabond
Copy link

 ./build/bin/re -k str -pl erl '^ab+c?.?[a-z]{2,3}$'
-module(fsm).-export([main/1]).main([String])->tryfsm(start,list_to_binary(String))catchthrow:fail ->io:format("failed~n"),halt(1);throw:{matched,N} ->io:format("matched~b~n", [N]),halt(0)end.fsm(start, <<_A,_B,_C,_Rest/binary>>)->if_A/=97 ->throw(fail);true ->okend,if_B/=98 ->throw(fail);true ->okend,if_C=<96 ->fsm(0,_Rest);_C==97 ->fsm(4,_Rest);_C==98 ->fsm(6,_Rest);_C==99 ->fsm(8,_Rest);_C=<122 ->fsm(4,_Rest)end;fsm(0, <<>>)->% e.g. "abA"throw({matched,3});fsm(0=_State, <<_A,_Rest/binary>>)->% e.g. "abA"if_A=<96 ->throw(fail);_A>122 ->throw(fail);true ->fsm(_State,_Rest)end;fsm(1, <<>>)->% e.g. "abAa"throw({matched,13});fsm(1=_State, <<_A,_Rest/binary>>)->% e.g. "abAa"if_A=<96 ->throw(fail);_A>122 ->throw(fail);true ->fsm(_State,_Rest)end;fsm(2, <<>>)->% e.g. "abaaa"throw({matched,9});fsm(2=_State, <<_A,_Rest/binary>>)->% e.g. "abaaa"if_A=<96 ->throw(fail);_A>122 ->throw(fail);true ->fsm(_State,_Rest)end;fsm(3, <<>>)->% e.g. "abaaaa"throw({matched,10});fsm(3=_State, <<_A,_Rest/binary>>)->% e.g. "abaaaa"iftrue ->throw(fail)end;fsm(4, <<>>)->% e.g. "aba"throw({matched,4});fsm(4=_State, <<_A,_Rest/binary>>)->% e.g. "aba"if_A=<96 ->throw(fail);_A>122 ->throw(fail);true ->fsm(_State,_Rest)end;fsm(5, <<>>)->% e.g. "abaa"throw({matched,8});fsm(5=_State, <<_A,_Rest/binary>>)->% e.g. "abaa"if_A=<96 ->throw(fail);_A=<122 ->fsm(2,_Rest);true ->throw(fail)end;fsm(6, <<>>)->% e.g. "abb"throw({matched,5});fsm(6=_State, <<_A,_Rest/binary>>)->% e.g. "abb"if_A=<96 ->fsm(0,_Rest);_A==97 ->fsm(7,_Rest);_A==98 ->fsm(9,_Rest);_A==99 ->fsm(10,_Rest);_A>122 ->fsm(0,_Rest);true ->fsm(_State,_Rest)end;fsm(7, <<>>)->% e.g. "abca"throw({matched,7});fsm(7=_State, <<_A,_Rest/binary>>)->% e.g. "abca"if_A=<96 ->throw(fail);_A=<122 ->fsm(5,_Rest);true ->throw(fail)end;fsm(8, <<>>)->% e.g. "abc"throw({matched,6});fsm(8=_State, <<_A,_Rest/binary>>)->% e.g. "abc"if_A=<96 ->fsm(0,_Rest);_A=<122 ->fsm(7,_Rest);true ->fsm(0,_Rest)end;fsm(9, <<>>)->% e.g. "abbb"throw({matched,11});fsm(9=_State, <<_A,_Rest/binary>>)->% e.g. "abbb"if_A=<96 ->fsm(0,_Rest);_A==97 ->fsm(7,_Rest);_A==98 ->fsm(9,_Rest);_A==99 ->fsm(10,_Rest);_A=<122 ->fsm(7,_Rest);true ->fsm(0,_Rest)end;fsm(10, <<>>)->% e.g. "abbc"throw({matched,12});fsm(10=_State, <<_A,_Rest/binary>>)->% e.g. "abbc"if_A=<96 ->fsm(0,_Rest);_A=<122 ->fsm(7,_Rest);true ->fsm(0,_Rest)end;fsm(_,_)->throw(fail).
; escript fsm.erl hellofailed; escript fsm.erl abcdfmatched 8; escript fsm.erl abdmatched 4; escript fsm.erl acfailed; escript fsm.erl abcdefghmatched 9

The code generator is really kind of terrible, could use some help dealing with the edge conditions better...

katef reacted with heart emoji
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

@Vagabond

[8]ページ先頭

©2009-2025 Movatter.jp