Skip to content

Commit

Permalink
Closes #148 (removes !is, !in, and !null in favor of the keyword-base…
Browse files Browse the repository at this point in the history
…d spellings).
  • Loading branch information
JarrettBillingsley committed Nov 9, 2014
1 parent 117f0a9 commit 29240c5
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 62 deletions.
3 changes: 0 additions & 3 deletions crocgrammar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ ReturnTypes:

Type:
BasicType
! null
not null
any
@ DottedName
Expand Down Expand Up @@ -425,7 +424,6 @@ EqualExpression:
ShiftExpression == ShiftExpression
ShiftExpression != ShiftExpression
ShiftExpression is ShiftExpression
ShiftExpression ! is ShiftExpression
ShiftExpression is not ShiftExpression

RelExpression:
Expand All @@ -435,7 +433,6 @@ RelExpression:
ShiftExpression >= ShiftExpression
ShiftExpression <=> ShiftExpression
ShiftExpression in ShiftExpression
ShiftExpression ! in ShiftExpression
ShiftExpression not in ShiftExpression

ShiftExpression:
Expand Down
2 changes: 1 addition & 1 deletion samples/threadtest.croc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Thread
{
if(:mNeedMessage)
{
assert(:mMessageHead !is null)
assert(:mMessageHead is not null)
:mNeedMessage = false
local ok, value = :receive()
assert(ok)
Expand Down
21 changes: 1 addition & 20 deletions src/croc/compiler/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ namespace croc

ret = cast(uint32_t)TypeMask::Any;
}
else if(l.type() == Token::Not || l.type() == Token::NotKeyword)
else if(l.type() == Token::NotKeyword)
{
l.next();
l.expect(Token::Null);
Expand Down Expand Up @@ -1901,25 +1901,6 @@ namespace croc
exp1 = new(c) NotEqualExp(location, exp2->endLocation, exp1, exp2);
break;

case Token::Not:
if(l.peek().type == Token::Is)
{
l.next();
l.next();
exp2 = parseShiftExp();
exp1 = new(c) NotIsExp(location, exp2->endLocation, exp1, exp2);
}
else if(l.peek().type == Token::In)
{
l.next();
l.next();
exp2 = parseShiftExp();
exp1 = new(c) NotInExp(location, exp2->endLocation, exp1, exp2);
}
// no, there should not be an 'else' here

break;

case Token::NotKeyword:
if(l.peek().type == Token::In)
{
Expand Down
2 changes: 1 addition & 1 deletion src/croc/stdlib/docs.croc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ access their doc tables through their parents' \tt{children} doctable member. Th
*/
function childDocs(obj: class|namespace, child: string)
{
if(child !in obj)
if(child not in obj)
throw ValueError("Object has no child named '{}'".format(child))

local docs = docsOf(obj)
Expand Down
4 changes: 2 additions & 2 deletions src/croc/stdlib/doctools_console.croc
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class BasicConsoleOutputter : DocOutputter
{
:beginParagraph()

if(name !is "docs")
if(name is not "docs")
{
:beginBold()

Expand Down Expand Up @@ -494,7 +494,7 @@ class BasicConsoleOutputter : DocOutputter

local first, second = splitAtWS(s, remaining)

if(first !is null)
if(first is not null)
:baseWrite(first)

:newline()
Expand Down
32 changes: 16 additions & 16 deletions src/croc/stdlib/doctools_output.croc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class LinkResolver
// Might be some globals added by user code that aren't in docsOf(_G).children
foreach(name, val; _G)
{
if(name !is "_G" && name !in :_globals && name !in modules.loaded)
if(name is not "_G" && name not in :_globals && name not in modules.loaded)
{
if(local dt = docsOf(val))
:_globals[name] = :_makeMapRec(dt)
Expand Down Expand Up @@ -99,7 +99,7 @@ class LinkResolver
*/
function enterModule(name: string)
{
if(:_item !is null || :_module !is null)
if(:_item is not null || :_module is not null)
throw StateError("Attempting to enter a module from {} scope".format(:currentScope()))

if(local m = :_modules[name])
Expand All @@ -117,7 +117,7 @@ class LinkResolver
*/
function enterItem(name: string)
{
if(:_item !is null || :_module is null)
if(:_item is not null || :_module is null)
throw StateError("Attempting to enter an item from {} scope".format(:currentScope()))

if(local i = :_module.children[name])
Expand All @@ -133,9 +133,9 @@ class LinkResolver
*/
function leave()
{
if(:_item !is null)
if(:_item is not null)
:_item = null
else if(:_module !is null)
else if(:_module is not null)
:_module = null
else
throw StateError("Attempting to leave at global scope")
Expand Down Expand Up @@ -196,10 +196,10 @@ class LinkResolver
// Private

function _inItem(link: string) =
:_item !is null && link in :_item.children
:_item is not null && link in :_item.children

function _inCurModule(link: string) =
:_module !is null && :_inModule(:_module, link)
:_module is not null && :_inModule(:_module, link)

function _inModules(link: string)
{
Expand Down Expand Up @@ -262,7 +262,7 @@ class LinkResolver
local f = link[dot + 1 ..]
local i = :_globals[n]

return i !is null && i.children && f in i.children
return i is not null && i.children && f in i.children
}

function _inGlobals(link: string) =
Expand Down Expand Up @@ -376,7 +376,7 @@ class LinkTranslator

/// Checks if a given name is a valid name for a doc section.
function validSectionName(name: string) =
!(#name == 0 || (#name == 1 && name[0] == '_') || (name[0] != '_' && name !in stdSections))
!(#name == 0 || (#name == 1 && name[0] == '_') || (name[0] != '_' && name not in stdSections))

/// Checks if a paragraph list is empty (has no actual text).
function isPlistEmpty(plist: array) =
Expand Down Expand Up @@ -502,7 +502,7 @@ function toHeader(doctable: table, parentFQN: string, full: bool = true)

if(doctable.name == "constructor")
{
if(parentFQN !is "")
if(parentFQN is not "")
ret.append(parentFQN, ".")

ret.append("this")
Expand All @@ -512,7 +512,7 @@ function toHeader(doctable: table, parentFQN: string, full: bool = true)
if(full)
ret.append("function ")

if(parentFQN !is "")
if(parentFQN is not "")
ret.append(parentFQN, ".")

ret.append(doctable.name)
Expand Down Expand Up @@ -544,7 +544,7 @@ function toHeader(doctable: table, parentFQN: string, full: bool = true)
if(full)
ret.append(doctable.kind, " ")

if(parentFQN !is "")
if(parentFQN is not "")
ret.append(parentFQN, ".")

ret.append(doctable.name)
Expand All @@ -557,7 +557,7 @@ function toHeader(doctable: table, parentFQN: string, full: bool = true)
break

case "field":
if(parentFQN !is "")
if(parentFQN is not "")
ret.append(parentFQN, ".")

ret.append(doctable.name)
Expand All @@ -573,7 +573,7 @@ function toHeader(doctable: table, parentFQN: string, full: bool = true)
if(full)
ret.append(doctable.protection, " ")

if(parentFQN !is "")
if(parentFQN is not "")
ret.append(parentFQN, ".")

ret.append(doctable.name)
Expand Down Expand Up @@ -706,7 +706,7 @@ class SectionOrder

// Make sure all standard sections are accounted for
foreach(sec; stdSections)
if(sec !in order)
if(sec not in order)
throw ValueError("Standard section '{}' does not exist in the given order".format(sec))

// Make sure there are no duplicates
Expand Down Expand Up @@ -749,7 +749,7 @@ class SectionOrder
throw ValueError("Invalid section name '{}'".format(target))
else if(sec == target)
throw ValueError("Section names must be different")
else if(target !in ord)
else if(target not in ord)
throw ValueError("Section '{}' does not exist in the section order".format(target))

local ord = :_sectionOrder
Expand Down
2 changes: 1 addition & 1 deletion src/croc/stdlib/doctools_trac.croc
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class TracWikiOutputter : DocOutputter

override function beginSection(name: string)
{
if(name !is "docs")
if(name is not "docs")
{
:beginParagraph()
:beginBold()
Expand Down
14 changes: 7 additions & 7 deletions src/croc/stdlib/hash_weaktables.croc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class WeakKeyTable : WeakTableBase
{
local v = :_data[keys[idx]]

if(v !is null)
if(v is not null)
return deref(keys[idx]), v
}
}
Expand Down Expand Up @@ -107,7 +107,7 @@ class WeakKeyTable : WeakTableBase
/**
Gets an array of the keys (dereferenced) of this table.
*/
function keys() = [deref(k) foreach k, _; :_data if deref(k) !is null]
function keys() = [deref(k) foreach k, _; :_data if deref(k) is not null]

/**
Gets an array of the values of this table.
Expand Down Expand Up @@ -171,7 +171,7 @@ class WeakValTable : WeakTableBase
{
local v = deref(:_data[keys[idx]])

if(v !is null)
if(v is not null)
return keys[idx], v
}
}
Expand Down Expand Up @@ -209,7 +209,7 @@ class WeakValTable : WeakTableBase
/**
Gets an array of the values (dereferenced) of this table.
*/
function values() = [deref(v) foreach _, v; :_data if deref(v) !is null]
function values() = [deref(v) foreach _, v; :_data if deref(v) is not null]

/**
Normalizes the table by removing any key-value pairs where the value has been collected. This is usually called
Expand Down Expand Up @@ -266,7 +266,7 @@ class WeakKeyValTable : WeakTableBase
{
local v = deref(:_data[keys[idx]])

if(v !is null)
if(v is not null)
return deref(keys[idx]), v
}
}
Expand Down Expand Up @@ -299,12 +299,12 @@ class WeakKeyValTable : WeakTableBase
/**
Gets an array of the keys (dereferenced) of this table.
*/
function keys() = [deref(k) foreach k, _; :_data if deref(k) !is null]
function keys() = [deref(k) foreach k, _; :_data if deref(k) is not null]

/**
Gets an array of the values (dereferenced) of this table.
*/
function values() = [deref(v) foreach _, v; :_data if deref(v) !is null]
function values() = [deref(v) foreach _, v; :_data if deref(v) is not null]

/**
Normalizes the table by removing any key-value pairs where the key or value have been collected. This is usually
Expand Down
4 changes: 2 additions & 2 deletions src/croc/stdlib/serialization.croc
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ local class Serializer
}

local method = SerializeMethods[typeof(val)]
assert(method !is null, "t: " ~ typeof(val))
assert(method is not null, "t: " ~ typeof(val))
return :(method)(val)
}

Expand Down Expand Up @@ -508,7 +508,7 @@ local class Deserializer
throw ValueError("Malformed data (expected object of type '{}' but found '{}' instead)".format(r))
}

if(typeof(val) !is w)
if(typeof(val) is not w)
{
throw ValueError("Malformed data (expected type '{}' but found a backref to type '{}' instead)".format(
w, niceTypeof(val)))
Expand Down
4 changes: 2 additions & 2 deletions src/croc/stdlib/stream.croc
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ class TextReader

#:_chunks = 0

while outer(:_string !is "")
while outer(:_string is not "")
{
foreach(pos, c; :_string)
{
Expand Down Expand Up @@ -1294,7 +1294,7 @@ class NativeStream : Stream
*/
override this(stream: nativeobj, caps: string)
{
if(hidden(with this, "handle") !is null)
if(hidden(with this, "handle") is not null)
throw StateError("Attempting to call constructor on an already-initialized stream")

nativeStreamCtor(this, stream, caps)
Expand Down
14 changes: 7 additions & 7 deletions tools/depgrapher.croc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import string: StringBuffer

function as_(c: class) =
\i: instance ->
(i as c) !is null
(i as c) is not null

local cats =
{
Expand Down Expand Up @@ -269,7 +269,7 @@ digraph d

function cycleColor(c)
{
if(c !in cycleColors)
if(c not in cycleColors)
{
// local r, g, b =
cycleColors[c] = "\"#{:x2}{:x2}{:x2}\"".format(math.rand(128) + 127, math.rand(128) + 127, math.rand(128) + 127)
Expand All @@ -282,7 +282,7 @@ digraph d
{
if(cat is :ignore)
continue
else if(cat !is :uncat)
else if(cat is not :uncat)
{
ret.append(@'
subgraph cluster_' ~ cat.name ~ @'
Expand All @@ -299,7 +299,7 @@ digraph d
foreach(mod; cat.modules)
ret.formatln("\t\"{}\" [style = filled, fillcolor = {}]", mod.name, mod.cycle ? cycleColor(mod.cycle) : "grey")

if(cat !is :uncat)
if(cat is not :uncat)
ret.formatln("\t}")

foreach(mod; cat.modules)
Expand Down Expand Up @@ -355,7 +355,7 @@ digraph d

foreach(w, _; v.deps)
{
if(w !in index)
if(w not in index)
{
tarjan(w)
lowlink[v] = min(lowlink[v], lowlink[w])
Expand All @@ -372,7 +372,7 @@ digraph d
{
local n = S.pop()
cycle.append(n)
} while(n !is v)
} while(n is not v)

if(#cycle > 1)
foreach(mod; cycle)
Expand All @@ -381,7 +381,7 @@ digraph d
}

foreach(mod; :allModules)
if(mod !in index)
if(mod not in index)
tarjan(mod)

hash.clear(index)
Expand Down

0 comments on commit 29240c5

Please sign in to comment.