Skip to content

Commit

Permalink
Use INFIX_OP for more operators
Browse files Browse the repository at this point in the history
  • Loading branch information
vipentti committed Dec 25, 2023
1 parent 914a687 commit 8b1f5a4
Show file tree
Hide file tree
Showing 12 changed files with 2,069 additions and 2,173 deletions.
10 changes: 4 additions & 6 deletions src/Visp.Compiler/Lexer.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ let nonWhitespace = [^ ' ' '\t' '\r' '\n']
// keep in sync with LexHelpers.infixOperatorSet
// src/Visp.Compiler/Syntax/LexHelpers.fs
let infix_operators = (
"|>"
"&&"
| "||"
| ":>"
| "|>"
| "||>"
| "|||>"
| "<<"
Expand Down Expand Up @@ -290,8 +293,6 @@ rule token (args: LexArgs) (skip: bool) = parse
| '(' infix_operators { TOKENLIST [LPAREN; INFIX_OP (lexemeTrimLeft lexbuf 1)] }
| unary_operators { UNARY_OP (lexeme lexbuf) }
| '(' unary_operators { TOKENLIST [LPAREN; UNARY_OP (lexemeTrimLeft lexbuf 1)] }
| "||" { BAR_BAR }
| "-||" { BAR_BAR }
| '(' { LPAREN }
| ')' { RPAREN }
| '{' { LBRACE }
Expand Down Expand Up @@ -319,7 +320,6 @@ rule token (args: LexArgs) (skip: bool) = parse
| "[|" { BRACKET_BAR }
| "|]" { BAR_BRACKET }
| "(||)" { TOKENLIST [PAREN_BAR; BAR_PAREN] }
| "(||" { TOKENLIST [LPAREN; BAR_BAR] }
| "(|" { PAREN_BAR }
| "|)" { BAR_PAREN }
| ".." { DOTDOT }
Expand Down Expand Up @@ -475,15 +475,13 @@ rule token (args: LexArgs) (skip: bool) = parse
| '.' { DOT }
| ">=" { GREATER_EQUALS }
| "<=" { LESS_EQUALS }
| "&&" { AMP_AMP }
| "!=" { BANG_EQUALS }
| '=' { EQUALS }

| "->>" { THREAD_LAST }
| "->" { THREAD_FIRST }
| "<" { OP_LESS }
| ">" { OP_GREATER }
| ":>" { COLON_GREATER }
| ":?" { COLON_QMARK }

| "#()" { UNIT }
Expand Down
8 changes: 2 additions & 6 deletions src/Visp.Compiler/Parser.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ let mkRecoveryPat s = Syntax.parserRecoveryPat (lhs s)
%token LPAREN RPAREN
%token LBRACKET RBRACKET
%token LBRACE RBRACE HASH_BRACE HASH_PAREN HASH_BRACKET BRACE_BAR BAR_BRACE PAREN_BAR BAR_PAREN BRACKET_BAR BAR_BRACKET
%token TRUE FALSE NIL COLON COLON_COLON COMMA UNIT BAR COLON_GREATER
%token OP_PLUS OP_MINUS OP_MULT OP_DIV QUOTE_SYM OP_GREATER OP_LESS COLON_QMARK EQUALS AMP_AMP BAR_BAR GREATER_EQUALS LESS_EQUALS GREATER_GREATER BANG_EQUALS
%token TRUE FALSE NIL COLON COLON_COLON COMMA UNIT BAR
%token OP_PLUS OP_MINUS OP_MULT OP_DIV QUOTE_SYM OP_GREATER OP_LESS COLON_QMARK EQUALS GREATER_EQUALS LESS_EQUALS GREATER_GREATER BANG_EQUALS
%token BANG_RANGE FOR_IN FOR_TO BANG_LIST BANG_MAP BANG_SET BANG_ARRAY BANG_VEC BANG_TUPLE
%token DOTDOT
%token AT
Expand Down Expand Up @@ -729,11 +729,7 @@ infix_op_text:
| OP_MINUS { ("-", (rhs parseState 1) )}
| OP_GREATER { (">", (rhs parseState 1) )}
| OP_LESS { ("<", (rhs parseState 1) )}
| COLON_GREATER { (":>", (rhs parseState 1) )}
| EQUALS { ("=", (rhs parseState 1) )}
| AMP_AMP { ("&&", (rhs parseState 1) )}
| BAR_BAR { ("||", (rhs parseState 1) )}
| OP_GREATER OP_GREATER { (">>", (rhs2 parseState 1 2)) }
| GREATER_EQUALS { (">=", (rhs parseState 1) )}
| LESS_EQUALS { ("<=", (rhs parseState 1) )}
| BANG_EQUALS { ("!=", (rhs parseState 1) )}
Expand Down
1,311 changes: 640 additions & 671 deletions src/Visp.Compiler/Syntax/FsLexYaccOutput/Lexer.fs

Large diffs are not rendered by default.

Loading

0 comments on commit 8b1f5a4

Please sign in to comment.