MarpaX::Languages::M4 - M4 pre-processor


version 0.020


     use POSIX qw/EXIT_SUCCESS/;
     use MarpaX::Languages::M4;
     use Log::Any;
     use Log::Any::Adapter;
     use Log::Any::Adapter::Callback;

     Log::Any::Adapter->set('Callback', min_level => 'trace', logging_cb => \&_logging_cb);

     my $m4 = MarpaX::Languages::M4->new_with_options();
     print "Value: " . $m4->value . "\n";
     print "Rc: " . $m4->rc . "\n";

     sub _logging_cb {
         my ($method, $self, $format, @params) = @_;
         printf STDERR  "$format\n", @args;


This package is an implementation of M4.


$class->new(%options --> ConsumerOf[M4Impl])

Please do m4pp --help for a list of all options. Returns a new M4 object instance.

$self->quote(Str $string --> Str)

Returns $string enclosed by current quote start and quote end.

$self->unquote(Str $string --> Str)

Returns the unquoted $string.

$self->appendValue(Str $result --> ConsumerOf[M4Impl])

Append string $result to M4 preprocessing output.

$self->value(--> Str)

Return M4 preprocessing output.

$self->valueRef(--> Ref['SCALAR'])

Return a reference to the M4 preprocessing output.

$self->parseIncremental(Str $input --> ConsumerOf[M4Impl])

Parses $input. Can be called any number of times.

$self->parse(Str $input --> Str)

Wrapper on parseIncremental(). Calling this method parses a single input and disable any later call to parseIncremental().

$self->unparsed(--> Str)

Returns the input not yet parsed. For example, when input ends with a macro call that requires parameters, and the parameters list is not complete.

$self->setEoi(--> ConsumerOf[M4Impl])

Turns on end-of-input flag. Then no call to parseIncremental() or parse() will be possible.

$self->eoi(--> Bool)

Get current end-of-input flag.

$self->raiseException(Str $message --> Undef)

Log $message to error stream and throw an exception of class ImplException.

$self->file(--> Str)

Get current file name. See NOTES.

$self->line(--> PositiveOrZeroInt)

Get current line number. See NOTES.

$self->rc(--> Int)

Get current parse return code. Should be POSIX::EXIT_SUCCESS() or POSIX::EXIT_FAILURE().

$self->isImplException(Any $obj --> Bool)

Return a boolean saying if $obj argument is an ImplException consumer.

$self->macroExecute(ConsumerOf[M4Macro] $macro, @args --> Str|M4Macro)

Execute macro $macro with arguments @args. Output is dependent of current parsing context, and can return an internal token instead of a string.

$self->macroCallId(--> PositiveOrZeroInt)

Return current macro internal call identifier. This number increases every time a macro is called.

$self->nbInputProcessed(--> PositiveOrZeroInt)

Return number of input processed so far.

$self->readFromStdin(--> ConsumerOf[M4Impl])

Enters interactive mode.

$self->debugFile(--> Undef|Str)

Return debug file, undef if none.

$class->defaultWarnMacroSequence(--> Str)

Return default --warn-macro-sequence option value (used by m4pp to handle MooX::Option non support of optional value on the command-line)


file() and line() methods, nor synchronisation output, are currently not supported. This is on the TODO list for this package.

M4 is a MooX::Role::Logger consumer, using explicitely Log::Any's "f" functions in all its logging methods. This mean that the message, in case you would use something like e.g. Log::Any::Adapter::Callback, is always formatted, with no additional parameter.


Marpa::R2, Moops, MooX::Role::Logger, Log::Any, Log::Any::Adapter::Callback, POSIX, M4 POSIX, M4 GNU


Jean-Damien Durand <>


This software is copyright (c) 2015 by Jean-Damien Durand.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.