Skip to content

Commit

Permalink
Implement initial support for multi-dimensional arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
vipentti committed Dec 14, 2023
1 parent 9fd3c9a commit 1e29cc9
Show file tree
Hide file tree
Showing 16 changed files with 2,188 additions and 1,961 deletions.
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
31 changes: 21 additions & 10 deletions src/Visp.Compiler/Parser.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,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 +491,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 +531,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 Down Expand Up @@ -967,7 +978,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

0 comments on commit 1e29cc9

Please sign in to comment.