78d20c1359
Signed-off-by: Alejandro Mery <amery@jpi.io>
41 lines
893 B
Go
41 lines
893 B
Go
package parser
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"asciigoat.org/core/lexer"
|
|
)
|
|
|
|
var (
|
|
// IsNewLine tells if a rune represents a line break or the start of one
|
|
IsNewLine = lexer.NewIsIn("\n\r")
|
|
// IsNotNewLine tells if a rune is anything other than line breaks
|
|
IsNotNewLine = lexer.NewIsNot(IsNewLine)
|
|
// IsNotSpace tells if a rune is anything other than whitespace
|
|
IsNotSpace = lexer.NewIsNot(lexer.IsSpace)
|
|
// IsSpace tells if a rune is considered whitespace by unicode
|
|
IsSpace = lexer.IsSpace
|
|
|
|
IsCommentStart = lexer.NewIsIn(";#")
|
|
)
|
|
|
|
// IsSpaceNotNewLine indicates a rune is whitespace but not a new line
|
|
func IsSpaceNotNewLine(r rune) bool {
|
|
return IsSpace(r) && !IsNewLine(r)
|
|
}
|
|
|
|
func IsSectionStart(r rune) bool {
|
|
return r == '['
|
|
}
|
|
|
|
func IsName(r rune) bool {
|
|
switch {
|
|
case IsSpace(r):
|
|
return false
|
|
case strings.ContainsRune("=\"'[];#", r):
|
|
return false
|
|
default:
|
|
return true
|
|
}
|
|
}
|