Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Testing syntax parsing in editors (especially emacs)

by LanX (Cardinal)
on Mar 15, 2021 at 15:19 UTC ( #11129676=perlquestion: print w/replies, xml ) Need Help??

LanX has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I'm looking for a way to use Perl to test syntax parsing of Perl code in various editors.

Regarding emacs:

it should be possible to run an emacs-versions in batch mode (aka headless) to load a Perl snippet and execute various elisp snippets.

It's also possible - at least in cperl-mode - to export a html postscript version of the Perl code.

Another, way would be to use describe-text-properties at a text position to learn the current syntax:

e.g. my %hash

will show on my

Text content at position 1: There are text properties here: face font-lock-keyword-face fontified t

and on %hash

Text content at position 4: There are text properties here: face cperl-hash-face fontified t

"face" is emacs equivalent for "style" in HTML

any ideas?

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

) sorry I think I confused that with perltidy which offers html.

Replies are listed 'Best First'.
Re: Testing syntax parsing in editors (especially emacs)
by choroba (Archbishop) on Mar 15, 2021 at 18:16 UTC
    This is what I usually use to htmlize text the Emacs way:htmlize.sh. It uses the Htmlize package.

    I don't use headless Emacs, as without the "head", the colours are different, and I haven't found a way how to enable them (but I haven't tried hard).

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      Thanks, a very similar approach, but your htmlize.el seems to be an external package, htmlfontify seems to be core.

      Still a hack but does the job so far. :)

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

Re: Testing syntax parsing in editors (especially emacs)
by LanX (Cardinal) on Mar 15, 2021 at 19:00 UTC
    my solution so far for emacs on linux

    $ $ rm $file.html; emacs -Q -batch $file -f cperl-mode -f htmlfontify- +buffer -f save-buffer 2>$file.err; grep y_max $file.html <span class="keyword">sub</span> <span class="function-name">y_max</sp +an> {

    the -Q is not necessary, it's just speeding up startup by not loading any ini-files

    the rm $file.html was necessary, otherwise the html isn't saved.

    the grep is a cheap workaround for parsing the html.

    Please note that the names of the CSS-classes are not 1-to-1 to emacs faces for Perl, but the included attributes - like colors - are.

    As a generic option also for other editors (if they allow remote execution)

    It's also possible to trigger a PS or PDF save ...

    A pdftohtml -xml generates again a a similar <xml> output which can be parsed for correctness.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11129676]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2021-06-16 13:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (74 votes). Check out past polls.

    Notices?