]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.databoard/src-isv/spec/Text Format.mediawiki
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / src-isv / spec / Text Format.mediawiki
diff --git a/bundles/org.simantics.databoard/src-isv/spec/Text Format.mediawiki b/bundles/org.simantics.databoard/src-isv/spec/Text Format.mediawiki
new file mode 100644 (file)
index 0000000..eb57f0e
--- /dev/null
@@ -0,0 +1,215 @@
+=Type Notation=\r
+Types are written with ''type definitions'' <tt>''type <name> = <type>''</tt>. \r
+The builtin types are denoted by their names (<tt>Boolean</tt>, <tt>Byte</tt>, <tt>Integer</tt>, <tt>Long</tt>, <tt>Float</tt>, <tt>Double</tt>, <tt>String</tt>, <tt>Variant</tt>)\r
+    type Name = String\r
+    type Length = Integer\r
+\r
+Complex type definitions and in particular recursive ones can be defined in pieces by giving names to types:\r
+    type NodeDescription = referable { name : String, children : NodeDescription[] }\r
+\r
+All other type constructors have form <tt>C(T<sub>1</sub>, ..., T<sub>k</sub>)</tt>, where <tt>C</tt> is a type constructor\r
+and parameters are datatypes. The following constructors are defined:\r
+    type Example = Optional( BaseType )\r
+\r
+Parametrised type constructors can be defined as follows:\r
+    type Tree(A) = | Leaf A | Node referable { left : Tree(A), right : Tree(A) }\r
+    \r
+    type Sample(Value) = { time : Double, value : Value }\r
+\r
+==Meta-data==\r
+Built-in types can be annotated. Annotations are written as <tt>T(key<sub>1</sub>=value<sub>1</sub>, ..., key<sub>k</sub>=value<sub>k</sub>)</tt>,\r
+where <tt>key<sub>i</sub></tt> is an identifier and <tt>value<sub>i</sub></tt> a value of some built-in type (depending on the annotation).\r
+\r
+    type value = Integer(range=[1..10000])\r
+    type Probability = Double(range=[0..1.0])\r
+    type XML = String(mimeType="text/xml") \r
+    type Html = String(pattern="^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?", length=[..4096])\r
+\r
+\r
+The following annotations are defined:\r
+* all numerical types\r
+** unit : String\r
+** range: Range\r
+* String\r
+** pattern : String (regular expression pattern of allowed strings, case sensitive)\r
+** mimeType : String\r
+** length : Range\r
+\r
+    type Size = Integer(range=[1..10000], unit="m")\r
+    type Amplitude = Double(range=[-1.0..1.0])\r
+    type Frequency = Double(unit="1/s")\r
+    type Document = String(mimeType="text/xml")\r
+\r
+==Record==\r
+A record type is constructed as <tt>{ f<sub>1</sub> : T<sub>1</sub>, ..., f<sub>k</sub> : T<sub>k</sub> }</tt>,\r
+where <tt>f<sub>i</sub></tt> is a field name and <tt>T<sub>i</sub></tt> its datatype.  A field name cannot be empty and two field names cannot\r
+be equal.\r
+Field names are usually written in lowercase.\r
+    type Color = { red : Double, \r
+                   green : Double,\r
+                   blue : Double }\r
+\r
+===Referable Record===\r
+Referable record is a record prefixed with keyword <tt>referable</tt>.     \r
+    type Tree = referable { children : Tree[] }\r
+\r
+====Tuple Type====\r
+A tuple type is a special case of record type where all components have empty names. The construction is in the following format (''T''<sub>1</sub>, ..., ''T''<sub>k</sub>).\r
+    type Vector = (Integer, Integer, Integer)\r
+\r
+==Union==\r
+A union type is constructed as <tt>| n<sub>1</sub> T<sub>1</sub> | ... | n<sub>k</sub> T<sub>k</sub></tt>, where <tt>n<sub>i</sub></tt> is a tag name and <tt>T<sub>i</sub></tt> its datatype. \r
+The tag type is optional and is assumed to be <tt>{}</tt>, if left out. Tag names have to be non-empty and distinct.\r
+Tag names are usually capitalized.    \r
+    type Color = | RGB (Float, Float, Float)\r
+                 | RGBA (Float, Float, Float, Float)\r
+    \r
+Enumerations are also unions. The type names are left out. Name of the type is used as the tag name. \r
+    type Method = | Disabled | Adaptive | Manual\r
+    \r
+    type CommandResponse = | Success\r
+                           | Error String\r
+\r
+A tag may have the same name as a builtin datatype\r
+    type Example = | Double Double | Long Long\r
+\r
+==Array==\r
+The textual notation for the array type construction is <tt>T[]</tt>, where <tt>T</tt> is the base type.\r
+    type VGA = Double[320][240]\r
+    type Names = String[]\r
+\r
+Minimum and maximum length of the array can be specified as <tt>T[a..]</tt>, <tt>T[..b]</tt>, <tt>T[a..b]</tt> or <tt>T[a]</tt>,\r
+where <tt>a</tt> and <tt>b</tt> are integers and <tt>a</tt> &le; <tt>b</tt>.\r
+*Exact Value <tt>Double[ 0 ]</tt>\r
+*Unlimited <tt>Double[]</tt>\r
+*Limited <tt>Double[ ..100 ]</tt>, <tt>Double[ 10..100 ]</tt>, <tt>Double[ 10.. ]</tt>\r
+\r
+==Map==\r
+Map type is defined as <tt>Map(K, V)</tt>, where <tt>K</tt> is key datatype, and <tt>V</tt> is value datatype.\r
+\r
+    type TimeSeries = Map( Long(unit="ms"), Double );\r
+    type PropertyMap = Map( String, String )\r
+\r
+==Variant==\r
+If is defined as <tt>''type : value''</tt>. \r
+ 50 : Integer\r
+ {x=50, y=50, z=50} : { x:Double, y:Double, z:Double }\r
+ (50, 50, 50) : { x:Double, y:Double, z:Double }\r
+\r
+==Optional==\r
+An optional type is constructed with a base type. Its values are the values of\r
+the base type and a special value ''null''.\r
+\r
+    type Name = Optional( String )\r
+    exmpl1 : Name = "Hei"\r
+    exmpl2 : Name = null\r
+    \r
+=Value Notation=\r
+Value if (''.dbv'') is a text file that contains a single data value in text format. \r
+The type must be known to the reader. \r
+\r
+Value definition file is a text file (''.dbd'') that contains a list of value definitions.\r
+There is a name, type, and value in a ''Value definition'' in the following format: <tt>''<name> : <type> = <value>''</tt>. \r
+\r
+It is assumed that the datatype of the value written in textual format is always known\r
+in the context. Thus it is not necessary to be able to completely infer the type from\r
+the value notation itself.\r
+\r
+  obj1 : Integer = 5\r
+  obj2 : { name : String } = { name = "ABC" }\r
+  obj3 : Node = { id = "123", parent = obj4 }\r
+\r
+''Strings'' are written by enclosing the string in double quotes. The special characters \r
+in the strings are escaped following Java-specification. [http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#101089]\r
+ "some string"\r
+ "string with special characters such as:\n - \\\n - \"\n" \r
+\r
+''Long strings'' containing special characters and new lines are enclosed in triple double quotes:\r
+ """Long string\r
+ spanning multiple\r
+ lines"""\r
+Characters cannot be escaped in this notation (?).\r
+\r
+''Integers'' are specified with a sequence of digits preceded by an optional '-'. ''Floating point numbers'' can contain also dot and exponent. The exact syntax follows the Java specification for ''int'' and ''double'' literals.\r
+ 1\r
+ -345\r
+ 3.1415\r
+ 1e-10\r
+\r
+==Record==\r
+The fields of a record value are enclosed in curly brackets {} and separated by comma. Each field consists of the field name, equality mark and the value.\r
+   pink : Color = { red = 1.0, green = 0.4, blue = 0.4 }\r
+\r
+Long field names are escaped with single quotes. The special characters \r
+in the strings are escaped following Java-specification. [http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#101089]\r
+    type Example = { 'long field name' : Double }\r
+    value : Example = { 'long field name' = 5.0 }\r
+\r
+===Referable Record===\r
+value in the following format: ''<name> : <type> = <value>''. \r
+Referable values are referred by name. \r
+    root : Tree = { children = [ node1, node2 ] }\r
+    node1 : Tree = { children = [] }\r
+    node2 : Tree = { children = [] }\r
+\r
+===Tuple Type===\r
+    vec1 : Vector = (1, 2, 3)\r
+\r
+When exactly one value is enclosed in parenthesis, the parenthesis are interpreted as grouping not as a tuple. Thus the following two lines are equal:\r
+ (34)\r
+ 34\r
+\r
+==Union==\r
+The value consists of the union tag name followed by a value:\r
+    result : CommandResponse = Error "The method call failed."\r
+    white : Color = RGBA (1,1,1,0)\r
+\r
+Long union tags are escaped with single quotes. The special characters \r
+in the strings are escaped following Java-specification. [http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#101089]\r
+    type Example2 = | 'long union name' (1,1,1)\r
+\r
+==Array==\r
+The values are enclosed in brackets [] and separated by comma.\r
+    image : Names = ["a", "b", "c"]\r
+\r
+==Map==\r
+Map value is a collection of entries. They are enclosed in curly brackets {} and separated by comma (,). Each entry consists of the key name, equals (=) mark and the value.\r
+    properties : PropertyMap = map { Name = "Somename", Id = "6.0" }\r
+\r
+Long field names are escaped with single quotes. The special characters \r
+in the strings are escaped following Java-specification. [http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#101089]\r
+    properties : PropertyMap = map { "string key name" = "5.0", "another key name" = "6.0" }\r
+\r
+==Variant==\r
+Type can be omited for strings and booleans\r
+ "Hello World" : String\r
+ "Hello World"\r
+ true : Boolean\r
+ true \r
+\r
+Type can also be omited for numbers with the following rule. If there is a full stop (.) then the type is a Double, otherwise an Integer.\r
+ 5.0 : Double\r
+ 5.0\r
+ 5 : Integer\r
+ 5\r
+\r
+==Optional==\r
+Record fields of optional type can be omited, if there is no value.\r
+    type Example = {\r
+             name : Optional (String)\r
+         }\r
+    exmpl : Example = {}\r
+    exmp2 : Example = { name = "abc" }\r
+\r
+\r
+=File types=\r
+{| border="1" cellpadding="3" cellspacing="0" align="center"\r
+|'''Extension'''\r
+|'''Description'''\r
+|- \r
+|<tt>.dbt</tt> ||Databoard Type Definition File. Consists of type definitions in text format.\r
+|- \r
+|<tt>.dbd</tt> ||Databoard Value Definition file. Consists of value definitions in text format.\r
+|- \r
+|<tt>.dbv</tt> ||Databoard Value File. Contains a single value in text format without type information.\r
+|}    
\ No newline at end of file