Skip to content

Instantly share code, notes, and snippets.

@frame-lang
Last active November 7, 2018 22:18
Show Gist options
  • Save frame-lang/b5a1d7345baab584fc8e586135172601 to your computer and use it in GitHub Desktop.
Save frame-lang/b5a1d7345baab584fc8e586135172601 to your computer and use it in GitHub Desktop.
Frame Machine Notation for W3.ORG HTTP 1.0 client
//-------------------------------------------------//
// //
// FMN //
// //
//-------------------------------------------------//
// see W3.ORG Spec - https://dev.w3.org/libwww/Library/User/Architecture/HTTPFeatures.html
#Http_1_0_Client
-interface-
start @(|>>|)
ok @(|OK|)
status200 @(|200|)
status203 @(|203|)
status204 @(|204|)
status301 @(|301|)
status302 @(|302|)
status304 @(|304|)
status401 @(|401|)
http_0_9 @(|Http 0.9|)
error @(|Error|)
-machine-
$Begin
|>>| ->> $NeedConnection ^
$NeedConnection
|OK| ->> $NeedRequest ^
|Error| ->> $ErrorFailure ^
$NeedRequest
|OK| ->> $SentRequest ^
|Error| ->> $ErrorFailure ^
$SentRequest
|301|302| ->> $Redirection ^
|204|304| ->> $NoData ^
|200|203|Http 0.9| ->> $NeedBody ^
|401| ->> $NeedAccessAuth ^
|Error| ->> $ErrorFailure ^
$Redirection
$NoData
$NeedBody
|OK| ->> $GotData ^
|Error| ->> $ErrorFailure ^
$GotData
$NeedAccessAuth
|OK| ->> $NeedConnection ^
$ErrorFailure
//-------------------------------------------------//
// //
// Implementation //
// //
//-------------------------------------------------//
class FrameEvent {
var _msg:String
var _params:Object
var _return:Object
FrameEvent(msg:String, params:Object = null) {
_msg = msg
_params = params
}
}
//-------------------------------------------------//
class Http_1_0_Client {
/**********************************
-interface-
start @(|>>|)
ok @(|OK|)
status200 @(|200|)
status203 @(|203|)
status204 @(|204|)
status301 @(|301|)
status302 @(|302|)
status304 @(|304|)
status401 @(|401|)
http_0_9 @(|Http 0.9|)
error @(|Error|)
***********************************/
func start() { _state(new FrameEvent(">>")) }
func OK() { _state(new FrameEvent("OK")) }
func status200() { _state(new FrameEvent("200")) }
func status203() { _state(new FrameEvent("203")) }
func status204() { _state(new FrameEvent("204")) }
func status301() { _state(new FrameEvent("301")) }
func status302() { _state(new FrameEvent("302")) }
func status304() { _state(new FrameEvent("304")) }
func status401() { _state(new FrameEvent("401")) }
func http_0_9() { _state(new FrameEvent("Http 0.9")) }
func error() { _state(new FrameEvent("Error")) }
// -machine-
var _state(e:FrameEvent) = Begin
/**********************************
$Begin
|>>| ->> $NeedConnection ^
***********************************/
func Begin(e:FrameEvent) {
if (e._msg == ">>") {
_state = NeedConnection
return
}
}
/**********************************
$NeedConnection
|OK| ->> $NeedRequest ^
|Error| ->> $ErrorFailure ^
***********************************/
func NeedConnection(e:FrameEvent) {
if (e._msg == "OK") {
_state = NeedRequest
return
}
if (e._msg == "Error") {
_state = ErrorFailure
return
}
}
/**********************************
$NeedRequest
|OK| ->> $SentRequest ^
|Error| ->> $ErrorFailure ^
***********************************/
func NeedRequest(e:FrameEvent) {
if (e._msg == "OK") {
_state = SentRequest
return
}
if (e._msg == "Error") {
_state = ErrorFailure
return
}
}
/**********************************
$SentRequest
|301|302| ->> $Redirection ^
|204|304| ->> $NoData ^
|200|203|Http 0.9| ->> $NeedBody ^
|401| ->> $NeedAccessAuth ^
|Error| ->> $ErrorFailure ^
***********************************/
func SentRequest(e:FrameEvent) {
if (e._msg == "301" || e._msg == "302") {
_state = Redirection
return
}
if (e._msg == "301" || e._msg == "302") {
_state = NoData
return
}
if (e._msg == "200" || e._msg == "203" || e._msg == "Http 0.9") {
_state = NeedBody
return
}
if (e._msg == "401") {
_state = NeedAccessAuth
return
}
if (e._msg == "Error") {
_state = ErrorFailure
return
}
}
/**********************************
$Redirection
***********************************/
func Redirection(e:FrameEvent) {
}
/**********************************
$NoData
***********************************/
func NoData(e:FrameEvent) {
}
/**********************************
$NeedBody
|OK| ->> $GotData ^
|Error| ->> $Error ^
***********************************/
func NeedBody(e:FrameEvent) {
if (e._msg == "OK") {
_state = GotData
return
}
if (e._msg == "Error") {
_state = Error
return
}
}
/**********************************
$GotData
***********************************/
func GotData(e:FrameEvent) {
}
/**********************************
$NeedAccessAuth
|OK| ->> $NeedConnection ^
***********************************/
func NeedAccessAuth(e:FrameEvent) {
if (e._msg == "OK") {
_state = NeedConnection
return
}
}
/**********************************
$ErrorFailure
***********************************/
func ErrorFailure(e:FrameEvent) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment