diff --git a/index.html b/index.html index d676dc2..06bd2f1 100644 --- a/index.html +++ b/index.html @@ -1,6 +1,6 @@ -UBF Home Page

UBF Home Page


UBF, a framework for Getting Erlang to talk to the outside world. +UBF Home Page

UBF Home Page


UBF, a framework for Getting Erlang to talk to the outside world. This document and the corresponding open-source code repositories are based on Joe Armstrong’s original UBF site and code with an MIT license file added to the distribution. Since then, a large number of diff --git a/misc-codes/irc_plugin.con b/misc-codes/irc_plugin.con new file mode 100644 index 0000000..8c47112 --- /dev/null +++ b/misc-codes/irc_plugin.con @@ -0,0 +1,55 @@ ++NAME("irc"). + ++VSN("ubf1.0"). + ++TYPES +info() = info; +description() = description; +contract() = contract; + +ok() = ok; +bool() = true | false; +nick() = string(); +oldnick() = nick(); +newnick() = nick(); +group() = string(); +groups() = [group()]; + +logon() = logon; +proceed() = {ok, nick()}; +listGroups() = groups; +joinGroup() = {join, group()}; +leaveGroup() = {leave, group()}; +changeNick() = {nick, nick()}; +msg() = {msg, group(), string()}; + +msgEvent() = {msg, nick(), group(), string()}; +joinEvent() = {joins, nick(), group()}; +leaveEvent() = {leaves, nick(), group()}; +changeNameEvent() = {changesName, oldnick(), newnick(), group()}. + ++STATE start + logon() => proceed() & active. %% Nick randomly assigned + ++STATE active + listGroups() => groups() & active; + joinGroup() => ok() & active; + leaveGroup() => ok() & active; + changeNick() => bool() & active; + msg() => bool() & active; %% False if you have not joined a group + + EVENT => msgEvent(); %% Group sends me a message + EVENT => joinEvent(); %% Nick joins group + EVENT => leaveEvent(); %% Nick leaves group + EVENT => changeNameEvent(). %% Nick changes name + ++ANYSTATE + info() => string(); + description() => string(); + contract() => term(). + + + + + + diff --git a/ubf-user-guide.en.html b/ubf-user-guide.en.html index acda49a..2ec2225 100644 --- a/ubf-user-guide.en.html +++ b/ubf-user-guide.en.html @@ -1,6 +1,6 @@ -UBF User’s Guide DRAFT - UNDER CONSTRUCTION

UBF User’s Guide DRAFT - UNDER CONSTRUCTION

Revision History
Revision 0.12010/10/24

1. Preface

UBF, a framework for Getting Erlang to talk to the outside world. +UBF User’s Guide DRAFT - UNDER CONSTRUCTION

UBF User’s Guide DRAFT - UNDER CONSTRUCTION

Revision History
Revision 0.12010/10/24

1. Preface

UBF, a framework for Getting Erlang to talk to the outside world. This document and the corresponding open-source code repositories are based on Joe Armstrong’s original UBF site and code with an MIT license file added to the distribution. Since then, a large number of @@ -19,7 +19,7 @@ UBF(c) is a meta-level protocol used between a UBF client and a UBF server.

While the XML series of languages had the goal of having a human readable format the UBF languages take the opposite view and provide a -"machine friendly" format. UBF is designed to be easy to implement.

Figure 1. Programming By Contract

+"machine friendly" format. UBF is designed to be easy to implement.

Figure 1. Programming By Contract


Central to UBF is the idea of a "Contract" which regulates the set of legal conversations that can take place between a client and a server. @@ -40,9 +40,7 @@ types of "glue" for making compound objects. The compound types are Tuple and List. Lastly, the operator $ (i.e. "end of object") signifies when objects are finished.

For example, the following UBF(a) object:

'person'>p # {p,"Joe",123} & {p, 'fred', 3~abc~} & $

Represents the following UBF(b) term:

[{person, fred, <<"abc">>}, {person, "Joe", 123}].

See Section 10.2.1, “UBF(a)” for a formal definition of the UBF(a) syntax.

3.1.1. Integer: [-][0-9]+

Integers are sequences of bytes which could be described by the regular expression [-][0-9]+, that is an optional minus (to denote a -negative integer) and then a sequence of at least one digit. No -restrictions are made as to the precision of the integer, precision -issues will be dealt with in UBF(b).

3.1.2. String: "…"

Strings are written enclosed in double quotes. Within a string two +negative integer) and then a sequence of at least one digit.

3.1.2. String: "…"

Strings are written enclosed in double quotes. Within a string two quoting conventions are observed, " must be written \" and \ must be written \\ - no other quotings are allowed.

3.1.3. Binary: [0-9]+ ~…~

Uninterpreted blocks of binary data are encoded. First an integer, representing the length of the binary data is encoded, this is @@ -80,25 +78,145 @@ stack. For caching optimizations, subsequent reuse of the single character C means push register C onto the recognition stack.

3.1.11. Object

Objects represent either a Term, a Register push, or a Register pop with an optional Tag. The operator $ signifies "end of object". When $ is encountered there should be only one item on the -recognition stack.

3.2. UBF(b)

See Section 10.2.2, “UBF(b)” for a formal definition of the UBF(b) syntax.

3.2.1. Name

3.2.2. Version

3.2.3. Types

3.2.3.1. Definition
3.2.3.2. Alternative
3.2.3.3. Reference
3.2.3.4. Tuple
3.2.3.5. Record
3.2.3.6. List
3.2.3.7. Range
3.2.3.8. Atom
3.2.3.9. Binary
3.2.3.10. Float
3.2.3.11. Integer
3.2.3.12. Predefined
  • +recognition stack.

3.2. UBF(b)

UBF(b) is a language independent type system and protocol description +language. The protocol description language allows one to specify +client server interaction in terms of a non-deterministic finite state +machine. The type system allows one to specify the asynchronous +events and synchronous request/response pairs that define transitions +of this finite state machine.

The type system and protocol description language together define the +basis of "Contracts" between clients and servers. All data sent by +both the client and the server is verified by the "Contract Manager" +(an Erlang process on the "server" side of the protocol). Any data +that violates the contract is rejected.

A UBF(b) contract is defined by 2 mandatory sections and 3 optional +sections. The mandatory sections are the "name" and the "version" of +the contract. The optional sections are the "types", the "states", +and the "anystates" of the contract.

For example, the following UBF(b) contract defines a simple IRC +(Internet Relay Chat) protocol between clients and a server:

+NAME("irc").
+
++VSN("ubf1.0").
+
++TYPES
+info()            = info;
+description()     = description;
+contract()        = contract;
+
+ok()              = ok;
+bool()            = true | false;
+nick()            = string();
+oldnick()         = nick();
+newnick()         = nick();
+group()           = string();
+groups()          = [group()];
+
+logon()           = logon;
+proceed()         = {ok, nick()};
+listGroups()      = groups;
+joinGroup()       = {join, group()};
+leaveGroup()      = {leave, group()};
+changeNick()      = {nick, nick()};
+msg()             = {msg, group(), string()};
+
+msgEvent()        = {msg, nick(), group(), string()};
+joinEvent()       = {joins, nick(), group()};
+leaveEvent()      = {leaves, nick(), group()};
+changeNameEvent() = {changesName, oldnick(), newnick(), group()}.
+
++STATE start
+   logon()       => proceed() & active. %% Nick randomly assigned
+
++STATE active
+   listGroups()  => groups() & active;
+   joinGroup()   => ok() & active;
+   leaveGroup()  => ok() & active;
+   changeNick()  => bool() & active;
+   msg()         => bool() & active;    %% False if you have not joined a group
+
+   EVENT         => msgEvent();         %% Group sends me a message
+   EVENT         => joinEvent();        %% Nick joins group
+   EVENT         => leaveEvent();       %% Nick leaves group
+   EVENT         => changeNameEvent().  %% Nick changes name
+
++ANYSTATE
+   info()        => string();
+   description() => string();
+   contract()    => term().

See Section 10.2.2, “UBF(b)” for a formal definition of the UBF(b) syntax.

3.2.1. Name: +NAME("…").

3.2.2. Version: +VSN("…").

3.2.3. Types: +TYPES.

The UBF(b) type system has user-defined types and predefined types. +User-defined types and predefined types are either primitive types or +complex types.

The primitive types are Integer, Range, Float, Binary, String, Atom, +and Reference. The complex types are Alternative, Tuple, Record, +Extended Record, and List. User-defined "complex types" are defined +recursively.

3.2.3.1. Definition: X() = T

New types are defined by the notation:

X() = T

The name of the type is X and the type’s definition T is either a +user-defined type or a predefined type.

3.2.3.2. Integer: [-][0-9]+ or [0-9]+#[0-9a-f]+

Postive and negative integer constants are expressed as in UBF(a). +Integer constants may also be expressed in other bases using Erlang +syntax.

3.2.3.3. Range: [-][0-9]+..[-][0-9]+ or [-][0-9]+.. or ..[-][0-9]+

Bounded, left unbounded, and right unbounded integer ranges are +supported.

3.2.3.4. Float: [-][0-9]+.[0-9]+

Positive and negative float constants are supported for network +transports other than UBF(a).

3.2.3.5. Binary: <<"…">>

Binary constants are expressed similiarly as strings in UBF(a) but +having two leading "less than brackets" and two following "greater +than brackets".

3.2.3.6. String: "…"

String constants are expressed as in UBF(a).

3.2.3.7. Atom: '…' or [a-z][a-zA-Z0-9_]*

Atom constants are expressed as UBF(a) atoms. Atom constants starting +with lowercase letters do not require single quotes.

3.2.3.8. Reference: R()

Defined types are referenced by the notation:

R()

The name of the type is R.

3.2.3.9. Alternative: T1 | T2

A type X is of type "T1 | T2" if X is of type T1 or if X is of type +T2.

3.2.3.10. Tuple: {T1, T2, …, Tn}

A type {X1, X2, …, Xn} is of type "{T1, T2, …, Tn}" if X1 is of +type T1, X2 is of type T2, … and Xn is of type Tn.

3.2.3.11. Record: name#T1, y=T2, …, z=Tn

A record type is syntactic sugar for a tuple of type "{name, T1, T2, +…, Tn}" where name, x, y, …, and z are atoms.

3.2.3.12. Extended Record: name##T1, y=T2, …, z=Tn

An extended record type is syntactic sugar for a tuple of type "{name, +T1, T2, …, Tn, $fields=[x,y,…,z], $extras=[T1, T2, …, Tn]}" +where name, x, y, …, and z are atoms.

3.2.3.13. List: [T]

A type [X1, X2, …, Xn] is of type [T] if all of Xi are of type T.

3.2.3.14. Predefined: P() or P(A1, A2, …, An)

Predefined types are referenced by the notation:

P()

or by the notation:

P(A1, A2, ..., An)

The name of the predefined type is P. Using the second notation, +attributes can be specified to make the predefined type more specific.

The following predefined types and optional attributes are supported:

atom +
  • +ascii
  • +asciiprintable +
  • +nonempty +
  • +nonundefined +
binary +
  • +ascii
  • +asciiprintable +
  • +nonempty +
float -
  • +
  • +no optional attributes are supported +
    integer -
  • +
  • +no optional attributes are supported +
    list -
  • +
    • +nonempty +
    proplist +
    • +nonempty +
    +string +
    • +ascii
    • +asciiprintable +
    • +nonempty +
    term +
    • +nonempty
    • +nonundefined +
    tuple +
    • +nonempty
    • +nonundefined +
    void -

    3.2.4. States

    • +
      +no optional attributes are supported +

    3.2.4. States

    • Name
    • Transitions @@ -122,12 +240,12 @@ download build

    • test -

    9. Reference

    +

    9. Reference

    [RFC5234] D. Crocker, Ed. Brandenburg, "Augmented BNF for Syntax Specifications: ABNF", RFC5234, January 2008. -

    +

    [UBF] Joe Armstrong, http://www.sics.se/~joe/ubf.html, March 2003.