]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
tweaked lexers for text and ruby lexers
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 12 Dec 2017 02:23:59 +0000 (21:23 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 12 Dec 2017 02:23:59 +0000 (21:23 -0500)
Makefile
lib/lexers/lex_ruby.mll
lib/lexers/lex_text.mll

index 0d98c925aeb6e807cb112dd18871168af9dd5293..60af2a75957fb5bf8501cd02d9154065c13bd141 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -38,7 +38,10 @@ BINSRCS = \
        unittests.ml
 
 LEXERS = \
-       lib/lexers/lex_cpp.ml
+       lib/lexers/lex_text.ml \
+       lib/lexers/lex_cpp.ml \
+       lib/lexers/lex_ruby.ml \
+       lib/lexers/lex_ocaml.ml
 
 LIBSRCS = \
        lib/misc.ml \
@@ -76,7 +79,7 @@ all: $(BINS) lib/lexers/lex_cpp.ml
 clean:
        $(RM) *.byte *.bin *.cm* *.o *.a
        $(RM) lib/*.cm* lib/*.o tests/*.cm* tests/*.o
-       $(RM) lib/lexers/*.cm* lib/lexers/*.ml
+       $(RM) lib/lexers/*.cm* lib/lexers/*.ml lib/lexers/*.o
 
 # Executable targets
 edit.$(BINEXT): tide.$(LIBEXT) edit.$(OBJEXT)
index 48fea7cedb4ea47515940fb5428e0937be468ee7..e5c479c7dbb42a47f73c292a1f919356899e8cc8 100644 (file)
@@ -3,60 +3,38 @@
 let oct = ['0'-'9']
 let dec = ['0'-'9']
 let hex = ['0'-'9' 'a'-'f' 'A'-'F']
-let exp = ['e''E'] ['+''-']? dec+
 
 let alpha_ = ['a'-'z' 'A'-'Z' '_']
 let alnum_ = (alpha_ | dec)
 
-let fstyle = ['f' 'F' 'l' 'L']
-let istyle = ['u' 'U' 'l' 'L']
+let ln_cmt = '#' [^'\n']*
+let typedef = ['A'-'Z'] alnum_*
+let identifier = ['@' '$']? ['a'-'z'] alnum_* ['!' '=' '?']?
 
-let ln_cmt = "//" [^ '\n']*
-let character = "'" ([^'\\' '\''] | '\\' _) "'"
-let string = '"' ([^'\\' '"'] | '\\' _)* ['"' '\n']
-let identifier = alpha_ alnum_*
-let preprocess = "#" [' ' '\t']* alpha_+
-let sys_incl = (' '|'\t')* '<' [^ '\n' '>']* '>'
+let keyword = "if" | "not" | "then" | "else" | "elsif" | "end" | "def" | "do"
+    | "exit" | "nil" | "begin" | "rescue" | "raise" | "pass" | "class" | "goto"
+    | "break" | "return" | "continue" | "case" | "default" | "switch" | "while"
+    | "for"
 
 let number = (
-    dec+ istyle*
-  | '0' ['x''X'] hex+ istyle*
-  | dec+ exp? fstyle?
-  | dec* '.' dec+ exp? fstyle?
-  | dec+ '.' dec* exp? fstyle?
+    dec+
+  | '0' ['o''O'] oct+
+  | '0' ['d''D'] dec+
+  | '0' ['x''X'] hex+
 )
 
-let const = "true" | "false" | "NULL"
-
-let keyword = "goto" | "break" | "return" | "continue" | "asm" | "case"
-    | "default" | "if" | "else" | "switch" | "while" | "for" | "do" | "sizeof"
-
-let typedef = "bool" | "short" | "int" | "long" | "unsigned" | "signed" | "char"
-    | "size_t" | "void" | "extern" | "static" | "inline" | "struct" | "enum"
-    | "typedef" | "union" | "volatile" | "auto" | "const" | "int8_t" | "int16_t"
-    | "int32_t" | "int64_t" | "uint8_t" | "uint16_t" | "uint32_t" | "uint64_t"
-    | "float" | "double"
+let string = (
+    '"' ([^'\\' '"'] | '\\' _)* '"'
+  | '/' ([^'\\' '/'] | '\\' _)* '/'
+  | '\'' ([^'\\' '\''] | '\\' _)* '\''
+)
 
 rule scan ctx = parse
-  | "/*"       { range_start ctx; comment ctx lexbuf }
   | ln_cmt     { set_color ctx Comment }
   | number     { set_color ctx Constant }
-  | character  { set_color ctx Constant }
   | string     { set_color ctx Constant }
-  | const      { set_color ctx Constant }
   | keyword    { set_color ctx Keyword }
   | typedef    { set_color ctx Type }
-  | preprocess { set_color ctx PreProcessor; preproc ctx lexbuf }
   | identifier { (* skip *) }
   | _          { scan ctx lexbuf }
   | eof        { raise Eof }
-
-and comment ctx = parse
-  | "*/" { range_stop ctx Comment }
-  | _    { comment ctx lexbuf }
-  | eof  { raise Eof }
-
-and preproc ctx = parse
-  | sys_incl { set_color ctx Constant }
-  | _        { (* skip *) }
-  | eof      { raise Eof }
index b58b158fba90801d7cda70e3353da1300fd29e2f..6800d332816f9946bf6b37de086ff1c1b0387b56 100644 (file)
@@ -1,8 +1,5 @@
 { open Colormap }
 
-let ident = ['a'-'z' 'A'-'Z']+
-
 rule scan ctx = parse
-  | ident { scan ctx lexbuf }
-  | _     { scan ctx lexbuf }
-  | eof   { raise Eof }
+  | _   { raise Eof }
+  | eof { raise Eof }