Silverfly
  • Welcome
  • Getting Started
    • Quickstart
    • Tokens
  • Basics
    • Lexer
      • Matcher
        • IgnoreMatcher
        • Custom Matcher
    • Parser
      • Parselet
    • Traverse the Tree
    • Read Eval Print Loop
    • Looking at the tree
  • Experts
    • Custom Naming Rules
    • Tree Rewriting
  • Guides
    • JSON
    • Parsing Predecesors
    • Using Multiple Tokens As Operators
  • Support
Powered by GitBook
On this page
  1. Experts

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();
        }
    }
}
PreviousLooking at the treeNextTree Rewriting

Last updated 8 months ago