Posted 18 years ago by Kasper
Avatar
Hi,

I have been using the SynEdit package for Delphi for years now, so I have grown custom so some things, like being able to use their highlighters to parse a file. For instance, I could create new instance of the CSS Highlighter, assign some CSS code to it, and then step through the entire content, finding the things I was interested it. This was kinda cool, since it saved me from making a parser to e.g. get the selectors of a CSS document. I was kinda hoping that I would be able to do the same thing with SyntaxEditor, but I can't find anything specific on this in the manual. Is this possible, or can I only do things like this by creating a SyntaxEditor instance, loading a language and then use a TokenStream or something like this?

Comments (3)

Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
The language definitions tell SyntaxEditor how to break up text into tokens. So if you design your language a certain way, you can scan the tokens in the document for specific token types (like selectors). A TokenStream is a good way to iterate through the tokens.

However with the work we're doing for SyntaxEditor 4.0, we're making it easier for advanced programmers to build abstract syntax trees for documents. With those sorts of features you could build a grammar that would generate the AST. Then you could iterate through the AST to see a direct list of selectors, etc. if you made one for CSS. We are prototyping everything out with C# but eventually want to support other languages as well.


Actipro Software Support

Posted 18 years ago by Kasper
Avatar
Well, actually I don't want this for a custom made language or anything, just for the ones included with SyntaxEditor now. For instance, how can I easily parse a custom piece of CSS code, to get all selectors, properties and values? I'm pretty sure I can do this by loading the code into a SyntaxEditor, but since I need to do this in the background on some occasions, I would like to avoid this, and access some sort of parser directly. How can I do this?
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
SyntaxEditor has complete separation of the UI and document layers. So you can load a Document object, set it to the CSS language, and load text into it. That means you can use it in the background and never load a SyntaxEditor control. Then use a TokenStream to examine the tokens in the Document. Document.GetTokenStream gets you the TokenStream.


Actipro Software Support

The latest build of this product (v24.1.0) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.