diff options
author | mitchell <unknown> | 2018-03-11 23:04:41 -0400 |
---|---|---|
committer | mitchell <unknown> | 2018-03-11 23:04:41 -0400 |
commit | 519b7328b66c4c84f03893a31e4be5ba6b1395f2 (patch) | |
tree | 2055cd79006357e94c185f341d0df17b9a8769eb /lexlua/caml.lua | |
parent | c0373e036e965a70045971e2abc582cb4bf12a4e (diff) | |
download | scintilla-mirror-519b7328b66c4c84f03893a31e4be5ba6b1395f2.tar.gz |
Added optional Lua lexer support.
This support is disabled by default and must be enabled via compile-time option.
Diffstat (limited to 'lexlua/caml.lua')
-rw-r--r-- | lexlua/caml.lua | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/lexlua/caml.lua b/lexlua/caml.lua new file mode 100644 index 000000000..10e308af0 --- /dev/null +++ b/lexlua/caml.lua @@ -0,0 +1,62 @@ +-- Copyright 2006-2018 Mitchell mitchell.att.foicica.com. See License.txt. +-- OCaml LPeg lexer. + +local lexer = require('lexer') +local token, word_match = lexer.token, lexer.word_match +local P, R, S = lpeg.P, lpeg.R, lpeg.S + +local lex = lexer.new('caml') + +-- Whitespace. +lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) + +-- Keywords. +lex:add_rule('keyword', token(lexer.KEYWORD, word_match[[ + and as asr begin class closed constraint do done downto else end exception + external failwith false flush for fun function functor if in include incr + inherit land let load los lsl lsr lxor match method mod module mutable new not + of open option or parser private raise rec ref regexp sig stderr stdin stdout + struct then to true try type val virtual when while with +]])) + +-- Types. +lex:add_rule('type', token(lexer.TYPE, word_match[[ + bool char float int string unit +]])) + +-- Functions. +lex:add_rule('function', token(lexer.FUNCTION, word_match[[ + abs abs_float acos asin atan atan2 at_exit bool_of_string ceil char_of_int + classify_float close_in close_in_noerr close_out close_out_noerr compare cos + cosh decr epsilon_float exit exp failwith float float_of_int float_of_string + floor flush flush_all format_of_string frexp fst ignore in_channel_length incr + infinity input input_binary_int input_byte input_char input_line input_value + int_of_char int_of_float int_of_string invalid_arg ldexp log log10 max + max_float max_int min min_float min_int mod modf mod_float nan open_in + open_in_bin open_in_gen open_out open_out_bin open_out_gen out_channel_length + output output_binary_int output_byte output_char output_string output_value + pos_in pos_out pred prerr_char prerr_endline prerr_float prerr_int + prerr_newline prerr_string print_char print_endline print_float print_int + print_newline print_string raise read_float read_int read_line really_input + seek_in seek_out set_binary_mode_in set_binary_mode_out sin sinh snd sqrt + stderr stdin stdout string_of_bool string_of_float string_of_format + string_of_int succ tan tanh truncate +]])) + +-- Identifiers. +lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) + +-- Strings. +lex:add_rule('string', token(lexer.STRING, lexer.delimited_range("'", true) + + lexer.delimited_range('"', true))) + +-- Comments. +lex:add_rule('comment', token(lexer.COMMENT, lexer.nested_pair('(*', '*)'))) + +-- Numbers. +lex:add_rule('number', token(lexer.NUMBER, lexer.float + lexer.integer)) + +-- Operators. +lex:add_rule('operator', token(lexer.OPERATOR, S('=<>+-*/.,:;~!#%^&|?[](){}'))) + +return lex |