このページは2007年 12月 1日, 11:59に更新されました by RickCogley

出来るデキスクリップト

From $1

Deki Wiki includes an expression notation for creating dynamic content and invoking functions.

Table of Contents


Syntax

This section describes the syntax and the semantics of DekiScript, including which tokens are valid, how they can be combined, and what their combinations mean.

The language is explained using the extended BNF notation, in which ( x )* means 0 or more x's, and ( x )? means an optional x.  Non-terminals are shown like non-terminal, terminals are shown like terminal, and tokens are shown like token.

Lexical Conventions

Names in DekiScript can be any string of letters, digits, and underscores, not beginning with a digit. Note that any character considered alphabetic by the current locale can be used in an identifier.  Identifiers are used to refer to variables and table fields.

The following tokens are reserved and cannot be used as names: _, nil, null, true, false.  DekiScript is not case-sensitive, meaning page.path and PAGE.PATH are identical.

Syntax

A DekiScript block allows for a single expression with the following syntax: 

expr ::= simple ( call | access | default-value  | string-concat )*
simple ::= nil| bool | number | string | name | magic-id | map | list | ( expr )
map ::= { ( field ( , field )* )? }
field ::= ( name | string ) : expr
list
::= [ ( expr ( , expr )* )? ]
call ::= ( ( expr ( , expr )* )? ) | map
access ::= [ expr ] | . name
default-value ::= ?? expr
string-concat ::= .. expr
magic-id ::= @ name

Nil (1.8.1)

The empty value is represented by _, nil, and null.  All tokens are synonymous and their variations are provided for convenience.

Bool (1.8.1)

Logical values are represented by true and false.

Number (1.8.1)

Numbers must have a decimal part and may have an optional decimal exponent.  DekiScript also accepts hexadecimal constants, by prefixing them with 0x.  Numbers are stored as 64-bit floating point values.

Examples of valid numbers are:

  • 3
  • 3.1416
  • 314.16e-2
  • 0.31416E1
  • 0xff
  • 0xFFFFFF

String (1.8.1)

Strings can be delimited by matching single or double quotes and can contain these escape sequences: '\a' (bell), '\b' (backspace), '\f' (form feed), '\n' (newline), '\r' (carriage return), '\t' (horizontal tab), '\uXXXX' (encoded character where 'XXXX' is the hexadecimal unicode value), '\v' (vertical tab), '\\' (backslash), '/' (slash), '\"' (double quote), and '\'' (single quote).  Strings in DekiScript may contain any 16-bit value, including embedded zeros, which can be specified as '\0'.

Examples of valid strings are:

  • 'Hello World!'
  • 'Say "hello"!'
  • "Say 'bye'!"
  • 'Line 1\nLine 2'

Map (1.8.1)

A map is an associative array that assigns a key to an expression.  The key can either be a name or a string.  The evaluation order of expressions inside a map is non-deterministic.

map ::= { ( field ( , field )* )? }
field ::= ( name | string ) : expr

Examples of valid maps are:

  • { }
  • {  first: "Hi", second: "bye" }
  • { "#1": "First", '#2': { } }

Note: Because DekiScript blocks can be enclosed inside double curly braces (i.e. {{ }} ) , care must be applied when nesting tables, as two consecutive }} will be interpreted as the end of the DekiScript block.

The values of a map are accessed by providing the key either as a name preceded by a dot (.) or as an expression surrounded by brackets ([]).  Valid examples of accessing a map are:

  • map.first
  • map['#1'] 

If the key is not found in the map, the expression evaluates to nil.

List (1.8.1)

A list is an indexed array of expressions.  The evaluation order of expressions inside a list is non-deterministic.

list ::= [ ( expr ( , expr )* )? ]

Examples of valid lists are:

  • [ ]
  • [ 1, 2, 3 ]
  • [ 1, _, "hi" ]

The values of a list are accessed by using a numeric expression surrounded by brackets ([]).  The first value in a list has index 0.  Valid examples accessing a list are:

  • list[0]
  • list[1000]

If the index is not within range, the expression evaluates to nil.

Function Call (1.8.1)

In a function call, the prefix is evaluated first.  If the value of the prefix has type uri, the arguments are evaluated in a non-deterministic order.  Otherwise, an exception is thrown.  Arguments can be specified with two different notations, either as a list or as a map.

Valid examples of calling a function with an argument list are:

  • fn()
  • fn(1, 2, 3)
  • fn(1, _, "hi")

Valid examples of calling a function with an argument map are:

  • fn{}
  • fn{ first: 1, second: 2, third: 3 }
  • fn{ "arg#1": 1, 'arg#3':"hi" }

Using an argument map enables the caller to pass in arguments by name.  Unspecified arguments have value nil, while specified arguments that don't correspond to the parameter name will be ignored (but they are evaluated).

Operator .. (1.8.2)

The .. operator is used to concatenate two strings.  If the values being concatenated are not strings, they are converted to strings first.

Valid examples of the .. operator are:

  • "Hello " .. "World!"
  • "1+1=" .. 2
  • nil .. '123' .. [ 1, 2, 3 ]

Operator ?? (1.8.2)

The ?? operator is used to test for nil.  First, the expression to the left of the ?? operator is evaluated.  If the resulting value is nil, the expression to the right is evaluated and returned instead.

Valid examples of the ?? operator are:

  • nil ?? 123
  • map.value ?? map.alternate ?? "default"

Magic Identifier (1.8.2)

A magic identifier is an automatically generated string that is guaranteed to be unique across scopes.  The scope of a magic identifier is a single page or template instance.  For example, if a page or template is loaded multiple times via inclusion, each page will have unique values for its magic identifiers.

Magic identifiers are commonly used to create channels for PubSub communication.  By using magic identifiers, the channels are guaranteed to be unique and not interfere with similarly named channels on other included pages.

Valid examples of the magic identifiers are:

  • @abc
  • @abc123
  • @_1

Built-in Functions & Variables

The following functions and variables are part the Deki Wiki runtime environment and are always available.

Wiki Functions

Function Description
wiki.contributors() : xml
Insert a list of top contributors on the site. (1.8.2)
wiki.contributors(path : str) : xml
Insert a list of top contributors for a wiki page or site if path is 'nil'. (1.8.2)
wiki.contributors(path : str, max : num) : xml
Insert a list of up to 'max' contributors for a wiki page or site if path is 'nil'. (1.8.2)
wiki.directory(query : str) : xml
Insert an alphabetical directory of the search results. (1.8.1)
wiki.page(path : str) : xml
Include a wiki page. (1.8.1)
wiki.page(path : str, section : str) : xml
Include a section from a wiki page. (1.8.1)
wiki.pagecount() : num
Insert the total number of pages that exist. (1.8.1)
wiki.search(query : str) : xml
Insert a list of search results. (1.8.1)
wiki.search(query : str, max : num) : xml
Insert a list of at most 'max' search results. (1.8.1)
wiki.template(name : str) : xml
Insert dynamically a wiki template. (1.8.2)
wiki.template(name : str, args : map) : xml
Insert dynamically a wiki template with parameters. (1.8.2)
wiki.text(path : str, section : str) : xml
Include unformatted contents of a wiki page. (1.8.2)
wiki.text(path : str, section : str) : xml
Include unformatted contents of a section from a wiki page. (1.8.2)
wiki.toc(path : str) : xml
Insert table of contents of a wiki page. (1.8.1)
wiki.tree(path : str) : xml
Insert a list of all pages that exist below the given page. (1.8.1)
wiki.tree(path : str, depth : num) : xml
Insert a list of all pages that exist below the given page up to a given depth. (1.8.2)

Wiki Function Examples

Date Functions & Variables

Function Description
date.day(datetime :str) : str Get day of month from date-time. (1.8.1)
date.dayname(datetime :str) : str Get name of day from date-time. (1.8.1)
date.dayofweek(datetime :str) : num Get day of the week from date-time. (1.8.1)
date.dayofyear(datetime :str) : num Get day of the year from date-time. (1.8.1)
date.format(datetime : str, format : str) : str
Show date-time in custom format. (1.8.1)  See .Net documentation for formatting string. (1.8.1)
date.month(datetime :str) : str Get month from date-time. (1.8.1)
date.monthname(datetime :str) : str Get name of the month from date-time. (1.8.1)
date.now : str
Current date-time in GMT. (1.8.1)
date.week(datetime :str) : num Get week of year from date-time. (1.8.1)
date.time(datetime :str) : str Get time from date-time. (1.8.1)
date.year(datetime :str) : str
Get 4-digit year from date-time. (1.8.1)

Date Functions & Variables Examples

Site Variables

Function Description
site.host : str
Site host name. (1.8.1)
site.language : str
Site language code. (1.8.1)
site.name : str
Site name. (1.8.1)
site.uri : uri
Site URI. (1.8.1)

Site, Page, and User Variables Examples

Page Variables

Function Description
page.counter : num
View counter for the current page. (1.8.2)
page.date : str
Date-time in GMT when the current page was last modified. (1.8.2)
page.id : num
ID of the current page. (1.8.2)
page.namespace : str
Namespace of the current page. (1.8.1)
page.path : str
Path of the current page. (1.8.1)
page.title : str
Title of the current page. (1.8.1)
page.toc : xml
Table of content for the current page. (1.8.1)
page.uri : uri
URI of the current page. (1.8.2)

Site, Page, and User Variables Examples

User Variables

Function Description
user.id ID of the current user. (1.8.1)
user.name Name of the current user. (1.8.1)
user.uri
URI for user's page. (1.8.2)

Site, Page, and User Variables Examples

 

 
コメント(0)
あなたはコメントを投稿するには ログイン しなければなりません。