Use String for DefineObject and DefineTrait names

This keeps the type consistent with other AST nodes such as
DefineMethod.
parent 42bc9b0b
Pipeline #107413063 passed with stages
in 15 minutes and 58 seconds
......@@ -8,7 +8,7 @@ import std::compiler::source_location::SourceLocation
# A named object defined using the "object" keyword.
object DefineObject {
# The name of the defined object.
@name: Constant
@name: String
# The type parameters of the defined object.
@type_parameters: Array!(TypeParameter)
......@@ -20,7 +20,7 @@ object DefineObject {
@location: SourceLocation
def init(
name: Constant,
name: String,
type_parameters: Array!(TypeParameter),
body: Body,
location: SourceLocation
......@@ -32,7 +32,7 @@ object DefineObject {
}
# Returns the name of this object.
def name -> Constant {
def name -> String {
@name
}
......@@ -90,7 +90,7 @@ impl Node for DefineAttribute {
# A trait defined using the "trait" keyword.
object DefineTrait {
# The name of the trait that is defined.
@name: Constant
@name: String
# The type parameters of the trait.
@type_parameters: Array!(TypeParameter)
......@@ -105,7 +105,7 @@ object DefineTrait {
@location: SourceLocation
def init(
name: Constant,
name: String,
type_parameters: Array!(TypeParameter),
required_traits: Array!(Constant),
body: Body,
......@@ -119,7 +119,7 @@ object DefineTrait {
}
# Returns the name of this object.
def name -> Constant {
def name -> String {
@name
}
......
......@@ -216,12 +216,12 @@ object Parser {
}
def object_definition(token: Token) !! ParseError -> DefineObject {
let name = constant_from_token(try token_of_type('constant'))
let name = try token_of_type('constant')
let params = try type_parameter_definitions
let body = try next_as_restricted_body
DefineObject.new(
name: name,
name: name.value,
type_parameters: params,
body: body,
location: token.location
......@@ -238,13 +238,13 @@ object Parser {
}
def trait_definition(token: Token) !! ParseError -> DefineTrait {
let name = constant_from_token(try token_of_type('constant'))
let name = try token_of_type('constant')
let params = try type_parameter_definitions
let required_traits = try required_traits
let body = try next_as_restricted_body
DefineTrait.new(
name: name,
name: name.value,
type_parameters: params,
required_traits: required_traits,
body: body,
......
......@@ -228,9 +228,7 @@ test.group('Parsing object definitions') do (g) {
g.test('Parsing an empty body') {
let node = parse_as(input: 'object A {}', type: DefineObject)
assert.equal(node.name.name, 'A')
assert.equal(node.name.location.column, 8)
assert.equal(node.name, 'A')
assert.true(node.body.children.empty?)
assert.equal(node.body.location.column, 10)
}
......@@ -313,9 +311,7 @@ test.group('Parsing trait definitions') do (g) {
g.test('Parsing an empty body') {
let node = parse_as(input: 'trait A {}', type: DefineTrait)
assert.equal(node.name.name, 'A')
assert.equal(node.name.location.column, 7)
assert.equal(node.name, 'A')
assert.true(node.body.children.empty?)
assert.equal(node.body.location.column, 9)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment