Skip to content

Commit

Permalink
Remove special cases in lexer for #
Browse files Browse the repository at this point in the history
  • Loading branch information
tjammer committed Oct 11, 2024
1 parent ab03153 commit 2a2d1c0
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 34 deletions.
12 changes: 2 additions & 10 deletions lib/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,6 @@ let white = [' ' '\t']+
let newline = '\r' | '\n' | "\r\n"
let backslash_escapes = ['\\' '\'' '"' 'n' 't' 'b' 'r' ' ']
let hashnum = '#' int
let hashnumbrack = hashnum '['
let sized_id = lowercase_alpha+ hashnum
let hashquest = '#' '?'
let unknown_sized_id = lowercase_alpha+ hashquest
let plus_ops = '+' | '-'
let mult_ops = '*' | '/'
let cmp_ops = '<' | '>'
Expand Down Expand Up @@ -182,10 +176,8 @@ rule read =
| '}' { Rcurly }
| '[' { Lbrack }
| ']' { Rbrack }
| "#[" { Hashtag_brack }
| hashnumbrack { Hashnum_brack (int_of_hashnum (Lexing.lexeme lexbuf)) }
| sized_id { Sized_ident (Lexing.lexeme lexbuf) }
| unknown_sized_id { Unknown_sized_ident (Lexing.lexeme lexbuf) }
| "#?" { Hash_quest }
| '#' { Hash }
| "->" { Right_arrow }
| "--" { line_comment lexbuf }
| eq_op { Eq_op (Lexing.lexeme lexbuf) }
Expand Down
18 changes: 8 additions & 10 deletions lib/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
%token <string> String_lit
%token True
%token False
%token Hashtag_brack
%token <int> Hashnum_brack
%token Hash
%token Hash_quest
%token Semicolon
%token Right_arrow
%token With
Expand All @@ -56,8 +56,6 @@
%token <string> Builtin_id
%token Val
%token Rec
%token <string> Sized_ident
%token <string> Unknown_sized_ident

/* ops */

Expand All @@ -84,7 +82,7 @@
%left Lcurly
%left Lbrack
%left Lpar
%left Path Hashtag_brack
%left Path Hash

%start <Ast.prog> prog

Expand Down Expand Up @@ -373,7 +371,7 @@ special_builtins:
{App ($loc, Var ($loc, "__array_get"),
[{apass = Dnorm; aloc = $loc(e); aexpr = e};
{apass = Dnorm; aloc = $loc(i); aexpr = i}])}
| e = expr; Hashtag_brack; i = expr; Rbrack
| e = expr; Hash; Lbrack; i = expr; Rbrack
{App ($loc, Var ($loc, "__fixed_array_get"),
[{apass = Dnorm; aloc = $loc(e); aexpr = e};
{apass = Dnorm; aloc = $loc(i); aexpr = i}])}
Expand Down Expand Up @@ -420,8 +418,8 @@ separated_trailing_list(sep, item, terminator):
| lst = separated_nonempty_trailing_list(sep, item, terminator) { lst }

fixed_array_lit:
| Hashtag_brack; items = separated_nonempty_trailing_list(Comma, expr, Rbrack) { Fixed_array items }
| num = Hashnum_brack; item = expr; Rbrack { Fixed_array_num (num, item) }
| Hash; Lbrack; items = separated_nonempty_trailing_list(Comma, expr, Rbrack) { Fixed_array items }
| Hash; num = Int; Lbrack; item = expr; Rbrack { Fixed_array_num (num, item) }

call_arg:
| aexpr = expr { {apass = Dnorm; aexpr; aloc = $loc} }
Expand Down Expand Up @@ -468,8 +466,8 @@ parens(x):
type_spec:
| id = Ident { Ty_id id }
| id = poly_id { Ty_var id }
| id = Sized_ident { Ty_id id }
| id = Unknown_sized_ident { Ty_id id }
| id = Ident; Hash; i = Int { Ty_id (id ^ "#" ^ string_of_int i) }
| id = Ident; Hash_quest { Ty_id (id ^ "#?") }
| path = type_path { Ty_use_id ($loc, path) }
| head = type_spec; Lbrack; tail = separated_nonempty_list(Comma, type_spec); Rbrack
{ Ty_applied (head :: tail) }
Expand Down
48 changes: 34 additions & 14 deletions lib/syntax_errors.messages
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ prog: External Ident Colon Lpar Rpar Right_arrow With

<YOUR SYNTAX ERROR MESSAGE HERE>

prog: External Ident Colon Lpar Rpar Right_arrow Ident With
prog: External Ident Colon Ident With

<YOUR SYNTAX ERROR MESSAGE HERE>

prog: External Ident Colon Ident Hash With

<YOUR SYNTAX ERROR MESSAGE HERE>

