Skip to content

Commit

Permalink
Merge pull request #1255 from hylo-lang/nil-literal
Browse files Browse the repository at this point in the history
Remove `NilLiteralExpr`
  • Loading branch information
kyouko-taiga authored Dec 27, 2023
2 parents e1348cc + 65cccc1 commit bd02583
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 37 deletions.
7 changes: 0 additions & 7 deletions Sources/Core/AST/AST+Walk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ extension AST {
traverse(self[n] as! MatchExpr, notifying: &o)
case NameExpr.self:
traverse(self[n] as! NameExpr, notifying: &o)
case NilLiteralExpr.self:
traverse(self[n] as! NilLiteralExpr, notifying: &o)
case ParameterTypeExpr.self:
traverse(self[n] as! ParameterTypeExpr, notifying: &o)
case PragmaLiteralExpr.self:
Expand Down Expand Up @@ -542,11 +540,6 @@ extension AST {
walk(roots: n.arguments.map(\.value), notifying: &o)
}

/// Visits the children of `n` in pre-order, notifying `o` when a node is entered or left.
public func traverse<O: ASTWalkObserver>(
_ n: NilLiteralExpr, notifying o: inout O
) {}

/// Visits the children of `n` in pre-order, notifying `o` when a node is entered or left.
public func traverse<O: ASTWalkObserver>(
_ n: ParameterTypeExpr, notifying o: inout O
Expand Down
10 changes: 0 additions & 10 deletions Sources/Core/AST/Expr/NilLiteralExpr.swift

This file was deleted.

1 change: 0 additions & 1 deletion Sources/Core/AST/NodeIDs/NodeKind.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ extension NodeKind {
MapLiteralExpr.self,
MatchExpr.self,
NameExpr.self,
NilLiteralExpr.self,
ParameterTypeExpr.self,
PragmaLiteralExpr.self,
RemoteExpr.self,
Expand Down
1 change: 0 additions & 1 deletion Sources/FrontEnd/Parse/Lexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public struct Lexer: IteratorProtocol, Sequence {
case "let": token.kind = .`let`
case "match": token.kind = .`match`
case "namespace": token.kind = .`namespace`
case "nil": token.kind = .`nil`
case "operator": token.kind = .`operator`
case "postfix": token.kind = .`postfix`
case "prefix": token.kind = .`prefix`
Expand Down
6 changes: 0 additions & 6 deletions Sources/FrontEnd/Parse/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1661,12 +1661,6 @@ public enum Parser {
site: head.site))
return AnyExprID(expr)

case .nil:
// Nil literal.
_ = state.take()
let expr = state.insert(NilLiteralExpr(site: head.site))
return AnyExprID(expr)

case .under:
// Wildcard expression.
_ = state.take()
Expand Down
1 change: 0 additions & 1 deletion Sources/FrontEnd/Parse/Token.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public struct Token {
case `let`
case `match`
case `namespace`
case `nil`
case `operator`
case `poundElse`
case `poundElseif`
Expand Down
9 changes: 9 additions & 0 deletions StandardLibrary/Sources/Core/Optional.hylo
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ public type None<T> {

}

public extension Optional {

/// Returns a value denoting the absence of an instance.
public static fun none() -> Self {
None() as Optional
}

}

public conformance None: Regular {

// TODO: Remove when #1078 is implemented.
Expand Down
7 changes: 3 additions & 4 deletions Tests/HyloTests/LexerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ final class LexerTests: XCTestCase {
func testKeywords() {
let input: SourceFile = """
any break catch conformance continue do else extension for fun if import in infix init inout
let match namespace nil operator postfix prefix property private public remote return set
sink some spawn static subscript trait try type typealias var where while yield yielded
#if #else #elseif #endif
let match namespace operator postfix prefix property private public remote return set sink
some spawn static subscript trait try type typealias var where while yield yielded #if #else
#elseif #endif
"""

assert(
Expand All @@ -160,7 +160,6 @@ final class LexerTests: XCTestCase {
TokenSpecification(.`let`, "let"),
TokenSpecification(.`match`, "match"),
TokenSpecification(.`namespace`, "namespace"),
TokenSpecification(.`nil`, "nil"),
TokenSpecification(.`operator`, "operator"),
TokenSpecification(.`postfix`, "postfix"),
TokenSpecification(.`prefix`, "prefix"),
Expand Down
6 changes: 0 additions & 6 deletions Tests/HyloTests/ParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1160,12 +1160,6 @@ final class ParserTests: XCTestCase {
XCTAssertEqual(expr.value, "Hylo")
}

func testNilLiteralExpr() throws {
let input: SourceFile = "nil"
let (exprID, _) = try input.parse(with: Parser.parseExpr(in:))
XCTAssertEqual(exprID?.kind, .init(NilLiteralExpr.self))
}

func testPragmaLiteralExpr() throws {
let input: SourceFile = "#file"
let (exprID, ast) = try input.parse(with: Parser.parseExpr(in:))
Expand Down
2 changes: 1 addition & 1 deletion Tests/LibraryTests/TestCases/OptionalTests.hylo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public fun main() {
let y = if let i: Int = x { i.copy() } else { 0 }
precondition(y == 42)

&x = None()
&x = .none()
let z = if let i: Int = x { i.copy() } else { 0 }
precondition(z == 0)
}

0 comments on commit bd02583

Please sign in to comment.