nitasema  Check-in [75008c4bb6]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:initial commit ← git
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:75008c4bb6d34a3a53b9e43b9d0445920a349777c8565709472ce21bb972d950
User & Date: lexi 2019-04-28 03:40:46
Context
2019-04-28
04:17
fix readme check-in: 48d289b8b2 user: lexi tags: trunk
03:40
initial commit ← git check-in: 75008c4bb6 user: lexi tags: trunk
02:20
initial empty check-in check-in: 5c209f9c93 user: lexi tags: trunk
Changes

Added LICENSE.





































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
	sample  story "example/example.n"  and its  html translation
	"example/example.html"  ("Bone Heresy")  are copyright  2014
	alexis hale, all rights reserved.

	sample  story   "example/spectrum.n"  is   the  intellectual
	property of @sigfig@twitter.com

	the  nitasema  source code  (all  files  in this  repository
	outside the "example" directory) is released under the terms
	of the Affero General Public License; full text below


                    GNU AFFERO GENERAL PUBLIC LICENSE

                       Version 3, 19 November 2007

 Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

                            Preamble

  The GNU Affero General Public License is a free, copyleft license for
software and other kinds of works, specifically designed to ensure
cooperation with the community in the case of network server software.

  The licenses for most software and other practical works are designed
to take away your freedom to share and change the works.  By contrast,
our General Public Licenses are intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.

  When we speak of free software, we are referring to freedom, not
price.  Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.

  Developers that use our General Public Licenses protect your rights
with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.

  A secondary benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate.  Many developers of free software are heartened and
encouraged by the resulting cooperation.  However, in the case of
software used on network servers, this result may fail to come about.
The GNU General Public License permits making a modified version and
letting the public access it on a server without ever releasing its
source code to the public.

  The GNU Affero General Public License is designed specifically to
ensure that, in such cases, the modified source code becomes available
to the community.  It requires the operator of a network server to
provide the source code of the modified version running there to the
users of that server.  Therefore, public use of a modified version, on
a publicly accessible server, gives the public access to the source
code of the modified version.

  An older license, called the Affero General Public License and
published by Affero, was designed to accomplish similar goals.  This is
a different license, not a version of the Affero GPL, but Affero has
released a new version of the Affero GPL which permits relicensing under
this license.

  The precise terms and conditions for copying, distribution and
modification follow.

                       TERMS AND CONDITIONS

  0. Definitions.

  "This License" refers to version 3 of the GNU Affero General Public License.

  "Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.

  "The Program" refers to any copyrightable work licensed under this
License.  Each licensee is addressed as "you".  "Licensees" and
"recipients" may be individuals or organizations.

  To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy.  The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.

  A "covered work" means either the unmodified Program or a work based
on the Program.

  To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy.  Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.

  To "convey" a work means any kind of propagation that enables other
parties to make or receive copies.  Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.

  An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License.  If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.

  1. Source Code.

  The "source code" for a work means the preferred form of the work
for making modifications to it.  "Object code" means any non-source
form of a work.

  A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.

  The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form.  A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.

  The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities.  However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work.  For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.

  The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.

  The Corresponding Source for a work in source code form is that
same work.

  2. Basic Permissions.

  All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met.  This License explicitly affirms your unlimited
permission to run the unmodified Program.  The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work.  This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.

  You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force.  You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright.  Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.

  Conveying under any other circumstances is permitted solely under
the conditions stated below.  Sublicensing is not allowed; section 10
makes it unnecessary.

  3. Protecting Users' Legal Rights From Anti-Circumvention Law.

  No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.

  When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.

  4. Conveying Verbatim Copies.

  You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.

  You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.

  5. Conveying Modified Source Versions.

  You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:

    a) The work must carry prominent notices stating that you modified
    it, and giving a relevant date.

    b) The work must carry prominent notices stating that it is
    released under this License and any conditions added under section
    7.  This requirement modifies the requirement in section 4 to
    "keep intact all notices".

    c) You must license the entire work, as a whole, under this
    License to anyone who comes into possession of a copy.  This
    License will therefore apply, along with any applicable section 7
    additional terms, to the whole of the work, and all its parts,
    regardless of how they are packaged.  This License gives no
    permission to license the work in any other way, but it does not
    invalidate such permission if you have separately received it.

    d) If the work has interactive user interfaces, each must display
    Appropriate Legal Notices; however, if the Program has interactive
    interfaces that do not display Appropriate Legal Notices, your
    work need not make them do so.

  A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit.  Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.

  6. Conveying Non-Source Forms.

  You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:

    a) Convey the object code in, or embodied in, a physical product
    (including a physical distribution medium), accompanied by the
    Corresponding Source fixed on a durable physical medium
    customarily used for software interchange.

    b) Convey the object code in, or embodied in, a physical product
    (including a physical distribution medium), accompanied by a
    written offer, valid for at least three years and valid for as
    long as you offer spare parts or customer support for that product
    model, to give anyone who possesses the object code either (1) a
    copy of the Corresponding Source for all the software in the
    product that is covered by this License, on a durable physical
    medium customarily used for software interchange, for a price no
    more than your reasonable cost of physically performing this
    conveying of source, or (2) access to copy the
    Corresponding Source from a network server at no charge.

    c) Convey individual copies of the object code with a copy of the
    written offer to provide the Corresponding Source.  This
    alternative is allowed only occasionally and noncommercially, and
    only if you received the object code with such an offer, in accord
    with subsection 6b.

    d) Convey the object code by offering access from a designated
    place (gratis or for a charge), and offer equivalent access to the
    Corresponding Source in the same way through the same place at no
    further charge.  You need not require recipients to copy the
    Corresponding Source along with the object code.  If the place to
    copy the object code is a network server, the Corresponding Source
    may be on a different server (operated by you or a third party)
    that supports equivalent copying facilities, provided you maintain
    clear directions next to the object code saying where to find the
    Corresponding Source.  Regardless of what server hosts the
    Corresponding Source, you remain obligated to ensure that it is
    available for as long as needed to satisfy these requirements.

    e) Convey the object code using peer-to-peer transmission, provided
    you inform other peers where the object code and Corresponding
    Source of the work are being offered to the general public at no
    charge under subsection 6d.

  A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.

  A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling.  In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage.  For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product.  A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.

  "Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source.  The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.

  If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information.  But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).

  The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed.  Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.

  Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.

  7. Additional Terms.

  "Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law.  If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.

  When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it.  (Additional permissions may be written to require their own
removal in certain cases when you modify the work.)  You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.

  Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:

    a) Disclaiming warranty or limiting liability differently from the
    terms of sections 15 and 16 of this License; or

    b) Requiring preservation of specified reasonable legal notices or
    author attributions in that material or in the Appropriate Legal
    Notices displayed by works containing it; or

    c) Prohibiting misrepresentation of the origin of that material, or
    requiring that modified versions of such material be marked in
    reasonable ways as different from the original version; or

    d) Limiting the use for publicity purposes of names of licensors or
    authors of the material; or

    e) Declining to grant rights under trademark law for use of some
    trade names, trademarks, or service marks; or

    f) Requiring indemnification of licensors and authors of that
    material by anyone who conveys the material (or modified versions of
    it) with contractual assumptions of liability to the recipient, for
    any liability that these contractual assumptions directly impose on
    those licensors and authors.

  All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10.  If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term.  If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.

  If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.

  Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.

  8. Termination.

  You may not propagate or modify a covered work except as expressly
provided under this License.  Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).

  However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.

  Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.

  Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License.  If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.

  9. Acceptance Not Required for Having Copies.

  You are not required to accept this License in order to receive or
