Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named Arguments #625

Merged
merged 32 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8ac5b1d
Initial commit for semantic tokenizer.
gdotdesign Jun 12, 2023
60f1bb5
Simplify semantic tokenizer a bit.
gdotdesign Jun 13, 2023
0e865c6
Working language server implementation.
gdotdesign Jun 13, 2023
1c14a5a
Cleanup semantic tokenizer class.
gdotdesign Jun 13, 2023
ca01ad6
Save keywords automatically instead of manually.
gdotdesign Jun 13, 2023
6926d57
Use an array derived from the actual token types.
gdotdesign Jun 13, 2023
29fb79b
Implement suggestions from code review.
gdotdesign Jun 14, 2023
6b25fc8
Update src/ls/semantic_tokens.cr
gdotdesign Jun 14, 2023
0eea575
Implement HTML highlighting.
gdotdesign Jun 14, 2023
1cd96da
Implement highlight directive.
gdotdesign Jun 14, 2023
529117d
Avoid unnecessary interations.
gdotdesign Jun 14, 2023
79c3f11
Implement suggestions from code review.
gdotdesign Jun 14, 2023
6faec26
Use the ast from the workspace semantic tokens.
gdotdesign Jun 25, 2023
37db9b6
Implementation of localization language structures.
gdotdesign Jun 26, 2023
6e51ae0
Update operation.cr
gdotdesign Jul 18, 2023
673b361
Merge branch 'master' into locales
gdotdesign Jul 18, 2023
92833ca
Update test.
gdotdesign Jul 21, 2023
5e9eef7
Merge branch 'master' into locales
gdotdesign Aug 8, 2023
44ab595
Revert change to the operation formatting.
gdotdesign Aug 8, 2023
a8ecd78
Update Locale.md
gdotdesign Aug 8, 2023
cb99c78
Implement labelled calls.
gdotdesign Jul 21, 2023
dd254f8
Don't reorder arguments in the formatter.
gdotdesign Jul 22, 2023
630c080
Minor fixes.
gdotdesign Jul 26, 2023
d28c7a3
Merge branch 'master' into locales
gdotdesign Sep 6, 2023
095ab66
Merge branch 'locales' into labelled-calls
gdotdesign Sep 6, 2023
d171155
Merge branch 'master' into locales
gdotdesign Sep 7, 2023
88bd4cc
Merge branch 'locales' into labelled-calls
gdotdesign Sep 7, 2023
36c9d98
Apply suggestions from code review
gdotdesign Sep 7, 2023
a2a0c04
Update src/compilers/call.cr
gdotdesign Sep 7, 2023
687550d
Finish renaming an error from code review.
gdotdesign Sep 7, 2023
99a1bac
Merge branch 'master' into labelled-calls
gdotdesign Sep 17, 2023
99acd9f
Merge branch 'master' into labelled-calls
gdotdesign Sep 17, 2023
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
Prev Previous commit
Next Next commit
Simplify semantic tokenizer a bit.
  • Loading branch information
gdotdesign committed Jun 13, 2023
commit 60f1bb51614ca1074afcce15052e1cdb84314fea
2 changes: 1 addition & 1 deletion src/commands/highlight.cr
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module Mint
in SemanticTokenizer::TokenType::String
item[0].colorize(:green)
in SemanticTokenizer::TokenType::Number
item[0].colorize.fore(:white).back(:red)
item[0].colorize(:red)
in SemanticTokenizer::TokenType::Regexp
item[0].colorize.fore(:white).back(:red)
in SemanticTokenizer::TokenType::Operator
Expand Down
30 changes: 30 additions & 0 deletions src/ls/definition/type_id.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module Mint
module LS
class Definition < LSP::RequestMessage
def definition(node : Ast::TypeId, server : Server, workspace : Workspace, stack : Array(Ast::Node))
found =
workspace.ast.enums.find(&.name.value.==(node.value)) ||
workspace.ast.records.find(&.name.value.==(node.value)) ||
workspace.ast.stores.find(&.name.value.==(node.value)) ||
find_component(workspace, node.value)

if found.nil? && (next_node = stack[1])
definition(next_node, server, workspace, stack)
else
return if Core.ast.nodes.includes?(found)

case found
when Ast::Store
location_link server, node, found.name, found
when Ast::Enum
location_link server, node, found.name, found
when Ast::Component
location_link server, node, found.name, found
when Ast::RecordDefinition
location_link server, node, found.name, found
end
end
end
end
end
end
6 changes: 6 additions & 0 deletions src/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@ module Mint
begin
node = yield position
@position = start_position unless node
clear_nodes(start_position) unless node
node
rescue error : Error
@position = start_position
clear_nodes(start_position)
raise error
end
end

def clear_nodes(from_position)
ast.nodes.reject! { |node| node.from >= from_position }
end

def step
@position += 1
end
Expand Down
2 changes: 1 addition & 1 deletion src/parsers/get.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Mint
start do |start_position|
comment = self.comment

next unless keyword "get"
next unless keyword("get", true)
whitespace

