Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/src/main/kotlin/tools/samt/cli/TypePrinter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal object TypePrinter {
appendLine(" ${bold("record")} ${yellow(record.name)}")
}
for (alias in samtPackage.aliases) {
appendLine(" ${bold("alias")} ${yellow(alias.name)} = ${gray(alias.fullyResolvedType?.humanReadableName ?: "Unknown")}")
appendLine(" ${bold("typealias")} ${yellow(alias.name)} = ${gray(alias.fullyResolvedType?.humanReadableName ?: "Unknown")}")
}
for (service in samtPackage.services) {
appendLine(" ${bold("service")} ${yellow(service.name)}")
Expand Down
8 changes: 4 additions & 4 deletions cli/src/test/kotlin/tools/samt/cli/ASTPrinterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ASTPrinterTest {

enum E { A, B, C }

alias B : E
typealias B = E

@Description("This is a service")
service MyService {
Expand Down Expand Up @@ -92,9 +92,9 @@ class ASTPrinterTest {
│ ├─IdentifierNode B <11:13>
│ └─IdentifierNode C <11:16>
├─TypeAliasNode <13:1>
│ ├─IdentifierNode B <13:7>
│ └─BundleIdentifierNode E <13:11>
│ └─IdentifierNode E <13:11>
│ ├─IdentifierNode B <13:11>
│ └─BundleIdentifierNode E <13:15>
│ └─IdentifierNode E <13:15>
├─ServiceDeclarationNode <16:1>
│ ├─IdentifierNode MyService <16:9>
│ ├─RequestResponseOperationNode <17:3>
Expand Down
2 changes: 1 addition & 1 deletion lexer/src/main/kotlin/tools/samt/lexer/Lexer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ class Lexer private constructor(
"record" to { RecordToken(it) },
"enum" to { EnumToken(it) },
"service" to { ServiceToken(it) },
"alias" to { AliasToken(it) },
"typealias" to { TypealiasToken(it) },
"package" to { PackageToken(it) },
"import" to { ImportToken(it) },
"provide" to { ProvideToken(it) },
Expand Down
4 changes: 2 additions & 2 deletions lexer/src/main/kotlin/tools/samt/lexer/Tokens.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ sealed interface StaticToken: Token
data class RecordToken(override val location: Location): StaticToken
data class EnumToken(override val location: Location): StaticToken
data class ServiceToken(override val location: Location): StaticToken
data class AliasToken(override val location: Location): StaticToken
data class TypealiasToken(override val location: Location): StaticToken
data class PackageToken(override val location: Location): StaticToken
data class ImportToken(override val location: Location): StaticToken
data class ProvideToken(override val location: Location): StaticToken
Expand Down Expand Up @@ -79,7 +79,7 @@ fun getHumanReadableTokenName(key: KClass<out Token>): String = when (key) {
// StaticToken
EnumToken::class -> "enum"
ServiceToken::class -> "service"
AliasToken::class -> "alias"
TypealiasToken::class -> "typealias"
PackageToken::class -> "package"
ImportToken::class -> "import"
ProvideToken::class -> "provide"
Expand Down
4 changes: 2 additions & 2 deletions lexer/src/test/kotlin/tools/samt/lexer/LexerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ SAMT!""", stream.next()
record
enum
service
alias
typealias
package
import
provide
Expand Down Expand Up @@ -334,7 +334,7 @@ SAMT!""", stream.next()
assertIs<RecordToken>(stream.next())
assertIs<EnumToken>(stream.next())
assertIs<ServiceToken>(stream.next())
assertIs<AliasToken>(stream.next())
assertIs<TypealiasToken>(stream.next())
assertIs<PackageToken>(stream.next())
assertIs<ImportToken>(stream.next())
assertIs<ProvideToken>(stream.next())
Expand Down
8 changes: 4 additions & 4 deletions parser/src/main/kotlin/tools/samt/parser/Parser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Parser private constructor(
when (current) {
is RecordToken -> parseRecordDeclaration(annotations)
is EnumToken -> parseEnumDeclaration(annotations)
is AliasToken -> parseTypeAlias(annotations)
is TypealiasToken -> parseTypeAlias(annotations)
is ServiceToken -> parseServiceDeclaration(annotations)

else -> {
Expand All @@ -100,7 +100,7 @@ class Parser private constructor(
is PackageToken -> parsePackageDeclaration()
is RecordToken -> parseRecordDeclaration()
is EnumToken -> parseEnumDeclaration()
is AliasToken -> parseTypeAlias()
is TypealiasToken -> parseTypeAlias()
is ServiceToken -> parseServiceDeclaration()
is ProvideToken -> parseProviderDeclaration()
is ConsumeToken -> parseConsumerDeclaration()
Expand Down Expand Up @@ -214,9 +214,9 @@ class Parser private constructor(

private fun parseTypeAlias(annotations: List<AnnotationNode> = emptyList()): TypeAliasNode {
val start = currentStart
expect<AliasToken>()
expect<TypealiasToken>()
val name = parseIdentifier()
expect<ColonToken>()
expect<EqualsToken>()
val type = parseExpression()
return TypeAliasNode(locationFromStart(start), name, type, annotations)
}
Expand Down
22 changes: 11 additions & 11 deletions parser/src/test/kotlin/tools/samt/parser/ParserTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ class ParserTest {
val source = """
package aliases

alias A: String? ( foo(1..2.3..3) )
alias B: List<A?>?
alias C: Map<String, Integer> ( uniqueKeys((false)) )
typealias A = String? ( foo(1..2.3..3) )
typealias B = List<A?>?
typealias C = Map<String, Integer> ( uniqueKeys((false)) )
"""
val fileTree = parse(source)
assertPackage("aliases", fileTree.packageDeclaration)
Expand Down Expand Up @@ -266,8 +266,8 @@ class ParserTest {
val source = """
package aliases

alias A: String?
alias B: List<A?>?
typealias A = String?
typealias B = List<A?>?
"""
val fileTree = parse(source)
assertPackage("aliases", fileTree.packageDeclaration)
Expand All @@ -293,7 +293,7 @@ class ParserTest {
val source = """
package illegalAliases

alias A: List<>
typealias A = List<>
"""
val (fileTree, diagnostics) = parseWithRecoverableError(source)
assertEquals(
Expand Down Expand Up @@ -466,7 +466,7 @@ class ParserTest {
val source = """
package a

alias A: List<B
typealias A = List<B
"""
val exception = parseWithFatalError(source)
assertEquals("Expected '>' but reached end of file", exception.message)
Expand All @@ -477,7 +477,7 @@ class ParserTest {
val source = """
package a

alias A: List<B}
typealias A = List<B}
"""
val exception = parseWithFatalError(source)
assertEquals("Unexpected token '}', expected '>'", exception.message)
Expand All @@ -488,10 +488,10 @@ class ParserTest {
val source = """
package a

alias A 42.0
typealias A 42.0
"""
val exception = parseWithFatalError(source)
assertEquals("Unexpected token '42.0', expected ':'", exception.message)
assertEquals("Unexpected token '42.0', expected '='", exception.message)
}

@Test
Expand Down Expand Up @@ -693,7 +693,7 @@ class ParserTest {

@Password
@Encrypted
alias Password: String
typealias Password = String

@Foo
@Bar
Expand Down
16 changes: 8 additions & 8 deletions semantic/src/main/kotlin/tools/samt/semantic/SemanticModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class SemanticModelBuilder private constructor(

for (unresolvableAlias in workingSet) {
controller.getOrCreateContext(unresolvableAlias.declaration.location.source).error {
message("Could not resolve alias '${unresolvableAlias.name}', are there circular references?")
highlight("unresolved alias", unresolvableAlias.declaration.name.location)
message("Could not resolve type alias '${unresolvableAlias.name}', are there circular references?")
highlight("unresolved type alias", unresolvableAlias.declaration.name.location)
}
}
}
Expand Down Expand Up @@ -108,22 +108,22 @@ class SemanticModelBuilder private constructor(
}
is ServiceType -> {
controller.getOrCreateContext(typeReference.typeNode.location.source).error {
message("Alias cannot reference service")
highlight("alias", typeReference.typeNode.location)
message("Type alias cannot reference service")
highlight("type alias", typeReference.typeNode.location)
}
typeReference
}
is ProviderType -> {
controller.getOrCreateContext(typeReference.typeNode.location.source).error {
message("Alias cannot reference provider")
highlight("alias", typeReference.typeNode.location)
message("Type alias cannot reference provider")
highlight("type alias", typeReference.typeNode.location)
}
typeReference
}
is PackageType -> {
controller.getOrCreateContext(typeReference.typeNode.location.source).error {
message("Alias cannot reference package")
highlight("alias", typeReference.typeNode.location)
message("Type alias cannot reference package")
highlight("type alias", typeReference.typeNode.location)
}
typeReference
}
Expand Down
22 changes: 11 additions & 11 deletions semantic/src/test/kotlin/tools/samt/semantic/SemanticModelTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class SemanticModelTest {
}

enum E { }
alias E : Int
typealias E = Int
""".trimIndent()
parseAndCheck(
source to listOf(
Expand Down Expand Up @@ -508,7 +508,7 @@ class SemanticModelTest {
val source = """
package color

alias UShort: Int (0..256)
typealias UShort = Int (0..256)

record Color {
r: UShort
Expand All @@ -526,18 +526,18 @@ class SemanticModelTest {
val source = """
package color

alias A : Int
alias B : A // Int
alias C : B // Int
alias D : F // Cycle!
alias E : D // Cycle!
alias F : E // Cycle!
typealias A = Int
typealias B = A // Int
typealias C = B // Int
typealias D = F // Cycle!
typealias E = D // Cycle!
typealias F = E // Cycle!
""".trimIndent()
parseAndCheck(
source to listOf(
"Error: Could not resolve alias 'D', are there circular references?",
"Error: Could not resolve alias 'E', are there circular references?",
"Error: Could not resolve alias 'F', are there circular references?",
"Error: Could not resolve type alias 'D', are there circular references?",
"Error: Could not resolve type alias 'E', are there circular references?",
"Error: Could not resolve type alias 'F', are there circular references?",
)
)
}
Expand Down
3 changes: 2 additions & 1 deletion specification/ebnf.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion specification/examples/greeter.samt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import samt.stuff.*
package samt.greeter

// define type alias for names
alias Name : String(size(20..100))
typealias Name = String(size(20..100))

record GreetRequest {
name: Name
Expand Down
10 changes: 5 additions & 5 deletions specification/examples/parser_errors.samt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import package

import foo

alias Test : Int(0..1000000000000000000000000)
typealias Test = Int(0..1000000000000000000000000)

alias ^foobar : String
typealias ^foobar = String

alias ^ : String
typealias ^ = String

alias test : String(pattern("\n\x"))
typealias test = String(pattern("\n\x"))

package debug

Expand All @@ -31,4 +31,4 @@ enum Foo {
Baz
}

alias foo = String
typealias foo : String
2 changes: 1 addition & 1 deletion specification/examples/todo-service/common.samt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package tools.samt.examples.common

alias UUID: String ( pattern("[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}") )
typealias UUID = String ( pattern("[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}") )

record NotFoundFault extends Fault
record MissingPermissionsFault extends Fault
2 changes: 1 addition & 1 deletion specification/grammar.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ RecordField = { Annotation }, Identifier, ":", Expression;

EnumDeclaration = { Annotation }, "enum", Identifier, "{", [IdentifierList], "}";

TypeAliasDeclaration = { Annotation }, "alias", Identifier, ":", Expression;
TypeAliasDeclaration = { Annotation }, "typealias", Identifier, "=", Expression;

ServiceDeclaration = { Annotation }, "service", Identifier, "{", { OperationDeclaration | OnewayOperationDeclaration }, "}";

Expand Down