{"id":22946607,"url":"https://github.com/mmower/statec","last_synced_at":"2025-09-16T03:39:07.297Z","repository":{"id":2361510,"uuid":"3325195","full_name":"mmower/statec","owner":"mmower","description":"Objective-C/Cocoa based State Machine Compiler","archived":false,"fork":false,"pushed_at":"2012-03-04T13:00:12.000Z","size":267,"stargazers_count":54,"open_issues_count":0,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-08-12T23:49:38.891Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mmower.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-02-01T13:52:48.000Z","updated_at":"2025-05-16T22:19:40.000Z","dependencies_parsed_at":"2022-08-26T16:00:23.924Z","dependency_job_id":null,"html_url":"https://github.com/mmower/statec","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mmower/statec","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmower%2Fstatec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmower%2Fstatec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmower%2Fstatec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmower%2Fstatec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mmower","download_url":"https://codeload.github.com/mmower/statec/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmower%2Fstatec/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275358014,"owners_count":25450439,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-16T02:00:10.229Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-14T14:47:26.655Z","updated_at":"2025-09-16T03:39:07.257Z","avatar_url":"https://github.com/mmower.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# statec\n\n## introduction\n\nPronounced \"static\", statec is an Objective-C/Foundation tool to compile Obj-C state machine classes from a little language that describes them.\n\nThe goal was to have a simple, clear, language to express a state machine that compiles into an easy to use class to operate them. There are other, similar, tools available for example [SMC](http://smc.sourceforge.net/) or [Ragel](http://www.complang.org/ragel/) which are more comprehensive, support a wide range of languages, and so forth. They are good tools but they did not immediately fit my needs and thus began a monumental exercise in Yak shaving.\n\nTwo days later and I have a \"little language\" for expressing state machines that is parsed - using a parser built with Tom Davie's [CoreParse](https://github.com/beelsebob/CoreParse) framework (itself quite young but promising) - into an intermediate representation of a machine and then converted directly into Objective-C source using an Objective-C code generator framework built as part of the framework.\n\nSimilar to the approach taken by Rentzsch's [mogenerator](https://github.com/rentzsch/mogenerator) statec generates two classes for each machine, a completely generated implementation class and a user-managed class that subclasses it. The implementation provides methods to respond to state changes that the user-managed class can override to provide context specific processing.\n\n## language\n\nThe statec language is a little language for describing state machines. It has a few keywords and a simple structure, here's an example:\n\n\u003ccode\u003e\u003cpre\u003e\n@machine \"TrafficLight\" {\n  @initial \"off\"\n\t@state \"off\" {\n\t\t@event \"on\" =\u003e \"green\"\n\t}\n\t@state \"green\" {\n\t\t@enter\n\t\t@exit\n\t\t@event \"amber\" =\u003e \"amber\"\n\t\t@event \"off\" =\u003e \"off\"\n\t}\n\t@state \"amber\" {\n\t\t@enter\n\t\t@exit\n\t\t@event \"green\" =\u003e \"green\"\n\t\t@event \"red\" =\u003e \"red\"\n\t}\n\t@state \"red\" {\n\t\t@enter\n\t\t@exit\n\t\t@event \"amber\" =\u003e \"amber\"\n\t}\n}\n\u003c/pre\u003e\u003c/code\u003e\n\n\u003cdl\u003e\n\t\u003cdt\u003e@machine\u003c/dt\u003e\n\t\u003cdd\u003enames the machine and contains its states. The name is used as the basis of the classes generated, in our example they would be _TrafficLightMachine (the implementation class) and TrafficLightMachine (the user class).\u003c/dd\u003e\n\t\u003cdt\u003e@initial\u003c/dt\u003e\n\t\u003cdd\u003edefines the initial state of the machine (an enter event is not generated for the machine being started in this state).\u003c/dd\u003e\n\t\u003cdt\u003e@state\u003c/dt\u003e\n\t\u003cdd\u003edefines a named state\u003c/dd\u003e\n\t\u003cdt\u003e@enter\u003c/dt\u003e\n\t\u003cdd\u003especifies that a callback (e.g. enterGreenState) should be generated and invoked when the machine enters this state.\u003c/dd\u003e\n\t\u003cdt\u003e@exit\u003c/dt\u003e\n\t\u003cdd\u003especifies than a callback (e.g. exitAmberState) should be generated and invoked before the machine leaves this state.\u003c/dd\u003e\n\t\u003cdt\u003e@event\u003c/dt\u003e\n\t\u003cdd\u003edefines a named event and the state the event transitions the machine into. The event name is used to name the event method in the machine (e.g. amberEvent) to cause the transition.\u003c/dd\u003e\n\u003c/dl\u003e\n\nThe current behaviour is to raise an exception when an event is invoked that is not legal in the current state. In the future this might - optionally - return a condition \u0026 NSError instead.\n\n## running\n\nThe statec command line tool requires the CoreParse.framework be installed in /Library/Frameworks.\n\nThe statec command line tool has three arguments:\n\n* -i \u0026lt;machine file\u0026gt; \n\t* e.g. trafficlight.smd\n* -d \u0026lt;target folder\u0026gt;\n\t* e.g. ~/Projects/TrafficLightSim/\n* -g\n\t* Generate a GraphViz digraph of the machine and, if the `dot` command is available convert it into a PNG image.\n\nThe generated files should be added to your Xcode project. The *\\_\u0026lt;Name\u0026gt;Machine.m* file should not be edited as this will be regenerated every time the statec command is generated. The *\u0026lt;Name\u0026gt;Machine.m* is intended for the user to edit and will not be regenerated if it exists.\n\n## machine\n\nThe generated machine does not employ a switch statement or lookup table but, rather, stateless classes that represent the states in the machine and that have methods that represent the available transitions.\n\nIn our example a class `TrafficLightState` is generated along with a subclass for each state, e.g. `TrafficLightOnState`. The `TrafficLightMachine` has a state variable that points at an instance representing the current state. When an event method e.g. `greenEvent` is called on the machine it is passed to the current state class that either transitions the calling machine into a new state (optionally invoking exit \u0026 enter callbacks), or raises an exception if the transition is not legal from that state.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmower%2Fstatec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmmower%2Fstatec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmower%2Fstatec/lists"}