Im trying to understand how to use PEG.js for simple search/replace in a text. Surely this is not the intended use for a parser but anyway Im curious about the logic behind these kind of languages to produce some search/replace.
The problem that Im having is that is hard to define positively the complementary of some definitions. An example: imagine I want to search and replace something like this syntax:
rule = (whatever_is_not_my_syntax* m:my_syntax)+ {replace m}
word = [a-z0-9_]+
my_syntax = word "." word
whatever_is_not_my_syntax = ???
It is hard to describe, positively, what is whatever_is_not_my_syntax
in PEG.js without partial collision (and consequent parser error) with my_syntax
, or at least I dont know how to do it, because the only negative parser functions on PEG.js are !expression
and [^characters]
.
Can you help me? I will appreciate any book or bibliography, if exists, about this topic. Thank you in advance.