diff --git a/compiler/lexer.ts b/compiler/lexer.ts index 982ac7f..b1e26e5 100644 --- a/compiler/lexer.ts +++ b/compiler/lexer.ts @@ -1,7 +1,6 @@ import { Reporter } from "./info.ts"; import { Pos, Token } from "./token.ts"; - export class Lexer { private index = 0; private line = 1; @@ -77,12 +76,11 @@ export class Lexer { if (this.done()) { break; } - value += - { - n: "\n", - t: "\t", - "0": "\0", - }[this.current()] ?? this.current(); + value += { + n: "\n", + t: "\t", + "0": "\0", + }[this.current()] ?? this.current(); } else { value += this.current(); } @@ -132,6 +130,16 @@ export class Lexer { this.step(); return this.token("->", pos); } + if (first === ":") { + if (!this.done() && this.test(":")) { + this.step(); + if (!this.done() && this.test("<")) { + this.step(); + return this.token("::<", pos); + } + return this.token("::", pos); + } + } return this.token(first, pos); } if (this.test("/")) { diff --git a/editors/vim/syntax/slige.vim b/editors/vim/syntax/slige.vim index dd6da3a..188c068 100644 --- a/editors/vim/syntax/slige.vim +++ b/editors/vim/syntax/slige.vim @@ -26,6 +26,8 @@ syn match Operator '>=' syn match Operator '\.' syn match Operator ':' syn match Operator '->' +syn match Operator '::' +syn match Operator '::<' syn match Number '0' syn match Number '[1-9][0-9]*' diff --git a/editors/vscode/syntaxes/slige.tmLanguage.json b/editors/vscode/syntaxes/slige.tmLanguage.json index 70c5dbc..871b1aa 100644 --- a/editors/vscode/syntaxes/slige.tmLanguage.json +++ b/editors/vscode/syntaxes/slige.tmLanguage.json @@ -1,84 +1,84 @@ { - "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", - "name": "Slige", - "patterns": [ - { "include": "#keywords" }, - { "include": "#strings" }, - { "include": "#numbers" }, - { "include": "#operators" }, - { "include": "#punctuation" }, - { "include": "#functions" }, - { "include": "#idents" } - ], - "repository": { - "keywords": { - "patterns": [ - { - "name": "keyword.control.slige", - "match": "\\b(break|return|let|fn|loop|if|else|struct|import|or|and|not)\\b" - }, - { - "name": "constant.language.slige", - "match": "\\b(null|false|true)\\b" - }, - { - "name": "storage.type.slige", - "match": "\\b(int|string|bool)\\b" - } - ] - }, - "strings": { - "name": "string.quoted.double.slige", - "begin": "\"", - "end": "\"", - "patterns": [ - { - "name": "constant.character.escape.slige", - "match": "\\\\." - } - ] - }, - "numbers": { - "patterns": [ - { - "name": "constant.numeric.slige", - "match": "\\b0\\b" - }, - { - "name": "constant.numeric.slige", - "match": "\\b[1-9][0-9]*(\\.[0-9]+)?\\b" - }, - { - "name": "constant.numeric.slige", - "match": "\\b0x[0-9a-fA-F]+?\\b" - }, - { - "name": "constant.numeric.slige", - "match": "\\b0b[01]+?\\b" - } - ] - }, - "operators": { + "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", + "name": "Slige", + "patterns": [ + { "include": "#keywords" }, + { "include": "#strings" }, + { "include": "#numbers" }, + { "include": "#operators" }, + { "include": "#punctuation" }, + { "include": "#functions" }, + { "include": "#idents" } + ], + "repository": { + "keywords": { "patterns": [ { - "match": "\\+|\\-|\\*|\\/|=|(==)|(!=)|<|>|(<=)|(>=)|\\.|:|(\\->)", + "name": "keyword.control.slige", + "match": "\\b(break|return|let|fn|loop|if|else|struct|import|or|and|not)\\b" + }, + { + "name": "constant.language.slige", + "match": "\\b(null|false|true)\\b" + }, + { + "name": "storage.type.slige", + "match": "\\b(int|string|bool)\\b" + } + ] + }, + "strings": { + "name": "string.quoted.double.slige", + "begin": "\"", + "end": "\"", + "patterns": [ + { + "name": "constant.character.escape.slige", + "match": "\\\\." + } + ] + }, + "numbers": { + "patterns": [ + { + "name": "constant.numeric.slige", + "match": "\\b0\\b" + }, + { + "name": "constant.numeric.slige", + "match": "\\b[1-9][0-9]*(\\.[0-9]+)?\\b" + }, + { + "name": "constant.numeric.slige", + "match": "\\b0x[0-9a-fA-F]+?\\b" + }, + { + "name": "constant.numeric.slige", + "match": "\\b0b[01]+?\\b" + } + ] + }, + "operators": { + "patterns": [ + { + "match": "\\+|\\-|\\*|\\/|=|(==)|(!=)|<|>|(<=)|(>=)|\\.|:|(\\->)|(::)|(::<)", "name": "keyword.operator.slige" } ] }, - "punctuation": { - "patterns": [ - { - "match": ";", - "name": "punctuation.terminator.statement.slige" - }, - { - "match": ",", - "name": "punctuation.separator.delimiter.slige" - } - ] - }, - "functions": { + "punctuation": { + "patterns": [ + { + "match": ";", + "name": "punctuation.terminator.statement.slige" + }, + { + "match": ",", + "name": "punctuation.separator.delimiter.slige" + } + ] + }, + "functions": { "patterns": [ { "match": "(?>\\b[a-zA-Z_][a-zA-Z0-9_]*)\\s*(?=(?>\\:\\:<.*?>)?\\()", @@ -86,14 +86,18 @@ } ] }, - "idents": { + "idents": { "patterns": [ { - "match": "\\b[a-zA-Z_][a-zA-Z0-9_]*\\b", + "match": "\\b[a-z_][a-zA-Z0-9_]*\\b", "name": "variable.other.slige" + }, + { + "match": "\\b[A-Z][a-zA-Z0-9_]*\\b", + "name": "entity.name.type.slige" } ] } - }, - "scopeName": "source.slige" -} \ No newline at end of file + }, + "scopeName": "source.slige" +}