run a copy of the Program.  Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance.  However,
nothing other than this License grants you permission to propagate or
modify any covered work.  These actions infringe copyright if you do
not accept this License.  Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.

  10. Automatic Licensing of Downstream Recipients.

  Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License.  You are not responsible
for enforcing compliance by third parties with this License.

  An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations.  If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.

  You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License.  For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.

  11. Patents.

  A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based.  The
work thus licensed is called the contributor's "contributor version".

  A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version.  For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.

  Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.

  In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement).  To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.

  If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients.  "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.

  If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.

  A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License.  You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.

  Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.

  12. No Surrender of Others' Freedom.

  If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all.  For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.

  13. Remote Network Interaction; Use with the GNU General Public License.

  Notwithstanding any other provision of this License, if you modify the
Program, your modified version must prominently offer all users
interacting with it remotely through a computer network (if your version
supports such interaction) an opportunity to receive the Corresponding
Source of your version by providing access to the Corresponding Source
from a network server at no charge, through some standard or customary
means of facilitating copying of software.  This Corresponding Source
shall include the Corresponding Source for any work covered by version 3
of the GNU General Public License that is incorporated pursuant to the
following paragraph.

  Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU General Public License into a single
combined work, and to convey the resulting work.  The terms of this
License will continue to apply to the part which is the covered work,
but the work with which it is combined will remain governed by version
3 of the GNU General Public License.

  14. Revised Versions of this License.

  The Free Software Foundation may publish revised and/or new versions of
the GNU Affero General Public License from time to time.  Such new versions
will be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

  Each version is given a distinguishing version number.  If the
Program specifies that a certain numbered version of the GNU Affero General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation.  If the Program does not specify a version number of the
GNU Affero General Public License, you may choose any version ever published
by the Free Software Foundation.

  If the Program specifies that a proxy can decide which future
versions of the GNU Affero General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.

  Later license versions may give you additional or different
permissions.  However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.

  15. Disclaimer of Warranty.

  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

  16. Limitation of Liability.

  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.

  17. Interpretation of Sections 15 and 16.

  If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.

                     END OF TERMS AND CONDITIONS

            How to Apply These Terms to Your New Programs

  If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.

  To do so, attach the following notices to the program.  It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.

Also add information on how to contact you by electronic and paper mail.

  If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source.  For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code.  There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.

  You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<https://www.gnu.org/licenses/>.

Added README.md.

































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# nitasema
nitasema strives to be a versatile interactive fiction generator. it takes a script file and produces a self-contained html file that can be played in a web brower. nitasema has minimal dependencies and is fast. the name is Swahili and means "I will speak."

## dependencies
* a C++11 compiler (default is `clang++`)
* libc
* libstdc++

## building
to build, run `./make.sh` from the root directory.

## file format
the nitasema *.n file format is based on simplified s-exps. it is designed primarily as an intermediate format for a forthcoming GUI editor but in the meantime it's perfectly intelligible to humans to and only slightly verbose.

lines can be commented out with the `;` character. there are currently no multiline comments.

whitespace is used to delimit values and is otherwise insignificant.

