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

Feature/day24 #38

Merged
merged 13 commits into from
Dec 25, 2023
1 change: 1 addition & 0 deletions src/Visp.Compiler/CoreParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ let state = { Todo = () }
try
let mutable res = start tokenizer lexbuf

// eprintfn "%A" res
// eprintfn "%s" (res.Pretty())

if returnLast then
Expand Down
14 changes: 12 additions & 2 deletions src/Visp.Compiler/Lexer.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ let xint8 = xinteger 'y'
let xint16 = xinteger 's'
let xint = xinteger
let xint32 = xinteger 'l'
let floatp = digit ((digit | separator)* digit)? '.' (digit ((digit | separator)* digit)?)?
let floate = digit ((digit | separator)* digit)? ('.' (digit ((digit | separator)* digit)?)? )? ('e'| 'E') ['+' '-']? digit ((digit | separator)* digit)?
let floatp = ['-' '+']? digit ((digit | separator)* digit)? '.' (digit ((digit | separator)* digit)?)?
let floate = ['-' '+']? digit ((digit | separator)* digit)? ('.' (digit ((digit | separator)* digit)?)? )? ('e'| 'E') ['+' '-']? digit ((digit | separator)* digit)?
let float = floatp | floate
let bignum = integer ('I' | 'N' | 'Z' | 'Q' | 'R' | 'G')
let ieee64 = float
Expand Down Expand Up @@ -424,6 +424,10 @@ rule token (args: LexArgs) (skip: bool) = parse
let n64 = (try int64 (removeUnderscores (lexemeTrimRight lexbuf 2)) with _ -> fail args lexbuf (SR.lexInvalidFloat()) 0L)
IEEE64 (System.BitConverter.Int64BitsToDouble(n64)) }

| bignum
{ let s = lexeme lexbuf
BIGNUM (removeUnderscores (lexemeTrimRight lexbuf 1), s.[s.Length-1..s.Length-1]) }

// --- END OF NUMBERS ---

| '+' { OP_PLUS }
Expand Down Expand Up @@ -552,6 +556,8 @@ and tokenStream (args: LexArgs) (skip: bool) = parse
| '=' { SYMBOL (lexeme lexbuf) }
| "&&" { SYMBOL (lexeme lexbuf) }
| "||" { SYMBOL (lexeme lexbuf) }
| ":>" { SYMBOL (lexeme lexbuf) }
| ":?" { SYMBOL (lexeme lexbuf) }

// Constants
| "#()" { UNIT }
Expand Down Expand Up @@ -697,6 +703,10 @@ and tokenStream (args: LexArgs) (skip: bool) = parse
let n64 = (try int64 (removeUnderscores (lexemeTrimRight lexbuf 2)) with _ -> fail args lexbuf (SR.lexInvalidFloat()) 0L)
IEEE64 (System.BitConverter.Int64BitsToDouble(n64)) }

| bignum
{ let s = lexeme lexbuf
BIGNUM (removeUnderscores (lexemeTrimRight lexbuf 1), s.[s.Length-1..s.Length-1]) }

// --- END OF NUMBERS ---

| '$' '"'
Expand Down
39 changes: 34 additions & 5 deletions src/Visp.Compiler/Parser.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ let mkRecoveryPat s = Syntax.parserRecoveryPat (lhs s)
%token <single> IEEE32
%token <double> IEEE64
%token <System.Decimal> DECIMAL
%token <(string * string)> BIGNUM

%token <string> HASH_IDENT
%token <string> PROP_PLUS
Expand Down Expand Up @@ -103,7 +104,7 @@ let mkRecoveryPat s = Syntax.parserRecoveryPat (lhs s)
%nonassoc prec_new_exprs
%nonassoc prec_new_no_exprs

