mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-28 00:59:31 +00:00
Anselme v2.0.0-alpha rewrite
Woke up and felt like changing a couple things. It's actually been worked on for a while, little at a time... The goal was to make the language and implementation much simpler. Well I don't know if it really ended up being simpler but it sure is more robust. Main changes: * proper first class functions and closures supports! proper scoping rules! no more namespace shenanigans! * everything is an expression, no more statements! make the implementation both simpler and more complex, but it's much more consistent now! the syntax has massively changed as a result though. * much more organized and easy to modify codebase: one file for each AST node, no more random fields or behavior set by some random node exceptionally, everything should now follow the same API defined in ast.abstract.Node Every foundational feature should be implemented right now. The vast majority of things that were possible in v2 are possible now; some things aren't, but that's usually because v2 is a bit more sane. The main missing things before a proper release are tests and documentation. There's a few other things that might be implemented later, see the ideas.md file.
This commit is contained in:
parent
2ff494d108
commit
fe351b5ca4
484 changed files with 7099 additions and 18084 deletions
78
parser/expression/secondary/init.lua
Normal file
78
parser/expression/secondary/init.lua
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
--- try to parse a secondary expression
|
||||
|
||||
local function r(name)
|
||||
return require("parser.expression.secondary."..name), nil
|
||||
end
|
||||
|
||||
local secondaries = {
|
||||
-- binary infix operators
|
||||
-- 1
|
||||
r("infix.semicolon"),
|
||||
-- 2
|
||||
r("infix.tuple"),
|
||||
r("infix.tag"),
|
||||
-- 4
|
||||
r("infix.while"),
|
||||
r("infix.if"),
|
||||
-- 6
|
||||
r("infix.choice"),
|
||||
r("infix.and"),
|
||||
r("infix.or"),
|
||||
-- 7
|
||||
r("infix.equal"),
|
||||
r("infix.different"),
|
||||
r("infix.greater_equal"),
|
||||
r("infix.lower_equal"),
|
||||
r("infix.greater"),
|
||||
r("infix.lower"),
|
||||
-- 8
|
||||
r("infix.addition"),
|
||||
r("infix.substraction"),
|
||||
-- 9
|
||||
r("infix.multiplication"),
|
||||
r("infix.integer_division"),
|
||||
r("infix.division"),
|
||||
r("infix.modulo"),
|
||||
-- 9.5
|
||||
r("infix.implicit_multiplication"),
|
||||
-- 10
|
||||
r("infix.exponent"),
|
||||
-- 11
|
||||
r("infix.type_check"),
|
||||
-- 12
|
||||
r("infix.call"),
|
||||
-- 14
|
||||
r("infix.index"),
|
||||
-- 3
|
||||
r("infix.assignment"), -- deported after equal
|
||||
r("infix.assignment_call"),
|
||||
r("infix.definition"),
|
||||
-- 5
|
||||
r("infix.pair"), -- deported after type_check
|
||||
|
||||
-- unary suffix operators
|
||||
-- 1
|
||||
r("suffix.semicolon"),
|
||||
-- 12
|
||||
r("suffix.exclamation_call"),
|
||||
-- 13
|
||||
r("suffix.call"),
|
||||
}
|
||||
|
||||
-- add generated assignement+infix operator combos, before the rest
|
||||
local assignment_operators = r("infix.assignment_with_infix")
|
||||
for i, op in ipairs(assignment_operators) do
|
||||
table.insert(secondaries, i, op)
|
||||
end
|
||||
|
||||
return {
|
||||
-- returns exp, rem if expression found
|
||||
-- returns nil if no expression found
|
||||
-- returns nil, err if error
|
||||
search = function(self, source, str, limit_pattern, current_priority, primary)
|
||||
for _, secondary in ipairs(secondaries) do
|
||||
local exp, rem = secondary:search(source, str, limit_pattern, current_priority, primary)
|
||||
if exp then return exp, rem end
|
||||
end
|
||||
end
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue