Added docs.
h3rald h3rald@h3rald.com
Sun, 19 Nov 2017 16:06:04 +0100
7 files changed,
305 insertions(+),
7 deletions(-)
M
Min_DeveloperGuide.htm
→
Min_DeveloperGuide.htm
@@ -3262,9 +3262,9 @@ text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
color: #eee; background-color: #222; border: 1px solid #ccc; - white-space: pre-wrap; padding: 0 3px; border: 2px solid #999; + white-space: pre-wrap; border-top: 10px solid #999; } .terminal a {@@ -3285,13 +3285,17 @@ }
} .terminal p, .terminal p:first-child { - margin-top: 0; + margin-top: -40px; margin-bottom: 0; text-shadow: none; font-weight: normal; font-family: "Source Code Pro", "Monaco", "DejaVu Sans Mono", "Courier New", monospace; font-size: 85%; color: #eee; +} +.terminal p:first-child, +.terminal p:first-child:first-child { + margin-top: 0px; } .terminal p:before, .terminal p:first-child:before {@@ -3315,9 +3319,9 @@ text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
color: #eee; background-color: #222; border: 1px solid #ccc; - white-space: pre-wrap; padding: 0 3px; border: 2px solid #999; + white-space: pre-wrap; border-top: 10px solid #999; } .terminal-su a {@@ -3338,13 +3342,17 @@ }
} .terminal-su p, .terminal-su p:first-child { - margin-top: 0; + margin-top: -40px; margin-bottom: 0; text-shadow: none; font-weight: normal; font-family: "Source Code Pro", "Monaco", "DejaVu Sans Mono", "Courier New", monospace; font-size: 85%; color: #eee; +} +.terminal-su p:first-child, +.terminal-su p:first-child:first-child { + margin-top: 0px; } .terminal-su p:before, .terminal-su p:first-child:before {@@ -4464,6 +4472,7 @@ <li><a href="#<code>num</code>-Module"><code>num</code> Module</a></li>
<li><a href="#<code>time</code>-Module"><code>time</code> Module</a></li> <li><a href="#<code>crypto</code>-Module"><code>crypto</code> Module</a></li> <li><a href="#<code>math</code>-Module"><code>math</code> Module</a></li> + <li><a href="#<code>net</code>-Module"><code>net</code> Module</a></li> </ul> </li> </ul>@@ -5286,6 +5295,8 @@ <dt><a href="#<code>crypto</code>-Module"><code>crypto</code> Module</a></dt>
<dd>Provides operators to compute hashes (MD5, SHA1, SHA224, SHA256, SHA384, sha512), base64 encoding/decoding, and AES encryption/decryption.</dd> <dt><a href="#<code>math</code>-Module"><code>math</code> Module</a></dt> <dd>Provides many mathematical operators and constants such as trigonometric functions, square root, logarithms, etc.</dd> +<dt><a href="#<code>net</code>-Module"><code>net</code> Module</a></dt> +<dd>Provides basic supports for sockets (some features are not supported on Windows systems).</dd> </dl> <a name="Notation"></a>@@ -5343,6 +5354,8 @@ (“line” 3)
(“column” 13) ) </code></pre></dd> +<dt><span class="kwd">dict:socket</span></dt> +<dd>A socket dictionary, created through the <a href="#op-socket"><code>socket</code></a> method.</dd> <dt><span class="kwd">true</span></dt> <dd>true (boolean type).</dd> <dt><span class="kwd">false</span></dt>@@ -7852,9 +7865,165 @@
<div class="operator"><p><span class="kwd"> <span class="kwd">num<sub>1</sub></span> <strong>⇒</strong> <span class="kwd">num<sub>2</sub></span></span></p> <p>Truncates <span class="kwd">num</span> to the decimal point.</p></div> + +<a name="<code>net</code>-Module"></a> +<h3><code>net</code> Module<a href="#document-top" title="Go to top"></a></h3> + +<p><a id="op-accept"></a> +<span class="reference-title">accept</span></p> + +<div class="operator"><p><span class="kwd"> <span class="kwd">dict:socket<sub>1</sub></span> <span class="kwd">dict:socket<sub>2</sub></span> <strong>⇒</strong> <span class="kwd">dict:socket<sub>1</sub></span></span></p> + +<p>Makes <span class="kwd">dict:socket<sub>2</sub></span> (server) accept a connection from <span class="kwd">dict:socket<sub>1</sub></span> (client). Returns the client socket <span class="kwd">dict:socket<sub>1</sub></span> from which it will be possible to receive data from.</p></div> + +<p><a id="op-close"></a> +<span class="reference-title">close</span></p> + +<div class="operator"><p><span class="kwd"> <span class="kwd">dict:socket</span> <strong>⇒</strong> ∅</span></p> + +<p>Closes a previously-opened socket.</p></div> + +<p><a id="op-connect"></a> +<span class="reference-title">connect</span></p> + +<div class="operator"><p><span class="kwd"> <span class="kwd">dict:socket</span> <span class="kwd">string</span> <span class="kwd">int</span> <strong>⇒</strong> <span class="kwd">dict:socket</span></span></p> + +<p>Connects socket <span class="kwd">dict:socket</span> to address <span class="kwd">string</span> and port <span class="kwd">int</span>.</p> + +<div class="sidebar"><p>Example</p> + +<p>The following code shows how to send a message to a server running on localhost:7777. The message is passed as the first argument to the program.</p> + +<pre><code>() socket "localhost" 7777 connect =cli + +args 1 get :msg + +"Sending message \"$1\" to localhost:7777..." (msg) => % puts! + +cli "$1\n" (msg) => % send + +"Done." puts! + +cli close +</code></pre></div></div> + +<p><a id="op-listen"></a> +<span class="reference-title">listen</span></p> + +<div class="operator"><p><span class="kwd"> <span class="kwd">dict</span> <span class="kwd">dict:socket<sub>1</sub></span> <strong>⇒</strong> <span class="kwd">dict:socket<sub>2</sub></span></span></p> + +<p>Makes socket <span class="kwd">dict:socket<sub>1</sub></span> listen to the specified address and port. <span class="kwd">dict</span> can be empty or contain any of the following properties, used to specify the address and port to listen to respectively.</p> + +<dl> +<dt>address</dt> +<dd>The address to listen to (default: <strong>0.0.0.0</strong>).</dd> +<dt>port</dt> +<dd>The port to listen to (default: <strong>80</strong>).</dd> +</dl> + +<div class="sidebar"><p>Example</p> + +<p>The following code shows how to create a simple server that listens on port 7777, prints data received from clients, and exits when it receives the string <code>exit</code>:</p> + +<pre><code>() socket (("address" "127.0.0.1") ("port" 7777)) listen =srv + +"Server listening on localhost:7777" puts! + +() socket =cli +"" :line +(line "exit" !=) +( + srv cli accept #cli + cli recv-line @line + "Received: $1" (line) => % puts! +) while + +"Exiting..." puts! + +srv close +</code></pre></div></div> + +<p><a id="op-recv"></a> +<span class="reference-title">recv</span></p> + +<div class="operator"><p><span class="kwd"> <span class="kwd">dict:socket</span> <span class="kwd">int</span> <strong>⇒</strong> <span class="kwd">string</span></span></p> + +<p>Waits to receive <span class="kwd">int</span> characters from <span class="kwd">dict:socket</span> and returns the resulting data <span class="kwd">string</span>.</p></div> + +<p><a id="op-recv-line"></a> +<span class="reference-title">recv-line</span></p> + +<div class="operator"><p><span class="kwd"> <span class="kwd">dict:socket</span> <strong>⇒</strong> <span class="kwd">string</span></span></p> + +<p>Waits to receive a line of data from <span class="kwd">dict:socket</span> and returns the resulting data <span class="kwd">string</span>. <code>""</code> is returned if <span class="kwd">dict:socket</span> is disconnected.</p> + +<div class="sidebar"><p>Example</p> + +<p>The following code shows how to make a simple GET request to <a href="http://httpbin.org/uuid">http://httpbin.org/uuid</a> to receive a random UUID and display its response:</p> + +<pre><code>() socket "httpbin.org" 80 connect =cli + +cli "GET /uuid HTTP/1.1\r\nHost: httpbin.org\r\n\r\n" send + +cli recv-line puts :line +(line "}" !=) +( + cli recv-line puts @line +) while +</code></pre></div></div> + +<p><a id="op-send"></a> +<span class="reference-title">send</span></p> + +<div class="operator"><p><span class="kwd"> <span class="kwd">dict:socket</span> <span class="kwd">string</span> <strong>⇒</strong> ∅</span></p> + +<p>Sends <span class="kwd">string</span> to the connected socket <span class="kwd">dict:socket</span>.</p></div> + +<p><a id="op-socket"></a> +<span class="reference-title">socket</span></p> + +<div class="operator"><p><span class="kwd"> <span class="kwd">dict</span> <strong>⇒</strong> <span class="kwd">dict:socket</span></span></p> + +<p>Opens a new socket.</p> + +<p><span class="kwd">dict</span> can be empty or contain any of the following properties, used to specify the domain, type and protocol of the socket respectively.</p> + +<dl> +<dt>domain</dt> +<dd><p>The socket domain. It can be set to one of the following values:</p> + +<ul> +<li><strong>ipv4</strong> (default): Internet Protocol version 4.</li> +<li><strong>ipv6</strong>: Internet Protocol version 6.</li> +<li><strong>unix</strong>: local Unix file (not supported on Windows systems).</li> +</ul> +</dd> +<dt>type</dt> +<dd><p>The socket type. It can be set to one of the following values:</p> + +<ul> +<li><strong>stream</strong> (default): Reliable stream-oriented service or Stream Socket.</li> +<li><strong>dgram</strong>: Datagram service or Datagram Socket.</li> +<li><strong>raw</strong>: Raw protocols atop the network layer.</li> +<li><strong>seqpacket</strong>: Reliable sequenced packet service.</li> +</ul> +</dd> +<dt>protocol</dt> +<dd><p>The socket protocol. It can be set to one of the following values:</p> + +<ul> +<li><strong>tcp</strong> (default): Transmission Control Protocol.</li> +<li><strong>udp</strong>: User Datagram Protocol.</li> +<li><strong>ipv4</strong>: Internet Protocol version 4 (not supported on Windows systems).</li> +<li><strong>ipv6</strong>: Internet Protocol version 6 (not supported on Windows systems).</li> +<li><strong>raw</strong>: Raw IP Packets protocol (not supported on Windows systems).</li> +<li><strong>icmp</strong>: Internet Control Message Protocol (not supported on Windows systems).</li> +</ul> +</dd> +</dl></div> </div> <div id="footer"> - <p><span class="copy"></span> Fabio Cevasco – November 18, 2017</p> + <p><span class="copy"></span> Fabio Cevasco – November 19, 2017</p> <p><span>Powered by</span> <a href="https://h3rald.com/hastyscribe"><span class="hastyscribe"></span></a></p> </div> </div>
M
Min_DeveloperGuide.md
→
Min_DeveloperGuide.md
@@ -134,6 +134,9 @@ ### `math` Module
{@ site/contents/reference-math.md || 1 @} +### `net` Module + +{@ site/contents/reference-net.md || 1 @} {#op =>
M
min.nimble
→
min.nimble
@@ -1,6 +1,6 @@
[Package] name = "min" -version = "0.12.0" +version = "0.13.0" author = "Fabio Cevasco" description = "A tiny concatenative programming language and shell." license = "MIT"
M
site/contents/_defs_.md
→
site/contents/_defs_.md
@@ -45,6 +45,9 @@ {{sl2 => ['sym<sub>2</sub>](class:kwd)}}
{{f => [false](class:kwd)}} {{t => [true](class:kwd)}} {{null => ∅}} +{{sock => [dict:socket](class:kwd)}} +{{sock1 => [dict:socket<sub>1</sub>](class:kwd)}} +{{sock2 => [dict:socket<sub>2</sub>](class:kwd)}} {{m => _min_}} {{sgregex => [sgregex](https://github.com/snake5/sgregex).}}
A
site/contents/reference-net.md
@@ -0,0 +1,119 @@
+----- +content-type: "page" +title: "net Module" +----- +{@ _defs_.md || 0 @} + +{#op||accept||{{sock1}} {{sock2}}||{{sock1}}|| +Makes {{sock2}} (server) accept a connection from {{sock1}} (client). Returns the client socket {{sock1}} from which it will be possible to receive data from. #} + +{#op||close||{{sock}}||{{null}}|| +Closes a previously-opened socket. #} + +{#op||connect||{{sock}} {{s}} {{i}}||{{sock}}|| +> Connects socket {{sock}} to address {{s}} and port {{i}}. +> +> > %sidebar% +> > Example +> > +> > The following code shows how to send a message to a server running on localhost:7777. The message is passed as the first argument to the program. +> > +> > () socket "localhost" 7777 connect =cli +> > +> > args 1 get :msg +> > +> > "Sending message \"$1\" to localhost:7777..." (msg) => % puts! +> > +> > cli "$1\n" (msg) => % send +> > +> > "Done." puts! +> > +> > cli close + #} + +{#op||listen||{{d}} {{sock1}}||{{sock2}}|| +> Makes socket {{sock1}} listen to the specified address and port. {{d}} can be empty or contain any of the following properties, used to specify the address and port to listen to respectively. +> +> address +> : The address to listen to (default: **0.0.0.0**). +> port +> : The port to listen to (default: **80**). +> +> > %sidebar% +> > Example +> > +> > The following code shows how to create a simple server that listens on port 7777, prints data received from clients, and exits when it receives the string `exit`: +> > +> > () socket (("address" "127.0.0.1") ("port" 7777)) listen =srv +> > +> > "Server listening on localhost:7777" puts! +> > +> > () socket =cli +> > "" :line +> > (line "exit" !=) +> > ( +> > srv cli accept #cli +> > cli recv-line @line +> > "Received: $1" (line) => % puts! +> > ) while +> > +> > "Exiting..." puts! +> > +> > srv close + #} + +{#op||recv||{{sock}} {{i}}||{{s}}|| +Waits to receive {{i}} characters from {{sock}} and returns the resulting data {{s}}.#} + +{#op||recv-line||{{sock}}||{{s}}|| +> Waits to receive a line of data from {{sock}} and returns the resulting data {{s}}. `""` is returned if {{sock}} is disconnected. +> +> > %sidebar% +> > Example +> > +> > The following code shows how to make a simple GET request to <http://httpbin.org/uuid> to receive a random UUID and display its response: +> > +> > +> > () socket "httpbin.org" 80 connect =cli +> > +> > cli "GET /uuid HTTP/1.1\r\nHost: httpbin.org\r\n\r\n" send +> > +> > cli recv-line puts :line +> > (line "}" !=) +> > ( +> > cli recv-line puts @line +> > ) while + #} + +{#op||send||{{sock}} {{s}}||{{null}}|| +Sends {{s}} to the connected socket {{sock}}. #} + +{#op||socket||{{d}}||{{sock}}|| +> Opens a new socket. +> +> {{d}} can be empty or contain any of the following properties, used to specify the domain, type and protocol of the socket respectively. +> +> domain +> : The socket domain. It can be set to one of the following values: +> +> * **ipv4** (default): Internet Protocol version 4. +> * **ipv6**: Internet Protocol version 6. +> * **unix**: local Unix file {{no-win -> (not supported on Windows systems)}}. +> type +> : The socket type. It can be set to one of the following values: +> +> * **stream** (default): Reliable stream-oriented service or Stream Socket. +> * **dgram**: Datagram service or Datagram Socket. +> * **raw**: Raw protocols atop the network layer. +> * **seqpacket**: Reliable sequenced packet service. +> protocol +> : The socket protocol. It can be set to one of the following values: +> +> * **tcp** (default): Transmission Control Protocol. +> * **udp**: User Datagram Protocol. +> * **ipv4**: Internet Protocol version 4 {{no-win}}. +> * **ipv6**: Internet Protocol version 6 {{no-win}}. +> * **raw**: Raw IP Packets protocol {{no-win}}. +> * **icmp**: Internet Control Message Protocol {{no-win}}. + #} +
M
site/contents/reference.md
→
site/contents/reference.md
@@ -30,6 +30,8 @@ {#link-module||crypto#}
: Provides operators to compute hashes (MD5, SHA1, SHA224, SHA256, SHA384, sha512), base64 encoding/decoding, and AES encryption/decryption. {#link-module||math#} : Provides many mathematical operators and constants such as trigonometric functions, square root, logarithms, etc. +{#link-module||net#} +: Provides basic supports for sockets (some features are not supported on Windows systems). ## Notation@@ -83,6 +85,8 @@ ("line" 3)
("column" 13) ) </code></pre> +{{sock}} +: A socket dictionary, created through the {#link-operator||net||socket#} method. {{t}} : true (boolean type). {{f}}
M
site/settings.json
→
site/settings.json
@@ -5,6 +5,6 @@ "templates": "templates",
"temp": "temp", "output": "output", "title": "min language", - "version": "0.12.0", + "version": "0.13.0", "rules": "rules.min" }