AutoSkill elixir_like_literal_parser

Parses a subset of Elixir-like data literals (atoms, lists, maps, tuples, primitives) into a specific JSON structure with '%k' and '%v' keys, handling map syntactic sugar and preserving key types.

install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/elixir_like_literal_parser" ~/.claude/skills/ecnu-icalk-autoskill-elixir-like-literal-parser && rm -rf "$T"
manifest: SkillBank/ConvSkill/english_gpt4_8_GLM4.7/elixir_like_literal_parser/SKILL.md
source content

elixir_like_literal_parser

Parses a subset of Elixir-like data literals (atoms, lists, maps, tuples, primitives) into a specific JSON structure with '%k' and '%v' keys, handling map syntactic sugar and preserving key types.

Prompt

Role & Objective

You are a parser for a subset of Elixir-like data literal syntax. Your task is to implement a lexer and recursive descent parser to convert input strings into a specific JSON format.

Grammar & Tokenization Rules

  1. Sentence: A sequence of zero or more data-literals.
  2. Data-Literal: List, Tuple, Map, or Primitive.
  3. List: Comma-separated data-literals within square brackets
    [
    and
    ]
    .
  4. Tuple: Comma-separated data-literals within braces
    {
    and
    }
    .
  5. Map: Comma-separated key-pairs within
    %{
    and
    }
    .
  6. Key-Pair: Either
    data-literal => data-literal
    or
    key data-literal
    (syntactic sugar).
  7. Primitives:
    • Integer: Match
      0
      or
      [1-9][0-9_]*
      . Underscores are allowed but must be removed in the output.
    • Atom: Match
      :[A-Za-z_]\w*
      . The value MUST retain the leading colon.
    • Boolean:
      true
      or
      false
      .
    • Key: Alphanumeric/underscore followed by colon
      :
      (e.g.,
      key:
      ). Treated as an atom with
      :
      moved to the front.
  8. Comments: Lines starting with
    #
    (regex
    #[^\n]*
    ) must be ignored completely.
  9. Whitespace: Ignored.

Parsing Logic

  • Empty Input: If the input is empty or contains only comments/whitespace, output
    []
    .
  • Map Syntactic Sugar: Handle map syntactic sugar where
    %{ key: 22 }
    is equivalent to
    %{ :key => 22 }
    .
  • Map Structure: To preserve the type of keys (e.g., distinguishing atoms from strings), map values must be represented as a list of pairs.

Output Contract

  • Format: Output strictly valid JSON. The output must be a single line without whitespace (except newline terminator).
  • Top-Level: A JSON array containing the JSON representations of the parsed data-literals.
  • Literal Object: Each literal is a JSON object with two properties:
    • %k
      : A string indicating the kind ("int", "atom", "bool", "list", "tuple", "map").
    • %v
      : The value of the literal.
  • Specific Formats:
    • Integer:
      {"%k": "int", "%v": <integer_value>}
    • Atom:
      {"%k": "atom", "%v": ":<atom_name>"}
    • Boolean:
      {"%k": "bool", "%v": <true|false>}
    • List/Tuple:
      {"%k": "list"|"tuple", "%v": [<list_of_literal_objects>]}
    • Map:
      {"%k": "map", "%v": [[<key_obj>, <val_obj>], ...]}

Anti-Patterns

  • Do NOT strip the leading colon from Atom values.
  • Do NOT use the format
    {"%<type>": value}
    ; strictly use
    {"%k": ..., "%v": ...}
    .
  • Do NOT treat comments as data.
  • Do NOT fail silently on syntax errors; report them explicitly.
  • Do NOT treat standalone colons
    :
    as separate tokens if they are part of an Atom or Map syntax.

Triggers

  • parse elixir data literals
  • parse custom data format
  • convert to specific JSON structure
  • parse %{ } and [ ] syntax
  • implement recursive descent parser
  • parse atoms with colon