prog: External Ident Colon Lpar Rpar Right_arrow Quote Ident With

<YOUR SYNTAX ERROR MESSAGE HERE>

Expand Down Expand Up @@ -94,7 +102,7 @@ prog: External Ident Colon Lpar Ident Rpar Right_arrow With

<YOUR SYNTAX ERROR MESSAGE HERE>

prog: External Ident Colon Lpar Ident Rpar Right_arrow Ident With
prog: External Ident Colon Lpar Ident Rpar Right_arrow Quote Ident With

<YOUR SYNTAX ERROR MESSAGE HERE>

Expand All @@ -110,7 +118,7 @@ prog: External Ident Colon Lpar Ident Ampersand Rpar Right_arrow With

<YOUR SYNTAX ERROR MESSAGE HERE>

prog: External Ident Colon Lpar Ident Ampersand Rpar Right_arrow Ident With
prog: External Ident Colon Lpar Ident Ampersand Rpar Right_arrow Quote Ident With

<YOUR SYNTAX ERROR MESSAGE HERE>

Expand Down Expand Up @@ -142,7 +150,7 @@ prog: External Ident Colon Lpar Ident Comma Ident Rpar Right_arrow With

<YOUR SYNTAX ERROR MESSAGE HERE>

prog: External Ident Colon Lpar Ident Comma Ident Rpar Right_arrow Ident With
prog: External Ident Colon Lpar Ident Comma Ident Rpar Right_arrow Quote Ident With

<YOUR SYNTAX ERROR MESSAGE HERE>

Expand Down Expand Up @@ -466,11 +474,11 @@ prog: If With

<YOUR SYNTAX ERROR MESSAGE HERE>

prog: Hashtag_brack With
prog: Hash With

<YOUR SYNTAX ERROR MESSAGE HERE>

prog: Hashnum_brack With
prog: Hash Lbrack With

<YOUR SYNTAX ERROR MESSAGE HERE>

Expand Down Expand Up @@ -650,11 +658,15 @@ prog: False Mult_op False Wildcard

<YOUR SYNTAX ERROR MESSAGE HERE>

prog: False Hashtag_brack With
prog: False Hash With

<YOUR SYNTAX ERROR MESSAGE HERE>

prog: False Hashtag_brack False Wildcard
prog: False Hash Lbrack With

<YOUR SYNTAX ERROR MESSAGE HERE>

prog: False Hash Lbrack False Wildcard

<YOUR SYNTAX ERROR MESSAGE HERE>

Expand Down Expand Up @@ -858,15 +870,23 @@ prog: Fun Lpar Rpar Colon False Wildcard

<YOUR SYNTAX ERROR MESSAGE HERE>

prog: Hashnum_brack False Wildcard
prog: Lbrack False Wildcard

<YOUR SYNTAX ERROR MESSAGE HERE>

prog: Lbrack False Comma With

<YOUR SYNTAX ERROR MESSAGE HERE>

prog: Hash Int With

<YOUR SYNTAX ERROR MESSAGE HERE>

prog: Hashtag_brack False Wildcard
prog: Hash Int Lbrack With

<YOUR SYNTAX ERROR MESSAGE HERE>

prog: Hashtag_brack False Comma With
prog: Hash Int Lbrack False Wildcard

<YOUR SYNTAX ERROR MESSAGE HERE>

Expand Down Expand Up @@ -1062,11 +1082,11 @@ prog: Functor Ident Lpar With

<YOUR SYNTAX ERROR MESSAGE HERE>

prog: Functor Ident Lpar Ident Colon Ident Rpar With
prog: Functor Ident Lpar Rpar With

<YOUR SYNTAX ERROR MESSAGE HERE>

prog: Functor Ident Lpar Ident Colon Ident Rpar Lcurly With
prog: Functor Ident Lpar Rpar Lcurly With

<YOUR SYNTAX ERROR MESSAGE HERE>

Expand Down Expand Up @@ -1098,7 +1118,7 @@ prog: Ident Semicolon With

<YOUR SYNTAX ERROR MESSAGE HERE>

prog: Functor Ident Lpar Ident Colon Ident Rpar Lcurly Ident Eof
prog: Functor Ident Lpar Rpar Lcurly Ident Eof

<YOUR SYNTAX ERROR MESSAGE HERE>

Expand Down
5 changes: 5 additions & 0 deletions test/modules.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -1087,3 +1087,8 @@ Fix handling of parameterized abstract types

Fix external declarations in inner modules
$ schmu inner_module_externals.smu

Make applied functors hidden behind signatures usable. Does this apply to local module too?
$ schmu -m hidden_functor_app.smu
$ schmu use_hidden_functor_app.smu
$ valgrind -q --leak-check=yes --show-reachable=yes ./use_hidden_functor_app

0 comments on commit 2a2d1c0

Please sign in to comment.