All Projects → Hejsil → mecha

Hejsil / mecha

Licence: MIT license
A parser combinator library for Zig

Programming Languages

Zig
133 projects
AMPL
153 projects

Projects that are alternatives of or similar to mecha

Opal
Self-contained monadic parser combinators for OCaml
Stars: ✭ 105 (-52.27%)
Mutual labels:  parser-combinators
Fireward
A concise and readable language for Firestore security rules, similar to Firebase Bolt.
Stars: ✭ 174 (-20.91%)
Mutual labels:  parser-combinators
Funcparserlib
Recursive descent parsing library for Python based on functional combinators
Stars: ✭ 250 (+13.64%)
Mutual labels:  parser-combinators
Cppcmb
A generic C++17 parser-combinator library with a natural grammar notation.
Stars: ✭ 108 (-50.91%)
Mutual labels:  parser-combinators
Parseback
A Scala implementation of parsing with derivatives
Stars: ✭ 168 (-23.64%)
Mutual labels:  parser-combinators
Goparsec
Parser combinator in Go. If there are any cross platform issues or backward compatibility issues, please reach out.
Stars: ✭ 198 (-10%)
Mutual labels:  parser-combinators
Pegtl
Parsing Expression Grammar Template Library
Stars: ✭ 1,295 (+488.64%)
Mutual labels:  parser-combinators
Syntax
Write value-driven parsers quickly in Swift with an intuitive SwiftUI-like DSL
Stars: ✭ 134 (-39.09%)
Mutual labels:  parser-combinators
Combine
A parser combinator library for Elixir projects
Stars: ✭ 174 (-20.91%)
Mutual labels:  parser-combinators
Parsica
Parsica - PHP Parser Combinators - The easiest way to build robust parsers.
Stars: ✭ 223 (+1.36%)
Mutual labels:  parser-combinators
Parze
A clean, efficient parser combinator
Stars: ✭ 113 (-48.64%)
Mutual labels:  parser-combinators
Parjs
JavaScript parser-combinator library
Stars: ✭ 145 (-34.09%)
Mutual labels:  parser-combinators
Urlformat
Type safe url pattern matching without regular expressions and arguments type mismatches based on parser combinators.
Stars: ✭ 213 (-3.18%)
Mutual labels:  parser-combinators
Pasukon
JavaScript practical parser generator library using combinators
Stars: ✭ 107 (-51.36%)
Mutual labels:  parser-combinators
autumn
A Java parser combinator library written with an unmatched feature set.
Stars: ✭ 112 (-49.09%)
Mutual labels:  parser-combinators
Parsec.el
A parser combinator library for Emacs Lisp, similar to Haskell's Parsec library.
Stars: ✭ 98 (-55.45%)
Mutual labels:  parser-combinators
Swiftparsec
A parser combinator library written in the Swift programming language.
Stars: ✭ 192 (-12.73%)
Mutual labels:  parser-combinators
Kt2Dart
🔦 [Deprecated] Transpile Kotlin codes into Dart, Make Flutter Great Again
Stars: ✭ 84 (-61.82%)
Mutual labels:  parser-combinators
XParsec
extensible, type-and-source-polymorphic, non-linear applicative parser combinator library for F# 3.0 and 4.0
Stars: ✭ 40 (-81.82%)
Mutual labels:  parser-combinators
Baby
Create models from a JSON file, even a Baby can do it.
Stars: ✭ 214 (-2.73%)
Mutual labels:  parser-combinators

Mecha

A parser combinator library for the Zig programming language. Time to make your own parser mech! mech

const mecha = @import("mecha");
const std = @import("std");

const Rgb = struct {
    r: u8,
    g: u8,
    b: u8,
};

fn toByte(v: u4) u8 {
    return @as(u8, v) * 0x10 + v;
}

const hex1 = mecha.map(u8, toByte, mecha.int(u4, .{
    .parse_sign = false,
    .base = 16,
    .max_digits = 1,
}));
const hex2 = mecha.int(u8, .{
    .parse_sign = false,
    .base = 16,
    .max_digits = 2,
});
const rgb1 = mecha.map(Rgb, mecha.toStruct(Rgb), mecha.manyN(hex1, 3, .{}));
const rgb2 = mecha.map(Rgb, mecha.toStruct(Rgb), mecha.manyN(hex2, 3, .{}));
const rgb = mecha.combine(.{
    mecha.ascii.char('#'),
    mecha.oneOf(.{
        rgb2,
        rgb1,
    }),
});

test "rgb" {
    const testing = std.testing;
    const allocator = testing.allocator;
    const a = (try rgb(allocator, "#aabbcc")).value;
    try testing.expectEqual(@as(u8, 0xaa), a.r);
    try testing.expectEqual(@as(u8, 0xbb), a.g);
    try testing.expectEqual(@as(u8, 0xcc), a.b);

    const b = (try rgb(allocator, "#abc")).value;
    try testing.expectEqual(@as(u8, 0xaa), b.r);
    try testing.expectEqual(@as(u8, 0xbb), b.g);
    try testing.expectEqual(@as(u8, 0xcc), b.b);

    const c = (try rgb(allocator, "#000000")).value;
    try testing.expectEqual(@as(u8, 0), c.r);
    try testing.expectEqual(@as(u8, 0), c.g);
    try testing.expectEqual(@as(u8, 0), c.b);

    const d = (try rgb(allocator, "#000")).value;
    try testing.expectEqual(@as(u8, 0), d.r);
    try testing.expectEqual(@as(u8, 0), d.g);
    try testing.expectEqual(@as(u8, 0), d.b);
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].