Giter Club home page Giter Club logo

macro-parser's Introduction

Example of using nom parsers from a proc macro

This project is organised as 3 crates:

  • nom_macro is the main project, exposing the proc macro and the generated types
  • parser holds the nom parsers
  • macro_parser provides the macro to parse at compile time

We need to separate them because a proc macro project can only export proc macros functions, no other types. If we want the main project to expose the parsers or the generated types along with the macro, we need to have them available in their own crate. So the parser crate is imported by macro_parser, and the parsers are reexported by nom_macro. If we do not need to make them available outside of the proc_macro, they can stay inside the proc macro crate.

The macro_parser crate provides a function-like macro that expects a string literal. If anything other than a string literal is provided (number, variable, etc), the macro will fail. The string literal then goes through a nom parser, that extracts a part of it. The quote crate is then used to generate a structure that contains the parsed value, and that structure is compiled in place of the macro.

macro-parser's People

Contributors

geal avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.