JP van Oosten

Flexc++ textmate language

Jun 18, 2008

While working on our replacement for flex / flex++, I was getting lost in all the comments and regular expressions in our lexer-file. I needed syntax highlighting badly.

So, I opened up the bundle editor and wrote a language-file for flexc++. Because it's basically the same syntax, it also works on lexers for flex.

If someone's interested, drop me a line at jp@thisdomain, and I'll send the bundle to you (to save you some cut'n'paste work :)

{   scopeName = 'source.flexc++';
    fileTypes = ( );
    foldingStartMarker = '/\*\*|[^%]\{\s*$';
    foldingStopMarker = '\*\*/|^\s*\}';
    patterns = (
        {   name = 'comment.block.flexc++';
            begin = '\s*/\*';
            end = '\*/\s*';
        },
        {   name = 'meta.codeblock.flexc++';
            begin = '%\{';
            end = '%\}';
            patterns = ( { include = 'source.c++'; } );
        },
        {   name = 'constant.other.namedefinition.flexc++';
            match = '^\s*[A-Z_0-9]+';
        },
        {   name = 'string.regexp.namedefinition.flexc++';
            match = '(?<=[A-Z_0-9])\s+.+$';
        },
        {   name = 'meta.rulessection.flexc++';
            begin = '^%%$';
            end = '%%';
            patterns = (
                {   name = 'meta.blankline.flexc++';
                    match = '^$';
                },
                {   name = 'comment.block.rulessection.flexc++';
                    begin = '\s*/\*';
                    end = '\*/\s*';
                },
                {   name = 'entity.name.other.startconditionlist.flexc++';
                    match = '^\s*<[a-zA-Z_,]+>';
                },
                {   name = 'string.regexp.flexc++';
                    begin = '^\s*(?=[^\s\n])|(?<=>)(?=[^\s])';
                    end = '(?=\s|\n)';
                    patterns = (
                        {   name = 'string.regexp.characterclass.flexc++';
                            match = '\[.+\]';
                        },
                        {   name = 'string.regexp.escape.flexc++';
                            match = '\\.';
                        },
                        {   name = 'string.regexp.string.flexc++';
                            begin = '"';
                            end = '"';
                            patterns = (
                                {   name = 'string.regexp.string.escapechar.flexc++';
                                    match = '\\.';
                                },
                            );
                        },
                        {   name = 'constant.other.name.flexc++';
                            match = '\{[A-Z_0-9]*[A-Z_][A-Z_0-9]+\}';
                        },
                    );
                },
                {   name = 'meta.actionblock.flexc++';
                    begin = '\{';
                    end = '\}';
                    patterns = (
                        {   name = 'entity.name.function.builtin.flexc++';
                            match = '\b(BEGIN)\b';
                        },
                        {   name = 'meta.actionblock.source.flexc++';
                            include = 'source.c++';
                        },
                    );
                },
                {   name = 'entity.function.builtin.flexc++';
                    match = '\b(BEGIN)\b';
                },
                {   name = 'meta.action.flexc++';
                    contentName = 'source.c++';
                    match = '(?<=[^\s\n])\s+.+$';
                    include = 'source.c++';
                },
            );
        },
        {   name = 'entity.other.attribute-name.flexc++';
            match = '^%[^ ]+';
        },
    );
}