Re: Semantic questions for my language mode
Eric Ludlam <[email protected]> Tue, 10 Feb 2015 20:35:18 -0500
| Newsgroups | gmane.emacs.cedet |
|---|---|
| Message-ID | <[email protected]> |
On 02/10/2015 01:07 PM, Isak Andersson wrote: > Hello people! > > I'm making my own mode for the Boo programming language, to replace the > current one that existed because I wasn't quite happy with how the > current one behaved. > > I wanted to try and make one that integrates well with CEDET tools. So I > was wondering a few things. > > First, as auto indentation is quite the task since it pretty much > requires some parsing to work reliably, I was wondering if it's possible > to perhaps use the semantic parser to build an indentation system with > and how one would go about doing so if it's possible. > > Second, I was hoping it would be possible to somehow utilize semantic > for building the syntax highlighting system as well. For example > highlighting things based on what kind of type they are (function or > variable). Boo also allows you to add new keywords by using macros, so > if I could parse the project and detect macros and start highlighting > macro invokations as keywords automatically (rather than manually like > you do with the current boo-mode) that would be super swell. Would it be > possible to do this? Both those tasks are theoretically possible, but there is no example or infrastructure to support using the parser for indentation and coloring. The premis is pretty simple - in the actions for rule matching, you could apply some additional logic, such as building a syntax tree you could then use to place color. In practice, I suspect you would need some infrastructure outside of the parser to do the work, such as the way to build a colorizing syntax tree. I don't know boo, but you might be able to do indentation by creating a typical tag parser, and using the tags to start/end indentation regions, and possibly the semantic-ctxt-* overloads for parts of your code. For dynamically adding keywords, there is an example of doing the same in the C parser. In C's case, there is a lexical step for preprocessor symbols where it happens. In your case, you could just parse the buffer the normal way for tags, then scan the list of tags for things that need to be added to the boo keyword list. If this is project based, you'd need some special function to parse relevant files, scan for tags, and update. This type of activity is well supported by semantic APIs with semantic-fetch-tags and semantic-find- routines, or by using semanticdb to load tag tables without loading files if previously parsed. Eric ------------------------------------------------------------------------------ Dive into the World of Parallel Programming. The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/