diff options
| author | Alasdair Armstrong | 2018-01-25 00:30:24 +0000 |
|---|---|---|
| committer | Alasdair Armstrong | 2018-01-25 00:30:24 +0000 |
| commit | d87d4ad3a6d2ec2804cb7b20128fecb6d9df4e6e (patch) | |
| tree | 76a85742db61e8f4dcac8471c6c0856603453543 /src/lexer.mll | |
| parent | 10e2be330c14aaddbd8ada6b6ce8a8a63c7d605e (diff) | |
Add simple conditional processing and file include
Can now use C-style include declarations to include files within other sail files. This is done in such a way that all the location information is preserved in error messages. As an example:
$include "aarch64/prelude.sail"
$define SYM
$ifndef SYM
$include <../util.sail>
$endif
would include the file aarch64/prelude.sail relative to the file where the include is contained. It then defines a symbol SYM and includes another file if it is not defined. The <../util.sail> include will be accessed relative to $SAIL_DIR/lib, so $SAIL_DIR/lib/../util.sail in this case.
This can be used with the standard C trick of
$ifndef ONCE
$define ONCE
val f : unit -> unit
$endif
so no matter how many sail files include the above file, the valspec for f will only appear once.
Currently we just have $include, $define, $ifdef and $ifndef (with $else and $endif). We're using $ rather than # because # is already used in internal identifiers, although this could be switched.
Diffstat (limited to 'src/lexer.mll')
| -rw-r--r-- | src/lexer.mll | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/lexer.mll b/src/lexer.mll index 21b70c5f..77fba70b 100644 --- a/src/lexer.mll +++ b/src/lexer.mll @@ -186,9 +186,10 @@ let alphanum = letter|digit let startident = letter|'_' let ident = alphanum|['_''\'''#'] let tyvar_start = '\'' -let oper_char = ['!''$''%''&''*''+''-''.''/'':''<''=''>''@''^''|'] +let oper_char = ['!''%''&''*''+''-''.''/'':''<''=''>''@''^''|'] let operator = (oper_char+ ('_' ident)?) let escape_sequence = ('\\' ['\\''\"''\'''n''t''b''r']) | ('\\' digit digit digit) | ('\\' 'x' hexdigit hexdigit) +let lchar = [^'\n'] rule token = parse | ws @@ -236,6 +237,8 @@ rule token = parse | "//" { line_comment (Lexing.lexeme_start_p lexbuf) lexbuf; token lexbuf } | "/*" { comment (Lexing.lexeme_start_p lexbuf) 0 lexbuf; token lexbuf } | "*/" { raise (LexError("Unbalanced comment", Lexing.lexeme_start_p lexbuf)) } + | "$" (ident+ as i) (lchar* as f) "\n" + { Lexing.new_line lexbuf; Pragma(i, String.trim f) } | "infix" ws (digit as p) ws (operator as op) { operators := M.add op (mk_operator Infix (int_of_string (Char.escaped p)) op) !operators; Fixity (Infix, Big_int.of_string (Char.escaped p), op) } |
