// NewLexer creates a new regex-based Lexer.
//
// "rules" is a state machine transitition map. Each key is a state. Values are sets of rules
// that match input, optionally modify lexer state, and output tokens.
NewLexer creates a new regex-based Lexer.

"rules" is a state machine transitition map. Each key is a state. Values are sets of rules
that match input, optionally modify lexer state, and output tokens.
// NewLexer creates a new regex - based Lexer . // // " rules " is a state machine transitition map . Each key is a state . Values are sets of rules // that match input optionally modify lexer state and output tokens .
func NewLexer(config *Config, rules Rules) (*RegexLexer, error) {
	if config == nil {
		config = &Config{}
	}
	if _, ok := rules["root"]; !ok {
		return nil, fmt.Errorf("no \"root\" state")
	}
	compiledRules := map[string][]*CompiledRule{}
	for state, rules := range rules {
		compiledRules[state] = nil
		for _, rule := range rules {
			flags := ""
			if !config.NotMultiline {
				flags += "m"
			}
			if config.CaseInsensitive {
				flags += "i"
			}
			if config.DotAll {
				flags += "s"
			}
			compiledRules[state] = append(compiledRules[state], &CompiledRule{Rule: rule, flags: flags})
		}
	}
	return &RegexLexer{
		config: config,
		rules:  compiledRules,
	}, nil
}
func NewLexer ( config * Config , rules Rules ) ( * RegexLexer , error ) { if config == nil { config = & Config { } } if _ , ok := rules [ " " ] ; ! ok { return nil , fmt . Errorf ( " \" \" " ) } compiledRules := map [ string ] [ ] * CompiledRule { } for state , rules := range rules { compiledRules [ state ] = nil for _ , rule := range rules { flags := " " if ! config . NotMultiline { flags += " " } if config . CaseInsensitive { flags += " " } if config . DotAll { flags += " " } compiledRules [ state ] = append ( compiledRules [ state ] , & CompiledRule { Rule : rule , flags : flags } ) } } return & RegexLexer { config : config , rules : compiledRules , } , nil }
NewLexer creates a new regex-based Lexer.
NewLexer creates a new regex - based Lexer .