%nonassoc INT8 INT16 INT32 INT64 NATIVEINT UINT8 UINT16 UINT32 UINT64 UNATIVEINT IEEE32 IEEE64 DECIMAL
%nonassoc INT8 INT16 INT32 INT64 NATIVEINT UINT8 UINT16 UINT32 UINT64 UNATIVEINT IEEE32 IEEE64 DECIMAL BIGNUM
%nonassoc TRUE FALSE NIL SYMBOL KEYWORD RAWSTRING DOT_METHOD APPLY_METHOD STRING UNIT CHAR
%nonassoc HASH_IDENT
%nonassoc prec_symbol
Expand Down Expand Up @@ -165,6 +166,7 @@ let mkRecoveryPat s = Syntax.parserRecoveryPat (lhs s)

%nonassoc prec_record_expr_only
%nonassoc prec_record_init
%nonassoc prec_lambda_short_record

%nonassoc prec_recover
// %nonassoc EOF
Expand Down Expand Up @@ -273,14 +275,14 @@ expr:
{ SynExpr.Quote(true, $2, lhs parseState) }
| LBRACE expr_list_or_empty RBRACE { CollExpr.mkHashMap $2 (lhs parseState)}
| HASH_BRACE expr_list_or_empty RBRACE { CollExpr.mkHashSet $2 (lhs parseState)}
| brace_bar %prec prec_lambda { $1 }
| bracket_bar { $1 }
| paren_bar { $1 }
| HASH_PAREN lambda_short_expr_list RPAREN
{ SynExpr.LambdaShort($2, lhs parseState)}
| vector_start %prec prec_expr
{ $1 }

| brace_bar { $1 }
| bracket_bar { $1 }
| paren_bar { $1 }
| inside_parens %prec prec_paren { $1 }

brace_bar:
Expand All @@ -298,7 +300,7 @@ paren_bar:
| PAREN_BAR expr_list BAR_PAREN { CollExpr.mkFsList $2 (lhs parseState)}

lambda_short_expr_list:
| parens_expr { $1 }
| parens_expr_start { $1 }

vector_start:
| LBRACKET RBRACKET %prec prec_vector { CollExpr.mkVector [] (lhs parseState) }
Expand Down Expand Up @@ -1205,6 +1207,8 @@ rawConstant:

| DECIMAL { SynConst.Decimal($1)}

| BIGNUM { SynConst.UserNum $1 }

| TRUE { SynConst.Bool(true)}
| FALSE { SynConst.Bool(false)}
| NIL { SynConst.Nil }
Expand Down Expand Up @@ -1315,6 +1319,28 @@ pat_open_kind:
| BRACKET_BAR %prec prec_syn_pat_open { CollectionKind.FsArray }
| PAREN_BAR %prec prec_syn_pat_open { CollectionKind.FsList }

pat_record_open:
| BRACE_BAR { () }
| LBRACE { () }

pat_record_close:
| BAR_BRACE { () }
| RBRACE { () }

pat_record_init:
| symbol syn_pat { ($1, $2) }
| LPAREN symbol syn_pat RPAREN { ($2, $3) }
| LBRACKET symbol syn_pat RBRACKET { ($2, $3) }

pat_record_init_list: rev_pat_record_init_list { List.rev $1 }
rev_pat_record_init_list:
| pat_record_init { [$1] }
| rev_pat_record_init_list pat_record_init { $2 :: $1 }

pat_record:
| pat_record_open pat_record_close { SynPat.Record([], lhs parseState) }
| pat_record_open pat_record_init_list pat_record_close { SynPat.Record($2, lhs parseState) }

syn_pat_named:
| SYMBOL %prec prec_syn_pat {
let text = $1
Expand Down Expand Up @@ -1344,6 +1370,9 @@ syn_pat:

| pat_open_kind syn_pat_trivia_list collection_close_kind %prec prec_syn_pat
{ SynPat.Collection(SynCollection($1, $2, lhs parseState)) }

| pat_record { $1 }

| LPAREN BANG_TUPLE syn_pat_trivia_list RPAREN
{ let lst = List.intersperse (SynPat.Trivia (SynPatternTriviaKind.Comma, rhs parseState 1)) $3
SynPat.Collection(SynCollection(CollectionKind.Paren, lst, lhs parseState))
Expand Down
Loading