Skip to content

Commit

Permalink
Merge pull request #48 from tonyfettes/bitwise-op
Browse files Browse the repository at this point in the history
Support bitwise op
  • Loading branch information
tonyfettes authored Dec 25, 2024
2 parents ef712bb + b7fec74 commit 299a3b2
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 9 deletions.
14 changes: 9 additions & 5 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ const
multiplicative: 16,
additive: 15,
comparative: 14,
and: 13,
or: 12,
pipe: 11,
orPattern: 10,
asPattern: 9,
bitwise_and : 13,
bitwise_or : 12,
and: 11,
or: 10,
pipe: 9,
orPattern: 8,
asPattern: 7,
},
multiplicative_operators = ['*', '/', '%'],
additive_operators = ['+', '-'],
Expand Down Expand Up @@ -381,6 +383,8 @@ module.exports = grammar({
[PREC.multiplicative, choice(...multiplicative_operators)],
[PREC.additive, choice(...additive_operators)],
[PREC.comparative, choice(...comparative_operators)],
[PREC.bitwise_and, '&'],
[PREC.bitwise_or, '|'],
[PREC.and, '&&'],
[PREC.or, '||'],
[PREC.pipe, $.pipe_operator],
Expand Down
50 changes: 46 additions & 4 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1945,7 +1945,7 @@
},
{
"type": "STRING",
"value": "&&"
"value": "&"
},
{
"type": "SYMBOL",
Expand All @@ -1966,7 +1966,7 @@
},
{
"type": "STRING",
"value": "||"
"value": "|"
},
{
"type": "SYMBOL",
Expand All @@ -1978,6 +1978,48 @@
{
"type": "PREC_LEFT",
"value": 11,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "STRING",
"value": "&&"
},
{
"type": "SYMBOL",
"name": "expression"
}
]
}
},
{
"type": "PREC_LEFT",
"value": 10,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "STRING",
"value": "||"
},
{
"type": "SYMBOL",
"name": "expression"
}
]
}
},
{
"type": "PREC_LEFT",
"value": 9,
"content": {
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -4286,7 +4328,7 @@
},
"as_pattern": {
"type": "PREC",
"value": 9,
"value": 7,
"content": {
"type": "SEQ",
"members": [
Expand All @@ -4307,7 +4349,7 @@
},
"or_pattern": {
"type": "PREC_RIGHT",
"value": 10,
"value": 8,
"content": {
"type": "SEQ",
"members": [
Expand Down
4 changes: 4 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -2581,6 +2581,10 @@
"type": "%",
"named": false
},
{
"type": "&",
"named": false
},
{
"type": "&&",
"named": false
Expand Down
Binary file modified src/parser.c
Binary file not shown.
57 changes: 57 additions & 0 deletions test/corpus/expression.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1001,3 +1001,60 @@ fn init {
(atomic_expression
(literal
(integer_literal))))))))))))))))))

================================================================================
apply expression with labeled argument
================================================================================
fn main {
let a = 1 | 2 && 3 & 4 || 5
}
--------------------------------------------------------------------------------

(structure
(structure_item
(function_definition
(function_identifier
(lowercase_identifier))
(block_expression
(statement_expression
(let_expression
(pattern
(simple_pattern
(lowercase_identifier)))
(expression
(simple_expression
(binary_expression
(expression
(simple_expression
(binary_expression
(expression
(simple_expression
(binary_expression
(expression
(simple_expression
(atomic_expression
(literal
(integer_literal)))))
(expression
(simple_expression
(atomic_expression
(literal
(integer_literal))))))))
(expression
(simple_expression
(binary_expression
(expression
(simple_expression
(atomic_expression
(literal
(integer_literal)))))
(expression
(simple_expression
(atomic_expression
(literal
(integer_literal)))))))))))
(expression
(simple_expression
(atomic_expression
(literal
(integer_literal))))))))))))))

0 comments on commit 299a3b2

Please sign in to comment.