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.mdsource 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
- Sentence: A sequence of zero or more data-literals.
- Data-Literal: List, Tuple, Map, or Primitive.
- List: Comma-separated data-literals within square brackets
and[
.] - Tuple: Comma-separated data-literals within braces
and{
.} - Map: Comma-separated key-pairs within
and%{
.} - Key-Pair: Either
ordata-literal => data-literal
(syntactic sugar).key data-literal - Primitives:
- Integer: Match
or0
. Underscores are allowed but must be removed in the output.[1-9][0-9_]* - Atom: Match
. The value MUST retain the leading colon.:[A-Za-z_]\w* - Boolean:
ortrue
.false - Key: Alphanumeric/underscore followed by colon
(e.g.,:
). Treated as an atom withkey:
moved to the front.:
- Integer: Match
- Comments: Lines starting with
(regex#
) must be ignored completely.#[^\n]* - 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
is equivalent to%{ key: 22 }
.%{ :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:
: A string indicating the kind ("int", "atom", "bool", "list", "tuple", "map").%k
: The value of the literal.%v
- 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>], ...]}
- Integer:
Anti-Patterns
- Do NOT strip the leading colon from Atom values.
- Do NOT use the format
; strictly use{"%<type>": value}
.{"%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