Skip to main content

Macro parser

Project description

PyPI Version License Python Version

Macro-parser is a Python package that provides a macro parser.

Basic Usage

Installation

Install with pip:

pip install macro-parser

Get Started

If you save the following text as test.txt:

# This is comment
# There are `new_macro` and `renew_macro`
# Its syntax is like Python:
# \new_macro(
# 	\func_name(func_args){
# 		func_body
# 	}
# )
\new_macro(
	\hello(*args){
		for arg in args:
			print('hello', arg)
	}
	\bye(*args){
		for arg in args:
			print('bye', arg)
	}
)#

# Verbatim environment
\verb(\new_macro)
\verb_(\new_macro(\hello(*args){print(args)}))

# Use the personal defined macros
\hello('world', 'iydon', 'vian')
\bye('world', 'iydon', 'vian')

# See what the built-in macors are
Built-in macros: \builtins().

Then you can parse the macros by:

from macro_parser import parse_macro_in

file = 'test.txt'
print(parse_macro_in(file))

Finally, the result is:


\new_macro
\new_macro(\hello(*args){print(args)})

hello world
hello iydon
hello vian

bye world
bye iydon
bye vian


Built-in macros: ('builtins', 'input', 'new_macro', 'parse', 'renew_macro', 'verb', 'verb_').

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

macro-parser-0.3.1.tar.gz (4.8 kB view hashes)

Uploaded source

Built Distribution

macro_parser-0.3.1-py3-none-any.whl (5.6 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page