All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.aya.concrete.remark.CodeOptions Maven / Gradle / Ivy

There is a newer version: 0.33.0
Show newest version
// Copyright (c) 2020-2021 Yinsen (Tesla) Zhang.
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.concrete.remark;

import org.aya.api.distill.DistillerOptions;
import org.aya.api.util.NormalizeMode;
import org.aya.concrete.parse.AyaParsing;
import org.aya.concrete.parse.AyaProducer;
import org.commonmark.node.Code;
import org.jetbrains.annotations.NotNull;

/**
 * @author ice1000
 */
public record CodeOptions(
  @NotNull NormalizeMode mode,
  @NotNull DistillerOptions options,
  @NotNull ShowCode showCode
) {
  public static final @NotNull CodeOptions DEFAULT =
    new CodeOptions(NormalizeMode.NULL, DistillerOptions.pretty(), ShowCode.Core);

  public static @NotNull Literate.Code analyze(@NotNull Code code, @NotNull AyaProducer producer) {
    var distillOpts = new DistillerOptions();
    var expr = producer.visitExpr(AyaParsing.parser(code.getLiteral()).expr());
    if (code.getFirstChild() instanceof CodeAttrProcessor.Attr attr) {
      return new Literate.Code(expr, attr.options);
    } else return new Literate.Code(expr, DEFAULT);
  }

  public enum ShowCode {
    Concrete, Core, Type
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy