Q:

How do I create a function-like procedural macro?

How should a_proc_macro be defined so it "returns" a 5?
fn main() {
    let a = a_proc_macro!();
    assert!(a == 5);
}

A:

Reading The Rust Programming Language's chapter on macros says:

Function-like macros define macros that look like function calls. Similarly to
  macro_rules! macros, they’re more flexible than functions; for example, they
  can take an unknown number of arguments. However, macro_rules! macros can be
  defined only using the match-like syntax we discussed in the section
  “Declarative Macros with macro_rules! for General Metaprogramming”
  earlier. Function-like macros take a TokenStream parameter and their
  definition manipulates that TokenStream using Rust code as the other two
  types of procedural macros do. An example of a function-like macro is an sql!
  macro that might be called like so:
let sql = sql!(SELECT * FROM posts WHERE id=1);

This macro would parse the SQL statement inside it and check that it’s
  syntactically correct, which is much more complex processing than a
  macro_rules! macro can do. The sql! macro would be defined like this:
#[proc_macro]
pub fn sql(input: TokenStream) -> TokenStream {

This definition is similar to the custom derive macro’s signature: we receive
  the tokens that are inside the parentheses and return the code we wanted to
  generate.

example
├── Cargo.toml
├── example-macro
│   ├── Cargo.toml
│   ├── src
│   │   └── lib.rs
├── src
│   └── main.rs

Cargo.toml
[package]
name = "example"
version = "0.1.0"
edition = "2018"

[dependencies]
example-macro = { path = "example-macro" }

src/main.rs
#![feature(proc_macro_hygiene)]

fn main() {
    assert_eq!(example_macro::a_proc_macro!(), 5);
}

As of Rust 1.39, you cannot invoke a function-like procedural macro anywhere except at the top-level of a module (which includes the root module of a crate). You will need to use nightly Rust if you wish to use it as an expression. 
example-macro/Cargo.toml
[package]
name = "example-macro"
version = "0.1.0"
edition = "2018"

[lib]
proc-macro = true

example-macro/src/lib.rs
extern crate proc_macro;

use proc_macro::TokenStream;

#[proc_macro]
pub fn a_proc_macro(_input: TokenStream) -> TokenStream {
    "5".parse().unwrap()
}

See also:

How do I create a proc_macro_attribute?
Convert string into TokenStream
Why do proc-macros have to be defined in proc-macro crate?
Tracking issue for procedural macros and "hygiene 2.0" (#54727)
What is a crate attribute and where do I add it?

