Skip to content

Commit

Permalink
Fix type alias highlighting in promptfiddle
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniosarosi committed Jan 17, 2025
1 parent 243c834 commit 23e1015
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions typescript/codemirror-lang-baml/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export const BAMLLanguage = LRLanguage.define({
ClassDecl: t.keyword,
'ClassDecl/IdentifierDecl': t.typeName,

TypeAliasDecl: t.keyword,
'TypeAliasDecl/IdentifierDecl': t.typeName,

ClientDecl: t.keyword,
'ClientDecl/IdentifierDecl': t.typeName,

Expand Down Expand Up @@ -122,6 +125,7 @@ const exampleCompletion = BAMLLanguage.data.of({
snippetCompletion('template_string MyString(${arg1}: string) #"\n A jinja string\n"#', {
label: 'template_string',
}),
snippetCompletion('type ${AliasName} = ${TypeExpr};', { label: 'type alias' }),
],
})

Expand Down
15 changes: 10 additions & 5 deletions typescript/codemirror-lang-baml/src/syntax.grammar
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
@top Baml { Decl* }

Decl { ClassDecl | EnumDecl | FunctionDecl | ClientDecl | TemplateStringDecl | TestDecl }
Decl { ClassDecl | EnumDecl | FunctionDecl | ClientDecl | TemplateStringDecl | TestDecl | TypeAliasDecl }

ClassDecl { "class" IdentifierDecl "{" (BlockAttribute | ClassField)* "}" }

ClassField {
IdentifierDecl TypeExpr FieldAttribute*
}

TypeAliasDecl {
"type" IdentifierDecl "=" TypeExpr
}

TypeExpr { ComplexTypeExpr | UnionTypeExpr }
ComplexTypeExpr {
"(" UnionTypeExpr ")" |
Expand Down Expand Up @@ -51,7 +56,7 @@ ClientDecl {
}

TestDecl {
"test" IdentifierDecl "{" (BlockAttribute | TupleValue)* "}"
"test" IdentifierDecl "{" (BlockAttribute | TupleValue)* "}"
}

LiteralDecl { NumericLiteral | QuotedString | UnquotedString }
Expand Down Expand Up @@ -87,15 +92,15 @@ TemplateStringDecl {
whitespace { $[ \n\r\t] }

UnquotedStringChar { ![#@{}()[\]<>,'\n\r\t/ ]}

TrailingComment { "//" ![\n]* }
MultilineComment { "{//"![]*"//}" }

"{" "}" "[" "]"
}

@skip {
whitespace | MultilineComment | TrailingComment
whitespace | MultilineComment | TrailingComment
}

@skip {} {
Expand All @@ -108,4 +113,4 @@ TemplateStringDecl {

}

@detectDelim
@detectDelim

0 comments on commit 23e1015

Please sign in to comment.