Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8cda4b6
Update .ocamlformat
dyzsr Aug 25, 2022
62b678a
Add field `alias` to Sedlex.node
dyzsr Sep 3, 2022
73e31fa
Update `regexp_of_pattern` to analyze aliases
dyzsr Sep 3, 2022
2144578
Refactor tracking path
dyzsr Sep 5, 2022
d2b29d9
Implement path tracing
dyzsr Sep 18, 2022
5f3dea9
Fix location messages
dyzsr Sep 19, 2022
8f741b2
Fix version number
dyzsr Sep 19, 2022
ad3d0a0
Bug fixes & Add testcases
dyzsr Sep 20, 2022
8e706d9
Optimize traces generation
dyzsr Sep 20, 2022
214f689
Make allow_alias a mandatory argument
dyzsr Sep 21, 2022
dc02370
Add testcases
dyzsr Sep 22, 2022
9081c14
Fix mark and backtrack
dyzsr Sep 22, 2022
fad0f51
Maintain alias starts/stops instead of pos/len
dyzsr Sep 22, 2022
e02fd3c
Fix path tracing & Use expect test
dyzsr Sep 22, 2022
86f42a8
Fix path tracing
dyzsr Sep 23, 2022
53488c6
Fix char set guard
dyzsr Sep 23, 2022
9154025
Optimize trace cases generation
dyzsr Sep 24, 2022
18f54cf
Dup case fixes
dyzsr Sep 24, 2022
18d7062
Merge alias offsets
dyzsr Sep 26, 2022
0e5dbd4
Fix merging actions
dyzsr Sep 26, 2022
72e6f3f
Optimize error message
dyzsr Sep 26, 2022
1a2961a
Update gen_alias & gen_offsets
dyzsr Sep 27, 2022
23bf119
Update actions
dyzsr Sep 27, 2022
e7258ef
Updates
dyzsr Sep 27, 2022
5ae1589
Remove nodes_idx
dyzsr Sep 27, 2022
5b63621
Optimize tracking path
dyzsr Sep 27, 2022
c8224bf
Update tracking path
dyzsr Sep 28, 2022
c63ff90
Fix the use of try with
dyzsr Sep 28, 2022
5f0bad9
Update tests
dyzsr Sep 28, 2022
f54e94d
Fix is_relevant
dyzsr Sep 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=0.19.0
#version=0.19.0
profile = conventional
break-separators = after
space-around-lists = false
Expand Down
16 changes: 15 additions & 1 deletion examples/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
(executables
(names tokenizer regressions complement subtraction repeat performance)
(names
tokenizer
regressions
complement
subtraction
repeat
performance
number_lexer)
(libraries sedlex sedlex_ppx)
(preprocess
(pps sedlex.ppx))
Expand Down Expand Up @@ -46,3 +53,10 @@
(:< performance.exe))
(action
(run %{<})))

(rule
(alias runtest)
(deps
(:< number_lexer.exe))
(action
(run %{<})))
1,164 changes: 1,164 additions & 0 deletions examples/number_lexer.gen.ml

Large diffs are not rendered by default.

93 changes: 93 additions & 0 deletions examples/number_lexer.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
let digit_2 = [%sedlex.regexp? '0' .. '1']
let digit_8 = [%sedlex.regexp? '0' .. '7']
let digit = [%sedlex.regexp? '0' .. '9']
let digit_16 = [%sedlex.regexp? digit | 'A' .. 'F' | 'a' .. 'f']
let prefix_2 = [%sedlex.regexp? "0b"]
let prefix_8 = [%sedlex.regexp? "0o"]
let prefix_16 = [%sedlex.regexp? "0x"]
let sign = [%sedlex.regexp? "" | '+' | '-']
let sign_op = [%sedlex.regexp? '+' | '-']
let num_2 = [%sedlex.regexp? Plus digit_2]
let num_8 = [%sedlex.regexp? Plus digit_8]
let num_10 = [%sedlex.regexp? Plus digit]
let num_16 = [%sedlex.regexp? Plus digit_16]

let rec token buf =
let sub (a, b) = Sedlexing.Latin1.sub_lexeme buf a b in
match%sedlex buf with
(* {Integers} *)
| (sign as s), prefix_2, (num_2 as n) ->
Printf.printf "Bin %s%s\n" (sub s) (sub n);
token buf
| (sign as s), prefix_8, (num_8 as n) ->
Printf.printf "Oct %s%s\n" (sub s) (sub n);
token buf
| (sign as s), (num_10 as n) ->
Printf.printf "Dec %s%s\n" (sub s) (sub n);
token buf
| (sign as s), prefix_16, (num_16 as n) ->
Printf.printf "Hex %s%s\n" (sub s) (sub n);
token buf
(* {Fractions} *)
| (sign as s), prefix_2, (num_2 as n), '/', (num_2 as d) ->
Printf.printf "Bin %s%s/%s\n" (sub s) (sub n) (sub d);
token buf
| (sign as s), prefix_8, (num_8 as n), '/', (num_8 as d) ->
Printf.printf "Oct %s%s/%s\n" (sub s) (sub n) (sub d);
token buf
| (sign as s), (num_10 as n), '/', (num_10 as d) ->
Printf.printf "Dec %s%s/%s\n" (sub s) (sub n) (sub d);
token buf
| (sign as s), prefix_16, (num_16 as n), '/', (num_16 as d) ->
Printf.printf "Hex %s%s/%s\n" (sub s) (sub n) (sub d);
token buf
(* {Complex Numbers} *)
| (sign as s), prefix_2, (num_2 as r), (sign_op as o), (num_2 as i), 'i' ->
Printf.printf "Bin %s%s%s%si\n" (sub s) (sub r) (sub o) (sub i);
token buf
| (sign as s), prefix_8, (num_8 as r), (sign_op as o), (num_8 as i), 'i' ->
Printf.printf "Oct %s%s%s%si\n" (sub s) (sub r) (sub o) (sub i);
token buf
| (sign as s), (num_10 as r), (sign_op as o), (num_10 as i), 'i' ->
Printf.printf "Dec %s%s%s%si\n" (sub s) (sub r) (sub o) (sub i);
token buf
| (sign as s), prefix_16, (num_16 as r), (sign_op as o), (num_16 as i), 'i'
->
Printf.printf "Hex %s%s%s%si\n" (sub s) (sub r) (sub o) (sub i);
token buf
(* {Others} *)
| Plus xml_blank -> token buf
| 128 .. 255 -> print_endline "Non ASCII"
| eof -> print_endline "EOF"
| _ -> failwith "Unexpected character"

let () =
let lexbuf =
Sedlexing.Latin1.from_string
{|
123
+123
-123
0b01010101
-0b11110000
+0b11111111
0o12345670
+0o76543210
-0o17263540
0x123abcdef
-0x456DEFabc
+0x789ABCdef
123/456
-456/789
+987/654
0o777/100
+0o200/666
1+1i
1-1i
0x1f+2ei
+0x1f-2ei
0b10+11i
-0b10-11i
|}
in
token lexbuf
2 changes: 1 addition & 1 deletion src/lib/sedlexing.mli
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ val next : lexbuf -> Uchar.t option
lexer buffer and increments to current position. If the input stream
is exhausted, the function returns -1.
If a ['\n'] is encountered, the tracked line number is incremented.

This is a private API, it should not be used by code using this module's
API and can be removed at any time. *)
val __private__next_int : lexbuf -> int
Expand Down
Loading