Implement #2811 - Unicode en-dash (U+2013) as hump/snake alt.
This commit is contained in:
parent
6820b2fea9
commit
1b4db5a34c
3 changed files with 29 additions and 7 deletions
|
|
@ -12,7 +12,7 @@
|
||||||
# id. This module is essential for the compiler's performance.
|
# id. This module is essential for the compiler's performance.
|
||||||
|
|
||||||
import
|
import
|
||||||
hashes, strutils
|
hashes, strutils, etcpriv
|
||||||
|
|
||||||
type
|
type
|
||||||
TIdObj* = object of RootObj
|
TIdObj* = object of RootObj
|
||||||
|
|
@ -37,6 +37,8 @@ proc cmpIgnoreStyle(a, b: cstring, blen: int): int =
|
||||||
while j < blen:
|
while j < blen:
|
||||||
while a[i] == '_': inc(i)
|
while a[i] == '_': inc(i)
|
||||||
while b[j] == '_': inc(j)
|
while b[j] == '_': inc(j)
|
||||||
|
while isMagicIdentSeparatorRune(a, i): inc(i, magicIdentSeparatorRuneByteWidth)
|
||||||
|
while isMagicIdentSeparatorRune(b, j): inc(j, magicIdentSeparatorRuneByteWidth)
|
||||||
# tolower inlined:
|
# tolower inlined:
|
||||||
var aa = a[i]
|
var aa = a[i]
|
||||||
var bb = b[j]
|
var bb = b[j]
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
hashes, options, msgs, strutils, platform, idents, nimlexbase, llstream,
|
hashes, options, msgs, strutils, platform, idents, nimlexbase, llstream,
|
||||||
wordrecg
|
wordrecg, etcpriv
|
||||||
|
|
||||||
const
|
const
|
||||||
MaxLineLength* = 80 # lines longer than this lead to a warning
|
MaxLineLength* = 80 # lines longer than this lead to a warning
|
||||||
|
|
@ -143,7 +143,8 @@ proc isNimIdentifier*(s: string): bool =
|
||||||
while i < s.len:
|
while i < s.len:
|
||||||
if s[i] == '_':
|
if s[i] == '_':
|
||||||
inc(i)
|
inc(i)
|
||||||
if s[i] notin SymChars: return
|
elif isMagicIdentSeparatorRune(cstring s, i):
|
||||||
|
inc(i, magicIdentSeparatorRuneByteWidth)
|
||||||
if s[i] notin SymChars: return
|
if s[i] notin SymChars: return
|
||||||
inc(i)
|
inc(i)
|
||||||
result = true
|
result = true
|
||||||
|
|
@ -632,16 +633,27 @@ proc getSymbol(L: var TLexer, tok: var TToken) =
|
||||||
var c = buf[pos]
|
var c = buf[pos]
|
||||||
case c
|
case c
|
||||||
of 'a'..'z', '0'..'9', '\x80'..'\xFF':
|
of 'a'..'z', '0'..'9', '\x80'..'\xFF':
|
||||||
|
if c == '\226' and
|
||||||
|
buf[pos+1] == '\128' and
|
||||||
|
buf[pos+2] == '\147': # It's a 'magic separator' en-dash Unicode
|
||||||
|
if buf[pos + magicIdentSeparatorRuneByteWidth] notin SymChars:
|
||||||
|
lexMessage(L, errInvalidToken, "·")
|
||||||
|
break
|
||||||
|
inc(pos, magicIdentSeparatorRuneByteWidth)
|
||||||
|
else:
|
||||||
h = h !& ord(c)
|
h = h !& ord(c)
|
||||||
|
inc(pos)
|
||||||
of 'A'..'Z':
|
of 'A'..'Z':
|
||||||
c = chr(ord(c) + (ord('a') - ord('A'))) # toLower()
|
c = chr(ord(c) + (ord('a') - ord('A'))) # toLower()
|
||||||
h = h !& ord(c)
|
h = h !& ord(c)
|
||||||
|
inc(pos)
|
||||||
of '_':
|
of '_':
|
||||||
if buf[pos+1] notin SymChars:
|
if buf[pos+1] notin SymChars:
|
||||||
lexMessage(L, errInvalidToken, "_")
|
lexMessage(L, errInvalidToken, "_")
|
||||||
break
|
break
|
||||||
else: break
|
|
||||||
inc(pos)
|
inc(pos)
|
||||||
|
|
||||||
|
else: break
|
||||||
h = !$h
|
h = !$h
|
||||||
tok.ident = getIdent(addr(L.buf[L.bufpos]), pos - L.bufpos, h)
|
tok.ident = getIdent(addr(L.buf[L.bufpos]), pos - L.bufpos, h)
|
||||||
L.bufpos = pos
|
L.bufpos = pos
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@
|
||||||
## result = !$h
|
## result = !$h
|
||||||
|
|
||||||
import
|
import
|
||||||
strutils
|
strutils, etcpriv
|
||||||
|
|
||||||
type
|
type
|
||||||
THash* = int ## a hash value; hash tables using these values should
|
THash* = int ## a hash value; hash tables using these values should
|
||||||
|
|
@ -124,13 +124,21 @@ proc hash*(x: string): THash =
|
||||||
proc hashIgnoreStyle*(x: string): THash =
|
proc hashIgnoreStyle*(x: string): THash =
|
||||||
## efficient hashing of strings; style is ignored
|
## efficient hashing of strings; style is ignored
|
||||||
var h: THash = 0
|
var h: THash = 0
|
||||||
for i in 0..x.len-1:
|
var i = 0
|
||||||
|
let xLen = x.len
|
||||||
|
while i < xLen:
|
||||||
var c = x[i]
|
var c = x[i]
|
||||||
if c == '_':
|
if c == '_':
|
||||||
|
inc(i)
|
||||||
continue # skip _
|
continue # skip _
|
||||||
|
if isMagicIdentSeparatorRune(cstring(x), i):
|
||||||
|
inc(i, magicIdentSeparatorRuneByteWidth)
|
||||||
|
continue # skip '·' (unicode middle dot)
|
||||||
if c in {'A'..'Z'}:
|
if c in {'A'..'Z'}:
|
||||||
c = chr(ord(c) + (ord('a') - ord('A'))) # toLower()
|
c = chr(ord(c) + (ord('a') - ord('A'))) # toLower()
|
||||||
h = h !& ord(c)
|
h = h !& ord(c)
|
||||||
|
inc(i)
|
||||||
|
|
||||||
result = !$h
|
result = !$h
|
||||||
|
|
||||||
proc hashIgnoreCase*(x: string): THash =
|
proc hashIgnoreCase*(x: string): THash =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue