Re: Looking for Perl Grammar
- From: Fabian Pilkowski <pilkowsk@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 30 Apr 2005 22:13:17 +0200
* Khamis Abuelkomboz schrieb:
>
> However I still find clauses like
>
> if ( s{foo}{bar} ) ...
> if ( s[foo][var] ) ...
> if ( s<foo><bar> ) ...
>
> I still don't figure out what could be used as "brackets" for the
> s|tr|m commands???? So I'm looking as example for grammar descriping
> how the (s, tr, qq) could be built, something like
>
> S: s OP1 expr OP2 expr OP3
> OP1: '/' | '{' | '[' | ':' | ...
> OP2: '/' | '}{' | '][' | ...
> OP3: '/' | '}' | ']' | ':' | ...
>
> I'm still guissing :-)
This is mentioned in `perldoc perlop` in the section named "Quote and
Quote-like Operators".
Non-bracketing delimiters use the same character fore and aft, but
the four sorts of brackets (round, angle, square, curly) will all
nest, which means that
q{foo{bar}baz}
is the same as
'foo{bar}baz'
[...]
There can be whitespace between the operator and the quoting
characters, except when # is being used as the quoting character.
q#foo# is parsed as the string foo, while q #foo# is the operator q
followed by a comment. Its argument will be taken from the next
line. This allows you to write:
s {foo} # Replace foo
{bar} # with bar.
So, for s/// you could start with a grammar similar to
S: s WS BRACKETED WS BRACKETED | s WS DELIM expr DELIM expr DELIM
BRACKETED: '(' expr ')' | '<' expr '>' | '[' expr ']' | '{' expr '}'
WS: WHITE-SPACES *
DELIM: '/' | '!' | ':' | '^'
I'm not deeply familiar with grammar descriptions. Is there a way to
ensure that each DELIM is the same char?
Don't forget to add the special behavior of »#« to your grammar. And of
course, do you want to allow comments between the BRACKETED parts as in
the example above? ;-)
regards,
fabian
.
- References:
- Looking for Perl Grammar
- From: Khamis Abuelkomboz
- Re: Looking for Perl Grammar
- From: Joe Smith
- Re: Looking for Perl Grammar
- From: Khamis Abuelkomboz
- Looking for Perl Grammar
- Prev by Date: Re: missing the boat
- Next by Date: Re: perl versions and other stuff
- Previous by thread: Re: Looking for Perl Grammar
- Next by thread: advice for a gui for my perl scripts.
- Index(es):
Relevant Pages
|