code:
# meoiiovo

## Getting started

To make it easy for you to get started with GitLab, here's a list of recommended next steps.

Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!

## Add your files

- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command:

```
cd existing_repo
git remote add origin https://gitgud.io/meoiiovo/meoiiovo.git
git branch -M master
git push -uf origin master
```

## Integrate with your tools

- [ ] [Set up project integrations](https://gitgud.io/meoiiovo/meoiiovo/-/settings/integrations)

## Collaborate with your team

- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/)

## Test and Deploy

Use the built-in continuous integration in GitLab.

- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)

***

# Editing this README

When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.

## Suggestions for a good README

Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.

## Name
Choose a self-explaining name for your project.

## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.

## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.

## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.

## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.

## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.

## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.

## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.

## Contributing
State if you are open to contributions and what your requirements are for accepting them.

For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.

You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.

## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.

## License
For open source projects, say how it is licensed.

## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.

repo_name: meoiiovo/meoiiovo

license: unknown


code:
samples/**/*.json
samples/**/*.cache
samples/**/*.csproj
samples/**/*.dll
samples/**/*.pdb
samples/**/obj/**/*

repo_name: Xellos/qsharp

path: .gitignore

license: mit


code:
%YAML 1.2
---
name: Q#
file_extensions:
  - qs
scope: source.qs

variables:
  common_primitives: \b(Int|Double|Bool|Range|String|Unit)\b
  quantum_primitives: \b(Qubit|Pauli|Result)\b
  common_constants: \b(true|false)\b
  quantum_constants: \b(PauliI|PauliX|PauliY|PauliZ|One|Zero)\b

  quantum_gates: \b(X|Y|Z|H|T|S|I|CNOT|CCNOT|SWAP|Rx|Ry|Rz|RFrac|R1Frac|R1|R|MultiX|Exp|ExpFrac)\b
  measurements: \b(M|Measure|Reset|ResetAll)\b

# TODO: remove later if possible
  control_keywords: \b(repeat|until|fixup)\b

  functors: \b(Adjoint|Controlled|Controlled Adjoint)\b
  specialization_directives_adjoint: \b(intrinsic|invert|self|auto)\b
  specialization_directives_controlled: \b(intrinsic|distribute|auto)\b

  bitwise_operators: \&\&\&|\|\|\||\^\^\^|<<<|>>>|~~~
  arithmetic_operators: '[\+\-\*/%\^]'
  logical_operators: \&\&|\|\||==|!=|<=|>=|<|>

  cs_reserved: '\b(abstract|as|base|bool|break|byte|case|catch|char|checked|class|const|
    continue|decimal|default|delegate|do|double|enum|event|explicit|extern|finally|
    fixed|float|foreach|goto|implicit|int|interface|internal|is|lock|long|null|
    object|operator|out|override|params|private|protected|public|readonly|ref|
    sbyte|sealed|short|sizeof|stackalloc|static|string|struct|switch|this|throw|
    try|typeof|unit|ulong|unchecked|unsafe|ushort|virtual|void|volatile)\b'

  integer_suffix: '[lL]'
  exponent: '[eE][+\-]?[0-9]+(?![0-9])'
  decimal: (([0-9]+\.[0-9]*)|([0-9]*\.[0-9]+))
  floating_point_suffix: '[fFdDmM]'

  unicode_char: '\\u[0-9a-fA-F]{,4}'
  start_char: ({{unicode_char}}|[A-Za-z_\p{L}])
  other_char: ({{unicode_char}}|[A-Za-z_0-9\p{L}])
  name_normal: (?:\b{{start_char}}{{other_char}}*\b)

contexts:
  # The prototype context is prepended to all contexts but those setting
  # meta_include_prototype: false.
  prototype:
    - include: comments
    - include: cs_reserved
    - include: numbers
    - include: strings
    - include: constants

  main:
    # The main context is the initial starting point of our syntax.
    # Include other contexts from here (or specify them directly).
    - include: namespace_declaration

  terminator:
    - match: ';'
      scope: punctuation.terminator.qs
      pop: true
    - match: (?=\S)
      scope: invalid.illegal.qs

  namespace_block:
    - meta_scope: meta.block.namespace.qs
    - match: (?=\bopen\b)
      push: open_namespace
    - match: (?=\b(operation|function|newtype)\b)
      set:
        - meta_scope: meta.block.namespace.qs
        - match: \bopen\b
          scope: invalid.illegal.qs
        - include: operation_declaration
        - include: function_declaration
        - include: newtype
        - match: (?=\})
          pop: true

  constants:
    - match: ({{quantum_constants}}|{{common_constants}})
      scope: constant.language.qs

  numbers:
    # integers
    - match: (?:((?<![\.\w])|(?<=\.\.))(0x)?[0-9]+({{integer_suffix}})?((?![\.\w])|(?=\.\.)))
      scope: constant.numeric.qs
    # floating point numbers
    - match: (?:((?<![\.\w]){{decimal}}({{exponent}})?(?![\.\w]))|((?<![\.\w])[0-9]+{{exponent}}(?![\.\w])))
      scope: constant.numeric.qs

  strings:
    # Strings begin and end with quotes, and use backslashes as an escape
    # character.
    - match: '"'
      scope: punctuation.definition.string.begin.qs
      push: inside_string

  inside_string:
    - meta_include_prototype: false
    - meta_scope: string.quoted.double.qs
    - match: '\.'
      scope: constant.character.escape.qs
    - match: '"'
      scope: punctuation.definition.string.end.qs
      pop: true

  cs_reserved:
    - match: '{{cs_reserved}}'
      scope: invalid.illegal.cs_reserved.qs

  namespace_declaration:
    - match: \bnamespace\b
      scope: storage.type.namespace.qs
      push:
        - meta_scope: meta.namespace.qs
        - match: '[\{\.]'
          scope: invalid.illegal.qs
        - match: '{{name_normal}}'
          scope: entity.name.namespace.qs
          set:
          - meta_scope: meta.namespace.qs
          - match: (\.)({{name_normal}})
            captures:
              1: punctuation.separator.namespace.qs
              2: entity.name.namespace.qs
          - match: \.
            scope: invalid.illegal.qs
          - match: \{
            scope: punctuation.section.block.begin.namespace.qs
            set:
              - meta_scope: meta.namespace.qs
              - match: \}
                scope: punctuation.section.block.end.namespace.qs
                pop: true
              - include: namespace_block

  open_namespace:
    - match: \bopen\b
      scope: keyword.control.import.qs
      set:
        - match: '{{name_normal}}'
          scope: variable.namespace.qs
        - match: \.
          scope: punctuation.separator.namespace.qs
        - match: ';'
          scope: punctuation.terminator.open.qs
          pop: true

  newtype:
    - match: \bnewtype\b
      scope: storage.type.qs
      push:
        - match: ({{name_normal}})
          scope: entity.name.type.qs
          set: [terminating_semicolon, type, assignment_operator]
        - match: (?=\S)
          scope: invalid.illegal.qs

