~cricket/ckt

ref: 69b215d1c9f8434916fe585820ab46c380c760a6 ckt/SPEC -rw-r--r-- 3.6 KiB
69b215d1c piapiac add ockt 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# a totally incomplete / informal specification of ckt :P
# version 0.0.0

# DEFINITIONS:
newline = \n (0x0A)
whitespace = [ space (0x20), \t (0x09), \r (0x0D) ]
escape sequences = [
    \n = newline (0x0A)
    \r = carriage return (0x0D)
    \t = tab (0x09)
    \" = double quote (0x22)
    \\ = backslash (0x5C)
    \xNN = hexadecimal 8-bit value
]

# COMMENTS
# The hash symbol (#) starts a comment, and the comment goes all the way to the end of a line.
# They can be at the start of a line, or anywhere in the line.

# Every key is a string, and every value is either a string or a table.

# TABLES
# Tables are surrounded by [ ]
# The top level is also a table!

# Key-Value pairs are 'record style initializations':
record style initialization = this is the record style initialization
initialization with table = [ key = value ]

# Surrounding whitespace is trimmed; so this is equal
"initialization with table" = [ "key" = "value" ]

# Duplicate keys are overwritten!
x = 13
x = 16
# x now equals 16

# Unspecified keys in record-style initializations are invalid;
# = value
# However, empty keys are.
"" = value

# Bare values are 'list style initializations':
value1, value2
this has a list style table = [value 1, value 2]

# Ckt makes no ditinction between tables and lists.
# The keys of list style initialization is the previous list style key + 1, 
# starting at 0 and counting up in decimal.
equivelant to list style table = [
    0 = value 1,
    1 = value 2
]

# You can even mix and match record style and list style initializations.
polyline = [
    color = blue; thickness = 2; npionts = 4
    [ x = 0;   y = 0 ]
    [ x = -10; y = 0 ]
    [ x = -10; y = 1 ]
    [ x = 0;   y = 1 ]
]

# In a table, newliens, commas, or semicolons seperate items, and they are mostly interchangable
seperated = [
    seperated, by, commas; and; by; semicolons
    and
    by
    newlines
]

# With only one difference:
# The parser should go through newlines and whitespace until it finds a non-neline, non-whitespace character.
# If the character is '=' then its a k/v pair; EG
this is valid
= value

# This is fine. This should be interpreted the same as "this is valid" = "value"
# However;
this is invalid;
= value
# This is not valid. It will interpret "this is invalid" and "= value" as two items of a table using list initialization syntax,
# and will error, as '=' is not allowed in unquoted strings.

# Same goes here:
this is also valid= 
value

this is not also valid =;
value

# And of course:
this too is valid
=
value

# STRINGS
# Strings can be unquoted, quoted, or multiline

# Unquoted strings are not escaped (what you see is what you get)
this is a bare unquoted string
this string includes \n which is not interpreted as a newline

# Quoted strings are surrounded by ", and are escaped (see escape sequences under DEFINITIONS)
"this is a quoted string"

# This are useful if you need a string that includes any of [ ] = , ; | # "
tag = "#Epic"

# Or if you need escaped characters
multiple lines quoted = "this string\nspans\nmultiple lines"

# Multiline strings start with a | on every line, and are mostly not escaped.
multiline string =
    |This string spans multiple lines.
    |Isn't it so cool?

# Aside from escape hatches. A \ before a newline in a multiline string will cause the next line to be on the same.
# A \ before the EOF should be interpreted as nothing.
singleline multiline string =
    |This string only spans \
    |a single line.

singleline unquoted string = This string only spans a single line.

# Escape hatches themselves can be escaped.
escaped escape hatches =
    |This line ends in a single backslash. \\
    |This line ends with two! \\\