name = variable! GetExpectedName, track: false
Expand Down
20 changes: 12 additions & 8 deletions src/parsers/type_id.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Mint
class Parser
def type_id!(error : SyntaxError.class) : Ast::TypeId
def type_id!(error : SyntaxError.class, track : Bool = true) : Ast::TypeId
start do |start_position|
value = gather do
char(error, &.ascii_uppercase?)
Expand All @@ -10,19 +10,21 @@ module Mint
raise error unless value

if char! '.'
other = type_id! error
other = type_id!(error, false)
value += ".#{other.value}"
end

Ast::TypeId.new(
from: start_position,
value: value,
to: position,
input: data)
input: data).tap do |node|
self << node if track
end
end
end

def type_id : Ast::TypeId?
def type_id(track : Bool = true) : Ast::TypeId?
start do |start_position|
value = gather do
return unless char.ascii_uppercase?
Expand All @@ -36,7 +38,7 @@ module Mint
if char == '.'
other = start do
step
next_part = type_id
next_part = type_id(false)
next unless next_part
next_part
end
Expand All @@ -51,13 +53,15 @@ module Mint
from: start_position,
value: value,
to: position,
input: data)
input: data).tap do |node|
self << node if track
end
end
end

def type_id(error : SyntaxError.class) : Ast::TypeId?
def type_id(error : SyntaxError.class, track : Bool = true) : Ast::TypeId?
return unless char.ascii_uppercase?
type_id! error
type_id! error, track
end
end
end
111 changes: 20 additions & 91 deletions src/semantic_tokenizer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,63 +35,18 @@ module Mint
add(from, to, TokenType::Keyword)
end

tokenize(
ast.records +
ast.providers +
ast.components +
ast.modules +
ast.routes +
ast.stores +
ast.suites +
ast.enums +
ast.comments)
end

def tokenize(node : Ast::Component)
add(node.name, TokenType::Type)

tokenize(node.comment)

tokenize(
node.properties +
node.functions +
node.constants +
node.connects +
node.comments +
node.styles +
node.states +
node.gets +
node.uses)
end

def tokenize(node : Ast::Style)
add(node.name, TokenType::Variable)
tokenize(node.arguments)
tokenize(node.body)
tokenize(ast.nodes)
end

def tokenize(node : Ast::CssDefinition)
add(node.from, node.from + node.name.size, TokenType::Property)
tokenize(node.value.select(Ast::Node))
end

def tokenize(node : Ast::Function)
add(node.name, TokenType::Variable)

tokenize(node.arguments)
tokenize(node.comment)
tokenize(node.type)
tokenize(node.body)
end

def tokenize(node : Ast::Type)
add(node.name, TokenType::Type)

tokenize(node.parameters)
end

def tokenize(node : Ast::Block)
tokenize(node.statements)
def tokenize(node : Ast::ArrayAccess)
case index = node.index
when Int64
add(node.from + 1, node.from + 1 + index.to_s.size, TokenType::Number)
end
end

def tokenize(node : Ast::HtmlElement)
Expand All @@ -100,50 +55,36 @@ module Mint
end

add(node.tag, TokenType::Namespace)
add(node.ref, TokenType::Variable)

tokenize(node.attributes)
tokenize(node.comments)
tokenize(node.children)
tokenize(node.styles)
end

def tokenize(node : Ast::HtmlComponent)
node.closing_tag_position.try do |position|
add(position, position + node.component.value.size, TokenType::Type)
end

add(node.component, TokenType::Type)
add(node.ref, TokenType::Variable)

tokenize(node.attributes)
tokenize(node.comments)
tokenize(node.children)
end

def tokenize(node : Ast::HtmlAttribute)
add(node.name, TokenType::Variable)

tokenize(node.value)
def tokenize(node : Ast::StringLiteral)
add(node, TokenType::String)
end

def tokenize(node : Ast::HtmlStyle)
add(node.name, TokenType::Variable)
def tokenize(node : Ast::BoolLiteral)
add(node, TokenType::Keyword)
end

tokenize(node.arguments)
def tokenize(node : Ast::NumberLiteral)
add(node, TokenType::Number)
end

def tokenize(node : Ast::StringLiteral)
add(node, TokenType::String)
def tokenize(node : Ast::Comment)
add(node, TokenType::Comment)
end

def tokenize(node : Ast::Statement)
tokenize(node.expression)
tokenize(node.target)
def tokenize(node : Ast::Variable)
add(node, TokenType::Variable)
end

def tokenize(node : Ast::Comment)
add(node, TokenType::Comment)
def tokenize(node : Ast::TypeId)
add(node, TokenType::Type)
end

def add(from : Int32, to : Int32, type : TokenType)
Expand All @@ -161,19 +102,7 @@ module Mint
nodes.each { |node| tokenize(node) }
end

def tokenize(node : Nil)
end

def tokenize(node : Ast::Node)
puts "Tokenizer is not implemented for: #{node.class}"
def tokenize(node : Ast::Node?)
end
end
end

{% for subclass in Mint::Ast::Node.subclasses %}
{% puts "Missing implementation of tokenize for #{subclass.name}" unless Mint::SemanticTokenizer.methods.any? do |method|
if method.name == "tokenize"
method.args[0].restriction.id == subclass.name.gsub(/Mint::/, "")
end
end %}
{% end %}