Login | Register
My pages Projects Community openCollabNet

Example: SimpleSyntax Configuration

See trunk/config for the files shown below.

Configuration of the SimpleSyntax highlighting:


    [SimpleSyntax:V1.1]

    # Script Support
    ScriptClassPath: lib-groovy,lib-ruby

    # General Settings
    Name: SimpleSyntax
    Icon: SimpleSyntax/Icon.png
    Description: SimpleSyntax Configuration
    ExampleCode: SimpleSyntax/Example.config

    # Braces Configuration
    Braces.Pairs: (),[]

    # Commenter Configuration
    Comment.Line: #

    # FileType Configuration
    FileType.Icon: SimpleSyntax/Icon.png
    FileType.Extensions: config
    FileType.DefaultExtension: config

    # Syntax Definition
    SyntaxDefinition: SimpleSyntax/Syntax.groovy

    # Element Descriptions
    descriptions[ LINE_COMMENT ] = Line comment
    descriptions[ IDENTIFIER ] = Identifier
    descriptions[ DIRECTIVE ] = Directive
    descriptions[ ATTRIBUTE ] = Attribute
    descriptions[ CONTAINER ] = Container
    descriptions[ HEADER ] = Header
    descriptions[ VALUE ] = Value

    # Element Default Attributes
    attributes[ LINE_COMMENT ] = #008000
    attributes[ IDENTIFIER ] = #800000
    attributes[ DIRECTIVE ] = #808000
    attributes[ ATTRIBUTE ] = #000080
    attributes[ CONTAINER ] = BOLD,#000080
    attributes[ HEADER ] = BOLD
    attributes[ VALUE ] = #F000F0

The lexer configuration referenced above. You would normaly copy this, changing only the loaded .flux configuration file name and changing the name of the created lexer.


    package SimpleSyntax;

    def syntax = new File( configFolder, 'SimpleSyntax/Syntax.flux' ).text
    def code = new flux.FluxBuilder( configFolder ).using( syntax ).create( "SimpleSyntaxSyntaxFlexer" )
    def clazz = evaluate( code )
    def instance = clazz.newInstance( configuration )
    return new com.intellij.lexer.FlexAdapter( instance )

This is the real lexer configuration loaded by the Groovy code above:


    WS = [ \t]*
    EOL = [\n\r]+

    HEADER = "[SimpleSyntax:".+"]"?
    LINE_COMMENT = "#"[^\r\n]*

    IDENTIFIER = [a-zA-Z][a-zA-Z_]*

    EQUAL = "="
    COLON = ":"

    DIRECTIVE = [A-Z][a-zA-Z]*("."{IDENTIFIER})*
    ATTRIBUTE = "["{WS}{IDENTIFIER}{WS}"]"

    VALUE = [^\n\r]*
    UNKNOWN = [^ \t\n\r\[\]=:]+

    %state ASSIGNMENT

    %%

    [\n\r]+ { return sym( "LINE_BREAK" ); }
    [\ ] { return sym( "SPACE" ); }
    [\t] { return sym( "TAB" ); }
    [\f] { return sym( "FORMFEED" ); }

    <ASSIGNMENT> {
    {VALUE} { yybegin(YYINITIAL); return sym( "VALUE" ); }
    }

    {HEADER} { return sym( "HEADER" ); }
    {LINE_COMMENT} { return sym( "LINE_COMMENT" ); }
    {DIRECTIVE} { return sym( "DIRECTIVE" ); }
    {ATTRIBUTE} { return sym( "ATTRIBUTE" ); }

    "descriptions" { return sym( "CONTAINER" ); }
    "attributes" { return sym( "CONTAINER" ); }

    {EQUAL} { yybegin(ASSIGNMENT); return sym( "OP_EQUAL" ); }
    {COLON} { yybegin(ASSIGNMENT); return sym( "OP_COLON" ); }

    {UNKNOWN} { return sym( "UNKNOWN" ); }

    . { return sym( "BAD_CHARACTER" ); }