summaryrefslogtreecommitdiff
path: root/lib/blog
diff options
context:
space:
mode:
Diffstat (limited to 'lib/blog')
-rwxr-xr-xlib/blog/dune21
-rwxr-xr-xlib/blog/hash_host/hash_blog.ml1
-rwxr-xr-xlib/blog/hash_host/hash_localhost.ml1
-rwxr-xr-xlib/blog/nord.ml2
-rwxr-xr-xlib/blog/sidebar.ml23
5 files changed, 48 insertions, 0 deletions
diff --git a/lib/blog/dune b/lib/blog/dune
new file mode 100755
index 0000000..648990f
--- /dev/null
+++ b/lib/blog/dune
@@ -0,0 +1,21 @@
+(rule
+ (targets hash_host.ml)
+ (enabled_if (= %{profile} dev))
+ (action (copy# hash_host/hash_localhost.ml hash_host.ml)))
+
+(rule
+ (targets hash_host.ml)
+ (enabled_if (<> %{profile} dev))
+ (action (copy# hash_host/hash_blog.ml hash_host.ml)))
+
+(library
+ (name blog)
+ (libraries
+ brr
+ brr.note
+ elements
+ )
+ (preprocess (pps ppx_hash))
+
+
+ )
diff --git a/lib/blog/hash_host/hash_blog.ml b/lib/blog/hash_host/hash_blog.ml
new file mode 100755
index 0000000..f5e172e
--- /dev/null
+++ b/lib/blog/hash_host/hash_blog.ml
@@ -0,0 +1 @@
+let expected_host = [%static_hash "blog.chimrod.com"]
diff --git a/lib/blog/hash_host/hash_localhost.ml b/lib/blog/hash_host/hash_localhost.ml
new file mode 100755
index 0000000..a41022e
--- /dev/null
+++ b/lib/blog/hash_host/hash_localhost.ml
@@ -0,0 +1 @@
+let expected_host = [%static_hash "localhost"]
diff --git a/lib/blog/nord.ml b/lib/blog/nord.ml
new file mode 100755
index 0000000..f0f2772
--- /dev/null
+++ b/lib/blog/nord.ml
@@ -0,0 +1,2 @@
+let nord0 = Jstr.v "#2e3440"
+let nord8 = Jstr.v "#81a1c1"
diff --git a/lib/blog/sidebar.ml b/lib/blog/sidebar.ml
new file mode 100755
index 0000000..1df0f1a
--- /dev/null
+++ b/lib/blog/sidebar.ml
@@ -0,0 +1,23 @@
+open StdLabels
+open Brr
+
+(** Return the sidebar *)
+let get
+ : unit -> El.t option
+ = fun () ->
+
+ List.find_opt (El.children @@ Document.body G.document)
+ ~f:(fun t -> El.has_tag_name El.Name.aside t)
+
+let rec clean
+ : El.t -> unit
+ = fun el ->
+ List.iter (El.children el)
+ ~f:(fun el ->
+ (* Remove the links from the sidebar, keep h1 and other stuff *)
+ if (El.has_tag_name (Jstr.v "nav") el)
+ || (El.has_tag_name (Jstr.v "ul") el) then
+ El.remove el
+ else
+ clean el
+ )
al.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# QSP Type system

Internally, there is only two types in the engine : String and Integer. This is
represented with this C struct :

```C
typedef struct
{
    union
    {
        QSPString Str;
        int Num;
    } Val;
    QSP_TINYINT Type;
} QSPVariant;
```

## Variables and assignation

The type of a variable is determined by the first character in the name:

```C
#define QSP_STRCHAR QSP_FMT("$")

// …

#define QSP_VARBASETYPE(name) (*(name).Str == QSP_STRCHAR[0]) /* QSP_TYPE_STRING | QSP_TYPE_NUMBER */
```

But during the assignation, a conversion is automatically done when the types does not match :

```C
INLINE void qspSetVar(QSPString name, QSPVariant *val, QSP_CHAR op)
{
    
    if (QSP_VARBASETYPE(name) != QSP_BASETYPE(val->Type))
    {
        if (!qspConvertVariantTo(val, QSP_VARBASETYPE(name)))
        {
            qspSetError(QSP_ERR_TYPEMISMATCH);
            return;
        }
        qspSetVarValueByReference(var, index, val);
    
    }
```

This can raise uncontrolled error with some functions like `INPUT` if you
directly the result into a numeric variable.

## Conversion and comparaison between values

Most of the functions provide automatic conversion between them: a string will
be converted in integer if the other operand is an integer:

- math operation

    That’s why `'1' + 1` will give the result `2` and not `'11'`

- comparaison


    For example, the source code for the comparaison is the following one:
    
    ```C
    case qspOpEq:
        QSP_NUM(tos) = QSP_TOBOOL(qspAutoConvertCompare(args, args + 1) == 0);
        break;
    ```


When string cannot be converted into a number, the number will be converted in
string, and the comparaison will compare thoses two strings. In the ASCII
table, a text will always be greater than a number (`'a' > 9999` will return
`-1` and `'$' > 0` will return `0`)


## Explicit conversion

### From string to integer

`isnum(…)` will tell you if a value is an integer or not: 

```
isnum('123') -> -1
isnum('abc') -> 0
```

Using `val(…)` you can convert a string into a integer:

```
val('123') -> 123
val('abc') -> 0     ! No error here
```

### From integer to string

`str(…)` will convert a number in string.

## QSP Syntax Parser 

> [!NOTE]  
> This parts describe how QSP Syntax Parser deal with the type system. This is
> not a part of the language reference.

### No implicit conversion

*Explicit is better than implicit.*

Implicit conversion is a bad thing. It can raise errors during the game if you
don’t care, and can hide other error in the code:

This code is valid, but does not work as expected (because of a `$` is missing
in the if clause, `$myvar` and `myvar` are two differents variables):

```
$myvar = 'VALUE'

if myvar = 'VALUE':

```

In order to spot this kind of errors, a warning will be raised here.

### The boolean type

I’ve added a boolean type which does not exists in the original syntax. In QSP,
the value `-1` stand for `True` and `0` for `False.`

Because *Readability counts.* , the application will raise a warning if a
String or an integer is directly given in an if clause. A comparaison operator
is required.