| 72 | } |
| 73 | |
| 74 | func validateNodeName(s string) error { |
| 75 | if len(s) == 0 { |
| 76 | return errors.New("empty directive name") |
| 77 | } |
| 78 | |
| 79 | if unicode.IsDigit([]rune(s)[0]) { |
| 80 | return errors.New("directive name cannot start with a digit") |
| 81 | } |
| 82 | |
| 83 | allowedPunct := map[rune]bool{'.': true, '-': true, '_': true} |
| 84 | |
| 85 | for _, ch := range s { |
| 86 | if !unicode.IsLetter(ch) && |
| 87 | !unicode.IsDigit(ch) && |
| 88 | !allowedPunct[ch] { |
| 89 | return errors.New("character not allowed in directive name: " + string(ch)) |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | return nil |
| 94 | } |
| 95 | |
| 96 | // readNode reads node starting at current token pointed by the lexer's |
| 97 | // cursor (it should point to node name). |