Parser/lexer of Vinora Screenplay
  • C 50.3%
  • Shell 33.8%
  • C++ 12%
  • HTML 3%
  • Makefile 0.9%
Find a file
2026-11-08 10:40:23 +03:00
src Initial commit 2026-11-08 10:40:23 +03:00
tests Initial commit 2026-11-08 10:40:23 +03:00
.gitignore Initial commit 2026-11-08 10:40:23 +03:00
LICENSE.md Initial commit 2026-11-08 10:40:23 +03:00
Makefile Initial commit 2026-11-08 10:40:23 +03:00
README.md Initial commit 2026-11-08 10:40:23 +03:00

vinora-parser

vnrs2html converts a Vinora Screenplay scene into an HTML fragment. It reads a .vnrs file on stdin and writes paragraphs, headings, choices, images, and media elements to stdout.

The parser implements the chunk grammar from Vinora Screenplay 0.0.4 (docs/vnrs_specification.md in the engine repository, usually checked out as ../vinora-engine). It is written in C99 and built with make. The line scanner is generated with re2c from src/vnrs_scan.re; the generated C source is committed, so a normal build needs only a C compiler.

Quick start

make
./vnrs2html < scene.vnrs > scene.html

Example input:

::
Rain drums on the window.

Alice::
Do you hear that?

+ [Go outside](outside.vnrs)
- [(TODO) Stay in](stay.vnrs)
* [Check the door](door.vnrs){brave>2}

Output:

<p>Rain drums on the window.</p>
<p><b class="name">Alice</b><br>
Do you hear that?</p>
<ul class="choices">
<li class="choice"><a href="outside.vnrs">Go outside</a></li>
<li class="choice blocked" data-target="stay.vnrs"><span>(TODO) Stay in</span></li>
<li class="choice hidden" data-target="door.vnrs" data-condition="brave&gt;2"><span>Check the door</span></li>
</ul>

The result is a fragment, with no <html>, <head>, or <body> wrapper. Put it inside your own template:

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Scene</title>
<link rel="stylesheet" href="vnrs.css">
<body>
  <!-- vnrs2html output goes here -->
</body>
</html>

Build

make

This produces ./vnrs2html. There is no install target; copy the binary where you need it.

make uses cc with -std=c99 -Wall -Wextra -Wpedantic -Werror -O2. Override CC and CFLAGS to change the compiler or flags.

After editing src/vnrs_scan.re, regenerate the scanner and rebuild:

make lexer
make

The lexer target requires re2c. The rest of the build does not.

Usage

./vnrs2html [--debug] < scene.vnrs > scene.html
cat scene.vnrs | ./vnrs2html

Options:

Option Effect
--debug Render commentary chunks as <p class="comment"> instead of dropping them
--help Print usage to stdout and exit 0

The program reads stdin only. Passing a file name, or an unknown option, prints usage to stderr and exits 1. I/O failures also exit 1.

Supported chunks

Vinora Screenplay HTML output
Plain text <p>text</p>
Alice:: Sets the speaker. Following dialog is <p><b class="name">Alice</b><br>text</p>
:: Clears the speaker; dialog renders as plain <p>text</p>
# Title through ###### Title <h1> through <h6>
+ [Label](target) <li class="choice"><a href="target">Label</a></li>
- [Label](target) Blocked choice: <li class="choice blocked" data-target="target"><span>Label</span></li>
* [Label](target){cond} Hidden choice: <li class="choice hidden" data-target="target" data-condition="cond"><span>Label</span></li>
![](path){left} <img src="path" alt="" class="left">
![Alt](path) <img src="path" alt="Alt">
[](path) <audio>, <video>, or <a class="link">, depending on the extension
> comment Dropped; with --debug, <p class="comment"><i>comment</i></p>
{{NVL}} Dropped
Triple-backtick fences <p class="literal"> with escaped text and no inline markup

Consecutive choice lines become one <ul class="choices"> list. Consecutive > lines become one comment, with the lines joined by spaces. Consecutive dialog lines inside one paragraph become one <p>, with the lines joined by spaces.

A character name stays active until the next Name:: or bare ::, across blank lines and chapter headings. The name is printed only on chunks that contain text.

A + choice with an empty label becomes a continue link: <a href="target" class="continue" aria-label="Continue"></a>.

