diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2015-06-04 11:37:26 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2015-06-04 11:37:26 +0200 |
commit | 8264c3cbeef6a4b86f7613c05d036658cbd9a24d (patch) | |
tree | 3e62ce8c9ae45b85b3d2d96a752a9f99c7ad8905 /compiler/lexer.nim | |
parent | 874637be32e4dcecb1301a5c436013945fc90cd0 (diff) | |
parent | dd30bab480f59e4bb4ab8fad5aabd13c08aa1b11 (diff) | |
download | Nim-8264c3cbeef6a4b86f7613c05d036658cbd9a24d.tar.gz |
Merge pull request #2849 from ozra/feature-2811-hump-snake-dash
Feature #2811 hump, snake and now dash
Diffstat (limited to 'compiler/lexer.nim')
-rw-r--r-- | compiler/lexer.nim | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/compiler/lexer.nim b/compiler/lexer.nim index 8080e0e8c..eaabe05e2 100644 --- a/compiler/lexer.nim +++ b/compiler/lexer.nim @@ -17,7 +17,7 @@ import hashes, options, msgs, strutils, platform, idents, nimlexbase, llstream, - wordrecg + wordrecg, etcpriv const MaxLineLength* = 80 # lines longer than this lead to a warning @@ -140,10 +140,12 @@ proc isKeyword*(kind: TTokType): bool = proc isNimIdentifier*(s: string): bool = if s[0] in SymStartChars: var i = 1 - while i < s.len: + var sLen = s.len + while i < sLen: if s[i] == '_': inc(i) - if s[i] notin SymChars: return + elif isMagicIdentSeparatorRune(cstring s, i): + inc(i, magicIdentSeparatorRuneByteWidth) if s[i] notin SymChars: return inc(i) result = true @@ -632,16 +634,27 @@ proc getSymbol(L: var TLexer, tok: var TToken) = var c = buf[pos] case c of 'a'..'z', '0'..'9', '\x80'..'\xFF': - h = h !& ord(c) + 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) + inc(pos) of 'A'..'Z': c = chr(ord(c) + (ord('a') - ord('A'))) # toLower() h = h !& ord(c) + inc(pos) of '_': if buf[pos+1] notin SymChars: lexMessage(L, errInvalidToken, "_") break + inc(pos) + else: break - inc(pos) h = !$h tok.ident = getIdent(addr(L.buf[L.bufpos]), pos - L.bufpos, h) L.bufpos = pos |