이 가이드는 다양한 에디터에서 T-Ruby 구문 강조를 설정하고 커스터마이징하는 방법을 설명합니다.
T-Ruby 구문 강조는 다음 요소들을 시각적으로 구분합니다:
- 키워드:
type,interface,def,end - 타입:
String,Integer,Boolean,Array,Hash등 - 타입 어노테이션: 매개변수 및 반환 타입 선언
- 타입 연산자:
|(유니온),&(인터섹션),<>(제네릭) - 주석:
#한 줄 주석 - 문자열: 작은따옴표 및 큰따옴표
- 숫자: 정수 및 부동소수점
- 심볼:
:symbol_name
type UserId = String # 'type' 키워드, 'UserId' 타입명
type Age = Integer # '=' 연산자, 내장 타입
type UserMap = Hash<UserId, User> # 제네릭 타입
interface Printable # 'interface' 키워드, 인터페이스명
to_string: String # 멤버명, 타입 어노테이션
print: void
end # 'end' 키워드
def greet(name: String): String # 함수명, 타입이 있는 매개변수, 반환 타입
"안녕하세요, #{name}님!"
end
def process(items: Array<String>, count: Integer): Hash<String, Integer>
# 제네릭 타입도 강조됨
end
type StringOrInt = String | Integer # '|'를 사용한 유니온 타입
type ReadWrite = Readable & Writable # '&'를 사용한 인터섹션 타입
type MaybeString = String | nil # Nullable 타입
VS Code 확장은 자동으로 구문 강조를 제공합니다. 다음에서 설치:
- VS Code 마켓플레이스: "T-Ruby" 검색
- 또는
editors/vscode디렉토리에서 수동 설치
테마 커스터마이징:
settings.json에 추가:
{
"editor.tokenColorCustomizations": {
"[사용 중인 테마]": {
"textMateRules": [
{
"scope": "keyword.declaration.type.t-ruby",
"settings": {
"foreground": "#C678DD"
}
},
{
"scope": "entity.name.type.t-ruby",
"settings": {
"foreground": "#E5C07B"
}
},
{
"scope": "support.type.builtin.t-ruby",
"settings": {
"foreground": "#56B6C2"
}
}
]
}
}
}구문 파일을 설정에 복사:
# Vim
cp editors/vim/syntax/truby.vim ~/.vim/syntax/
cp editors/vim/ftdetect/truby.vim ~/.vim/ftdetect/
# Neovim
cp editors/vim/syntax/truby.vim ~/.config/nvim/syntax/
cp editors/vim/ftdetect/truby.vim ~/.config/nvim/ftdetect/색상 커스터마이징:
~/.vimrc 또는 init.vim에 추가:
" 사용자 정의 T-Ruby 강조 색상
augroup truby_colors
autocmd!
autocmd ColorScheme * highlight tRubyKeyword ctermfg=176 guifg=#C678DD
autocmd ColorScheme * highlight tRubyTypeName ctermfg=180 guifg=#E5C07B
autocmd ColorScheme * highlight tRubyBuiltinType ctermfg=73 guifg=#56B6C2
autocmd ColorScheme * highlight tRubyInterface ctermfg=114 guifg=#98C379
augroup ENDLua를 사용하는 Neovim:
vim.api.nvim_create_autocmd("ColorScheme", {
callback = function()
vim.api.nvim_set_hl(0, "tRubyKeyword", { fg = "#C678DD" })
vim.api.nvim_set_hl(0, "tRubyTypeName", { fg = "#E5C07B" })
vim.api.nvim_set_hl(0, "tRubyBuiltinType", { fg = "#56B6C2" })
end,
})| 요소 | 스코프 |
|---|---|
type, interface 키워드 |
keyword.declaration.type.t-ruby |
| 타입명 | entity.name.type.t-ruby |
| 내장 타입 | support.type.builtin.t-ruby |
| 함수명 | entity.name.function.t-ruby |
| 매개변수 | variable.parameter.t-ruby |
타입 연산자 (|, &) |
keyword.operator.type.t-ruby |
| 제네릭 괄호 | punctuation.definition.generic.t-ruby |
| 요소 | 그룹 |
|---|---|
| 키워드 | tRubyKeyword |
| 타입명 | tRubyTypeName |
| 내장 타입 | tRubyBuiltinType |
| 인터페이스 | tRubyInterface |
| 인터페이스 멤버 | tRubyInterfaceMember |
| 타입 어노테이션 | tRubyTypeAnnotation |
| 반환 타입 | tRubyReturnType |
| 타입 연산자 | tRubyTypeOperator |
# simple.trb - 기본 T-Ruby 구문
type UserId = String
type Score = Integer
def get_score(user_id: UserId): Score
100
end
# complex.trb - 고급 T-Ruby 구문
type UserId = String
type Email = String
type Timestamp = Integer
interface Identifiable
id: UserId
end
interface Timestamped
created_at: Timestamp
updated_at: Timestamp
end
interface User
id: UserId
name: String
email: Email
age: Integer | nil
roles: Array<String>
metadata: Hash<String, String>
end
type UserWithTimestamp = User & Timestamped
def create_user(name: String, email: Email): User
# 구현
end
def find_user(id: UserId): User | nil
# 구현
end
def get_users_by_role(role: String): Array<User>
# 구현
end
- 파일 확장자 확인:
.trb또는.d.trb여야 함 - 파일타입 감지 확인:
- VS Code: 우측 하단 상태바 확인
- Vim:
:set filetype?실행
- 구문 파일 로드 확인:
- Vim:
:echo exists("g:truby_syntax_loaded")
- Vim:
- 컬러 스킴 호환성 확인
- 하이라이트 그룹 링크 확인:
- Vim:
:highlight tRubyKeyword
- Vim:
- 사용자 정의 색상으로 오버라이드 (위 참조)
- 복잡한 중첩 타입은 구문 재로드가 필요할 수 있음:
- Vim:
:syntax sync fromstart
- Vim:
- 파싱을 방해하는 구문 오류 확인
T-Ruby 구문은 One Dark 및 유사한 테마와 잘 작동하도록 설계되었습니다:
| 요소 | One Dark 색상 |
|---|---|
| 키워드 | #C678DD (보라) |
| 타입 | #E5C07B (노랑) |
| 내장 타입 | #56B6C2 (청록) |
| 함수 | #61AFEF (파랑) |
| 문자열 | #98C379 (초록) |
| 요소 | Dracula 색상 |
|---|---|
| 키워드 | #FF79C6 (분홍) |
| 타입 | #8BE9FD (청록) |
| 함수 | #50FA7B (초록) |
| 문자열 | #F1FA8C (노랑) |
구문 강조 문제:
- GitHub Issues: https://github.com/type-ruby/t-ruby/issues
- 보고 시 에디터 버전과 테마 이름을 포함해 주세요