the data types are atoms, strings, and lists. strings are delimited by single-quotes (`'`) and can span any number of lines. lists are delimited by `[` and `]`. atoms may contain any character in the ascii range '-' ~ 'z' | 'A' ~ 'Z' and any unicode character outside the ascii range. backslash (`\`) can escape single quotes in a string.

the first term in the *.n file must be a string naming the story. it may be followed by atoms to mark various flags.

### flags
* `by`: sets the author. takes a string argument. currently has no effect on output. (`by 'alexis hale'`)
* `flags`: declares booleans. must be followed by a list of booleans. (`flags [bloodsoaked screaming bleeding]`)
* `vars`: declares variables. must be followed by a list of variables. (`vars [health sanity terror]`)
* `no-select`: disables text selection to make the story seem more app-like.
* `start`: indicates the starting passage. takes an atom argument. required. (`start the-beginning-of-the-end`)

### passages
a [passage name (stylesheet) ...] declaration creates a passage. the first term must be the id of the passage as an atom. optionally a stylesheet name may follow. all following terms must be nodes.

```
[passage the-beginning-of-the-end doom-passage]
```

creates a passage with the id `the-beginning-of-the-end` with stylesheet `doom-passage`. ids are used only in the front end of the compiler and do not appear in the compiled html.

```
[passage the-beginning-of-the-end
	'doom had at long last come to Las Vegas.'
]
```

creates a passage with the id `the-beginning-of-the-end` and adds a text node. all macro nodes regardless of position are evaluated before the passage renders, though macros in conditionals will only be evaluated if the conditional evaluates correctly.

```
[passage the-beginning-of-the-end
	[p 'doom had at long last come to Las Vegas.']
	[p 'soon the mushrooms clouds of thermonuclear armageddon would envelop the globe.']
]
```

instead of creating text nodes, this example creates paragraph nodes. paragraph nodes are a better way to organize text.

to link to another passage, use the `[link id 'title']` node.

```
[passage the-beginning-of-the-end
	[p 'doom had at long last come to Las Vegas.']
	[p 'soon the mushroom clouds of ' [link doooom 'thermonuclear armageddon'] ' would envelop the globe.']
]
```

to create a link to another passage that can only be clicked once (and will afterwards disappear forever), use `action`

```
[passage the-beginning-of-the-end
	[p 'doom had at long last come to Las Vegas.']
	[p 'soon the mushrooms clouds of thermonuclear armageddon would envelop the globe.']
	[p [action make-tea 'make tea.']]
]
```

to set a flag, use the `[set flag]` and `[clear flag]`.

```
[passage doooom
	[set world-destroyed]
	[clear hankering-for-brunch]
	[p 'welp looks like everyone\'s dead now. i hope you learned a'
	   'valuable lesson on the futility of existence.']
]
```

to test a flag, use the `[flag? flag [#t-pred] ([#f-pred])]` node. #f-preds (else clauses) are optional.

```
[passage tea-with-aunt-holly
	[flag? world-destroyed [
		[p 'unfortunately, the world where both all tea in the universe and'
		   'aunt holly were located has been destroyed in thermonuclear'
		   'armageddon.']
		[p 'better luck next time, sport!']
	][
		[clear hankering-for-brunch]
		[p 'you enjoy a lovely evening sipping tea with aunt holly.']
		[p 'you have been cured of <b>HANKERING FOR BRUNCH</b>!']
	]]
]
```
a link can invoke a passage as a subroutine.
```
[passage bed
	[p 'you are in bed.']
	[sub inventory 'inventory']]
[passage bridge
	[p 'you are on the bridge of the Unrelenting Fist of Endless Imperial Wrath.']
	[p 'crew bustle about, trying to make a good impression for your inspection.']
	[sub inventory 'inventory']]
[passage inventory
	[p 'you have <b>HALF-EATEN FISH HEAD</b>, <b>HORRIFIC STENCH</b>, and <b>REGRETS</b>.']
	[p [ret 'back']]]
```
an action can also invoke a subroutine, with the `sub-action` node. its syntax is identical to `action`.

to make nodes appear only once, and not on subsequent views, use `once`
```
[passage start
	[once [[p 'you wake up and immediately wish you hadn\'t, wish you\'d never wake up again.']]]
	[p 'you are in your office.']
	[p 'the papers that need grading are still here.']
	[once [
		[p 'you pick one up, wondering if they could possibly be as bad as you remembered.']
		[p 'they\'re not. they\'re worse.']
	]]
]
```
to create an event that will interrupt the story only on the first click of a link, use `gate`.

```
[passage home
	[p 'you are home with a nice cup of tea.']
	[p [gate fight-monster outside 'go outside.']]
]
[passage outside
	[p 'you admire the splendour of the great outdoors.']
]
[passage fight-monster
	[p 'a dreadful beast covered in the intestines of its victims bursts from the sewers!']
	[p [ret 'kill monster with umbrella.']]
]
```

`once` takes two lists of nodes, the second optional. the second will be displayed on any subsequent visits.
```
[passage offal-gardens
	[once [
		[p 'it is said the offal gardens of betelgeuse must be seen to be believed.']
		[p 'well, they\'re not wrong.']
	][
		[p 'the offal gardens stretch away into the distance. you wish they didn\'t.']
	]]
]
```
## colors

colors may be set by the "colors" declaration. this overrides the default stylesheet.

```
colors [
	bg '#121212'
]
```

the colors that may be changed are `bg`, `fg`, `shadow`, `link`, `hover`, and `shadow-hover`. any valid CSS color specification may be used. `url()` can also be used to set a background image:

```
colors [
	bg 'url(bg.png)'
]
```

## stylesheets

the default stylesheet is set by the `colors` declaration. different passages may have different stylesheets. stylesheets are declared as follows:

```
[style name
	[global-rule 'expression']
	[.link
		[local-rule 'expression']
	]
]
```

"rules" are simply css rules. `[rule 'expression']` is translated to `rule: expression;` at compile time.

anything in the global scope affects the entire passage. to set the background to slowly turn black on passages tagged "doom":

```
[style doom
	[background 'black']
	[transition '10s']
]
```

to style links, use the `.link` selector. to style text, use the `.text` selector.

to suppress the default stylesheet completely, use the `no-style` declaration.

## invocation
```
./nitasema input-file.n > output-file.html
```

the html file can be opened by any browser.

## issues
* code needs major refactoring
* i wrote the entire thing in a 12-hour bout of insanity and was up until 8am working on it, so there's bound to be lots wrong.

## todo
* fully implement all node types
* implement other types of variable assignment besides =
* show line number & context on compile errors, not just parse errors
* add multiline comments
* change colors, stylesheet
* tags
* title screens
* gui??
* enable determining whether a passage was invoked as a subroutine

nitasema is developed by alexis summer hale and released under the GPLv3 license.

Added compile.cc.

























































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
namespace compile {
	struct ecompile : public err {
		void print() override {
			std::cerr<<"\e[31;1mcompile error:\e[0m ";
		};
	};
	struct etype : public ecompile {
		enum parser::node::kind expected, got;
		const char* ref;
		etype(enum parser::node::kind e, enum parser::node::kind g, const char* r) {
			expected = e; got = g; ref = r;
		}
		void print() override {
			ecompile::print();
			const static char* types[] = {"null","atom","text","list"};
			std::cerr<<"invalid type: expected \e[1m"<<types[(size_t)expected]<<"\e[0m, got \e[1m"<<types[(size_t)got]<<"\e[0m for "<<ref<<"\n";
		}
	};
	struct einvalid : public ecompile {
		const char* thing, *lit;
		einvalid(const char* t, const char* l) { thing = t; lit = l; }
		void print() override {
			ecompile::print();
			std::cerr<<"invalid "<<thing<<" \""<<lit<<"\"\n";
		}
	};
	struct emissing : public ecompile {
		const char* thing;
		emissing(const char* t) { thing = t; }
		void print() override {
			ecompile::print();
			std::cerr<<"missing \e[1m"<<thing<<"\e[0m\n";
		}
	};
	struct eunrec : public ecompile {
		const char* term;
		eunrec(const char* t) { term = t; }
		void print() override {
			ecompile::print();
			std::cerr<<"unrecognized keyword \""<<term<<"\"\n";
		}
	};
	char* astext(const parser::cons* c, const char* ref = "") {
		if (c->car.kind == parser::node::text) {
			return (char*)c->car.v;
		} else {
			throw etype(parser::node::text,c->car.kind, ref);
		}
	}
	char* asatom(const parser::cons* c, const char* ref = "") {
		if (c->car.kind == parser::node::atom) {
			return (char*)c->car.v;
		} else {
			throw etype(parser::node::atom, c->car.kind, ref);
		}
	}
	parser::cons* aslist(const parser::cons* c, const char* ref = "") {
		if (c->car.kind == parser::node::list) {
			return (parser::cons*)c->car.v;
		} else {
			throw etype(parser::node::list,c->car.kind, ref);
		}
	}
	bool eq(const parser::cons* c, const char* test) {
		return strcmp((char*)c->car.v, test) == 0;
	}
	bool atomeq(const parser::cons* c, const char* test, const char* ref) {
		char* t = asatom(c, ref);
		return strcmp(t,test)==0;
	}
	typedef list<node::node*>* nodelist;

	idt find_id(list<char*>& list, const char* title) {
		idt i = 0;
		for(auto& p : list) {
			if (strcmp(p,title)==0) return i;
			++i;
		}; //else
		throw einvalid("ID", title);
	}

	void pnode(nodelist n, parser::cons* data);
	void linknode(nodelist n, parser::cons* data, bool push, bool action = false);
	void gatenode(nodelist n, parser::cons* data);
	void retnode(nodelist n, parser::cons* data);
	void setnode(nodelist n, parser::cons* data, bool value);
	void flagp(nodelist n, parser::cons* data);
	void oncep(nodelist n, parser::cons* data);
	void container_dispatch(nodelist n, parser::cons* data) {
		for(parser::cons* c = data; c->car.kind != parser::node::null; c=c->cdr) {
			if (c->car.kind == parser::node::text) { //special syntax for text node
				auto& t = n->ref(new node::text);
				t.str = (char*)c->car.v;
			} else if (c->car.kind == parser::node::list) {
				parser::cons* node = aslist(c, "node");
				const char* kind = asatom(node, "node type");
				if (strcmp(kind,"p")==0)			pnode		(n, node->cdr);
				else if (strcmp(kind,"link")==0)	linknode	(n, node->cdr,false);
				else if (strcmp(kind,"action")==0)	linknode	(n, node->cdr,false,true);
				else if (strcmp(kind,"sub-action")==0)	linknode	(n, node->cdr,true,true);
				else if (strcmp(kind,"sub")==0)		linknode	(n, node->cdr,true);
				else if (strcmp(kind,"gate")==0)		gatenode	(n, node->cdr);
				else if (strcmp(kind,"ret")==0)		retnode		(n, node->cdr);
				else if (strcmp(kind,"flag?")==0)	flagp		(n, node->cdr);
				else if (strcmp(kind,"once")==0)	oncep		(n, node->cdr);
				else if (strcmp(kind,"set")==0)		setnode		(n, node->cdr, true);
				else if (strcmp(kind,"clear")==0)	setnode		(n, node->cdr, false);
				

				else if (strcmp(kind,"=")==0)		setnode		(n, node->cdr, false);
				else if (strcmp(kind,"+")==0)		setnode		(n, node->cdr, false);
				else if (strcmp(kind,"-")==0)		setnode		(n, node->cdr, false);
				/*
				else if (strcmp(kind,"=?")==0)	setnode		(n, node->cdr, false);
				else if (strcmp(kind,">=?")==0)	setnode		(n, node->cdr, false);
				else if (strcmp(kind,"<=?")==0)	setnode		(n, node->cdr, false);
				else if (strcmp(kind,">?")==0)	setnode		(n, node->cdr, false);
				else if (strcmp(kind,"<?")==0)	setnode		(n, node->cdr, false);*/
				else {
					throw einvalid("node type",(char*)node->car.v);
				}
			} else {
				throw etype(parser::node::list,c->car.kind,"passage nodes");
			}
		}
	}
	void pnode(nodelist n, parser::cons* data) {
		auto& p = n->ref(new node::par);
		container_dispatch(&p.nodes, data);
	}
	void setnode(nodelist n, parser::cons* data, bool value) {
		auto& p = n->ref(new node::setflag);
		p.flag = find_id(global_story.flags, asatom(data,"flag ID"));
		p.value = value;
		if (data->cdr->car.kind != parser::node::null)
			throw etype(parser::node::null, data->cdr->car.kind, "set nodelist");
	}
	void flagp(nodelist n, parser::cons* data) {
		auto& c = n->ref(new node::test);
		cond::flag* cf = new cond::flag;
		c.condition=cf;
		cf -> flag=find_id(global_story.flags, asatom(data,"flag ID"));
		data=data->cdr;
		container_dispatch(&c.t, aslist(data,"list for #t"));
		data=data->cdr;
		if (data->car.kind != parser::node::null)
			container_dispatch(&c.f, aslist(data,"list for #f"));
	}
	void oncep(nodelist n, parser::cons* data) {
		auto& c = n->ref(new node::once);
		container_dispatch(&c.nodes, aslist(data,"list for #t in once clause"));
		data=data->cdr;
		if (data->car.kind != parser::node::null)
			container_dispatch(&c.after, aslist(data,"list for #f in once clause"));
	}
	struct pref { const char* title; const char* style; parser::cons* data; };
	list<pref> prefs;
	idt find_pref(const char* title) {
		idt i = 0;
		for(auto& p : prefs) {
			if (strcmp(p.title,title)==0) return i;
			++i;
		}; //else
		throw einvalid("passage ID", title);
	}

	// im bad
	struct style { const char* name; parser::cons* data; };
	list<style> styles;
	idt find_style(const char* name) {
		idt i = 0;
		for(auto& s : styles) {
			if(strcmp(s.name, name) == 0) return i;
			++i;
		};
		throw einvalid("style ID", name);
	}

	void linknode(nodelist n, parser::cons* data, bool push, bool action) {
		auto& l = n->ref(new node::link);
		l.push=push;
		l.to=find_pref(asatom(data,"page ID"));
		l.action=action;
		container_dispatch(&l.nodes, data->cdr);
	}
	void gatenode(nodelist n, parser::cons* data) {
		auto& l = n->ref(new node::gate);
		l.gate=find_pref(asatom(data,"gate"));
		l.to=find_pref(asatom(data->cdr,"page ID"));
		container_dispatch(&l.nodes, data->cdr->cdr); // :(
	}
	void retnode(nodelist n, parser::cons* data) {
		auto& l = n->ref(new node::retlink);
		container_dispatch(&l.nodes, data);
	}

	// naively outputs css, definitely want to do more processing here in the future
	// effectful functions are alien and new what happened to me i used to be normal
	string gen_css(style s) {

		string css;
		string global; // ugh
		const char* style_name = s.name;

		//how do i fold in c????
		//its for right? you can iterate with for?
		for(parser::cons* cur = s.data; cur->car.kind != parser::node::null; cur = cur->cdr) {
			parser::cons* slot = (parser::cons*)cur->car.v;
			
			if (slot->cdr->car.kind == parser::node::list) { //global
				const char* slot_name = asatom(slot, "style slot identifier");
				css += string(".") + style_name + " " + slot_name + "{"; //"\n";
				
				for(parser::cons* l = slot->cdr; l->car.kind != parser::node::null; l = l->cdr) {
					parser::cons* elem = (parser::cons*)l->car.v;
					const char* rule = asatom(elem, "css rule");
					const char* expr = astext(elem->cdr, "css expression");
					css += /* "\t" + */ string(rule) + ":" + expr + ";"; // "\n";
				}

				css += "}";
			} else {
				// this is so cheating
				const char* rule = asatom(slot, "css rule");
				const char* expr = astext(slot->cdr, "css expression");
				global += /* "\t" + */ string(rule) + ":" + expr + ";"; // "\n";
			}
		}
		if (!global.empty()) { //ewwww
			css += string(".") + style_name + "{"; //"\n";
			css += global;
			css += "}";
		}
		return css;
	}

	void compile(story& st, parser::cons* root) {
		st.title = astext(root, "title"); //title is always first element
		char* start_at = nullptr;
		for (parser::cons* cur = root->cdr;cur->car.kind!=parser::node::null;cur=cur->cdr) {
			switch (cur->car.kind) {
				case parser::node::atom:
					if (eq(cur,"by")) {
						cur=cur->cdr;
						st.author = astext(cur, "author");
						continue;
					} else if (eq(cur,"default-style")) {
						cur=cur->cdr;
						st.style = asatom(cur, "style");
						continue;
					} else if (eq(cur,"start")) {
						cur=cur->cdr;
						start_at = asatom(cur, "starting passage");
						continue;
					} else if (eq(cur,"flags")) {
						cur=cur->cdr;
						for (parser::cons* lflags = aslist(cur,"flag list");
						lflags->car.kind != parser::node::null; lflags = lflags->cdr) {
							char*& f = ++st.flags;
							f = asatom(lflags, "flag ID");
						}
						continue;
					} else if (eq(cur,"vars")) {
						cur=cur->cdr;
						for (parser::cons* lvars = aslist(cur,"variable list");
						lvars->car.kind != parser::node::null; lvars = lvars->cdr) {
							char*& v = ++st.vars;
							v = asatom(lvars, "variable ID");
						}
						continue;
					} else if (eq(cur,"no-select")) {
						st.noselect=true;
						continue;
					} else if (eq(cur,"colors")) {
						cur=cur->cdr;
						for (parser::cons* lsty = aslist(cur,"default stylesheet");
						lsty->car.kind != parser::node::null; lsty = lsty->cdr) {
							const char* f = asatom(lsty, "element");
							lsty = lsty->cdr;
							if (lsty->car.kind == parser::node::null) {
								throw einvalid("color spec", "(null)");
							}
							if (strcmp(f, "bg")==0) {
								st.colors.bg = astext(lsty, "background color spec");
							} else if (strcmp(f, "fg")==0) {
								st.colors.fg = astext(lsty, "foreground color spec");
							} else if (strcmp(f, "shadow")==0) {
								st.colors.shadow = astext(lsty, "shadow color spec");
							} else if (strcmp(f, "link")==0) {
								st.colors.link = astext(lsty, "link color spec");
							} else if (strcmp(f, "hover")==0) {
								st.colors.hover = astext(lsty, "hover color spec");
							} else if (strcmp(f, "shadow-hover")==0) {
								st.colors.shadowhover = astext(lsty, "shadow hover color spec");
							} else {
								throw einvalid("element", f);
							}
						}
						continue;
					}
					throw eunrec((char*)cur->car.v);
				break;
				case parser::node::list:{
					parser::cons* l = (parser::cons*)cur->car.v;
					if(atomeq(l,"passage","list tag")
					or atomeq(l,"scene",  "list tag")) {
						l=(parser::cons*)l->cdr;
						pref& p = ++prefs;
						p.title=asatom(l,"passage title");
						l=(parser::cons*)l->cdr; //traverse one more, probably a better way to do this?
						/////
						if (l->car.kind == parser::node::atom) {
							p.style=asatom(l,"passage style");
							p.data=l->cdr;
						} else {
							p.style=nullptr;
							p.data=l;
						}
						continue;
					} else if(atomeq(l,"style","list tag")) {
						l=(parser::cons*)l->cdr;
						style& s = ++styles;
						s.name=asatom(l,"style name");
						s.data=l->cdr;
					} else {
						throw einvalid("list tag",(char*)l->car.v);
					}}
				break;
				default:;
			}
		}
		idt i=0;
		if (start_at == nullptr) throw emissing("start passage");
		st.start = find_pref(start_at);

		for (style& s : styles) {
			st.usercss += gen_css(s);
		}

		for (pref& pr : prefs) {
			passage& p = ++st.passages;
			p.id=i;
			p.style=pr.style;
			container_dispatch(&p.nodes, pr.data);
			++i;
		}
	}
}

Added cond.cc.





























































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
struct var {
	enum class type {flag, num} type;
	idt id;
	string label;
};
struct value {
	enum class kind { lit, tvar, ptr } kind;
	union {
		signed long lit;
		idt var;
	};
	string js() const {
		stringstream s;
		switch (kind) {
			case kind::lit: s << lit; break;
			case kind::tvar: s << "vars["<<var<<"]"; break;
			case kind::ptr: s << "vars[vars["<<var<<"]]"; break;
		}
		return s.str();
	}
};
namespace cond {
	struct cond {
		virtual string js() const = 0;
	};
	struct flag : public cond {
		idt flag;
		string js() const override {
			stringstream s;
			s << "flags["<<flag<<"] === true";
			return s.str();
		}
	};
	struct var : public cond {
		enum class comp { eq, gt, lt, gte, lte, neq } comp;
		value against;
		idt lhs;

		string js() const override {
			const static char* ops[] = {"===",">","<",">=","<=","!=="};
			stringstream s;
			s << "vars["<<lhs<<"]" << ops[(size_t)comp] << against.js();
			return s.str();
		}
	};
}

Added constants.cc.











































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
namespace constants {
	const char* runtime =
		"var onEnter=[];"
		"function $(elem) {"
		    "return document.getElementById(\"p\" + elem);"
		"}"
		"function in_arr(elem, arr) {"
		    "for (var i = 0; i < arr.length; ++i) {"
		        "if (arr[i] === elem) return true;"
		    "}"
		    "return false;"
		"}"
		"var stack = [];"
		"var once = [];"
		"var styled = [];"
		"var gates = [];"
		"var pos = null;"
		"function show(e) {"
			"$(e).style.display=\"initial\";"
		"}"
		"function hide(e) {"
			"$(e).style.display=\"none\";"
		"}"
		"function gate(id, to, g) {"
			"if (in_arr(id,gates))"
				"goto(to);"
			"else {"
				"stack.push(to);"
				"gates.push(id);"
				"goto(g);"
			"}"
		"}"
		"function goto(div) {"
		    "hide(pos);"
		    "pos = div;"
		    "$(pos).style.display = \"block\";"
		    "if (div in onEnter) {"
		        "onEnter[div]();"
		    "}"
		    "if (div in styled) {"
		    	"document.body.className=styled[div];"
		    "} else {"
		    	"document.body.className=defstyle;"
		    "}"
		"}"
		"function gosub(div) {"
		    "stack.push(pos);"
		    "goto(div);"
		"}"
		"function ret() {"
		    "goto(stack.pop());"
		"}";
}

Added containers.cc.

























































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#include <cassert>
template <typename T> struct stack {
	struct node {
		T val;
		node* last;
	};
	node* top;
	stack() {
		top = nullptr;
	}
	T& operator++() {
		node* newnode = new node;
		newnode->last = top;
		top = newnode;
		return newnode->val;
	}
	T operator--() {
		T v = top->val;
		node* t = top;
		top = top->last;
		delete t;
		return v;
	}
	T& operator*() {
		return top->val;
	}
	void _delnode(node* n) {
		node* next = n->last;
		delete n;
		if (next!=nullptr) _delnode(next);
	}
	~stack() {
		if (top!=nullptr) _delnode(top);
	}
	bool empty() {return top==nullptr;}
};
template <typename T> struct list {
	struct node {
		T val;
		node* next;
	};
	node* front;
	node* back;
	size_t size;
	list() {
		front = nullptr;
		// back = nullptr;
		size = 0;
	}
	template <typename D> D& ref(D* downcast) {
		T& upcast = ++*this;
		upcast = downcast;
		return *downcast;
	}
	T& operator++() {
		node* newnode = new node;
		if (front==nullptr) {
			front=newnode;
			back=newnode;
		} else {
			back->next = newnode;
			back = newnode;
		}
		newnode->next = nullptr;
		size++;
		return newnode->val;
	}
	void operator<<(T elem) {
		auto i = ++*this;
		i=elem;
	}
	struct iterator {
		node* cur;
		void operator++()
			{ cur=cur->next; }
		bool operator!=(iterator i) const
			{ return i.cur != cur; }
		T& operator*() const
			{ return cur->val; }
	};
	iterator operator-=(iterator i) {
		if (front == i.cur) {
			node* saved=front->next;
			delete front;
			front=saved;
			iterator newi = {saved};
			return newi;
		}
		for(node* n = front;n!=nullptr;n=n->next) {
			if (n->next == i.cur) {
				node* saved;

				if (n->next!=nullptr) saved = n->next->next;
				else saved = nullptr;
				--size;
				delete n->next;
				n->next=saved;
				iterator newi = {saved};
				return newi;
			}
		}
		assert(false);
		return i;
	}
	iterator begin() const {
		iterator i = {front};
		return i;
	}
	iterator end() const {
		iterator i = {nullptr};
		return i;
	}
	void _delnode(node* n) {
		node* next = n->next;
		delete n;
		if (next != nullptr)
			_delnode(next);
	}
	~list() {
		if (front!=nullptr)
			_delnode(front);
	}
	bool empty() const { return front==nullptr; }
};

Added example/example.html.

cannot compute difference between binary files

Added example/example.n.















































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
'Bone Heresy'
by 'Summer Hale'

start it-is-dark
no-select

colors [
	bg '#29000e'
	fg '#ff8ab3'
	shadow '#eb0052'
	link '#ffc2d7'
	hover '#fff0f5'
	shadow-hover '#ff6198'
]

[style advanced-styling
	[background '#29000e']
	[transition '2s']
]

default-style advanced-styling

flags [
	hungry
	thirsty
	bloodsoaked
	dressed
]

[style memory
	[background 'black']
	[transition '5s']]

[style dark-memory
	[background '#100000']
	[transition '1s']
	[.text
		[color '#ff3030']
		[transition '1s']]
	]

[passage it-is-dark
	[set hungry]
	[set thirsty]
	[p 'You awake, your head pounding.']
	[p 'It is dark.']
	[p 'You remember nothing.']
	[p [link corridor/listen 'Listen'] ' to your surroundings']
]

[passage you
	[p [flag? dressed [
		'You are dressed in dark robes.'
	][
		'You are wearing a tank top and a miniskirt.'
	]]]

	[p [flag? bloodsoaked
		['You are spattered with blood.']
	]]

	[ret 'Back']
]

[passage corridor
	[p 'It is still dark.']
	[p 'You '[link remember/1 'remember'] ' very little.']
	[p [sub you 'You'] ' are very cold.']
	[p [link corridor/listen 'Listen'] ' to your surroundings']
]
[passage corridor/listen
	[flag? bloodsoaked [
		[p 'Blood drips from pipes far overhead into a bucket.']
	][
		[p 'You hear a fluid dripping nearby.']
		[p 'It splashes like it\'s falling into some sort of ' [link bucket 'bucket'] ' or tank.']
	]]
	[p 'You realize you are incredibly hungry and thirsty.']
	[p [link pocket 'Check your pockets'] '.']
]

[passage bucket
	[p 'You grope for a bucket. Maybe there\'s water&mdash;']
	[p 'Your shaking hand finds the bucket and it spills violently. You feel a thick liquid splash against your skin. You smell&mdash;']
	[p 'Blood.']
	[p 'Your clothes and skin and splattered with blood.']
	[set bloodsoaked]
	[p 'You ' [link corridor/listen 'stumble backwards']]
]

[passage pocket
	[p 'You fumble for your pockets. You prod at unyielding fabric for a moment before realizing you\'re still wearing your miniskirt with the fake pocke&mdash;']
	[p '&mdash;still&mdash;']
	[p 'You begin to ' [link remember/1 'remember'] '.']
]

[passage remember/1
	[p 'It\'s difficult, like the memories don\'t want to come back. When they do, they come in flashes. They don\'t feel like yours.']

	[p [link remember/party 'A party.']]

	[p [link remember/sky 'A jet-black sky.']]

	[p [link remember/snarling 'Snarling.']]

	[p 'Focus on '[link corridor 'what\'s around you']]
]

[passage remember/snarling memory
	[p 'It was a police raid.']
	[p 'A press of bodies, huddled against the wall. A roar as the packs filled the street like an endless tide of teeth and claws.']
	[p 'The relief.']
	[p [link remember/snarling/not-you 'They didn\'t want you'] '.']
]

[passage remember/snarling/not-you memory
	[p 'A few unlucky people who had stepped out for a smoke were taken. A few neighbors, out staring at the sky, ignoring the warnings bleating out from the radio. Some children, out past curfew. Their blood streaked the streets.']
	[p 'The police are never clean, but they\'ve been especially vicious since the mating season started.']
	[p 'But they weren\'t here for ' [link remember/party 'the party']'. They were after ' [link remember/snarling/someone-else 'someone else'] '.']
]

[passage remember/snarling/someone-else memory
	[p 'Who?']
	[p 'Nothing.']
	[p 'You know you knew once. Your memories point at it, the links are all still there, but the thing they\'re pointing at isn\'t. Like there\'s a hole in the middle of your memory, a hole as dark and wrong as the ' [link remember/sky 'jet-black sky'] '.']
	[p 'It feels like something was ripped out of your head.']
	[p 'Messily.']
	[p 'Your heart begins racing.']
	[p [link remember/1 'You don\'t want to think about this anymore.']]
]
[passage remember/sky memory
	[p '"Do not look at the sky."']
	[p 'Somewhere a radio was tuned to Approved News 6. For two hours it broadcast the same advisory. "Do not look at the sky." The ever-shifting voice of the announcer had taken on unusual tones of urgency. "Loyal citizens are urgently advised to <em>avoid observing the sky</em>."']
	[p [link remember/sky/look 'You looked.']]
]
[passage remember/sky/look memory
	[p 'There were no stars. There was no moon. There was only emptiness&mdash;']
	[p 'No.']
	[p 'There was something else.']
	[p 'You can hear your heart thumping in your chest.']
	[p [link remember/1 'You don\'t want to keep thinking about this.']]
]
[passage remember/party memory
	[p 'People shouting, laughing, dancing, kissing. A cute girl you laid your eyes on longingly, ' [link remember/cute-girl 'but turned away because...']]
	[p 'Nothing.']
	[p 'There was music.']
	[p [link remember/house 'It was someone\'s house.']]
]
[passage remember/house memory
	[p 'It was small. The walls were tan.']
	[p 'Could have been any house.']
	[p 'Except for that ' [link remember/thing '<em>thing</em>'] '.']
]
[passage remember/thing dark-memory
	[p 'The thought is physically painful. You struggle not to vomit.']
	[p 'There wasn\'t anything right about '[link remember/party 'that party'] ', not with that <em>thing</em> and ' [link remember/sky 'that sky'] '.']
]
[passage remember/cute-girl memory
	[p 'Who was she?']
	[p 'You remember her face, her body. Freckled, slim, sexy, <em>ruthless&mdash;</em>']
	[p 'The way she danced was almost inhuman.']
	[p '<em>she knew she knew '[link remember/cute-girl/nothing 'SHE KNEW'] '</em>']
]
[passage remember/cute-girl/nothing
	[p '...nothing.']
	[p [link remember/1 'The spark of memory fades quicker than it flared.']]
]

Added example/spectrum.n.











































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
'spectrum'
by 'sigfig'

start opening
no-select

colors [
	bg '#141414'
	fg '#bebebe'
	shadow 'rgb(150, 150, 150)'
	link 'rgb(255, 255, 255)'
	shadow-hover 'rgb(30, 170, 250)'
]

[passage opening
	[p 'the polycarbonate sheet that separates you from the void seems awfully thin now']
	[p 'a small emergency light weakly illuminates your controls']
	[p 'fuck, where\'s that ' [link opening/buttons 'button']]]

[passage opening/buttons
	[p 'you brush your fingers over a panel of manual controls']
	[p [link opening/power 'there it is']]]

[passage opening/power
	[p 'you toggle the aux power on']
	[p 'the generators make a faint whirring noise']
	[p 'the lights above the buttons are dancing']
	[p 'alright, ' [link opening/engine 'main engine']]]

[passage opening/engine
	[p 'the engine rumbles to life and delivers a swift kick to your lower back']
	[p 'you\'re moving forwards now, but the view outside doesn\'t believe it']
	[p 'the ' [link computer/boot 'computers'] ' are booting up']]

[passage computer/boot crt-boot
	[p [link computer/main 'ALTUS CONTROL SYSTEMS']]]

[passage computer/main crt
	[p 'todo']]

[style opening-style
	[background 'rgb(20, 20, 20)']
	[.text
		[font-family 'sans-serif']
		[color 'rgb(190, 190, 190)']
		[text-shadow '0px 0px 0.5em rgb(150, 150, 150)']]
	[.link
		[font-family 'sans-serif']
		[color 'rgb(255, 255, 255)']]
	[.link:hover
		[text-shadow '0px 0px 1em rgb(30, 170, 250)']]]

[style crt-boot
	[background-color '#8cc2ff']
	[.link
		[display 'block']
		[text-align 'center']
		[font-family 'sans-serif']
		[color '#fff']
		[font-size '72pt']
		[text-shadow '0px 0px 2em #fff']]
	[.link:hover
		[text-shadow '0px 0px 2em #fff']]]

[style crt
	[background-color 'rgb(0, 0, 0)']
	[.link
		[display 'block']]
]

Added make.sh.







>
>
>
1
2
3
#!/usr/bin/env bash

c++ -g -std=c++11 nitasema.cc -o nitasema

Added makefile.













>
>
>
>
>
>
1
2
3
4
5
6
CFLAGS=-std=c++11
CXX=c++ $(CFLAGS)
rel:
	$(CXX) nitasema.cc -o nitasema
dbg:
	$(CXX) -g nitasema.cc -o nitasema

Added nitasema.cc.















































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#include <iostream>
#include <sstream>
#include <string.h>
#include <fstream>

using std::string;
using std::stringstream;
typedef unsigned int idt;
struct err {
	virtual void print() = 0;
};
bool verbose;
#define log(exp) if(verbose)std::cerr<<"\e[33;1mdebug:\e[0m " exp "\n"

#include "constants.cc"
#include "containers.cc"
#include "cond.cc"
#include "passage.cc"
#include "nodes.cc"
#include "story.cc"
story global_story; ///haaaaack

#include "parser.cc"
#include "compile.cc"

int main(int argc, char** argv) {
	if (argc != 2 && !(argc == 3 && strcmp(argv[2],"--verbose") == 0)) {
		std::cerr << "usage: "<<argv[0]<<" storyfile [--verbose]\n";
		return 1;
	}
	verbose = argc == 3;
	try {
		char* input;
		/* read file */ {	
			std::ifstream t;
			log("opening file "<<argv[1]<<" for reading");
			t.open(argv[1]);
			if (t.is_open()) {
				t.seekg(0,std::ios::end);
				size_t size = t.tellg();
				t.seekg(0,std::iostream::beg);

				input = new char[size+1];
				log("reading file");
				t.read(input, size);
				input[size]=0;

				log("closing file");
				t.close();
			} else {
				std::cerr << "cannot open story file for reading";
				return 2;
			}
		};
		parser::cons root;
		log("parsing input");
		parser::parse(&root, input);
		delete[] input;
		if (verbose) {
			log("successfully parsed file; parser dump");
			root.dump();
		}
		compile::compile(global_story, &root);
		std::cout<<global_story.write()<<'\n';
	} catch (err& e) {
		e.print();
		return 1;
	}

	//std::cout << j.write() << '\n';
}

Added nodes.cc.































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
namespace node {
	struct container_node : public container, public node {
		virtual string html(const passage& p) const override {
			string h;
			for (auto& n : nodes) h += n->html(p);
			return h;
		}
		virtual string js(const passage& p) const override {
			string j;
			for (auto& n : nodes) j += n->js(p);
			return j;
		}
	};
	struct par : public container_node {
		string html(const passage& p) const override {
			string h="<p class=\"text\">";
			h+=container_node::html(p) + "</p>";
			return h;
		}
	};
	struct text : public node {
		string str;
		string html(const passage&) const override {
			return str;
		}
	};
	struct setflag : public node {
		idt flag;
		bool value;
		string js(const passage&) const override {
			stringstream s;
			s<<"flags["<<flag<<"] = "<<(value?"true":"false")<<";";
			return s.str();
		}
	};
	struct assign : public node {
		value lhs, rhs;
		string js(const passage&) const override {
			return lhs.js() + " = " + rhs.js() + ";"; // TODO add other kinds of assignment
		}
	};
	struct once : public node {
		list<node*> nodes, after;
		string html(const passage& p) const override {
			stringstream h;
			h << "<span id=\"p"<<p.id<<"-once-"<<id<<"\">";
			for (auto& n : nodes) h << n->html(p);
			h << "</span>";
			if (!after.empty()) {
				h << "<span style=\"display:none;\" id=\"p"<<p.id<<"-once-"<<id<<"-after\">";
				for (auto& n : after) h<<n->html(p);
				h << "</span>";
			}
			return h.str();
		}
		string js(const passage& p) const override {
			stringstream j;
			j << "if (in_arr("<<id<<",once)) {"
					"hide(\""<<p.id<<"-once-"<<id<<"\");";
					if (!after.empty())
						j<<"show(\""<<p.id<<"-once-"<<id<<"-after\");";
				for (auto& n : after) j<<n->js(p);
			j<<	"} else {"
					"once.push(\""<<id<<"\");"
					"show(\""<<p.id<<"-once-"<<id<<"\");";
					if (!after.empty())
						j<<"hide(\""<<p.id<<"-once-"<<id<<"-after\");";
				for (auto& n : nodes) j<<n->js(p);
			j << "}";
			return j.str();
		};
	};
	struct test : public node {
		list<node*> t;
		list<node*> f;
		cond::cond* condition;
		string html(const passage& p) const override {
			stringstream h;
			h << "<span style=\"display:none;\" id=\"p"<<p.id<<"-cond-"<<id<<"-t\">";
			for (auto& n : t) h << n->html(p);
			h << "</span>";
			if (!f.empty()) {
				h << "<span style=\"display:none;\" id=\"p"<<p.id<<"-cond-"<<id<<"-f\">";
				for (auto& n : f) h<<n->html(p);
				h << "</span>";
			}
			return h.str();
		}
		string js(const passage& p) const override {
			stringstream j;
			j << "if ("<<condition->js()<<") {"
					"show(\""<<p.id<<"-cond-"<<id<<"-t\");";
					if (!f.empty())
						j << "hide(\""<<p.id<<"-cond-"<<id<<"-f\");";
					for (auto& n : t) j<<n->js(p);
			j << " } else {"
					"hide(\""<<p.id<<"-cond-"<<id<<"-t\");";
					if (!f.empty())
						j << "show(\""<<p.id<<"-cond-"<<id<<"-f\");";
					for (auto& n : f) j<<n->js(p);
			j << "}";
			return j.str();
		};
	};
	struct gate : public container_node {
		idt to;
		idt gate;
		string html(const passage& p) const override {
			stringstream s;
			s << "<span class=\"link\" onclick=\"gate("<<id<<","<<to<<","<<gate<<")\">";
			s << container_node::html(p)+"</span>";
			return s.str();
		}
	};
	struct link : public container_node {
		idt to;
		bool push;
		bool action;
		string html(const passage& p) const override {
			stringstream s;
			s << "<span ";
			if (action) s << "id=\"pa"<<id<<"\" ";
			s << "class=\"link\" onclick=\"";
			if (action)
				s << "hide('a"<<id<<"');";
			if (push) {
				s << "gosub("<<to<<")";
			} else {
				s << "goto("<<to<<")";
			}
			s << "\">" << container_node::html(p)+"</span>";
			return s.str();
		}
	};
	struct retlink : public container_node {
		string html(const passage& p) const override {
			string s;
			s += "<span class=\"link\" onclick=\"ret()\">";
			s += container_node::html(p)+"</span>";
			return s;
		}
	};
}

Added parser.cc.

























































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
namespace parser {
	bool idcp(char c) {
		return (c >= '-' && c <= 'Z') || (c>='a' && c<='z') || c>127 || c<0; // unicode hack
	}
	bool wsp(char c) {
		return c==' ' || c=='\n' || c=='\t';
	}

	struct eparse : public err {
		const char* pos;
		const char* input;
		enum kind {bad_id_char, unexpected_eof, unrecognized_char} kind;
		eparse(const char* _pos, const char* _input, enum kind _kind) {
			pos=_pos; input=_input; kind=_kind;
		}
		const char* linestart() {
			const char* i;
			for (i = pos; *i != '\n' && i > input; --i);
			if (*i=='\n') return i+1;
			return i;
		}
		size_t linenum() {
			size_t l = 1;
			for (const char *i = input; i<pos; ++i) if (*i=='\n') ++l;
			return l;
		}
		void print() override {
			static const char* err[] = {"invalid character in id", "unexpected end of input",
			"unrecognized character"};
			std::cerr<<"\e[31;1mparse error:\e[0;1m "<<err[(size_t)kind]<<" "<<*pos<<"\e[0m\n";
			std::cerr<<"         \e[1m"<<linenum()<<" : \e[0m";
			const char* ls = linestart();
			for (const char* i = ls; *i!='\n' && *i!=0; ++i) {
				if (i==pos) std::cerr<<"\e[31;1;7m";
				std::cerr<<*i;
				if (i==pos) std::cerr<<"\e[0m";
			}
		}
	};

	struct node {
			enum kind { null = 0, atom, text, list } kind;
			void* v;
	};
	struct cons { node car; cons* cdr;
		void dump() {
			std::cerr << "(";
			if (car.kind == node::null) {
				std::cerr << ")"; return;	
			} else if (car.kind == node::list) {
				std::cerr << "[";
				((cons*)car.v)->dump();
				std::cerr << "]";
			} else if (car.kind == node::text) {
				std::cerr << "\"" << ((char*)car.v) << "\"";
			} else {
				std::cerr << (char*)car.v;;
			}
			std::cerr << " . ";
			cdr->dump();
			std::cerr << ")";
		}
	};

	void parse(cons* root, const char* input) {
		cons* cursor = root;
		string buffer = "";
		stack<cons*> pstack;
		for(const char* i = input;;++i) {
			if (*i==';') //line comment
				while (*i!='\n' && *i!=0) ++i;
			if (wsp(*i)) continue;
			if (idcp(*i)) {
				do {
					if (!idcp(*i)) throw eparse(i,input,eparse::bad_id_char);
					buffer += *i;
				} while(!wsp(i[1]) && i[1]!=']' && i[1]!=0 && i++); // this is it, the evilest thing i've ever done
				cursor->car.kind=node::atom;
				cursor->car.v=new char[buffer.size()+1];
				strcpy((char*)cursor->car.v, buffer.c_str());
				buffer="";
				cursor->cdr = new cons;
				cursor=cursor->cdr;
				continue;
			}
			if (*i==0) {
				cursor->car.kind=node::null;
				if (!pstack.empty()) {
					throw eparse(i,input,eparse::unexpected_eof);
				}
				break;
			}
			if (*i == '[') {
				++pstack = cursor;
				cursor->car.kind = node::list;
				cursor->car.v = new cons;
				cursor = (cons*)cursor->car.v;
				continue;
			}
			if (*i == '\'') {
				++i; while (*i!='\'') {
					if (*i == 0) throw eparse(i,input,eparse::unexpected_eof);
					buffer += *i++;
					if (*i == '\\' ) { buffer+=*++i; ++i; }
				}
				cursor->car.kind = node::text;
				cursor->car.v = new char[buffer.size()+1];
				strcpy((char*)cursor->car.v, buffer.c_str());
				buffer = "";
				cursor->cdr = new cons;
				cursor=cursor->cdr;
				continue;
			}
			if (*i == ']') {
				cursor->car.kind=node::null;
				cursor = --pstack;
				cursor->cdr = new cons;
				cursor = cursor->cdr;
				continue;
			}
			throw eparse(i,input,eparse::unrecognized_char);
		}
	}
}

Added passage.cc.











































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
struct passage;
namespace node {
	struct node {
		virtual string html(const passage&) const {return "";}
		virtual string js(const passage&) const {return "";}
		static size_t makeid() {
			static size_t init = 0;
			return init++;
		}
		size_t id = makeid();
	};
	struct container {
		list<node*> nodes;
	};
}
struct passage : public node::container {
	idt id;
	const char* style;
	string html(bool visible) const {
		stringstream html;
		html << "<div class=\"passage\"";
		if(!visible) html << "style=\"display:none;\" ";
		html << "id=\"p" << id << "\">";
		for (auto& n : nodes) {
			html << n->html(*this);
		}
		html << "</div>";
		return html.str();
	}
	string js() const {
		string j = "";
		for(auto& n : nodes) {
			j += n->js(*this);
		}
		return j;
	}
};

Added story.cc.







































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
130
131
struct story {
	list<char*> flags;
	list<char*> vars;
	list<passage> passages;
	idt start;
	bool noselect;
	bool nostyle;
	const char* style;
	struct {
		string bg, fg, shadow, link, hover, shadowhover;
	} colors;
	story() {
		nostyle = noselect = false;
		style = nullptr;
		// default stylesheet
		colors.bg = "black";
		colors.fg = "#f0f0f0";
		colors.shadow = "#adadad";
		colors.link = "white";
		colors.hover = "#f0ffff";
		colors.shadowhover = "#addede";
	}
	char* title, *author;
	string html() {
		stringstream h;
		idt i = 0; //haaack
		for (passage& p : passages) {
			h << p.html(i==start);
			++i;
		}
		return h.str();
	}
	string js() {
		stringstream j;
		for (passage& p : passages) {
			string jsc = p.js();
			if (p.style != nullptr) {
				j << "styled["<<p.id<<"] = \""<<p.style<<"\";";
			}
			if (jsc != "") {
				j << "onEnter[" << p.id << "] = function(){";
				j << jsc;
				j << "};";
			}
		}
		return j.str();
	}
	string wscript() {
		stringstream j;
		if (!flags.empty()) {
			j << "var flags=[];"
			"for(var i=0;i<"<<flags.size<<";++i)flags[i]=false;";
		}
		if (!vars.empty()) {
			j << "var vars=[];"
			"for(var i=0;i<"<<vars.size<<";++i)vars[i]=0;";
		}
		j << "window.onload=function(){pos="<<start<<";goto("<<start<<")};"; //haaaaaaaaaack
		if (style==nullptr)
			j << "var defstyle = \"\";";
		else
			j << "var defstyle = \"" << style << "\";";
		/* runtime */
		// this is an abjectly shitty way of doing this; in the long term i'd
		// like to add an option that allows storing the runtime separately
		// (i.e. so libraries of games don't duplicate the runtime over & over)
		// but for now this is the best way to do it.
		j << constants::runtime;
		/* end runtime */
		j << js();
		return j.str();
	};

	string usercss;
	string wstyle() {
		string css;
		if (!nostyle) {
			css+="body {"
		    	"cursor: default;"
		   		"background: "+colors.bg+";"
			"}"
			"::selection {"
			    "background-color: rgba(217, 165, 189, 0.17);"
			"}"
			".passage {"
			    "max-width: 40em;"
			    "margin: auto;"
			    "margin-top: 5em;"
			"}"
			".text {"
			    "color: "+colors.fg+";"
			    "text-shadow: 0px 0px 1em "+colors.shadow+";"
			    "font-size: 18pt;"
			    "font-family: GaramondNo8, serif;"
			    "font-weight: 100;"
			"}"
			".link {"
			    "color: "+colors.link+";"
			    "font-weight: bold;"
			    "cursor: pointer;"
			    "transition: .2s;"
			"}"
			".link:hover {"
			    "transition: 0s;"
			    "color: "+colors.hover+";"
			    "text-shadow: 0px 0px 1em "+colors.shadowhover+";"
			"}";
		}
		if (noselect) {
			css+="* { -webkit-touch-callout: none;-webkit-user-select: none;"
			"-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;"
			"user-select: none; } ";
		}
		css+=usercss;
		return css;
	}
	string write() {
		string h;
		try {
			h += std::string("<html><head><meta charset=\"UTF-8\"><style type=\"text/css\">") + wstyle() + "</style>"
			"<script type=\"text/javascript\">" + wscript() + "</script>"
			+ "<title>" + title + "</title></head><body";
			if (style != nullptr)
				h+=string(" class=\"")+style+"\"";
			h += ">" + html() + "</body></html>";
		} catch (const char* n) {
			exit(1);
		}
		return h;
	}
};