Choice targets are emitted as written. This renderer does not evaluate conditions, follow targets, or remove blocked and hidden choices. The classes and data-target attributes let a viewer make those decisions.

Media output depends on the path:

  • Audio extensions (.mp3, .ogg, .wav, .flac, .opus, .m4a) produce <audio controls src="...">.
  • Paths beginning with music/ produce <audio controls src="..." loop>.
  • Video extensions (.mp4, .webm, .ogv, .mov) produce <video controls src="...">.
  • Any other path produces <a class="link" href="...">path</a>.

Inline markup

The inline parser supports the baseline from S.3.3:

*italic*   **bold**   _italic_   __bold__   ***bold italic***

HTML special characters (&, <, >, ") are escaped. An underscore inside a word (SOME_LONG_NAME) stays literal, so identifiers survive unchanged. No other inline constructs are implemented: links, code spans, and raw HTML pass through as escaped text.

Literal chunks skip inline parsing and keep their line breaks as <br>.

Behaviour notes

  • Input is UTF-8 and is passed through as UTF-8.
  • Both LF and CRLF line endings work.
  • Empty lines separate chunks. Any number of consecutive empty lines has the same effect.
  • Lines longer than 80 characters produce a warning on stderr. The conversion still succeeds and exits 0. The limit counts UTF-8 characters, not bytes.
  • This is a scene renderer, not the book export pipeline from S.4.
  • characters.ini is not read. Names are printed as written in the scene.
  • The language has no escape for a literal line that starts with a block marker. Wrap such text in a literal chunk instead.

Parser API

The scanner can be used without the renderer. src/vnrs.h declares the types and the line-level functions; src/vnrs_scan.c implements them.

#include "vnrs.h"

VnrsChunk chunk;

VnrsChunkParse(line, &chunk);          /* always succeeds */
if (chunk.type == VNRS_CHUNK_CHOICE) {
    printf("%c -> %.*s\n", chunk.marker,
        (int)chunk.target.len, chunk.target.start);
}

VnrsChunkParse classifies one NUL-terminated line and fills a VnrsChunk. VnrsChunkTypeOf returns the type without the metadata. VnrsChunkTypeName returns a stable lowercase name for diagnostics.

Individual recognizers return 1 when the line matches the requested chunk type:

VnrsIsBlank          VnrsParseSpeaker    VnrsParseChapter
VnrsParseChoice      VnrsParseImage      VnrsParseMedia
VnrsParseComment     VnrsParseDirective  VnrsParseLiteral

The VnrsSlice fields are views into the caller's line and are not NUL-terminated. text holds a speaker name, chapter title, or comment text. label and target hold the label and destination of a choice, image, or media line. attrs holds the trimmed contents of {...}. marker is the choice bullet, and level is the chapter level.

Classification follows the order in S.3.2: speaker, chapter, choice, image, media, directive, commentary, literal, and dialog as the default.

VnrsRender reads a scene from a FILE *, writes the HTML fragment to another, and sends warnings to a third:

int VnrsRender(FILE *in, FILE *out, FILE *err, int debug);

It returns 1 on success and 0 on I/O or memory failure.

Tests

make test

make test builds the parser and runs two shell suites.

  • tests/edge.sh runs more than 230 edge-case checks through the command-line interface: line endings, blank lines, escaping, speaker state, chapter limits, choice and media syntax, literal blocks, inline markup, and long-line warnings.
  • tests/run.sh runs the golden tests. Each tests/cases/*.vnrs file is fed to the program on stdin and stdout is compared with the matching .html file. A .stderr file, when present, is compared too; otherwise stderr must be empty. A .debug.html file runs the same scene again with --debug. The runner also checks --help, unknown options, and extra arguments.

On a terminal, passes are green, failures are red, and each suite ends with a percentage-passed summary. Set NO_COLOR to disable color.

Layout

src/main.c        argument handling and stdin/stdout plumbing
src/vnrs.c        HTML renderer and inline parser
src/vnrs_scan.re  re2c source for line classification and metadata
src/vnrs_scan.c   generated scanner (checked in)
src/vnrs.h        parser and renderer interface
tests/edge.sh     scanner and renderer edge cases
tests/run.sh      golden test runner
tests/cases/      scenes and expected output

License

GNU GPL v3 or later, same as Vinora Engine. See LICENSE.md.