emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

antlr-mode.el - need some support by python.el


From: Wedler, Christoph
Subject: antlr-mode.el - need some support by python.el
Date: Fri, 16 Jan 2015 19:50:58 +0000

As the author of lisp/progmodes/antlr-mode.el, I finally found some time
to update this Emacs mode according to the changes of ANTLR (a tool for
language recognition, i.e. in the same area as Flex and Bison).  And
ANTLR has changed quite a bit...

For the changes I have done so far, see the README or the Changelog at
    http://sourceforge.net/projects/antlr-mode/
More changes (and some cleanup) is needed.

This brings me to 2 questions (I am currently not on the emacs-devel
mailing list, I just skim the archive once a month, i.e. please keep
my email address on replies / follow-ups - if useful, I could join the
mailing list for a month or two).

 1. How am I supposed to integrate this into the main Emacs branch?  My
    current idea is to do this after some cleanup.

 2. ANTLR (v3) supports that more languages can be used for actions
    inside the grammar - I support Java and Cpp as before, and now also
    C, ObjC, Delphi, JavaScript, Python and Ruby

    Syntax-highlighting support for these works quite well, indentation
    for Python actions inside the grammar needs support by that mode
    (support by opascal-mode and ruby-mode would also be appreciated,
    but is not entirely necessary).

    Q: Does the maintainer of python.el has some time to do some (small)
    change there, or am I supposed to send a patch?

There are three potential issues when I call the indentation engine of
the "sub-mode" (if it is not based on cc-mode) - see below for an
example.

 a. The indentation engine of the sub-mode might get confused by the
    grammar code around the code snippet.  Not an issue for JavaScript
    (has a Cish syntax).  I have avoided that for opascal and ruby via
    `narrow-to-region', but Python's indentation calls `widen'.

 b. The indentation engine might want to parse a correct program, not
    just some code snippet (not an issue so far).

 c. The indentation engine might want to indent the first statement
    inside the grammar action at column 0 (because it is the first
    statement it sees at all), but that might not be nice for the first
    statement inside a grammar action.

    A workaround for all modes except python was to do the indentation
    myself (or to be honest by cc-mode) if the submode indents the line
    at column 0.  For Python, this is no option as it cycles through the
    possible indentation columns.

Here is an extract from an example grammar for ANTLR v3:

//-------------------------------------------------------
grammar C;
options { language=Python; }

@members {
    def isTypeName(self, name):
        for scope in reversed(self.Symbols_stack):
            if name in scope.types:
                return True                                # line 09

        return False
}

direct_declarator
    :   (   IDENTIFIER
            {
                if len($declaration) > 0 and $declaration::isTypedef:
                    $Symbols::types.add($IDENTIFIER.text)
                    print "define type "+$IDENTIFIER.text  # line 19
            }
        |   '(' declarator ')'
        )
        declarator_suffix*
    ;
//-------------------------------------------------------

The indentation points for line 09 should be columns 16, 12,8 and 4, but
not 0 - for line 19 the columns should be 20 and 16, but not 12, 8, 4
and 0.

Therefore, before I call `python-indent-line, I need a possibility to
specify the region of the action, and the "minimal column position".

Regards,
Christoph



reply via email to

[Prev in Thread] Current Thread [Next in Thread]