Skip to content

Commit

Permalink
I have not been really good at comitting all my stuff :)
Browse files Browse the repository at this point in the history
  • Loading branch information
obiwac committed Jun 30, 2024
1 parent c80814c commit 00149a6
Show file tree
Hide file tree
Showing 9 changed files with 2,831 additions and 532 deletions.
82 changes: 47 additions & 35 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,56 @@ module.exports = grammar({
name: "flamingo",

rules: {
source_file: $ => repeat($.statement),

statement: $ => choice(
$.expression,
$.print,
$.assignment,
),

print: $ => seq(
"print",
field("msg", $.expression),
),

expression: $ => choice(
$.identifier,
$.literal,
),

literal: $ => choice(
$.number,
$.string,
),

assignment: $ => seq(
field("left", $.identifier),
"=",
field("right", $.expression),
),

block: $ => seq("{", repeat($.statement), "}"),

unary_expression: $ => choice(
seq("-", $.expression),
seq("!", $.expression),
),
source_file: $ => repeat(choice($.statement, $.comment)),

comment: _ => token(seq("#", /.*/)),

statement: $ =>
choice($.block, $.expression, $.print, $.assignment, $.import, $.function_declaration, $.class_declaration),

block: $ => seq("{", field("body", repeat($.statement)), "}"),

import: $ => seq("import", field("path", $.identifier)),

function_declaration: $ =>
prec(
100,
seq(
"fn",
field("name", $.identifier),
optional(seq("(", optional(field("params", $.param_list)), ")")),
field("body", $.statement),
),
),

function_expression: $ =>
seq("fn", optional(seq("(", optional(field("params", $.param_list)), ")")), field("body", $.statement)),

class_declaration: $ => seq("class", field("name", $.identifier), "{", field("body", repeat($.statement)), "}"),

print: $ => seq("print", field("msg", $.expression)),

expression: $ => prec(-1, choice($.identifier, $.literal, $.call, $.access_list, $.parenthesized_expression)),

parenthesized_expression: $ => seq("(", field("expression", $.expression), ")"),

access_list: $ => seq(field("accessed", $.expression), ".", field("accessor", $.identifier)),

call: $ => prec(99, seq(field("callable", $.expression), "(", field("args", optional($.argument_list)), ")")),

param_list: $ => choice($.identifier, seq($.identifier, ",", $.param_list)),

argument_list: $ => choice($.expression, seq($.expression, ",", $.argument_list)),

literal: $ => choice($.number, $.string, $.bool),

assignment: $ => seq(field("left", $.identifier), "=", field("right", $.expression)),

unary_expression: $ => choice(seq("-", $.expression), seq("!", $.expression)),

identifier: _ => /[_A-z][_A-z0-9]*/,
number: _ => /\d+/,
string: _ => /"([^"\\]|\\.)*"/,
bool: _ => choice("true", "false", "error"),
},
})
46 changes: 45 additions & 1 deletion queries/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@
"print" @keyword
; This Source Form is subject to the terms of the AQUA Software License,
; v. 1.0. Copyright (c) 2024 Aymeric Wibo

(comment) @comment

; function calls

(call
callable: (expression (identifier)) @function
)

; builtins

[
"print"
] @function.builtin

; identifiers

(identifier) @variable

; declarations

(function_declaration name: (identifier) @function)
(class_declaration name: (identifier) @function)

; operators

; [
; "+"
; ] @operator

; keywords

[
"print"
"fn"
"class"
"import"
] @keyword

; literals

(string) @string
(number) @number
(bool) @constant.builtin
Loading

0 comments on commit 00149a6

Please sign in to comment.