mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 16:49:31 +00:00
[language] remove integer division // operator
This commit is contained in:
parent
a3dded3935
commit
6cfb7fd7a3
5 changed files with 4 additions and 14 deletions
|
|
@ -48,7 +48,7 @@ local common = {
|
||||||
{ "&", 5 }, { "|", 5 },
|
{ "&", 5 }, { "|", 5 },
|
||||||
{ "==", 6 }, { "!=", 6 }, { ">=", 6 }, { "<=", 6 }, { "<", 6 }, { ">", 6 },
|
{ "==", 6 }, { "!=", 6 }, { ">=", 6 }, { "<=", 6 }, { "<", 6 }, { ">", 6 },
|
||||||
{ "+", 7 }, { "-", 7 },
|
{ "+", 7 }, { "-", 7 },
|
||||||
{ "//", 8 }, { "/", 8 }, { "*", 8 }, { "%", 8 },
|
{ "/", 8 }, { "*", 8 }, { "%", 8 },
|
||||||
{ "^", 10 },
|
{ "^", 10 },
|
||||||
{ "::", 11 },
|
{ "::", 11 },
|
||||||
{ ".", 14 },
|
{ ".", 14 },
|
||||||
|
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
local infix = require("anselme.parser.expression.secondary.infix.infix")
|
|
||||||
|
|
||||||
local operator_priority = require("anselme.common").operator_priority
|
|
||||||
|
|
||||||
return infix {
|
|
||||||
operator = "//",
|
|
||||||
identifier = "_//_",
|
|
||||||
priority = operator_priority["_//_"]
|
|
||||||
}
|
|
||||||
|
|
@ -23,7 +23,6 @@ local secondaries = {
|
||||||
r("infix.addition"),
|
r("infix.addition"),
|
||||||
r("infix.substraction"),
|
r("infix.substraction"),
|
||||||
r("infix.multiplication"),
|
r("infix.multiplication"),
|
||||||
r("infix.integer_division"),
|
|
||||||
r("infix.division"),
|
r("infix.division"),
|
||||||
r("infix.modulo"),
|
r("infix.modulo"),
|
||||||
r("infix.implicit_multiplication"),
|
r("infix.implicit_multiplication"),
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ return {
|
||||||
{ "_*_", "(a::is number, b::is number)", function(state, a, b) return Number:new(a.number * b.number) end },
|
{ "_*_", "(a::is number, b::is number)", function(state, a, b) return Number:new(a.number * b.number) end },
|
||||||
{ "_/_", "(a::is number, b::is number)", function(state, a, b) return Number:new(a.number / b.number) end },
|
{ "_/_", "(a::is number, b::is number)", function(state, a, b) return Number:new(a.number / b.number) end },
|
||||||
{
|
{
|
||||||
"_//_", "(a::is number, b::is number)", function(state, a, b)
|
"div", "(a::is number, b::is number)", function(state, a, b)
|
||||||
local r = a.number / b.number
|
local r = a.number / b.number
|
||||||
if r < 0 then
|
if r < 0 then
|
||||||
return Number:new(math.ceil(r))
|
return Number:new(math.ceil(r))
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ List of operators and their precedence:
|
||||||
5: _&_ _|_ _:_
|
5: _&_ _|_ _:_
|
||||||
6: _==_ _!=_ _>=_ _<=_ _<_ _>_
|
6: _==_ _!=_ _>=_ _<=_ _<_ _>_
|
||||||
7: _+_ _-_
|
7: _+_ _-_
|
||||||
8: _//_ _/_ _*_ _%_
|
8: _/_ _*_ _%_
|
||||||
9: _implicit*_
|
9: _implicit*_
|
||||||
10: _^_
|
10: _^_
|
||||||
11: _::_ !_ -_ +_ *_ %_
|
11: _::_ !_ -_ +_ *_ %_
|
||||||
|
|
@ -117,7 +117,7 @@ function(1, 2, 3)
|
||||||
|
|
||||||
The operators described in this section are defined using regular Anselme functions and can be redefined or overloaded. For example, `1+1` is equivalent `_+_(1, 1)`. For a detailled description of what these operators do by default, look at the [standard library](standard_library.md) documentation.
|
The operators described in this section are defined using regular Anselme functions and can be redefined or overloaded. For example, `1+1` is equivalent `_+_(1, 1)`. For a detailled description of what these operators do by default, look at the [standard library](standard_library.md) documentation.
|
||||||
|
|
||||||
`_+_`, `_-_`, `_*_`, `_/_`, `_//_`, `_%_`, `_^_` are intended to be used as addition, substraction, multiplication, division, integer division, modulo, and exponentiation respectively.
|
`_+_`, `_-_`, `_*_`, `_/_`, `_%_`, `_^_` are intended to be used as addition, substraction, multiplication, division, modulo, and exponentiation respectively.
|
||||||
|
|
||||||
`-_` and `+_` are intended to be used as the negation and positive prefixes.
|
`-_` and `+_` are intended to be used as the negation and positive prefixes.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue