{"library":"peberminta","title":"peberminta","description":"peberminta is a simple, transparent, and highly generic parser combinator toolkit for TypeScript/JavaScript, currently at version 0.10.0 and appearing actively maintained. Its core design principle is to be agnostic to token types, options, and output, making it suitable for 'weird things with parsers' where traditional string-based parsers fall short. It is lightweight with zero dependencies and provides a comprehensive set of building blocks, enabling users to easily define custom parsing logic. A key differentiator is its emphasis on transparency, allowing full access to the parser state, and its opinionated stance on input, accepting only fixed arrays of tokens rather than streams. It does not include a built-in lexer, requiring users to supply their own. The library prioritizes practicality and clear typing, offering a robust foundation for complex parsing tasks without imposing strict constraints on input structures.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install peberminta"],"cli":null},"imports":["import * as p from 'peberminta';","import * as pc from 'peberminta/char';","import type { Parser } from 'peberminta';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import * as p from 'peberminta';\nimport * as pc from 'peberminta/char';\n\n// Define a parser for a single hexadecimal digit (0-9, a-f, A-F)\nconst hexDigit = p.choice(\n  pc.digit, // 0-9\n  pc.charIn('abcdef'), // a-f\n  pc.charIn('ABCDEF')  // A-F\n);\n\n// Define a parser for a hex color code, e.g., #RRGGBB\nconst hexColorParser = p.seq(\n  pc.char('#'),\n  p.repeat(hexDigit, { min: 6, max: 6 })\n);\n\n// Function to parse and format the result\nconst parseHexColor = (input: string) => {\n  const tokens = input.split(''); // Simple tokenizer for char-based parsing\n  const result = hexColorParser({ tokens, offset: 0 });\n\n  if (result.type === 'Fail') {\n    return `Failed to parse: ${result.kind} at offset ${result.offset}`;\n  } else {\n    const hexChars = result.value[1].join(''); // Extract the hex digits\n    return `Successfully parsed hex color: #${hexChars}`;\n  }\n};\n\nconsole.log(parseHexColor('#AABBCC'));\nconsole.log(parseHexColor('#123xyz'));\nconsole.log(parseHexColor('ABCDEF'));","lang":"typescript","description":"Demonstrates defining and using basic parser combinators to parse a hexadecimal color string, including tokenization and result handling.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}