Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement aoc2023 day11 & language improvements #18

Merged
merged 3 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Visp.Compiler/CoreParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ module CoreParser =
let getLibFilePath name =
let src_dir = __SOURCE_DIRECTORY__

let my2DArray: int array2d = array2D [ [ 1; 0 ]; [ 0; 1 ] ]

let xx = Array2D.length1 my2DArray

let yy = my2DArray[0, 0]

Path.Combine(src_dir, "..", "..", "visp", "lib", name) |> Path.GetFullPath

let private tfs =
Expand Down
6 changes: 6 additions & 0 deletions src/Visp.Compiler/Lexer.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ let escape_char = ('\\' ( '\\' | "\"" | '\'' | 'a' | 'f' | 'v' | 'n' | 't' | 'b'
let ident_start_char = letter | SymbolicStartCharacters
let ident_char = ( ident_start_char | digit | SymbolicExtra )
let ident = ident_start_char ident_char*
let ident_array = letter (letter | digit)* '[' (',')* ']'

let anyspace = [' ' '\t' '\r' '\n']
let whitespace = [' ' '\t']+
Expand Down Expand Up @@ -467,6 +468,10 @@ rule token (args: LexArgs) (skip: bool) = parse
let text = lexeme lexbuf
symbolOrKeyword args.CurrentContext text
}
| ident_array {
let text = lexeme lexbuf
SYMBOL text
}
| _ { unexpected_char "token" lexbuf }

and tokenStream (args: LexArgs) (skip: bool) = parse
Expand Down Expand Up @@ -710,6 +715,7 @@ and tokenStream (args: LexArgs) (skip: bool) = parse
SYMBOL text
else
SYMBOL text }
| ident_array { SYMBOL (lexeme lexbuf)}
| _ { unexpected_char "tokenStream" lexbuf }

and singleQuoteString (sargs: LexerStringArgs) (skip: bool) = parse
Expand Down
41 changes: 30 additions & 11 deletions src/Visp.Compiler/Parser.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let parse_error_rich = Some(fun (ctxt: ParseErrorContext<_>) ->
%token LBRACE RBRACE HASH_BRACE HASH_PAREN HASH_BRACKET BRACE_BAR BAR_BRACE
%token TRUE FALSE NIL COLON COLON_COLON COMMA UNIT BAR
%token OP_PLUS OP_MINUS OP_MULT OP_DIV QUOTE_SYM
%token BANG_RANGE FOR_IN BANG_LIST BANG_MAP BANG_SET BANG_ARRAY BANG_VEC BANG_TUPLE
%token BANG_RANGE FOR_IN FOR_TO BANG_LIST BANG_MAP BANG_SET BANG_ARRAY BANG_VEC BANG_TUPLE
%token DOTDOT
%token AT
%token OPEN MODULE
Expand Down Expand Up @@ -294,6 +294,7 @@ parens_expr:
| record_expr { $1 }
| union_expr { $1 }
| for_in_expr { $1 }
| for_to_expr { $1 }
| record_init_expr { $1 }
| range_expr { $1 }
| list_expr { $1 }
Expand Down Expand Up @@ -479,8 +480,8 @@ threadable:
{ SynThreadable.Method($1, DotMethodKind.Tuple, lhs parseState) }
| apply_method
{ SynThreadable.Method($1, DotMethodKind.Apply, lhs parseState) }
| DOT_BRACKET expr RBRACKET
{ SynThreadable.Index($2, lhs parseState) }
| dot_bracket_expr_raw
{ SynThreadable.Index($1, lhs parseState) }
| expr
{ SynThreadable.Expr($1, lhs parseState) }

Expand All @@ -491,13 +492,24 @@ prop_plus:
SynSymbol(Ident(text, rhs parseState 1))
}

expr_comma_list: rev_expr_comma_list { List.rev $1 }
rev_expr_comma_list:
| expr { [$1] }
| rev_expr_comma_list COMMA expr { $3 :: $1 }

dot_bracket_expr_raw:
| DOT_BRACKET expr RBRACKET
{ [$2] }
| DOT_BRACKET expr COMMA rev_expr_comma_list RBRACKET
{ $2 :: $4 }

dot_expr:
| DOT_BRACKET expr RBRACKET expr
{ SynExpr.DotIndex($4, $2, lhs parseState)}
| DOT_BRACKET expr RBRACKET recover
{ SynExpr.DotIndex(Syntax.parserRecoveryExpr (lhs parseState), $2, lhs parseState)}
| dot_bracket_expr_raw expr
{ SynExpr.DotIndex($2, $1, lhs parseState)}
| dot_bracket_expr_raw recover
{ SynExpr.DotIndex(Syntax.parserRecoveryExpr (lhs parseState), $1, lhs parseState)}
| DOT_BRACKET expr recover
{ SynExpr.DotIndex(Syntax.parserRecoveryExpr (lhs parseState), $2, lhs parseState)}
{ SynExpr.DotIndex(Syntax.parserRecoveryExpr (lhs parseState), [$2], lhs parseState)}
| DOT_PLUS symbol expr
{ SynExpr.DotProperty($3, $2, lhs parseState)}
| prop_plus expr
Expand All @@ -520,8 +532,8 @@ dot_expr:
| DOT expr prop_plus
{ SynExpr.DotProperty($2, $3, lhs parseState) }

| DOT expr DOT_BRACKET expr RBRACKET
{ SynExpr.DotIndex($2, $4, lhs parseState) }
| DOT expr dot_bracket_expr_raw
{ SynExpr.DotIndex($2, $3, lhs parseState) }
| DOT expr symbol expr_list
{ SynExpr.DotMethod($2, $3, $4, DotMethodKind.Tuple, lhs parseState) }

Expand All @@ -541,6 +553,13 @@ for_in_expr:
| FOR_IN lparen_or_lbracket name expr rparen_or_rbracket expr_list
{ SynExpr.ForIn($3, $4, $6, lhs parseState) }

for_to_expr:
| FOR_TO lparen_or_lbracket name lparen_or_lbracket expr SYMBOL expr rparen_or_rbracket rparen_or_rbracket expr_list
{
let down = $6 = "downto"
SynExpr.ForTo($3, $5, $7, $10, down, lhs parseState)
}

range_expr:
| BANG_RANGE expr DOTDOT expr DOTDOT expr
{ SynExpr.RangeExpr ($2, Some($4), $6, lhs parseState) }
Expand Down Expand Up @@ -967,7 +986,7 @@ raw_syntype_ident:
}

syntype_ident:
| raw_syntype_ident_text { SynType.Ident(Ident($1, lhs parseState))}
| raw_syntype_ident_text %prec prec_syn_type { SynType.Ident(Ident($1, lhs parseState))}
| QUOTE_SYM raw_syntype_ident_text
{ let text = $2
SynType.Ident(Ident("'" + text, lhs parseState))
Expand Down
1,417 changes: 725 additions & 692 deletions src/Visp.Compiler/Syntax/FsLexYaccOutput/Lexer.fs

Large diffs are not rendered by default.

Loading