Rename a few AST nodes to use the pattern DefineX

This ensures all these nodes use the same naming pattern
(DefineAttribute, DefineMethod, etc), instead of sometimes being called
DefineX while other times being called XDefinition.
parent 81a8fd1e
Pipeline #106690979 passed with stages
in 40 minutes and 59 seconds
......@@ -235,7 +235,7 @@ impl Node for Lambda {
}
# A method created using the `def` keyword.
object MethodDefinition {
object DefineMethod {
# The name of the method.
@name: String
......@@ -317,14 +317,14 @@ object MethodDefinition {
}
}
impl Node for MethodDefinition {
impl Node for DefineMethod {
def location -> SourceLocation {
@location
}
}
# A required method created using the `def` keyword.
object RequiredMethodDefinition {
object DefineRequiredMethod {
# The name of the method.
@name: String
......@@ -396,7 +396,7 @@ object RequiredMethodDefinition {
}
}
impl Node for RequiredMethodDefinition {
impl Node for DefineRequiredMethod {
def location -> SourceLocation {
@location
}
......
......@@ -6,7 +6,7 @@ import std::compiler::ast::variables::Constant
import std::compiler::source_location::SourceLocation
# A named object defined using the "object" keyword.
object ObjectDefinition {
object DefineObject {
# The name of the defined object.
@name: Constant
......@@ -47,14 +47,14 @@ object ObjectDefinition {
}
}
impl Node for ObjectDefinition {
impl Node for DefineObject {
def location -> SourceLocation {
@location
}
}
# The definition of an attribute in an object.
object AttributeDefinition {
object DefineAttribute {
# The name of the attribute.
@name: String
......@@ -81,14 +81,14 @@ object AttributeDefinition {
}
}
impl Node for AttributeDefinition {
impl Node for DefineAttribute {
def location -> SourceLocation {
@location
}
}
# A trait defined using the "trait" keyword.
object TraitDefinition {
object DefineTrait {
# The name of the trait that is defined.
@name: Constant
......@@ -139,7 +139,7 @@ object TraitDefinition {
}
}
impl Node for TraitDefinition {
impl Node for DefineTrait {
def location -> SourceLocation {
@location
}
......
......@@ -215,12 +215,12 @@ object Parser {
ImportAlias.new(name: token.value, location: token.location)
}
def object_definition(token: Token) !! ParseError -> ObjectDefinition {
def object_definition(token: Token) !! ParseError -> DefineObject {
let name = constant_from_token(try token_of_type('constant'))
let params = try type_parameter_definitions
let body = try next_as_restricted_body
ObjectDefinition.new(
DefineObject.new(
name: name,
type_parameters: params,
body: body,
......@@ -228,22 +228,22 @@ object Parser {
)
}
def attribute_definition(token: Token) !! ParseError -> AttributeDefinition {
def attribute_definition(token: Token) !! ParseError -> DefineAttribute {
try token_of_type('colon')
let type = try type(next_token)
AttributeDefinition
DefineAttribute
.new(name: token.value, type: type, location: token.location)
}
def trait_definition(token: Token) !! ParseError -> TraitDefinition {
def trait_definition(token: Token) !! ParseError -> DefineTrait {
let name = constant_from_token(try token_of_type('constant'))
let params = try type_parameter_definitions
let required_traits = try required_traits
let body = try next_as_restricted_body
TraitDefinition.new(
DefineTrait.new(
name: name,
type_parameters: params,
required_traits: required_traits,
......@@ -302,7 +302,7 @@ object Parser {
let return_type = try optional_return_type
(peek_token.type == 'curly_open').if_false {
return RequiredMethodDefinition.new(
return DefineRequiredMethod.new(
name: name,
type_parameters: type_params,
arguments: arguments,
......@@ -313,7 +313,7 @@ object Parser {
)
}
MethodDefinition.new(
DefineMethod.new(
name: name,
type_parameters: type_params,
arguments: arguments,
......
......@@ -226,7 +226,7 @@ test.group('Parsing literls') do (g) {
test.group('Parsing object definitions') do (g) {
g.test('Parsing an empty body') {
let node = parse_as(input: 'object A {}', type: ObjectDefinition)
let node = parse_as(input: 'object A {}', type: DefineObject)
assert.equal(node.name.name, 'A')
assert.equal(node.name.location.column, 8)
......@@ -238,7 +238,7 @@ test.group('Parsing object definitions') do (g) {
g.test('Parsing an object definition with type parameters') {
let node = parse_as(
input: 'object A!(One: A, Two: B + C) {}',
type: ObjectDefinition
type: DefineObject
)
let params = node.type_parameters
......@@ -287,19 +287,19 @@ test.group('Parsing object definitions') do (g) {
g.test('Parsing an object containing a method') {
let node =
parse_as(input: 'object A { def foo {} }', type: ObjectDefinition)
parse_as(input: 'object A { def foo {} }', type: DefineObject)
assert_instance_of(node.body.children[0]!, MethodDefinition)
assert_instance_of(node.body.children[0]!, DefineMethod)
}
g.test('Parsing an object containing attribute definitions') {
let node =
parse_as(input: 'object A { @a: A @b: B }', type: ObjectDefinition)
parse_as(input: 'object A { @a: A @b: B }', type: DefineObject)
assert.equal(node.body.children.length, 2)
let attr1 = node.body.children[0] as AttributeDefinition
let attr2 = node.body.children[1] as AttributeDefinition
let attr1 = node.body.children[0] as DefineAttribute
let attr2 = node.body.children[1] as DefineAttribute
assert.equal(attr1.name, '@a')
assert.equal((attr1.type as Constant).name, 'A')
......@@ -311,7 +311,7 @@ test.group('Parsing object definitions') do (g) {
test.group('Parsing trait definitions') do (g) {
g.test('Parsing an empty body') {
let node = parse_as(input: 'trait A {}', type: TraitDefinition)
let node = parse_as(input: 'trait A {}', type: DefineTrait)
assert.equal(node.name.name, 'A')
assert.equal(node.name.location.column, 7)
......@@ -323,7 +323,7 @@ test.group('Parsing trait definitions') do (g) {
g.test('Parsing a trait definition with type parameters') {
let node = parse_as(
input: 'trait A!(One: A, Two: B + C) {}',
type: TraitDefinition
type: DefineTrait
)
let params = node.type_parameters
......@@ -347,7 +347,7 @@ test.group('Parsing trait definitions') do (g) {
}
g.test('Parsing a list of required traits') {
let node = parse_as(input: 'trait A: B + C {}', type: TraitDefinition)
let node = parse_as(input: 'trait A: B + C {}', type: DefineTrait)
let traits = node.required_traits
......@@ -386,20 +386,20 @@ test.group('Parsing trait definitions') do (g) {
g.test('Parsing a trait containing a method') {
let node =
parse_as(input: 'trait A { def foo {} }', type: TraitDefinition)
parse_as(input: 'trait A { def foo {} }', type: DefineTrait)
assert_instance_of(node.body.children[0]!, MethodDefinition)
assert_instance_of(node.body.children[0]!, DefineMethod)
}
g.test('Parsing a trait with a required method') {
let node = parse_as(
input: 'trait A { def foo(a: A) !! B -> C }',
type: TraitDefinition
type: DefineTrait
)
let method = node.body.children[0]! as RequiredMethodDefinition
let method = node.body.children[0]! as DefineRequiredMethod
assert_instance_of(method, RequiredMethodDefinition)
assert_instance_of(method, DefineRequiredMethod)
assert.equal(method.name, 'foo')
assert.equal(method.arguments.length, 1)
......@@ -503,7 +503,7 @@ test.group('Parsing implementation blocks') do (g) {
let node =
parse_as(input: 'impl A { def foo {} }', type: ReopenObject)
assert_instance_of(node.body.children[0]!, MethodDefinition)
assert_instance_of(node.body.children[0]!, DefineMethod)
}
}
......@@ -1290,7 +1290,7 @@ test.group('Parsing variable definitions') do (g) {
test.group('Parsing method definitions') do (g) {
g.test('Parsing a simple method') {
let node = parse_as(input: 'def foo { 10 }', type: MethodDefinition)
let node = parse_as(input: 'def foo { 10 }', type: DefineMethod)
assert.equal(node.name, 'foo')
assert.equal(node.body.children.length, 1)
......@@ -1304,7 +1304,7 @@ test.group('Parsing method definitions') do (g) {
}
g.test('Parsing a method with dynamically typed arguments') {
let node = parse_as(input: 'def foo(a, b) {}', type: MethodDefinition)
let node = parse_as(input: 'def foo(a, b) {}', type: DefineMethod)
assert.equal(node.arguments.length, 2)
......@@ -1316,7 +1316,7 @@ test.group('Parsing method definitions') do (g) {
}
g.test('Parsing a method with statically typed arguments') {
let node = parse_as(input: 'def foo(a: A, b: B) {}', type: MethodDefinition)
let node = parse_as(input: 'def foo(a: A, b: B) {}', type: DefineMethod)
assert.equal(node.arguments.length, 2)
......@@ -1328,26 +1328,26 @@ test.group('Parsing method definitions') do (g) {
}
g.test('Parsing a method with a throw type') {
let node = parse_as(input: 'def foo !! A {}', type: MethodDefinition)
let node = parse_as(input: 'def foo !! A {}', type: DefineMethod)
assert.equal((node.throw_type as Constant).name, 'A')
}
g.test('Parsing a method with a return type') {
let node = parse_as(input: 'def foo -> A {}', type: MethodDefinition)
let node = parse_as(input: 'def foo -> A {}', type: DefineMethod)
assert.equal((node.return_type as Constant).name, 'A')
}
g.test('Parsing a method with a throw and return type') {
let node = parse_as(input: 'def foo !! A -> B {}', type: MethodDefinition)
let node = parse_as(input: 'def foo !! A -> B {}', type: DefineMethod)
assert.equal((node.throw_type as Constant).name, 'A')
assert.equal((node.return_type as Constant).name, 'B')
}
g.test('Parsing a method with type parameters') {
let node = parse_as(input: 'def foo!(A, B) {}', type: MethodDefinition)
let node = parse_as(input: 'def foo!(A, B) {}', type: DefineMethod)
assert.equal(node.type_parameters.length, 2)
assert.equal(node.type_parameters[0].name, 'A')
......@@ -1355,28 +1355,28 @@ test.group('Parsing method definitions') do (g) {
}
g.test('Parsing a static method') {
let node = parse_as(input: 'static def foo {}', type: MethodDefinition)
let node = parse_as(input: 'static def foo {}', type: DefineMethod)
assert.equal(node.name, 'foo')
assert.true(node.static_method?)
}
g.test('Parsing a method with a mutable argument') {
let node = parse_as(input: 'def foo(mut a) {}', type: MethodDefinition)
let node = parse_as(input: 'def foo(mut a) {}', type: DefineMethod)
assert.equal(node.arguments[0].name, 'a')
assert.true(node.arguments[0].mutable?)
}
g.test('Parsing a method with a rest argument') {
let node = parse_as(input: 'def foo(*a) {}', type: MethodDefinition)
let node = parse_as(input: 'def foo(*a) {}', type: DefineMethod)
assert.equal(node.arguments[0].name, 'a')
assert.true(node.arguments[0].rest?)
}
g.test('Parsing a method with a mutable rest argument') {
let node = parse_as(input: 'def foo(mut *a) {}', type: MethodDefinition)
let node = parse_as(input: 'def foo(mut *a) {}', type: DefineMethod)
assert.equal(node.arguments[0].name, 'a')
assert.true(node.arguments[0].rest?)
......
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