Skip to content

Commit

Permalink
Merge pull request #359 from flintlang/revert-354-trait_specification…
Browse files Browse the repository at this point in the history
…_contracts

Revert "Trait specification contracts"
  • Loading branch information
bearbin authored Sep 7, 2018
2 parents ac580e9 + f379e0c commit 177163a
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 86 deletions.
7 changes: 0 additions & 7 deletions Sources/AST/ASTDumper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,6 @@ public class ASTDumper {
writeNode("ContractDeclaration") {
self.dump(contractDeclaration.contractToken)
self.dump(contractDeclaration.identifier)
if !contractDeclaration.conformances.isEmpty {
self.writeNode("Conforms to") {
for traitIdentifier in contractDeclaration.conformances {
self.dump(traitIdentifier)
}
}
}
if !contractDeclaration.states.isEmpty {
self.dump(contractDeclaration.states)
}
Expand Down
9 changes: 3 additions & 6 deletions Sources/AST/Declaration/ContractDeclaration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public struct ContractDeclaration: ASTNode {

public var contractToken: Token
public var identifier: Identifier
public var conformances: [Identifier]
public var states: [TypeState]
public var members: [ContractMember]

Expand Down Expand Up @@ -47,19 +46,17 @@ public struct ContractDeclaration: ASTNode {
return EnumDeclaration(enumToken: enumToken, identifier: stateEnumIdentifier, type: intType, cases: cases)
}

public init(contractToken: Token, identifier: Identifier, conformances: [Identifier], states: [TypeState], members: [ContractMember]) {
public init(contractToken: Token, identifier: Identifier, states: [TypeState], members: [ContractMember]) {
self.identifier = identifier
self.members = members
self.conformances = conformances
self.states = states
self.contractToken = contractToken
}

// MARK: - ASTNode
public var description: String {
let conformsText = conformances.map ({ $0.description }).joined(separator: ", ")
let stateText = states.map({ $0.description }).joined(separator: ", ")
let headText = "contract \(identifier): \(conformsText) \(stateText)"
let stateText = states.map({ $0.description }).joined(separator: " ")
let headText = "contract \(identifier) \(stateText)"
let memberText = members.map({ $0.description }).joined(separator: "\n")
return "\(headText) {\(memberText)}"
}
Expand Down
20 changes: 5 additions & 15 deletions Sources/Parser/Parser+Components.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ extension Parser {

func parseIdentifierGroup() throws -> (identifiers: [Identifier], closeBracketToken: Token) {
try consume(.punctuation(.openBracket), or: .badDeclaration(at: latestSource))
guard let closingIndex = indexOfFirstAtCurrentDepth([.punctuation(.closeBracket)]) else {
throw raise(.expectedCloseParen(at: latestSource))
}
let identifiers = try parseIdentifierList(upTo: closingIndex)
let identifiers = try parseIdentifierList()
let closeBracketToken = try consume(.punctuation(.closeBracket), or: .expectedCloseParen(at: latestSource))

return (identifiers, closeBracketToken)
}

func parseIdentifierList(upTo closingIndex: Int) throws -> [Identifier] {
func parseIdentifierList() throws -> [Identifier] {
var identifiers = [Identifier]()

guard let closingIndex = indexOfFirstAtCurrentDepth([.punctuation(.closeBracket)]) else {
return []
}
while currentIndex < closingIndex {
identifiers.append(try parseIdentifier())
if currentIndex < closingIndex {
Expand Down Expand Up @@ -158,15 +157,6 @@ extension Parser {
return (callerCapabilities, closeBracketToken)
}

// MARK: Conformances
func parseConformances() throws -> [Identifier] {
try consume(.punctuation(.colon), or: .expectedConformance(at: latestSource))
guard let endOfConformances = indexOfFirstAtCurrentDepth([.punctuation(.openBracket), .newline, .punctuation(.openBrace)]) else {
throw raise(.expectedConformance(at: latestSource))
}
return try parseIdentifierList(upTo: endOfConformances)
}

// MARK: Type State
func parseTypeStateGroup() throws -> [TypeState] {
let (identifiers, _) = try parseIdentifierGroup()
Expand Down
10 changes: 4 additions & 6 deletions Sources/Parser/Parser+Declaration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,17 @@ extension Parser {
func parseContractDeclaration() throws -> ContractDeclaration {
let contractToken = try consume(.contract, or: .badTopLevelDeclaration(at: latestSource))
let identifier = try parseIdentifier()
var states: [TypeState] = []
var conformances: [Identifier] = []
if currentToken?.kind == .punctuation(.colon) {
conformances = try parseConformances()
}
let states: [TypeState]
if currentToken?.kind == .punctuation(.openBracket) {
states = try parseTypeStateGroup()
} else {
states = []
}
try consume(.punctuation(.openBrace), or: .leftBraceExpected(in: "contract declaration", at: latestSource))
let members = try parseContractMembers(enclosingType: identifier.name)
try consume(.punctuation(.closeBrace), or: .rightBraceExpected(in: "contract declaration", at: latestSource))

return ContractDeclaration(contractToken: contractToken, identifier: identifier, conformances: conformances, states: states, members: members)
return ContractDeclaration(contractToken: contractToken, identifier: identifier, states: states, members: members)
}

func parseStructDeclaration() throws -> StructDeclaration {
Expand Down
1 change: 0 additions & 1 deletion Sources/Parser/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public class Parser {
switch tld {
case .contractDeclaration(let contract):
environment.addContract(contract)
// TODO: Add conformances here
if contract.isStateful {
environment.addEnum(contract.stateEnum)
}
Expand Down
3 changes: 0 additions & 3 deletions Sources/Parser/ParserError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ extension Diagnostic {
static func expectedBehaviourSeparator(at sourceLocation: SourceLocation) -> Diagnostic {
return Diagnostic(severity: .error, sourceLocation: sourceLocation, message: "Expected behaviour separator")
}
static func expectedConformance(at sourceLocation: SourceLocation) -> Diagnostic {
return Diagnostic(severity: .error, sourceLocation: sourceLocation, message: "Expected conformance")
}

// MARK: Statement
static func expectedStatement(at sourceLocation: SourceLocation) -> Diagnostic {
Expand Down
44 changes: 0 additions & 44 deletions Tests/ParserTests/conformance.flint

This file was deleted.

7 changes: 3 additions & 4 deletions docs/grammar.abnf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ topLevelDeclaration = contractDeclaration
/ enumDeclaration;

; CONTRACTS
contractDeclaration = %s"contract" SP identifier [":" WSP identifierList ] SP [identifierGroup] SP "{" *(WSP variableDeclaration CRLF) "}";
contractDeclaration = %s"contract" SP identifier SP [identifierGroup] SP "{" *(WSP variableDeclaration CRLF) "}";

; VARIABLES
variableDeclaration = [*(modifier SP)] SP (%s"var" / %s"let") SP identifier typeAnnotation [WSP "=" WSP expression];
Expand Down Expand Up @@ -55,11 +55,10 @@ contractBehaviourMember = functionDeclaration
/ fallbackDeclaration;

; ACCESS GROUPS
stateGroup = "@" identifierGroup;
stateGroup = "@" identifierGroup;
callerCapabilityBinding = identifier WSP "<-";
callerCapabilityGroup = identifierGroup;
identifierGroup = "(" identifierList ")";
identifierList = identifier *("," WSP identifier)
identifierGroup = "(" identifier *("," WSP identifier) ")";

; FUNCTIONS + INITIALIZER + FALLBACK
functionDeclaration = functionHead SP identifier parameterList [returnType] codeBlock;
Expand Down

0 comments on commit 177163a

Please sign in to comment.