# Operations.
  operation_declaration:
    - match: '\b(operation)\b\s*({{name_normal}})\b'
      captures:
        1: storage.type.function.qs
        2: entity.name.function.qs
      push: [operation_block, operation_signature]

  operation_signature:
    - match: \(
      scope: punctuation.section.sequence.parameters.begin.qs
      push: operation_argument_list
    - match: ':'
      scope: punctuation.separator.qs
      set: type

  operation_argument_list:
    - meta_scope: meta.arguments.qs
    - match: \)
      scope: punctuation.section.sequence.parameters.end.qs
      pop: true
    - match: ','
      scope: punctuation.separator.sequence.parameters.qs
    - match: ({{name_normal}})\s*(\:)
      captures:
        1: variable.parameter.qs
        2: punctuation.type.qs
      push: type

  operation_body:
    - meta_scope: meta.block.operation.body.qs
    - match: \}
      scope: punctuation.section.block.end.qs
      pop: true
    - include: operation_code

  operation_adjoint:
    - meta_scope: meta.block.operation.adjoint.qs
    - match: \}
      scope: punctuation.section.block.end.qs
      pop: true
    - include: operation_code

  operation_controlled:
    - meta_scope: meta.block.operation.controlled.qs
    - match: \}
      scope: punctuation.section.block.end.qs
      pop: true
    - include: operation_code

  operation_adjoint_controlled:
    - meta_scope: meta.block.operation.controlled.qs meta.block.operation.adjoint.qs
    - match: \}
      scope: punctuation.section.block.end.qs
      pop: true
    - include: operation_code

  operation_block:
    - match: \{
      scope: punctuation.section.block.operation.begin.qs
      set:
        - meta_scope: meta.block.operation.qs
        - match: \}
          scope: punctuation.section.block.operation.end.qs
          pop: true
        - match: \bbody\b
          scope: keyword.other.operation.body.qs
          push:
            - meta_scope: meta.operation.body.qs
            - match: \bintrinsic\b
              scope: keyword.other.qs
              set: terminator
            - match: \(\.\.\.\)
              scope: punctuation.definition.keyword.qs
              set:
              - match: \{
                scope: punctuation.section.block.begin.qs
                set: operation_body
            - match: \{
              scope: punctuation.section.block.begin.qs invalid.deprecated.qs
              set: operation_body
        - match: \b(adjoint\s*controlled|controlled\s*adjoint)\b
          scope: keyword.other.qs
          push:
            - meta_scope: meta.operation.controlled.qs meta.operation.adjoint.qs
            - match: \b({{specialization_directives_adjoint}}|{{specialization_directives_controlled}})\b
              scope: keyword.other.qs
              set: terminator
            - match: (\()\s*({{name_normal}})\s*(\))
              captures:
                1: punctuation.section.sequence.parameters.begin.qs
                2: variable.parameter.qs
                3: punctuation.section.sequence.parameters.end.qs
              set:
                - match: \{
                  scope: punctuation.section.block.begin.qs invalid.deprecated.qs
                  set: operation_adjoint_controlled
            - match: (\()\s*({{name_normal}})\s*(,)\s*(\.\.\.\))
              captures:
                1: punctuation.section.sequence.parameters.begin.qs
                2: variable.parameter.qs
                3: punctuation.separator.sequence.qs
                4: punctuation.section.sequence.parameters.end.qs
              set:
                - match: \{
                  scope: punctuation.section.block.begin.qs
                  set: operation_adjoint_controlled
        - match: \badjoint\b
          scope: keyword.other.operation.adjoint.qs
          push:
            - meta_scope: meta.operation.adjoint.qs
            - match: ({{specialization_directives_adjoint}})
              scope: keyword.other.qs
              set: terminator
            - match: \(\.\.\.\)
              scope: punctuation.definition.keyword.qs
              set:
              - match: \{
                scope: punctuation.section.block.begin.qs
                set: operation_adjoint
            - match: \{
              scope: punctuation.section.block.begin.qs invalid.deprecated.qs
              set: operation_adjoint
        - match: \bcontrolled\b
          scope: keyword.other.operation.controlled.qs
          push:
            - meta_scope: meta.operation.controlled.qs
            - match: ({{specialization_directives_controlled}})
              scope: keyword.other.qs
              set: terminator
            - match: (\()\s*({{name_normal}})\s*(\))
              captures:
                1: punctuation.section.sequence.parameters.begin.qs
                2: variable.parameter.qs
                3: punctuation.section.sequence.parameters.end.qs
              set:
                - match: \{
                  scope: punctuation.section.block.begin.qs invalid.deprecated.qs
                  set: operation_controlled
            - match: (\()\s*({{name_normal}})\s*(,)\s*(\.\.\.\))
              captures:
                1: punctuation.section.sequence.parameters.begin.qs
                2: variable.parameter.qs
                3: punctuation.separator.sequence.qs
                4: punctuation.section.sequence.parameters.end.qs
              set:
                - match: \{
                  scope: punctuation.section.block.begin.qs
                  set: operation_controlled
        - match: (?=\S)
          set: operation_body

# Functions.
  function_declaration:
    - match: '\b(function)\b\s*({{name_normal}})\b'
      captures:
        1: storage.type.function.qs
        2: entity.name.function.qs
      push: [function_block, function_signature]

  function_signature:
    - match: \(
      scope: punctuation.section.sequence.parameters.begin.qs
      push: function_argument_list
    - match: ':'
      scope: punctuation.separator.qs
      set: type_classical

  function_argument_list:
    - meta_scope: meta.arguments.qs
    - match: \)
      scope: punctuation.section.sequence.parameters.end.qs
      pop: true
    - match: ','
      scope: punctuation.separator.sequence.parameters.qs
    - match: ({{name_normal}})\s*(\:)
      captures:
        1: variable.parameter.qs
        2: punctuation.type.qs
      push: type_classical

  function_block:
    - match: \{
      scope: punctuation.section.block.function.begin.qs
      set:
        - meta_scope: meta.block.function.qs
        - match: \}
          scope: punctuation.section.block.function.end.qs
          pop: true
        - include: function_code

# Typenames.
  type:
    - meta_scope: meta.type.qs
    - match: ({{common_primitives}}|{{quantum_primitives}})
      scope: storage.type.qs
      set: type_suffix
    - match: ({{name_normal}})
      scope: storage.type.user-defined.qs
      set: type_suffix
    - match: \(
      scope: punctuation.section.sequence.type.begin.qs
      push: type_inner_start
    - match: (?=\S)
      pop: true

  type_inner_start:
    - meta_scope: meta.type.qs
    - match: \)
      scope: punctuation.section.sequence.type.end.qs
      set: type_suffix
    - match: ','
      scope: invalid.illegal.qs
    - match: (?=\S)
      set: [type_inner, type]

  type_inner:
    - meta_scope: meta.type.qs
    - match: \)
      scope: punctuation.section.sequence.type.end.qs
      set: type_suffix
    - match: ','
      scope: punctuation.separator.sequence.type.qs
      push: type
    - match: (?=\S)
      pop: true

  type_suffix:
    - meta_scope: meta.type.qs
    - match: \[\]
      scope: punctuation.definition.array.qs
    - match: '[=-]>'
      scope: punctuation.definition.callable.qs
      set: [type_callable_variants, type]
    - match: (?=:)
      set: type_callable_variants
    - match: (?=\S)
      pop: true

  type_callable_variants:
    - meta_scope: meta.type.qs
    - match: ':'
      scope: punctuation.definition.callable.variants.qs
      set:
        - meta_scope: meta.type.qs
        - match: ({{functors}})
          scope: keyword.other.functor.qs
        - match: ','
          scope: punctuation.separator.sequence.variants.qs
        - match: (?=\S)
          pop: true
    - match: (?=\S)
      pop: true

  type_classical:
    - meta_scope: meta.type.qs
    - match: ({{common_primitives}})
      scope: storage.type.qs
      set: type_suffix_classical
    - match: ({{name_normal}})
      scope: storage.type.user-defined.qs
      set: type_suffix_classical
    - match: \(
      scope: punctuation.section.sequence.type.begin.qs
      push: type_inner_start_classical
    - match: (?=\S)
      pop: true

  type_inner_start_classical:
    - meta_scope: meta.type.qs
    - match: \)
      scope: punctuation.section.sequence.type.end.qs
      set: type_suffix_classical
    - match: ','
      scope: invalid.illegal.qs
    - match: (?=\S)
      set: [type_inner_classical, type_classical]

  type_inner_classical:
    - meta_scope: meta.type.qs
    - match: \)
      scope: punctuation.section.sequence.type.end.qs
      set: type_suffix_classical
    - match: ','
      scope: punctuation.separator.sequence.type.qs
      push: type_classical
    - match: (?=\S)
      pop: true

  type_suffix_classical:
    - meta_scope: meta.type.qs
    - match: \[\]
      scope: punctuation.definition.array.qs
    - match: '->'
      scope: punctuation.definition.callable.qs
      set: type_classical
    - match: (?=\S)
      pop: true

# Code inside an operation.
  operation_code:
    - include: qubit_alloc_statement
    - include: for_loop
    - include: repeat_loop
    - include: if_condition
    - include: gate
    - include: measurement
    - include: variant
    - include: assignment
    - include: return
    - include: fail

  function_code:
    - include: for_loop_classical
    - include: repeat_loop_classical
    - include: if_condition_classical
    - include: assignment
    - include: return
    - include: fail

# Tuple construction/deconstruction.
  tuple_continue:
    - match: \)
      scope: punctuation.section.group.end.qs punctuation.section.parens.end.qs
      pop: true
    - match: ','
      scope: punctuation.separator.sequence.qs
      push: variable_or_tuple

  variable_or_tuple:
    - match: '{{name_normal}}'
      scope: variable.other.qs
      pop: true
    - match: \(
      scope: punctuation.section.group.begin.qs punctuation.section.parens.begin.qs
      set:
        - match: \)
          scope: punctuation.section.group.end.qs punctuation.section.parens.end.qs
          pop: true
        - match: (?=\S)
          set: [tuple_continue, variable_or_tuple]

# Expressions with specific values.
# TODO! The definitions for different expressions are placeholders - they work like
#   generic expressions, only checking if the bracket sequence is correct and
#   highlighting operators and builtin functions. This should be improved, but I have
#   no idea how to distinguish expressions, since it's impossible to do type recognition
#   or build a tree over operators.
#   Some ideas:
#     integer expression = (integer expression) (arithmetic/bitwise operator) (integer expression)
#     array expression = (\[) (sequence of array/value expressions) (\])
#     (generic) value expression = (array expression) (\[) (integer expression) (\])
#     value expression = (value expression) (operator) (value expression)
#     array expression = (array expression) (\[) (range expression) (\])
#     array expression = (array expression) (+) (array expression)
#     predicate = (predicate) (logical operator) (predicate)
#     no expression may start or end with an operator
  expression:
    - match: \(
      scope: punctuation.section.group.begin.qs punctuation.section.parens.begin.qs
      push:
        - match: \)
          scope: punctuation.section.group.end.qs punctuation.section.parens.end.qs
          pop: true
        - include: expression
    - match: (?=\))
      pop: true
    - match: ({{bitwise_operators}})
      scope: keyword.operator.bitwise.qs
    - match: ({{arithmetic_operators}})
      scope: keyword.operator.arithmetic.qs
    - match: ({{logical_operators}})
      scope: keyword.operator.logical.qs
    - match: \bLength\b
      scope: support.function.qs
      push: [closing_parenthesis, array, opening_parenthesis]
    - match: \.\.
      scope: keyword.operator.range.qs
    - include: measurement

  predicate: # boolean expression
    - meta_scope: meta.predicate.qs
    - match: \(
      scope: punctuation.section.group.begin.qs punctuation.section.parens.begin.qs
      push:
        - match: \)
          scope: punctuation.section.group.end.qs punctuation.section.parens.end.qs
          pop: true
        - include: predicate
    - include: expression

  array:
    - meta_scope: meta.array.qs
    - match: \(
      scope: punctuation.section.group.begin.qs punctuation.section.parens.begin.qs
      push:
        - match: \)
          scope: punctuation.section.group.end.qs punctuation.section.parens.end.qs
          pop: true
        - include: array
    - include: expression

  integer_expr:
    - meta_scope: meta.expression.qs
    - match: \(
      scope: punctuation.section.group.begin.qs punctuation.section.parens.begin.qs
      push:
        - match: \)
          scope: punctuation.section.group.end.qs punctuation.section.parens.end.qs
          pop: true
        - include: integer_expr
    - include: expression

  range:
    - meta_scope: meta.range.qs
    - match: (?=\S)
      set: [range_continue_or_end, range_continue, integer_expr]

  range_continue:
    - meta_scope: meta.range.qs
    - match: \.\.
      scope: keyword.operator.range.qs
      set: integer_expr
    - match: \S
      scope: invalid.illegal.qs

  range_continue_or_end:
    - meta_scope: meta.range.qs
    - match: \.\.
      scope: keyword.operator.range.qs
      set: integer_expr
    - match: (?=\S)
      pop: true

  range_or_array_expr:
    - meta_scope: meta.expression.qs
    - match: \(
      scope: punctuation.section.group.begin.qs punctuation.section.parens.begin.qs
      push:
        - match: \)
          scope: punctuation.section.group.end.qs punctuation.section.parens.end.qs
          pop: true
        - include: range_or_array_expr
    - include: expression

# Control statements: for.
  tuple_continue_special:
    - match: \)
      scope: punctuation.section.group.end.qs punctuation.section.parens.end.qs
      pop: true
    - match: ','
      scope: punctuation.separator.sequence.qs
      push: variable_or_tuple_special

  variable_or_tuple_special:
    - match: '{{name_normal}}'
      scope: variable.parameter.qs
      pop: true
    - match: \(
      scope: punctuation.section.group.begin.qs punctuation.section.parens.begin.qs
      set:
        - match: \)
          scope: punctuation.section.group.end.qs punctuation.section.parens.end.qs
          pop: true
        - match: (?=\S)
          set: [tuple_continue_special, variable_or_tuple_special]

  for_block_classical:
    - meta_scope: meta.block.qs
    - match: \{
      scope: punctuation.section.block.begin.qs punctuation.section.braces.begin.qs
      set:
        - match: \}
          scope: punctuation.section.block.end.qs punctuation.section.braces.end.qs
          pop: true
        - include: function_code

  for_loop_classical:
    - match: \b(for)\s*(\()
      captures:
        1: keyword.control.flow.loop.qs
        2: punctuation.section.group.begin.qs punctuation.section.parens.begin.qs
      set: [for_block_classical, closing_parenthesis, range_or_array_expr, in_keyword, variable_or_tuple_special]

  for_block:
    - meta_scope: meta.block.qs
    - match: \{
      scope: punctuation.section.block.begin.qs punctuation.section.braces.begin.qs
      set:
        - match: \}
          scope: punctuation.section.block.end.qs punctuation.section.braces.end.qs
          pop: true
        - include: operation_code

  for_loop:
    - match: \b(for)\s*(\()
      captures:
        1: keyword.control.flow.loop.qs
        2: punctuation.section.group.begin.qs punctuation.section.parens.begin.qs
      push: [for_block, closing_parenthesis, range_or_array_expr, in_keyword, variable_or_tuple_special]

  in_keyword:
    - match: \bin\b
      scope: keyword.other.qs
      pop: true
    - match: (?=\S)
      scope: invalid.illegal.qs

# Control statements: repeat-until-fixup.
  until_condition:
    - match: \buntil\b
      scope: keyword.control.conditional.qs
      set:
        - match: \(
          scope: punctuation.section.group.begin.qs punctuation.section.parens.begin.qs
          set:
            - match: \)
              scope: punctuation.section.group.end.qs punctuation.section.parens.end.qs
              pop: true
            - include: predicate

  repeat_fixup_block_classical:
    - meta_scope: meta.block.qs
    - match: \{
      scope: punctuation.section.block.begin.qs punctuation.section.braces.begin.qs
      set:
        - match: \}
          scope: punctuation.section.block.end.qs punctuation.section.braces.end.qs
          pop: true
        - include: function_code

  repeat_loop_classical:
    - match: \brepeat\b
      scope: keyword.control.flow.loop.qs
      push: [repeat_loop_end_classical, until_condition, repeat_fixup_block_classical]

  repeat_loop_end_classical:
    - match: \bfixup\b
      scope: keyword.control.flow.qs
      set: repeat_fixup_block_classical

  repeat_fixup_block:
    - meta_scope: meta.block.qs
    - match: \{
      scope: punctuation.section.block.begin.qs punctuation.section.braces.begin.qs
      set:
        - match: \}
          scope: punctuation.section.block.end.qs punctuation.section.braces.end.qs
          pop: true
        - include: operation_code

  repeat_loop:
    - match: \brepeat\b
      scope: keyword.control.flow.loop.qs
      push: [repeat_loop_end, until_condition, repeat_fixup_block]

  repeat_loop_end:
    - match: \bfixup\b
      scope: keyword.control.flow.qs
      set: repeat_fixup_block

# Control statements: if/else.
  if_condition_classical:
    - match: \b(if)\s*(\()
      captures:
        1: keyword.control.conditional.qs
        2: punctuation.section.group.begin.qs punctuation.section.parens.begin.qs
      push: [elif_condition_classical, if_block_classical, closing_parenthesis, predicate]

  elif_condition_classical:
    - match: \b(elif)\s*(\()
      captures:
        1: keyword.control.conditional.qs
        2: punctuation.section.group.begin.qs punctuation.section.parens.begin.qs
      push: [if_block_classical, closing_parenthesis, predicate]
    - match: \b(else)\b
      captures:
        1: keyword.control.conditional.qs
        2: punctuation.section.group.begin.qs punctuation.section.parens.begin.qs
      set: if_block_classical
    - match: (?=\S)
      pop: true

  if_block_classical:
    - meta_scope: meta.block.qs
    - match: \{
      scope: punctuation.section.block.begin.qs punctuation.section.braces.begin.qs
      set:
        - match: \}
          scope: punctuation.section.block.end.qs punctuation.section.braces.end.qs
          pop: true
        - include: function_code

  if_condition:
    - match: \b(if)\s*(\()
      captures:
        1: keyword.control.conditional.qs
        2: punctuation.section.group.begin.qs punctuation.section.parens.begin.qs
      push: [elif_condition, if_block, closing_parenthesis, predicate]

  elif_condition:
    - match: \b(elif)\s*(\()
      captures:
        1: keyword.control.conditional.qs
        2: punctuation.section.group.begin.qs punctuation.section.parens.begin.qs
      push: [if_block, closing_parenthesis, predicate]
    - match: \b(else)\b
      captures:
        1: keyword.control.conditional.qs
        2: punctuation.section.group.begin.qs punctuation.section.parens.begin.qs
      set: if_block
    - match: (?=\S)
      pop: true

  if_block:
    - meta_scope: meta.block.qs
    - match: \{
      scope: punctuation.section.block.begin.qs punctuation.section.braces.begin.qs
      set:
        - match: \}
          scope: punctuation.section.block.end.qs punctuation.section.braces.end.qs
          pop: true
        - include: operation_code

# Control statements: return/fail.
  return:
    - match: \breturn\b
      scope: keyword.control.flow.qs
      push: [terminating_semicolon, variable_or_tuple]

  fail:
    - match: \bfail\b
      scope: keyword.control.flow.qs
      push:
        - match: \$(?=\")
          scope: punctuation.definition.string.qs
          set: terminating_semicolon
        - match: \S
          scope: invalid.illegal.qs

# Qubit management/allocation: using, borrowing.
  qubit_alloc_statement:
    - match: \b(using|borrowing)\s*(\()
      captures:
        1: keyword.other.alloc.qs
        2: punctuation.section.group.begin.qs punctuation.section.parens.begin.qs
      push: [context_block, closing_parenthesis, value_qubit_or_tuple, assignment_operator, variable_or_tuple_special]

  value_qubit_or_tuple:
    - match: \b(Qubit)\s*(\()\s*(\))
      captures:
        1: storage.type.qs
        2: punctuation.definition.generic.begin.qs punctuation.section.parens.begin.qs
        3: punctuation.definition.generic.end.qs punctuation.section.parens.end.qs
      pop: true
    - match: \b(Qubit)\s*(\[)
      captures:
        1: storage.type.qs
        2: punctuation.definition.array.qs punctuation.section.brackets.begin.qs
      set:
        - match: \]
          scope: punctuation.definition.array.qs punctuation.section.brackets.end.qs
          pop: true
    - match: \(
      scope: punctuation.section.group.begin.qs punctuation.section.parens.begin.qs
      set:
        - match: \)
          scope: punctuation.section.group.end.qs punctuation.section.parens.end.qs
          pop: true
        - match: (?=\S)
          set: [qubit_value_tuple_continue, value_qubit_or_tuple]

  qubit_value_tuple_continue:
    - match: \)
      scope: punctuation.section.group.end.qs punctuation.section.parens.end.qs
      pop: true
    - match: ','
      scope: punctuation.separator.sequence.qs
      push: value_qubit_or_tuple

  context_block:
    - meta_scope: meta.block.qs
    - match: \{
      scope: punctuation.section.block.begin.qs
      set:
        - match: \}
          scope: punctuation.section.block.end.qs
          pop: true
        - include: operation_code

# TODO! Only basic highlighting, doesn't distinguish between a plain letter and a call.
#   The problem is that (Adjoint f)(x) is possible, the callable and the argument list
#   need to be detected correctly. It shouldn't be too hard if the callable ends
#   with the first top-level occurrence of \(.
# Callables: quantum gates from Prelude.
  gate:
    - match: ({{quantum_gates}})
      scope: support.function.qs

# Callables: measurements from Prelude.
  measurement:
    - match: ({{measurements}})
      scope: entity.name.qs

# Operation variants.
  variant:
    - match: ({{functors}})
      scope: keyword.other.functor.qs

# Assignment instructions.
  assignment:
    - match: \b(let|set|mutable)\b
      scope: keyword.other.assignment.qs
      push: [terminating_semicolon, assignment_rhs, assignment_operator, variable_or_tuple]

  assignment_rhs:
    - match: \bnew\b
      scope: keyword.other.qs
      set: [closing_bracket, integer_expr_in_brackets, opening_bracket, type]
    - match: (?=\S)
      set:
        - match: (?=;)
          pop: true
        - include: expression

  integer_expr_in_brackets:
    - match: (?=\])
      pop: true
    - include: integer_expr

# Named contexts for use in push/set lists.
  assignment_operator:
    - match: =
      scope: keyword.operator.assignment.qs
      pop: true

  opening_bracket:
    - match: \[
      scope: punctuation.section.block.begin.qs punctuation.section.brackets.begin.qs
      pop: true

  closing_bracket:
    - match: \]
      scope: punctuation.section.block.end.qs punctuation.section.brackets.end.qs
      pop: true

  opening_parenthesis:
    - match: \(
      scope: punctuation.section.group.begin.qs
      pop: true

  closing_parenthesis:
    - match: \)
      scope: punctuation.section.group.end.qs
      pop: true

  terminating_semicolon:
    - match: ;
      scope: punctuation.terminator.qs
      pop: true

  comments:
    # Comments begin with a '//' and finish at the end of the line.
    - match: '//'
      scope: punctuation.definition.comment.qs
      push:
        # This is an anonymous context push for brevity.
        - meta_scope: comment.line.double-slash.qs
        - match: $\n?
          pop: true
    # Documentation comments
    - match: '///'
      scope: punctuation.definition.comment.docs.qs
      push:
        - meta_scope: comment.line.triple-slash.qs
        - match: $\n?
          pop: true


code:
# Syntax definitions for Q\# language for Sublime Text 3

v1.0

### Installation

#### Linux

Copy `Q#.sublime-syntax` to `~/.config/sublime-text-3/Packages/User/`.

### Features

- `namespace` declaration and `open`-ing
- `operation` syntax, `function` syntax (difference: no qubits in `function` input, no `using` or `borrowing`)
- operation variants `body`, `controlled`, `adjoint`, `adjoint controlled`
- allocating qubits with `using` or `borrowing`
- `for` loops
- `if-elif-else` conditionals
- assignment with `let`, `mutable` or `set`
- type system supports arbitrarily nested tuples, callables
- tuple construction/deconstruction
- range expressions
- highlighting quantum gates
- highlighting keywords reserved for C#
- comments, documentation comments


code:
/*
   https://gist.github.com/brantb/928920
*/
using System;           // R# Namespace Identifier
using System.Dynamic;
using System.Linq;      // R# Dead code
using System.Xml.XPath;

// Disable various dead code warnings
#pragma warning disable 168
#pragma warning disable 219
// ReSharper disable RedundantAssignment
// ReSharper disable SuggestUseVarKeywordEvident
// ReSharper disable ConvertToConstant.Local
// ReSharper disable FieldCanBeMadeReadOnly.Local
// ReSharper disable UnusedMember.Global
// ReSharper disable RedundantNameQualifier
// ReSharper disable CheckNamespace

namespace Solarized
{
    /// <summary>Enterprisey Hello World</summary>
    public static class Hello                                           // R# Static Class Identifier
    {
        public static void Main(string[] parameters)
        {
            OnWorldGreeted = () => Console.WriteLine("World was greeted");
            var hello = new HelloTextFactory();
            System.Console.WriteLine(hello);                            // R# Namespace Identifier
            System.Console.WriteLine("You entered the following " +
                                     "{0} {1} command line arguments:", // R# Format String Item
                                     parameters.Length, "cool");
            foreach (var t in parameters)                               // R# Parameter Identifier
            {
                Console.WriteLine("{0}", t);
            }
            // TODO: Write unit tests!                                  // R# Todo Item
            OnWorldGreeted();
        }

        public static event OnHelloEventHandler OnWorldGreeted;
    }

    public delegate void OnHelloEventHandler();

    public class HelloTextFactory : IHasHello<String>
    {
        private const string CONSTANT = "Hello, World!";
        public string Text { get; protected set; }
        private int _field = 1;
        public int AlsoAField { get; set; }

        public HelloTextFactory()
        {
            string local = "test";
            Text = CONSTANT;                        // R# Constant Identifier
            AlsoAField = _field;                    // R# Field Identifier
            int mutableLocalVariable = 0;           // R# Mutable Local Variable Identifier
            int localVariable = 1;                  // R# Local Variable Identifier
            Text = "test".ExtensionMethod();        // R# Extension Mehod Identifier
            mutableLocalVariable += localVariable;
            mutableLocalVariable.ToString();        // R# Method Identifier
            var x = AlsoAField.CompareTo(4 + 4);    // R# Method Identifier
            dynamic thingy = new ExpandoObject();
            thingy.LateBoundIdentifier = @"Whee!";  // R# Late Bound Identifier
            Hello.OnWorldGreeted += () => "foo";    // R# Static Class Identifier

            // VS2010 highlight rules are ignored when R#'s "Color Identifiers" option is enabled
            C.D referenceType = new C.D();                  // VS: User Types               R#: Class Identifier
            Func<Object> foo = () => "x";                   // VS: User Types (Delegates)   R#: Delegate Identifier
            Int32 valueType = new Int32();                  // VS: User Types (Value Types) R#: Struct Identifier
            Languages enumType = Languages.Ruby;            // VS: User Types (Enums)       R#: Enum Identifier
            IHasHello<string> i = new HelloTextFactory();   // VS: User Types (Interfaces)  R#: Interface Identifier
        }
    }

    #region More tests

    public enum Languages
    {
        English,
        Ruby,
        CSharp
    }

    public interface IHasHello<out TOfGreeting>
    {
        TOfGreeting Text { get; }   // R# Type Parameter Identifier
    }

    public class C
    {
        public class D
        {
        }
    }
    #endregion

    public static class SyntaxTestExtensions
    {
        public static string ExtensionMethod(this string parameter)
        {
            return parameter;
        }
    }
}
#pragma warning restore 219
// ReSharper restore FieldCanBeMadeReadOnly.Local
// ReSharper restore SuggestUseVarKeywordEvident
// ReSharper restore ConvertToConstant.Local
// ReSharper restore UnusedMember.Global
// ReSharper restore RedundantNameQualifier
// ReSharper restore RedundantAssignment
// ReSharper restore CheckNamespace
#pragma warning restore 168


code:
namespace Namespace {
	operation Operation (N : Int, q : Qubit) : Unit {
/// Simple for loop over integer range.
		for (i in 1..N) {
			H(q);
		}
	}

	operation OperationWithArrays (ints : Int[][], qs : Qubit[], pairs: (Qubit, Int)[]) : Unit {
/// Loops over array elements.
		for (int_arr in ints) {
/// Nested for loop.
			for (i in int_arr) {
				H(qs[i]);
			}
		}
		for (q in qs[0..10]+qs[20..30]) {
		}
/// Tuple deconstruction.
		for ((c, q) in pairs) {
			CNOT(q, qs[c]);
		}
	}

/// This operation should be highlighted correctly.
	operation EmptyOperation () : () {}
}


code:
namespace Namespace {
	operation Operation1 (a : Int, q : Qubit) : Unit {
		if (a == 0) {
			H(q);
		}
		elif (a % 2 == 0) {
			X(q);
		}
		elif (a == 11) {
		}
		else {
			M(q);
		}
	}

	operation Operation2 (a : Int, q : Qubit) : Unit {
/// Only if, no elif/else.
/// Nested if.
		if (a % 2 == 0) {
			if (a != 4) {
				H(q);
			}
		}
/// Obviously invalid.
		if (a % 2 == 0) {
//			elif (a != 4) {
//				H(q);
//			}
		}
		if (a % 2 == 0) {
//			else {
//				H(q);
//			}
		}
	}

	operation Operation3 (a : Int, q : Qubit) : Unit {
/// If/else. Nested.
		if (a % 2 == 0) {
			if (a != 4) {
				H(q);
			}
			else {
				M(q);
			}
		}
		else {
			if (a == 1) {
				M(q);
			}
			else {
				H(q);
			}
		}
	}

	operation Operation4 (a : Int, b : Int, c : Bool, d : Double) : Unit {
/// 	Example conditions.
		if ((a &&& (a+11)) || (1<<<b) < a) {
		}
		if (d * 1.5 > b/a && not c) {
		}
	}

/// If is not allowed here.
	if () {}
}

/// If is not allowed here.
if () {}


code:
namespace Namespace {
	operation Operation (q : Qubit) : Unit {
		let res = M(q);
		let res2 = M(q);
	}

	operation Operation (N : Int, m : Int) : Unit {
		mutable n = N + 1;
		let arr = new Int[n];
		let arr2 = new (Int, Int)[n];
		let (arr3, arr4) = (arr2[0..1], arr3[0..m]);
		set arr[0] = m;
		set n = N;
		set (arr[0], n) = (m, N);
/// Missing semicolon.
		set n = N - 1
		set n = N;
	}
}


code:
/// Sample for namespaces.

namespace MainNamespace {
/// Nested namespaces are not valid.
//  namespace NestedNamespace {
//  }

//  namespace Nested.Namespace {
//  }

//  namespace {
//  }
}

/// These are valid namespaces.
namespace OtherNamespace {
}

namespace Other.Namespace {
}

namespace
OnMoreLines
{
}

/// Invalid namespace names.
namespace Too.Many..Dots {
}

namespace .DotAtFront {
}

namespace DotAtBack. {
}

/// Anonymous/unnamed namespaces are also not valid.
namespace {
}


code:
namespace Namespace {
	open Microsoft.Quantum.Primitive;

	newtype WrappedInt = Int;
	newtype PairOfInts = (Int, Int);

	operation Operation () : {}

	function Function () : {}

/// Newtype, operation, function possible in any order.
	newtype QuantumType = Qubit;

	operation AnotherOperation () : {}
}


code:
namespace Namespace {
/// Standard library namespaces.
	open Microsoft.Quantum.Canon;
/// Custom namespace.
	open CustomNamespace;

/// Placeholder operation.
	operation Op () : () {}

/// Directive open must appear at the beginning of a namespace block.
	open InvalidNamespace;
}

/// Directive open must appear within a namespace block.
open InvalidNamespace;


code:
namespace Namespace {
/// This is a valid operation signature.
    operation Solve (qs : Qubit[], bits : Bool[], type : Int) : (Bool)
	{
    }

/// Example signature with an operation as an argument.
    operation UsingSolve (solve : ((Qubit[], Bool[], Int) => Bool)) : Unit
	{
    }

/// Same as above, but with operation variants.
    operation UsingSolve2 (solve : (((Qubit[], Bool[], Int) => Bool) : Adjoint, Controlled))
		: (() => Unit)
	{
    }

/// This is also a valid operation signature.
    operation EmptyOperation () : () {}
}

operation EmptyOperation () : () {}


code:
namespace Namespace {
	operation OperationWithOnlyBody (x : Qubit) : () {
		H(x);
	}

	operation OperationIntrinsic () : () {
		body intrinsic;
		controlled adjoint auto;
		controlled auto;
	}

	operation Operation (x : Qubit) : () {
		body (...) {
			H(x);
		}

/// Different forms of adjoint operation.
		adjoint self;
		adjoint (...) {
			H(x);
		}

/// Different forms of controlled operation.
		controlled auto;
		controlled (control, ...) {
			(Controlled H)(control, x);
		}

/// Different forms of controlled adjoint operation.
		adjoint controlled auto;
		adjoint controlled self;
		adjoint controlled (control, ...) {
			(Controlled H)(control, x);
		}

		adjoint auto;
	}
}


code:
namespace Namespace {
	operation Operation (q : Qubit) : Unit {
		X(q);
		Y(q);
		Z(q);
		H(q);
		(Adjoint H)(q);
		S(q);
		T(q);
		I(q);
		R1(1., q);
		Rx(1., q);
		Ry(1., q);
		Rz(1., q);
		Exp([PauliI], 5e-1, [q]);
		M(q);
		Reset(q);
/// Not a gate.
		A(q);
	}

	operation Operation (qs : Qubit[]) : Unit {
		MultiX(qs[1..2]);
		SWAP(qs[0], qs[1]);
		CNOT(qs[3], qs[4]);
		CCNOT(qs[3], qs[4], qs[2]);
		(Controlled R1)(1., qs[0]);
		(Controlled Adjoint R1)(1., qs[1]);
		(Adjoint Controlled R1)(1., qs[1]);
		Measure([PauliX, PauliY, PauliZ], [qs[2]] + qs[0..1]);
		ResetAll(qs);
	}
}


code:
namespace Namespace {
	operation Operation (N : Int, q : Qubit) : Unit {
/// Simple repeat-until-fixup loop, equivalent to a for loop.
		mutable n = 0;
		repeat {
			H(q);
			set n = n+1;
		}
		until (N == n)
		fixup {
			set n = 0;
		}
	}

/// Missing repeat, until and/or fixup.

//	operation BadLoop (N : Int, q : Qubit) : Unit {
//		mutable n = 0;
//		repeat {
//			H(q);
//			set n = n+1;
//		}
//		until (N == n)
/// This statement shouldn't be highlighted, fixup is missing.
//		return n;
//	}

//	operation BadLoop2 (N : Int, q : Qubit) : Unit {
//		mutable n = 0;
//		repeat {
//			H(q);
//			set n = n+1;
//		}
/// This statement shouldn't be highlighted, until is missing.
//		fixup {
//			set n = 0;
//		}
//	}

	operation BadLoop3 (N : Int, q : Qubit) : Unit {
/// This statement shouldn't be highlighted, repeat is missing.
		until (N == 1)
	}
}


code:
namespace Namespace {
	operation Operation (x : Double, y : Int) : Unit {
		return x;
		return (y, x);
		return ();
		fail $"Error message.";
/// This is invalid.
//		fail x;
	}
}


code:
namespace Namespace {
	operation Operation (q : Qubit) : Unit {
		using (h = Qubit()) {
			CNOT(q, h);
			Reset(h);
		}
		borrowing (h = Qubit()) {
		}
	}

	operation OperationWithArrays (qs : Qubit[], w : Qubit) : Unit {
		using (hs = Qubit[Length(qs)]) {
			for (i in 0..Length(qs)-1) {
				CNOT(qs[i], hs[i]);
			}
			ResetAll(hs);
///	Nested using statement.
			using (h = Qubit()) {
			}
		}
/// Using with tuple deconstruction.
		using ((hs, h) = (Qubit[Length(qs) * 2 + 1], Qubit())) {
			CNOT(w, h);
			Reset(h);
		}
	}

/// Functions are not allowed to use using/borrowing statements.
	function Function (N : Int) : Unit {
		using (h = Qubit()) {
		}
		borrowing (h = Qubit()) {
		}
	}
}


code:
namespace Solution {
    open Microsoft.Quantum.Primitive;
    open Microsoft.Quantum.Canon;

    operation Solve (qs : Qubit[]) : ()
    {
        body {
            for (i in 0..Length(qs)-1) {
                H(qs[i]);
            }
        }
    }
}


code:
namespace Solution {
    open Microsoft.Quantum.Primitive;
    open Microsoft.Quantum.Canon;

    operation Solve (qs : Qubit[], bits : Bool[]) : ()
    {
        body {
			mutable first = -1;
			for (i in 0..Length(qs)-1) {
			    if (bits[i]) {
				    if (first == -1) {
						H(qs[i]);
						set first = i;
					}
					else {
					    CNOT(qs[first], qs[i]);
					}
				}
			}
        }
    }
}


code:
namespace Solution {
    open Microsoft.Quantum.Primitive;
    open Microsoft.Quantum.Canon;

    // X(q); // 0 -> 1
    // H(q); // 0 -> +; 1 -> -
    //
    // Bell |00> + |11>
    // H(q[0]); CNOT(q[0],q[1]);
    // to put "-": X(q[0]);
    // to switch to |01> +- |10>: X(q[1]);
    //
    // GHZ:
    // H(q[0])
    // for (i in 1..Length(q)) CNOT(q[0],q[i])
    //
    // output oracle x[k] => y:
    //        CNOT(x[k],y)

    operation Solve (qs : Qubit[], bits0 : Bool[], bits1 : Bool[]) : ()
    {
        body {
            mutable j = -1;
            for (i in 0..Length(qs)-1) {
                if (bits0[i] != bits1[i]) {
                    set j = i;
                }
            }

            H(qs[j]);
            for (i in 0..Length(qs)-1) {
                if (i != j) {
                    if (bits0[i] != bits1[i]) {
                        if (bits0[i] != bits0[j]) {
                            X(qs[i]);
                        }
                        CNOT(qs[j],qs[i]);
                    } else {
                        if (bits0[i]) {
                            X(qs[i]);
                        }
                    }
                }
            }
        }
    }
}


code:
namespace Solution {
    open Microsoft.Quantum.Primitive;
    open Microsoft.Quantum.Canon;

    operation ch (x : Qubit, y : Qubit) : () {
        body {
            S(x);
            H(y);
            (Adjoint S)(y);
            CNOT(x,y);
            H(y);
            T(y);
            CNOT(x,y);
            T(y);
            H(y);
            S(y);
            X(y);
        }
    }

    operation Solve (q : Qubit[]) : ()
    {
        body {
            if (Length(q) == 1) {
                X(q[0]);
            }
            else {
                H(q[0]);
                X(q[1]);
                CNOT(q[0],q[1]);
                if (Length(q) > 2) {
                    for (i in 0..1) {
                        ch(q[i],q[i+2]);
                        CNOT(q[i+2],q[i]);
                    }
                }
                if (Length(q) > 4) {
                    for (i in 0..3) {
                        ch(q[i],q[i+4]);
                        CNOT(q[i+4],q[i]);
                    }
                }
                if (Length(q) > 8) {
                    for (i in 0..7) {
                        ch(q[i],q[i+8]);
                        CNOT(q[i+8],q[i]);
                    }
                }
            }
        }
    }
}


code:
namespace Solution {
    open Microsoft.Quantum.Primitive;
    open Microsoft.Quantum.Canon;

    operation Solve (qs : Qubit[]) : Int
    {
        body {
            let n = Length(qs);
            for (i in 0..n-1) {
                if (M(qs[i]) == One) {
                    return 1;
                }
            }
            return 0;
        }
    }
}


code:
namespace Solution {
	open Microsoft.Quantum.Primitive;
	open Microsoft.Quantum.Canon;

	operation Solve (x : Qubit[], y : Qubit) : Unit
	{
		body (...) {
			(Controlled X)(x, y);
		}

		adjoint auto;
	}
}


code:
namespace Solution {
	open Microsoft.Quantum.Primitive;
	open Microsoft.Quantum.Canon;

	operation Solve (x : Qubit[], y : Qubit) : Unit
	{
		body (...) {
			for (i in 0..Length(x)-1) {
				X(x[i]);
			}
			(Controlled X)(x, y);
			X(y);
			for (i in 0..Length(x)-1) {
				X(x[i]);
			}
		}

		adjoint auto;
	}
}


code:
namespace Solution {
	open Microsoft.Quantum.Primitive;
	open Microsoft.Quantum.Canon;

	operation Solve (x : Qubit[], y : Qubit) : Unit
	{
		body (...) {
			let N = Length(x) / 2 - 1;
			for (i in 0..N) {
				CNOT(x[Length(x)-1-i], x[i]);
				X(x[i]);
			}
			(Controlled X)(x[0..N], y);
			for (i in 0..N) {
				CNOT(x[Length(x)-1-i], x[i]);
				X(x[i]);
			}
		}

		adjoint auto;
	}
}


code:
namespace Solution {
	open Microsoft.Quantum.Primitive;
	open Microsoft.Quantum.Canon;

	operation Solve (x : Qubit[]) : Unit
	{
		body (...) {
			for (i in 0..Length(x)-1) {
				X(x[i]);
			}
		}
	}
}


code:
namespace Solution {
	open Microsoft.Quantum.Primitive;
	open Microsoft.Quantum.Canon;

	operation Solve (x : Qubit[]) : Unit
	{
		body (...) {
			H(x[0]);
			for (i in 2..Length(x)-1) {
				H(x[i]);
			}
		}
	}
}


code:
namespace Solution {
	open Microsoft.Quantum.Primitive;
	open Microsoft.Quantum.Canon;

	operation Solve (x : Qubit[]) : Unit
	{
		body (...) {
			let N = Length(x)-1;
			for (i in 0..N-1) {
				(Controlled H)(x[N..N], x[i]);
				X(x[N]);
				CNOT(x[N], x[i]);
				X(x[N]);
			}
		}
	}
}


code:
using System;

using Microsoft.Quantum.Simulation.Core;
using Microsoft.Quantum.Simulation.Simulators;

namespace Quantum.HelloQ
{
    class Driver
    {
        static void Main(string[] args)
        {
            using (var qsim = new QuantumSimulator())
            {
                HelloQ.Run(qsim).Wait();
            }
        }
    }
}


code:
namespace Quantum.HelloQ
{
    open Microsoft.Quantum.Canon;
    open Microsoft.Quantum.Primitive;

    operation HelloQ () : Unit {
        Message("Hello quantum world!");
    }
}


code:
namespace Quantum.Bell
{
    open Microsoft.Quantum.Canon;
    open Microsoft.Quantum.Primitive;

    operation Set (desired: Result, q1: Qubit) : Unit {
        let current = M(q1);

        if (desired != current)
        {
            X(q1);
        }
    }

    operation BellTest (count : Int, initial: Result) : (Int, Int)
    {
        mutable numOnes = 0;
        using (qubit = Qubit())
        {
            for (test in 1..count)
            {
                Set (initial, qubit);

                let res = M (qubit);

                // Count the number of ones we saw:
                if (res == One)
                {
                    set numOnes = numOnes + 1;
                }
            }
            Set(Zero, qubit);
        }

        // Return number of times we saw a |0> and number of times we saw a |1>
        return (count-numOnes, numOnes);
    }
}


code:
using System;

using Microsoft.Quantum.Simulation.Core;
using Microsoft.Quantum.Simulation.Simulators;

namespace Quantum.Bell
{
    class Driver
    {
        static void Main(string[] args)
        {
            using (var qsim = new QuantumSimulator())
            {
                // Try initial values
                Result[] initials = new Result[] { Result.Zero, Result.One };
                foreach (Result initial in initials)
                {
                    var res = BellTest.Run(qsim, 1000, initial).Result;
                    var (numZeros, numOnes) = res;
                    System.Console.WriteLine(
                        $"Init:{initial,-4} 0s={numZeros,-4} 1s={numOnes,-4}");
                }
            }

            System.Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
    }
}


code:
# IDE, temp, generated, and other local-only files
.idea/
*.iml
node_modules/
tweego.exe
*.html

* Ignoring working folder for Quin2k
mod/

repo_name: Mauno/degrees


code:
<NotepadPlus>
	<UserLang name="Sugarcube4" ext="twee tw" udlVersion="2.1">
		<Settings>
			<Global caseIgnored="no" allowFoldOfComments="no" foldCompact="yes" forcePureLC="0" decimalSeparator="0" />
			<Prefix Keywords1="yes" Keywords2="no" Keywords3="no" Keywords4="no" Keywords5="no" Keywords6="no" Keywords7="no" Keywords8="no" />
		</Settings>
		<KeywordLists>
			<Keywords name="Comments">00 01 02 03/% 03/* 03<!-- 04%/ 04*/ 04--></Keywords>
			<Keywords name="Numbers, prefix1"></Keywords>
			<Keywords name="Numbers, prefix2"></Keywords>
			<Keywords name="Numbers, extras1"></Keywords>
			<Keywords name="Numbers, extras2"></Keywords>
			<Keywords name="Numbers, suffix1"></Keywords>
			<Keywords name="Numbers, suffix2"></Keywords>
			<Keywords name="Numbers, range"></Keywords>
			<Keywords name="Operators1">+ - * / = += -= *= /= ++ -- == != === !== > < >= <= ! && || & | ( )</Keywords>
			<Keywords name="Operators2"></Keywords>
			<Keywords name="Folders in code1, open"><<if</Keywords>
			<Keywords name="Folders in code1, middle"></Keywords>
			<Keywords name="Folders in code1, close"><</if>></Keywords>
			<Keywords name="Folders in code2, open"></Keywords>
			<Keywords name="Folders in code2, middle"></Keywords>
			<Keywords name="Folders in code2, close"></Keywords>
			<Keywords name="Folders in comment, open"></Keywords>
			<Keywords name="Folders in comment, middle"></Keywords>
			<Keywords name="Folders in comment, close"></Keywords>
			<Keywords name="Keywords1">$ _</Keywords>
			<Keywords name="Keywords2"></Keywords>
			<Keywords name="Keywords3"></Keywords>
			<Keywords name="Keywords4"></Keywords>
			<Keywords name="Keywords5"></Keywords>
			<Keywords name="Keywords6"></Keywords>
			<Keywords name="Keywords7"></Keywords>
			<Keywords name="Keywords8"></Keywords>
			<Keywords name="Delimiters">00:: 01 02((EOL)) 03<< 04 05>> 06[[ 07 08]] 09< 10 11> 12'' 13 14'' 15// 16 17// 18@@ 19 20@@ 21[img[ 22 23]]</Keywords>
		</KeywordLists>
		<Styles>
			<WordsStyle name="DEFAULT" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
			<WordsStyle name="COMMENTS" fgColor="808080" bgColor="FFFFFF" fontName="" fontStyle="2" nesting="0" />
			<WordsStyle name="LINE COMMENTS" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
			<WordsStyle name="NUMBERS" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
			<WordsStyle name="KEYWORDS1" fgColor="004080" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
			<WordsStyle name="KEYWORDS2" fgColor="8080C0" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
			<WordsStyle name="KEYWORDS3" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
			<WordsStyle name="KEYWORDS4" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
			<WordsStyle name="KEYWORDS5" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
			<WordsStyle name="KEYWORDS6" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
			<WordsStyle name="KEYWORDS7" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
			<WordsStyle name="KEYWORDS8" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
			<WordsStyle name="OPERATORS" fgColor="800040" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
			<WordsStyle name="FOLDER IN CODE1" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
			<WordsStyle name="FOLDER IN CODE2" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
			<WordsStyle name="FOLDER IN COMMENT" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
			<WordsStyle name="DELIMITERS1" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="5" fontSize="12" nesting="0" />
			<WordsStyle name="DELIMITERS2" fgColor="800080" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="50334724" />
			<WordsStyle name="DELIMITERS3" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="1024" />
			<WordsStyle name="DELIMITERS4" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
			<WordsStyle name="DELIMITERS5" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="32" />
			<WordsStyle name="DELIMITERS6" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="2" nesting="16" />
			<WordsStyle name="DELIMITERS7" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
			<WordsStyle name="DELIMITERS8" fgColor="8080FF" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
		</Styles>
	</UserLang>
</NotepadPlus>


code:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="48" height="48" version="1.1" inkscape:version="0.48.0 r9654">
  <defs id="defs4"/>
  <sodipodi:namedview id="base" pagecolor="#ffffff" bordercolor="#666666" borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="11.313708" inkscape:cx="27.203376" inkscape:cy="26.578528" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" inkscape:window-width="1280" inkscape:window-height="968" inkscape:window-x="-4" inkscape:window-y="-4" inkscape:window-maximized="1">
	<inkscape:grid type="xygrid" id="grid2985" empspacing="5" visible="true" enabled="true" snapvisiblegridlinesonly="true"/>
  </sodipodi:namedview>
  <g inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1" transform="translate(0,-1004.3622)">
	<g id="g3000" transform="translate(-6,1003)">
	  <path sodipodi:nodetypes="ccccc" inkscape:connector-curvature="0" id="path2987" d="m 30,2.3621826 -20,10.0000004 20,10 20,-10 z" style="fill:#f9f9f9;stroke:none"/>
	  <path style="fill:#ececec;stroke:none" d="m 30,22.362183 0,25 20,-10 0,-25 z" id="path2989" inkscape:connector-curvature="0" sodipodi:nodetypes="ccccc"/>
	  <path sodipodi:nodetypes="ccccc" inkscape:connector-curvature="0" id="path2991" d="m 30,22.362183 0,25 -20,-10 0,-25 z" style="fill:#cccccc;stroke:none"/>
	  <path inkscape:connector-curvature="0" id="path2993" d="M 30,2.3749996 10,12.375 l 0,25 20,10 20,-10 0,-25 L 30,2.3749996 z" style="fill:none;stroke:#4d4d4d;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"/>
	</g>
  </g>
  <metadata>
	<rdf:RDF>
	  <cc:Work>
		<dc:format>image/svg+xml</dc:format>
		<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
		<cc:license rdf:resource="http://creativecommons.org/licenses/publicdomain/"/>
		<dc:publisher>
		  <cc:Agent rdf:about="http://openclipart.org/">
			<dc:title>Open Clip Art Library</dc:title>
		  </cc:Agent>
		</dc:publisher>
		<dc:title>Sugar Cube icon</dc:title>
		<dc:date>2010-10-10T11:46:52</dc:date>
		<dc:description>A sugar cube.</dc:description>
		<dc:source>http://openclipart.org/detail/89407/sugar-cube-icon-by-jhnri4</dc:source>
		<dc:creator>
		  <cc:Agent>
			<dc:title>jhnri4</dc:title>
		  </cc:Agent>
		</dc:creator>
		<dc:subject>
		  <rdf:Bag>
			<rdf:li>SVG</rdf:li>
			<rdf:li>block</rdf:li>
			<rdf:li>clip art</rdf:li>
			<rdf:li>clipart</rdf:li>
			<rdf:li>cube</rdf:li>
			<rdf:li>icon</rdf:li>
			<rdf:li>sugar</rdf:li>
			<rdf:li>white</rdf:li>
		  </rdf:Bag>
		</dc:subject>
	  </cc:Work>
	  <cc:License rdf:about="http://creativecommons.org/licenses/publicdomain/">
		<cc:permits rdf:resource="http://creativecommons.org/ns#Reproduction"/>
		<cc:permits rdf:resource="http://creativecommons.org/ns#Distribution"/>
		<cc:permits rdf:resource="http://creativecommons.org/ns#DerivativeWorks"/>
	  </cc:License>
	</rdf:RDF>
  </metadata>
</svg>


code:
#!/bin/bash

if [ ! -f "$(command -v tweego)" ]; then
	echo "Cannot find tweego. Please install tweego before compiling."
	exit 1
fi

VERSION="$(git describe --tags --always --dirty)"

TWEEGO_PATH="./StoryFormats" tweego -o "Degrees of Lewdity $VERSION.html" game

path: compile


code:
@set TWEEGO_PATH=%cd%\StoryFormats
@tweego -o "Degrees of Lewdity VERSION.html" game


code:
function colourContainerClasses() {
	var V = State.variables;
	return 'hair-'  + (V.haircolour||'').replace(/ /g,'-') +
		' ' + 'eye-'   + (V.eyecolour||'').replace(/ /g,'-') +
		' ' + 'upper-' + (V.uppercolour||'').replace(/ /g,'-') +
		' ' + 'lower-' + (V.lowercolour||'').replace(/ /g,'-') +
		' ' + 'under-' + (V.undercolour||'').replace(/ /g,'-')
}
window.colourContainerClasses = colourContainerClasses; // export function


code:
:: Widgets Lower Clothing [widget]

<<widget "lowernaked">><<nobr>>
<<lowerstrip>>
<<if $lowertemp is "init">>
<<set $lowertemp to 1>>
<<elseif $lowertemp is 1>>
<<set $lowertemp to 0>>
<</if>>
<<set $lowerclothes to "naked">>
<<set $lowervariable to "naked">>
<<set $lowerintegrity to 0>>
<<set $lowerintegritymax to 0>>
<<set $lowerfabricstrength to 0>>
<<set $lowerreveal to 1000>>
<<set $lowerword to "n">>
<<set $loweronepiece to 0>>
<<set $lowerstate to 0>>
<<set $skirt to 0>>
<<set $skirtdown to 0>>
<<set $lowerstatebase to 0>>
<<set $lowervaginaexposed to 1>>
<<set $loweranusexposed to 1>>
<<set $lowerplural to 0>>
<<set $lowercolour to 0>>
<<set $lowerexposed to 2>>
<<set $lowerexposedbase to 2>>
<<set $lowervaginaexposedbase to 1>>
<<set $loweranusexposedbase to 1>>
<<set $lowertype to "naked">>
<<if $clothingchange isnot 1 and $ruined isnot 1>>
	<<if $upperset is $lowerset>>
	<<set $clothingchange to 1>><<uppernaked>>
	<</if>>
<</if>>
<<set $clothingchange to 0>>
<<set $lowerset to "lower">>
<<set $lowergender to "n">>
<</nobr>><</widget>>

<<widget "lowersundress">><<nobr>>
<<lowerstrip>><<lowerundress>>
<<set $lowerclothes to "sundress skirt">>
<<set $lowervariable to "lowersundress">>
<<set $lowersundressintegritymax to 100>>
<<set $lowerintegritymax to $lowersundressintegritymax>>
<<set $fabricstrength to 30>>
<<set $lowerreveal to 200>>
<<set $lowerword to "a">>
<<set $loweronepiece to 1>>
<<set $lowerstate to "waist">>
<<set $skirt to 1>>
<<set $skirtdown to 1>>
<<set $lowerstatebase to "waist">>
<<set $lowervaginaexposed to 0>>
<<set $loweranusexposed to 0>>
<<set $lowerplural to 0>>
<<if $lowersundressnew is 1>><<set $lowersundressnew to 0>><<set $lowersundressintegrity to $lowersundressintegritymax>>
<</if>>
<<set $lowercolour to $sundresscolour>>
<<set $lowerintegrity to $lowersundressintegrity>>
<<set $lowerexposed to 0>>
<<set $lowerexposedbase to 0>>
<<set $lowervaginaexposedbase to 0>>
<<set $loweranusexposedbase to 0>>
<<set $lowertype to "normal">>
<<if $clothingchange isnot 1>>
	<<if $upperset is $lowerset>>
	<<set $clothingchange to 1>><<upperstrip>><<upperundress>>
	<</if>>
<</if>>
<<set $clothingchange to 0>>
<<set $lowerset to "sundress">>
<<set $lowergender to "f">>
<</nobr>><</widget>>

<<widget "lowerpjs">><<nobr>>
<<lowerstrip>><<lowerundress>>
<<set $lowerclothes to "pyjama bottoms">>
<<set $lowervariable to "lowerpjs">>
<<set $lowerpjsintegritymax to 100>>
<<set $lowerintegritymax to $lowerpjsintegritymax>>
<<set $lowerfabricstrength to 20>>
<<set $lowerreveal to 100>>
<<set $lowerword to "n">>
<<set $loweronepiece to 0>>
<<set $lowerstate to "waist">>
<<set $skirt to 0>>
<<set $skirtdown to 0>>
<<set $lowerstatebase to "waist">>
<<set $lowervaginaexposed to 0>>
<<set $loweranusexposed to 0>>
<<set $lowerplural to 1>>
<<if $lowerpjsnew is 1>><<set $lowerpjsnew to 0>><<set $lowerpjsintegrity to $lowerpjsintegritymax>><<set $lowerpjscolour to either("blue", "white", "red", "green", "black", "pink", "purple", "tangerine", "yellow")>>
<<if $lowerpjscolourchoice isnot 0>>
<<set $lowerpjscolour to $lowerpjscolourchoice>>
<</if>>
<</if>>
<<set $lowercolour to $lowerpjscolour>>
<<set $lowerintegrity to $lowerpjsintegrity>>
<<set $lowerexposed to 0>>
<<set $lowerexposedbase to 0>>
<<set $lowervaginaexposedbase to 0>>
<<set $loweranusexposedbase to 0>>
<<set $lowertype to "sleep">>
<<if $clothingchange isnot 1>>
	<<if $upperset is $lowerset>>
	<<set $clothingchange to 1>><<upperstrip>><<upperundress>>
	<</if>>
<</if>>
<<set $clothingchange to 0>>
<<set $lowerset to "lower">>
<<set $lowergender to "n">>
<</nobr>><</widget>>

<<widget "lowertowel">><<nobr>>
<<lowerstrip>><<lowerundress>>
<<set $lowerclothes to "towel">>
<<set $lowervariable to "lowertowel">>
<<set $lowertowelintegritymax to 10>>
<<set $lowerintegritymax to $lowertowelintegritymax>>
<<set $lowerfabricstrength to 20>>
<<set $lowerreveal to 800>>
<<set $lowerword to "n">>
<<set $loweronepiece to 0>>
<<set $lowerstate to "waist">>
<<set $skirt to 1>>
<<set $skirtdown to 1>>
<<set $lowerstatebase to "waist">>
<<set $lowervaginaexposed to 0>>
<<set $loweranusexposed to 0>>
<<set $lowerplural to 0>>
<<if $lowertowelnew is 1>><<set $lowertowelnew to 0>><<set $lowertowelintegrity to $lowertowelintegritymax>><<set $lowertowelcolour to either("blue", "white", "red", "green", "black", "pink", "purple", "tangerine", "yellow")>>
<<if $lowertowelcolourchoice isnot 0>>
<<set $lowertowelcolour to $lowertowelcolourchoice>>
<<set $lowertowelcolourchoice to 0>>
<</if>>
<</if>>
<<set $lowercolour to $lowertowelcolour>>
<<set $lowerintegrity to $lowertowelintegrity>>
<<set $lowerexposed to 0>>
<<set $lowerexposedbase to 0>>
<<set $lowervaginaexposedbase to 0>>
<<set $loweranusexposedbase to 0>>
<<set $lowertype to "normal">>
<<if $clothingchange isnot 1>>
	<<if $upperset is $lowerset>>
	<<set $clothingchange to 1>><<upperstrip>><<upperundress>>
	<</if>>
<</if>>
<<set $clothingchange to 0>>
<<set $lowerset to "lower">>
<<set $lowergender to "n">>
<</nobr>><</widget>>

<<widget "lowerbikini">><<nobr>>
<<lowerstrip>><<lowerundress>>
<<set $lowerclothes to "bikini bottoms">>
<<set $lowervariable to "lowerbikini">>
<<set $lowerbikiniintegritymax to 20>>
<<set $lowerintegritymax to $lowerbikiniintegritymax>>
<<set $lowerfabricstrength to 20>>
<<set $lowerreveal to 900>>
<<set $lowerword to "n">>
<<set $loweronepiece to 0>>
<<set $lowerstate to "waist">>
<<set $skirt to 0>>
<<set $skirtdown to 0>>
<<set $lowerstatebase to "waist">>
<<set $lowervaginaexposed to 0>>
<<set $loweranusexposed to 0>>
<<set $lowerplural to 1>>
<<if $lowerbikininew is 1>><<set $lowerbikininew to 0>><<set $lowerbikiniintegrity to $lowerbikiniintegritymax>><<set $lowerbikinicolour to either("blue", "white", "red", "green", "black", "pink", "purple", "tangerine", "yellow")>>
<<if $lowerbikinicolourchoice isnot 0>>
<<set $lowerbikinicolour to $lowerbikinicolourchoice>>
<</if>>
<</if>>
<<set $lowercolour to $lowerbikinicolour>>
<<set $lowerintegrity to $lowerbikiniintegrity>>
<<set $lowerexposed to 1>>
<<set $lowerexposedbase to 1>>
<<set $lowervaginaexposedbase to 0>>
<<set $loweranusexposedbase to 0>>
<<set $lowertype to "swim">>
<<if $clothingchange isnot 1>>
	<<if $upperset is $lowerset>>
	<<set $clothingchange to 1>><<upperstrip>><<upperundress>>
	<</if>>
<</if>>
<<set $clothingchange to 0>>
<<set $lowerset to "lower">>
<<if $undertype isnot "chastity">>
<<underundress>>
<</if>>
<<set $lowergender to "f">>
<</nobr>><</widget>>

<<widget "waistapron">><<nobr>>
<<lowerstrip>><<lowerundress>>
<<set $lowerclothes to "waist apron">>
<<set $lowervariable to "waistapron">>
<<set $waistapronintegritymax to 10>>
<<set $lowerintegritymax to $waistapronintegritymax>>
<<set $lowerfabricstrength to 20>>
<<set $lowerreveal to 800>>
<<set $lowerword to "a">>
<<set $loweronepiece to 0>>
<<set $lowerstate to "waist">>
<<set $skirt to 1>>
<<set $skirtdown to 1>>
<<set $lowerstatebase to "waist">>
<<set $lowervaginaexposed to 1>>
<<set $loweranusexposed to 1>>
<<set $lowerplural to 0>>
<<if $waistapronnew is 1>><<set $waistapronnew to 0>><<set $waistapronintegrity to $waistapronintegritymax>><<set $waistaproncolour to either("blue", "white", "red", "green", "black", "pink", "purple", "tangerine", "yellow")>>
<<if $waistaproncolourchoice isnot 0>>
<<set $waistaproncolour to $waistaproncolourchoice>>
<</if>>
<</if>>
<<set $lowercolour to $waistaproncolour>>
<<set $lowerintegrity to $waistapronintegrity>>
<<set $lowerexposed to 1>>
<<set $lowerexposedbase to 1>>
<<set $lowervaginaexposedbase to 1>>
<<set $loweranusexposedbase to 1>>
<<set $lowertype to "normal">>
<<if $clothingchange isnot 1>>
	<<if $upperset is $lowerset>>
	<<set $clothingchange to 1>><<upperstrip>><<upperundress>>
	<</if>>
<</if>>
<<set $clothingchange to 0>>
<<set $lowerset to "lower">>
<<set $lowergender to "n">>
<</nobr>><</widget>>

<<widget "shorts">><<nobr>>
<<lowerstrip>><<lowerundress>>
<<set $lowerclothes to "shorts">>
<<set $lowervariable to "shorts">>
<<set $shortsintegritymax to 120>>
<<set $lowerintegritymax to $shortsintegritymax>>
<<set $lowerfabricstrength to 20>>
<<set $lowerreveal to 300>>
<<set $lowerword to "n">>
<<set $loweronepiece to 0>>
<<set $lowerstate to "waist">>
<<set $skirt to 0>>
<<set $skirtdown to 0>>
<<set $lowerstatebase to "waist">>
<<set $lowervaginaexposed to 0>>
<<set $loweranusexposed to 0>>
<<set $lowerplural to 1>>
<<if $shortsnew is 1>><<set $shortsnew to 0>><<set $shortsintegrity to $shortsintegritymax>><<set $shortscolour to either("blue", "white", "red", "green", "black", "pink", "purple", "tangerine", "yellow")>>
<<if $shortscolourchoice isnot 0>>
<<set $shortscolour to $shortscolourchoice>>
<</if>>
<</if>>
<<set $lowercolour to $shortscolour>>
<<set $lowerintegrity to $shortsintegrity>>
<<set $lowerexposed to 0>>
<<set $lowerexposedbase to 0>>
<<set $lowervaginaexposedbase to 0>>
<<set $loweranusexposedbase to 0>>
<<set $lowertype to "normal">>
<<if $clothingchange isnot 1>>
	<<if $upperset is $lowerset>>
	<<set $clothingchange to 1>><<upperstrip>><<upperundress>>
	<</if>>
<</if>>
<<set $clothingchange to 0>>
<<set $lowerset to "lower">>
<<set $lowergender to "n">>
<</nobr>><</widget>>

<<widget "schoolshorts">><<nobr>>
<<lowerstrip>><<lowerundress>>
<<set $lowerclothes to "school shorts">>
<<set $lowervariable to "schoolshorts">>
<<set $schoolshortsintegritymax to 160>>
<<set $lowerintegritymax to $schoolshortsintegritymax>>
<<set $lowerfabricstrength to 20>>
<<set $lowerreveal to 200>>
<<set $lowerword to "n">>
<<set $loweronepiece to 0>>
<<set $lowerstate to "waist">>
<<set $skirt to 0>>
<<set $skirtdown to 0>>
<<set $lowerstatebase to "waist">>
<<set $lowervaginaexposed to 0>>
<<set $loweranusexposed to 0>>
<<set $lowerplural to 1>>
<<if $schoolshortsnew is 1>><<set $schoolshortsnew to 0>><<set $schoolshortsintegrity to $schoolshortsintegritymax>><<set $schoolshortscolour to either("blue", "white", "red", "green", "black", "pink", "purple", "tangerine", "yellow")>>
<<if $schoolshortscolourchoice isnot 0>>
<<set $schoolshortscolour to $schoolshortscolourchoice>>
<</if>>
<</if>>
<<set $lowercolour to $schoolshortscolour>>
<<set $lowerintegrity to $schoolshortsintegrity>>
<<set $lowerexposed to 0>>
<<set $lowerexposedbase to 0>>
<<set $lowervaginaexposedbase to 0>>
<<set $loweranusexposedbase to 0>>
<<set $lowertype to "school">>
<<if $clothingchange isnot 1>>
	<<if $upperset is $lowerset>>
	<<set $clothingchange to 1>><<upperstrip>><<upperundress>>
	<</if>>
<</if>>
<<set $clothingchange to 0>>
<<set $lowerset to "lower">>
<<set $lowergender to "m">>
<</nobr>><</widget>>

<<widget "schoolskirt">><<nobr>>
<<lowerstrip>><<lowerundress>>
<<set $lowerclothes to "school skirt">>
<<set $lowervariable to "schoolskirt">>
<<set $schoolskirtintegritymax to 160>>
<<set $lowerintegritymax to $schoolskirtintegritymax>>
<<set $lowerfabricstrength to 20>>
<<set $lowerreveal to 200>>
<<set $lowerword to "a">>
<<set $loweronepiece to 0>>
<<set $lowerstate to "waist">>
<<set $skirt to 1>>
<<set $skirtdown to 1>>
<<set $lowerstatebase to "waist">>
<<set $lowervaginaexposed to 0>>
<<set $loweranusexposed to 0>>
<<set $lowerplural to 0>>
<<if $schoolskirtnew is 1>><<set $schoolskirtnew to 0>><<set $schoolskirtintegrity to $schoolskirtintegritymax>><<set $schoolskirtcolour to either("blue", "white", "red", "green", "black", "pink", "purple", "tangerine", "yellow")>>
<<if $schoolskirtcolourchoice isnot 0>>
<<set $schoolskirtcolour to $schoolskirtcolourchoice>>
<</if>>
<</if>>
<<set $lowercolour to $schoolskirtcolour>>
<<set $lowerintegrity to $schoolskirtintegrity>>
<<set $lowerexposed to 0>>
<<set $lowerexposedbase to 0>>
<<set $lowervaginaexposedbase to 0>>
<<set $loweranusexposedbase to 0>>
<<set $lowertype to "school">>
<<if $clothingchange isnot 1>>
	<<if $upperset is $lowerset>>
	<<set $clothingchange to 1>><<upperstrip>><<upperundress>>
	<</if>>
<</if>>
<<set $clothingchange to 0>>
<<set $lowerset to "lower">>
<<set $lowergender to "f">>
<</nobr>><</widget>>

<<widget "lowerschoolswimsuit">><<nobr>>
<<lowerstrip>><<lowerundress>>
<<set $lowerclothes to "school swimsuit bottom">>
<<set $lowervariable to "lowerschoolswimsuit">>
<<set $lowerschoolswimsuitintegritymax to 40>>
<<set $lowerintegritymax to $lowerschoolswimsuitintegritymax>>
<<set $fabricstrength to 30>>
<<set $lowerreveal to 600>>
<<set $lowerword to "a">>
<<set $loweronepiece to 1>>
<<set $lowerstate to "waist">>
<<set $skirt to 0>>
<<set $skirtdown to 0>>
<<set $lowerstatebase to "waist">>
<<set $lowervaginaexposed to 0>>
<<set $loweranusexposed to 0>>
<<set $lowerplural to 0>>
<<if $lowerschoolswimsuitnew is 1>><<set $lowerschoolswimsuitnew to 0>><<set $lowerschoolswimsuitintegrity to $lowerschoolswimsuitintegritymax>>
<</if>>
<<set $lowercolour to $schoolswimsuitcolour>>
<<set $lowerintegrity to $lowerschoolswimsuitintegrity>>
<<set $lowerexposed to 1>>
<<set $lowerexposedbase to 1>>
<<set $lowervaginaexposedbase to 0>>
<<set $loweranusexposedbase to 0>>
<<set $lowertype to "swim">>
<<if $clothingchange isnot 1>>
	<<if $upperset is $lowerset>>
	<<set $clothingchange to 1>><<upperstrip>><<upperundress>>
	<</if>>
<</if>>
<<set $clothingchange to 0>>
<<set $lowerset to "school swimsuit">>
<<if $undertype isnot "chastity">>
<<underundress>>
<</if>>
<<set $lowergender to "f">>
<</nobr>><</widget>>

<<widget "schoolswimshorts">><<nobr>>
<<lowerstrip>><<lowerundress>>
<<set $lowerclothes to "school swim shorts">>
<<set $lowervariable to "schoolswimshorts">>
<<set $schoolswimshortsintegritymax to 40>>
<<set $lowerintegritymax to $schoolswimshortsintegritymax>>
<<set $lowerfabricstrength to 20>>
<<set $lowerreveal to 600>>
<<set $lowerword to "n">>
<<set $loweronepiece to 0>>
<<set $lowerstate to "waist">>
<<set $skirt to 0>>
<<set $skirtdown to 0>>
<<set $lowerstatebase to "waist">>
<<set $lowervaginaexposed to 0>>
<<set $loweranusexposed to 0>>
<<set $lowerplural to 1>>
<<if $schoolswimshortsnew is 1>><<set $schoolswimshortsnew to 0>><<set $schoolswimshortsintegrity to $schoolswimshortsintegritymax>><<set $schoolswimshortscolour to either("blue", "white", "red", "green", "black", "pink", "purple", "tangerine", "yellow")>>
<<if $schoolswimshortscolourchoice isnot 0>>
<<set $schoolswimshortscolour to $schoolswimshortscolourchoice>>
<</if>>
<</if>>
<<set $lowercolour to $schoolswimshortscolour>>
<<set $lowerintegrity to $schoolswimshortsintegrity>>
<<set $lowerexposed to 1>>
<<set $lowerexposedbase to 1>>
<<set $lowervaginaexposedbase to 0>>
<<set $loweranusexposedbase to 0>>
<<set $lowertype to "swim">>
<<if $clothingchange isnot 1>>
	<<if $upperset is $lowerset>>
	<<set $clothingchange to 1>><<upperstrip>><<upperundress>>
	<</if>>
<</if>>
<<set $clothingchange to 0>>
<<set $lowerset to "lower">>
<<if $undertype isnot "chastity">>
<<underundress>>
<</if>>
<<set $lowergender to "m">>
<</nobr>><</widget>>

<<widget "lowerplant">><<nobr>>
<<lowerstrip>><<lowerundress>>
<<set $lowerclothes to "plant skirt">>
<<set $lowervariable to "lowerplant">>
<<set $lowerplantintegritymax to 10>>
<<set $lowerintegritymax to $lowerplantintegritymax>>
<<set $lowerfabricstrength to 20>>
<<set $lowerreveal to 900>>
<<set $lowerword to "a">>
<<set $loweronepiece to 0>>
<<set $lowerstate to "waist">>
<<set $skirt to 1>>
<<set $skirtdown to 1>>
<<set $lowerstatebase to "waist">>
<<set $lowervaginaexposed to 1>>
<<set $loweranusexposed to 1>>
<<set $lowerplural to 0>>
<<if $lowerplantnew is 1>><<set $lowerplantnew to 0>><<set $lowerplantintegrity to $lowerplantintegritymax>><<set $lowerplantcolour to "green">>
<</if>>
<<set $lowercolour to $lowerplantcolour>>
<<set $lowerintegrity to $lowerplantintegrity>>
<<set $lowerexposed to 1>>
<<set $lowerexposedbase to 1>>
<<set $lowervaginaexposedbase to 1>>
<<set $loweranusexposedbase to 1>>
<<set $lowertype to "swim">>
<<if $clothingchange isnot 1>>
	<<if $upperset is $lowerset>>
	<<set $clothingchange to 1>><<upperstrip>><<upperundress>>
	<</if>>
<</if>>
<<set $clothingchange to 0>>
<<set $lowerset to "lower">>
<<if $undertype isnot "chastity">>
<<underundress>>
<</if>>
<<set $lowergender to "n">>
<</nobr>><</widget>>

<<widget "lowereveninggown">><<nobr>>
<<lowerstrip>><<lowerundress>>
<<set $lowerclothes to "evening gown skirt">>
<<set $lowervariable to "lowereveninggown">>
<<set $lowereveninggownintegritymax to 200>>
<<set $lowerintegritymax to $lowereveninggownintegritymax>>
<<set $fabricstrength to 30>>
<<set $lowerreveal to 200>>
<<set $lowerword to "a">>
<<set $loweronepiece to 1>>
<<set $lowerstate to "waist">>
<<set $skirt to 1>>
<<set $skirtdown to 1>>
<<set $lowerstatebase to "waist">>
<<set $lowervaginaexposed to 0>>
<<set $loweranusexposed to 0>>
<<set $lowerplural to 0>>
<<if $lowereveninggownnew is 1>><<set $lowereveninggownnew to 0>><<set $lowereveninggownintegrity to $lowereveninggownintegritymax>>
<</if>>
<<set $lowercolour to $eveninggowncolour>>
<<set $lowerintegrity to $lowereveninggownintegrity>>
<<set $lowerexposed to 0>>
<<set $lowerexposedbase to 0>>
<<set $lowervaginaexposedbase to 0>>
<<set $loweranusexposedbase to 0>>
<<set $lowertype to "normal">>
<<if $clothingchange isnot 1>>
	<<if $upperset is $lowerset>>
	<<set $clothingchange to 1>><<upperstrip>><<upperundress>>
	<</if>>
<</if>>
<<set $clothingchange to 0>>
<<set $lowerset to "evening gown">>
<<set $lowergender to "f">>
<</nobr>><</widget>>


code:
:: Widgets Under Clothing [widget]

<<widget "undernaked">><<nobr>>
	<<if $undertype isnot "chastity">>
<<understrip>>
<<if $undertemp is "init">>
<<set $undertemp to 1>>
<<elseif $undertemp is 1>>
<<set $undertemp to 0>>
<</if>>
<<set $underclothes to "naked">>
<<set $undervariable to "naked">>
<<set $underintegrity to 0>>
<<set $underintegritymax to 0>>
<<set $underfabricstrength to 0>>
<<set $underreveal to 1000>>
<<set $underword to "n">>
<<set $understate to 0>>
<<set $understatebase to 0>>
<<set $undervaginaexposed to 1>>
<<set $underanusexposed to 1>>
<<set $underplural to 0>>
<<set $undercolour to 0>>
<<set $underexposed to 1>>
<<set $underexposedbase to 1>>
<<set $undervaginaexposedbase to 1>>
<<set $underanusexposedbase to 1>>
<<set $undertype to "naked">>
<<set $undergender to "n">>
	<</if>>
<</nobr>><</widget>>

<<widget "plainpanties">><<nobr>>
	<<if $undertype isnot "chastity">>
<<understrip>><<underundress>>
<<set $underclothes to "plain panties">>
<<set $undervariable to "plainpanties">>
<<set $plainpantiesintegritymax to 100>>
<<set $underintegritymax to $plainpantiesintegritymax>>
<<set $underfabricstrength to 15>>
<<set $underreveal to 200>>
<<set $underword to "n">>
<<set $understate to "waist">>
<<set $understatebase to "waist">>
<<set $undervaginaexposed to 0>>
<<set $underanusexposed to 0>>
<<set $underplural to 1>>
<<if $plainpantiesnew is 1>><<set $plainpantiesnew to 0>><<set $plainpantiesintegrity to $plainpantiesintegritymax>><<set $plainpantiescolour to either("blue", "white", "red", "green", "black", "pink", "purple", "tangerine", "yellow")>>
<<if $plainpantiescolourchoice isnot 0>>
<<set $plainpantiescolour to $plainpantiescolourchoice>>
<</if>>
<</if>>
<<set $undercolour to $plainpantiescolour>>
<<set $underintegrity to $plainpantiesintegrity>>
<<set $underexposed to 0>>
<<set $underexposedbase to 0>>
<<set $undervaginaexposedbase to 0>>
<<set $underanusexposedbase to 0>>
<<set $undertype to "normal">>
<<if $lowertype is "swim">>
	<<if $upperset is $lowerset>>
	<<uppernaked>>
	<</if>>
<<lowerundress>>
<</if>>
<<set $undergender to "f">>
	<</if>>
<</nobr>><</widget>>

<<widget "lacepanties">><<nobr>>
	<<if $undertype isnot "chastity">>
<<understrip>><<underundress>>
<<set $underclothes to "lace panties">>
<<set $undervariable to "lacepanties">>
<<set $lacepantiesintegritymax to 60>>
<<set $underintegritymax to $lacepantiesintegritymax>>
<<set $underfabricstrength to 15>>
<<set $underreveal to 400>>
<<set $underword to "n">>
<<set $understate to "waist">>
<<set $understatebase to "waist">>
<<set $undervaginaexposed to 0>>
<<set $underanusexposed to 0>>
<<set $underplural to 1>>
<<if $lacepantiesnew is 1>><<set $lacepantiesnew to 0>><<set $lacepantiesintegrity to $lacepantiesintegritymax>><<set $lacepantiescolour to either("blue", "white", "red", "green", "black", "pink", "purple", "tangerine", "yellow")>>
<<if $lacepantiescolourchoice isnot 0>>
<<set $lacepantiescolour to $lacepantiescolourchoice>>
<</if>>
<</if>>
<<set $undercolour to $lacepantiescolour>>
<<set $underintegrity to $lacepantiesintegrity>>
<<set $underexposed to 0>>
<<set $underexposedbase to 0>>
<<set $undervaginaexposedbase to 0>>
<<set $underanusexposedbase to 0>>
<<set $undertype to "normal">>
<<if $lowertype is "swim">>
	<<if $upperset is $lowerset>>
	<<uppernaked>>
	<</if>>
<<lowerundress>>
<</if>>
<<set $undergender to "f">>
	<</if>>
<</nobr>><</widget>>

<<widget "yfronts">><<nobr>>
	<<if $undertype isnot "chastity">>
<<understrip>><<underundress>>
<<set $underclothes to "Y fronts">>
<<set $undervariable to "yfronts">>
<<set $yfrontsintegritymax to 100>>
<<set $underintegritymax to $yfrontsintegritymax>>
<<set $underfabricstrength to 15>>
<<set $underreveal to 200>>
<<set $underword to "n">>
<<set $understate to "waist">>
<<set $understatebase to "waist">>
<<set $undervaginaexposed to 0>>
<<set $underanusexposed to 0>>
<<set $underplural to 1>>
<<if $yfrontsnew is 1>><<set $yfrontsnew to 0>><<set $yfrontsintegrity to $yfrontsintegritymax>><<set $yfrontscolour to either("blue", "white", "red", "green", "black", "pink", "purple", "tangerine", "yellow")>>
<<if $yfrontscolourchoice isnot 0>>
<<set $yfrontscolour to $yfrontscolourchoice>>
<</if>>
<</if>>
<<set $undercolour to $yfrontscolour>>
<<set $underintegrity to $yfrontsintegrity>>
<<set $underexposed to 0>>
<<set $underexposedbase to 0>>
<<set $undervaginaexposedbase to 0>>
<<set $underanusexposedbase to 0>>
<<set $undertype to "normal">>
<<if $lowertype is "swim">>
	<<if $upperset is $lowerset>>
	<<uppernaked>>
	<</if>>
<<lowerundress>>
<</if>>
<<set $undergender to "m">>
	<</if>>
<</nobr>><</widget>>

<<widget "chastitybelt">><<nobr>>
	<<if $undertype isnot "chastity">>
<<understrip>><<underundress>>
<<set $underclothes to "chastity belt">>
<<set $undervariable to "chastitybelt">>
<<set $chastitybeltintegritymax to 2000>>
<<set $underintegritymax to $chastitybeltintegritymax>>
<<set $underfabricstrength to 15>>
<<set $underreveal to 1000>>
<<set $underword to "a">>
<<set $understate to "chastity">>
<<set $understatebase to "chastity">>
<<set $undervaginaexposed to 0>>
<<set $undervaginaexposedbase to 0>>
<<if $analshield is 1>>
<<set $underanusexposed to 0>>
<<set $underanusexposedbase to 0>>
<<else>>
<<set $underanusexposed to 1>>
<<set $underanusexposedbase to 1>>
<</if>>
<<set $underplural to 0>>
<<if $chastitybeltnew is 1>><<set $chastitybeltnew to 0>><<set $chastitybeltintegrity to $chastitybeltintegritymax>>
<</if>>
<<set $undercolour to "restrictive">>
<<set $underintegrity to $chastitybeltintegrity>>
<<set $underexposed to 1>>
<<set $underexposedbase to 1>>
<<set $undertype to "chastity">>
<<set $undergender to "n">>
	<</if>>
<</nobr>><</widget>>

<<widget "tights">><<nobr>>
	<<if $undertype isnot "chastity">>
<<understrip>><<underundress>>
<<set $underclothes to "tights">>
<<set $undervariable to "tights">>
<<set $tightsintegritymax to 120>>
<<set $underintegritymax to $tightsintegritymax>>
<<set $underfabricstrength to 5>>
<<set $underreveal to 800>>
<<set $underword to "n">>
<<set $understate to "waist">>
<<set $understatebase to "waist">>
<<set $undervaginaexposed to 0>>
<<set $underanusexposed to 0>>
<<set $underplural to 1>>
<<if $tightsnew is 1>><<set $tightsnew to 0>><<set $tightsintegrity to $tightsintegritymax>><<set $tightscolour to "sheer">>
<<if $tightscolourchoice isnot 0>>
<<set $tightscolour to $tightscolourchoice>>
<</if>>
<</if>>
<<set $undercolour to $tightscolour>>
<<set $underintegrity to $tightsintegrity>>
<<set $underexposed to 1>>
<<set $underexposedbase to 1>>
<<set $undervaginaexposedbase to 0>>
<<set $underanusexposedbase to 0>>
<<set $undertype to "normal">>
<<if $lowertype is "swim">>
	<<if $upperset is $lowerset>>
	<<uppernaked>>
	<</if>>
<<lowerundress>>
<</if>>
<<set $undergender to "f">>
	<</if>>
<</nobr>><</widget>>