#lang racket/base

(require "../main.rkt")

(require racket/match)
(require racket/set)
(require racket/pretty)

(require rackunit)

(define P #<<ENDDOC
{
    key: value
    # example of a comment at the end of a dictionary
}
# example of a comment at the end of the input file
ENDDOC
  )

(define Q #<<ENDDOC
{
    setUp();
    # Now enter the loop
    loop: {
        greet("World");
    }
    tearDown();
}
ENDDOC
  )

(define R #<<ENDDOC
define ?ds (newDataspace);

define ?space (subspace (?ds: $ds) {
  $ds ::= 999;

  print {
    1: 2,
    3: 4,
  };

  print <record 1 2 3 +>;

  $ds during ?a {
    onStop print <retracted $a>;
    print <asserted $a>;
  }

  spawn {
    define ?root (currentFacet);
    $ds during =ready1 {
      $ds .= 123;
      $ds during =ready2 {
        $ds .= 123.5;
        stop $root;
      }
      $ds ::= 234;
    }

    spawn {
      print "hi there";
    }
  }
});

spawn {
  define ?root (currentFacet);
  $ds on message ?x {
    print <message $x>;
    snapshot $space (
      ?outcome:
      # TODO: save outcome?
      printFlat <post-snap $outcome>;
      unpause $space;
      turn $root (: $ds ::= =ready2);
    )
    $ds ::= =ready1;
  }
}
ENDDOC
  )

(define S #<<ENDDOC
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-FileCopyrightText: Copyright © 2016-2023 Tony Garnock-Jones <tonyg@leastfixedpoint.com>

import { SyndicateRollup } from "../../rollup.js";
const r = new SyndicateRollup("syndicate", { globalName: "Syndicate" });
export default [
  r.config("lib/index.js", r.umd, {
    output: {
      globals: {
        "crypto": "crypto",
      },
    },
  }),
  r.config("lib/index.js", r.es6, {
    resolve: {
      moduleDirectories: ["stubs", "node_modules"],
    },
  }),
];
ENDDOC
  )

(define T #<<ENDDOC
version 2;

Grammar = {
  "name": @<regexp "^[a-zA-Z_]\\w*"> string,
  "rules": { @<regexp "^[a-zA-Z_]\\w*$"> string: Rule, ... },
  optional "extras": [Rule ...],
  optional "externals": [Rule ...],
  optional "inline": [@<regexp "^[a-zA-Z_]\\w*$"> string  ...],
  optional "conflicts": [@<regexp "^[a-zA-Z_]\\w*$"> string ...],
  optional "word": @<regexp "^[a-zA-Z_]\\w*"> string,
  optional "supertypes": [string ...],
};

Rule =
/ @alias { "type": "ALIAS", "named": bool, "value": string, "content": Rule }
/ @blank { "type": "BLANK" }
/ @string { "type": "STRING", "value": string }
/ @pattern { "type": "PATTERN", "value": string }
/ @symbol { "type": "SYMBOL", "name": string }
/ @seq { "type": "SEQ", "members": [Rule ...] }
/ @choice { "type": "CHOICE", "members": [Rule ...] }
/ @repeat1 { "type": "REPEAT1", "content": Rule }
/ @repeat { "type": "REPEAT", "content": Rule }
/ @token { "type": TokenType, "content": Rule }
/ @field { "type": "FIELD", "name": string, "content": Rule }
/ @prec { "type": PrecType, "value": int, "content": Rule }
;

TokenType = "TOKEN" / "IMMEDIATE_TOKEN";
PrecType = "PREC" / "PREC_LEFT" / "PREC_RIGHT" / "PREC_DYNAMIC";
ENDDOC
  )

(parameterize ((pretty-print-columns 80)) (write-pexprs (string->pexprs P #:read-syntax? #t)) (newline))
(parameterize ((pretty-print-columns 10)) (write-pexprs (string->pexprs P #:read-syntax? #t)) (newline))

(parameterize ((pretty-print-columns 80)) (write-pexprs (string->pexprs Q #:read-syntax? #t)) (newline))
(parameterize ((pretty-print-columns 10)) (write-pexprs (string->pexprs Q #:read-syntax? #t)) (newline))

(parameterize ((pretty-print-columns 40)) (write-pexprs (string->pexprs R #:read-syntax? #t)) (newline))

(parameterize ((pretty-print-columns 40)) (write-pexprs (string->pexprs S #:read-syntax? #t)) (newline))

(parameterize ((pretty-print-columns 40)) (write-pexprs (string->pexprs T #:read-syntax? #t)) (newline))
