Skip to content

Commit

Permalink
Support ' in identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
DavePearce committed Dec 9, 2024
1 parent 055374c commit 6bec8ad
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/corset/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ func (p *Parser) parseColumnDeclaration(module string, e sexp.SExp) (*DefColumn,
// Check at least the name provided.
if len(l.Elements) == 0 {
return nil, p.translator.SyntaxError(l, "empty column declaration")
} else if !isIdentifier(l.Elements[0]) {
return nil, p.translator.SyntaxError(l.Elements[0], "invalid column name")
}
// Column name is always first
name = l.Elements[0].String(false)
Expand Down Expand Up @@ -859,9 +861,9 @@ func normParserRule(_ string, args []Expr) (Expr, error) {
func isIdentifier(sexp sexp.SExp) bool {
if symbol := sexp.AsSymbol(); symbol != nil && len(symbol.Value) > 0 {
runes := []rune(symbol.Value)
if unicode.IsLetter(runes[0]) || runes[0] == '_' {
if isIdentifierStart(runes[0]) {
for i := 1; i < len(runes); i++ {
if !unicode.IsLetter(runes[i]) && !unicode.IsDigit(runes[i]) && runes[i] != '_' {
if !isIdentifierMiddle(runes[i]) {
return false
}
}
Expand All @@ -872,3 +874,11 @@ func isIdentifier(sexp sexp.SExp) bool {
// Fail
return false
}

func isIdentifierStart(c rune) bool {
return unicode.IsLetter(c) || c == '_' || c == '\''
}

func isIdentifierMiddle(c rune) bool {
return unicode.IsDigit(c) || isIdentifierStart(c)
}

0 comments on commit 6bec8ad

Please sign in to comment.