Custom Naming Rules

Silverfly has two default naming conventions to choose. The default with lower case letters and underscore or a c-style naming. You can set the naming convention by calling the UseNameAdvancer method.

To build a custom naming convention you can implement the INameAdvancer interface.

A name has to be identified by its first character with the IsNameStart method. The AdvanceName advances the lexer to the right most valid name character that is included.

public class SampleNameAdvancer : INameAdvancer
{
    public bool IsNameStart(char c)
    {
        return char.IsLetter(c);
    }

    public void AdvanceName(Lexer lexer)
    {
        lexer.Advance();

        while (lexer.IsNotAtEnd())
        {
            if (!char.IsLetterOrDigit(lexer.Peek(0)) && lexer.Peek(0) != '_')
            {
                break;
            }

            lexer.Advance();
        }
    }
}

Last updated