Skip to content

Commit

Permalink
add more rule for infix, infixl, infixr
Browse files Browse the repository at this point in the history
  • Loading branch information
trdthg committed Jul 22, 2024
1 parent a116c07 commit f0bba3f
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 6 deletions.
28 changes: 26 additions & 2 deletions src/lib/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,36 @@ rule token comments = parse
Pragma (i, arg) }
| "infix" ws (digit as p) ws (operator as op)
{ Fixity (Infix, Big_int.of_string (Char.escaped p), op) }
| "infix" ws (digit as p) ws (operator as op) "//" {
line_comment comments (Lexing.lexeme_start_p lexbuf) (Buffer.create 10) lexbuf;
Fixity (Infix, Big_int.of_string (Char.escaped p), op)
}
| "infix" ws (digit as p) ws (operator as op) "/*" {
block_comment comments (Lexing.lexeme_start_p lexbuf) (Buffer.create 10) 0 lexbuf;
Fixity (Infix, Big_int.of_string (Char.escaped p), op)
}
| "infixl" ws (digit as p) ws (operator as op)
{ Fixity (InfixL, Big_int.of_string (Char.escaped p), op) }
| "infixl" ws (digit as p) ws (operator as op) "//" {
line_comment comments (Lexing.lexeme_start_p lexbuf) (Buffer.create 10) lexbuf;
Fixity (InfixL, Big_int.of_string (Char.escaped p), op)
}
| "infixl" ws (digit as p) ws (operator as op) "/*" {
block_comment comments (Lexing.lexeme_start_p lexbuf) (Buffer.create 10) 0 lexbuf;
Fixity (InfixL, Big_int.of_string (Char.escaped p), op)
}
| "infixr" ws (digit as p) ws (operator as op)
{ Fixity (InfixR, Big_int.of_string (Char.escaped p), op) }
| operator as op {
OpId op }
| "infixr" ws (digit as p) ws (operator as op) "//" {
line_comment comments (Lexing.lexeme_start_p lexbuf) (Buffer.create 10) lexbuf;
Fixity (InfixR, Big_int.of_string (Char.escaped p), op)
}
| "infixr" ws (digit as p) ws (operator as op) "/*" {
block_comment comments (Lexing.lexeme_start_p lexbuf) (Buffer.create 10) 0 lexbuf;
Fixity (InfixR, Big_int.of_string (Char.escaped p), op)
}
| operator as op
{ OpId op }
| ((oper_char* oper_char_no_slash) as op) "/*" {
block_comment comments (Lexing.lexeme_start_p lexbuf) (Buffer.create 10) 0 lexbuf;
if op = "=" then Eq op else OpId op
Expand Down
48 changes: 46 additions & 2 deletions test/format/default/operator.expect
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
default Order dec
$include <prelude.sail>

///// line_comment with more than two slash
// comment
//comment
/// line_comment with more than two slash
///line_comment with more than two slash
//// line_comment with more than two slash
////line_comment with more than two slash
// /*/*/
/*/ block_comment with slash near and
*/
Expand All @@ -18,6 +23,45 @@ infix 4 =/
val operator =/ : forall 'n. (int('n), int('n)) -> bool
function operator =/(x, y) = x == y

infix 4 =

// comment
infix 4 ==/
infix 4 -/-

//comment
infix 4 /-

//comment
infix 4 /-*

//comment
infixl 4 =

// comment
infixl 4 ==/
infixl 4 -/-

//comment
infixl 4 /-

//comment
infixl 4 /-*

//comment
infixr 4 =

// comment
infixr 4 ==/
infixr 4 -/-

//comment
infixr 4 /-

//comment
infixr 4 /-*

//comment
function f () = {
if op_eq2_with_block_comment == /**/ /**/ 1 then {
1
Expand All @@ -39,7 +83,7 @@ function f () = {
1;

if op_eq_with_line_comment =
// then { 1 } this is commeny
// comment
if eq_slash = /**/ 1 then {
1
} else {
Expand Down
26 changes: 24 additions & 2 deletions test/format/operator.sail
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
default Order dec
$include <prelude.sail>

///// line_comment with more than two slash
// comment
//comment
/// line_comment with more than two slash
///line_comment with more than two slash
//// line_comment with more than two slash
////line_comment with more than two slash

// /*/*/

Expand All @@ -23,6 +28,23 @@ infix 4 =/
val operator =/ : forall 'n. (int('n), int('n)) -> bool
function operator =/(x, y) = x == y

infix 4 =// comment
infix 4 ==/
infix 4 -/-//comment
infix 4 /-//comment
infix 4 /-*//comment

infixl 4 =// comment
infixl 4 ==/
infixl 4 -/-//comment
infixl 4 /-//comment
infixl 4 /-*//comment

infixr 4 =// comment
infixr 4 ==/
infixr 4 -/-//comment
infixr 4 /-//comment
infixr 4 /-*//comment

function f () = {
if op_eq2_with_block_comment /**/==/**/ 1 then { 1 };
Expand All @@ -36,7 +58,7 @@ function f () = {
let op_eq_with_line_comment =///
1;

if op_eq_with_line_comment =// then { 1 } this is commeny
if op_eq_with_line_comment =// comment
(if eq_slash =/**/1 then { 1 } else {2}) then {1};

if eq_with_blcok_comment =/**/1 then { 1 };
Expand Down

0 comments on commit f0bba3f

Please sign in to comment.