Security News
Supply Chain Attack Detected in @solana/web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Unicode-friendly lexer generator for OCaml.
This package is licensed by LexiFi under the terms of the MIT license.
Contact: alain.frisch@lexifi.com
sedlex is a lexer generator for OCaml, similar to ocamllex, but supporting Unicode. Contrary to ocamllex, lexer specifications for sedlex are embedded in regular OCaml source files.
The lexers work with a new kind of "lexbuf", similar to ocamllex Lexing lexbufs, but designed to support Unicode, and abstracting from a specific encoding. A single lexer can work with arbitrary encodings of the input stream.
sedlex is the successor of the ulex project. Contrary to ulex which was implemented as a Camlp4 syntax extension, sedlex is based on the new "-ppx" technology of OCaml, which allow rewriting OCaml parse trees through external rewriters. (And what a better name than "sed" for a rewriter?)
As any -ppx rewriter, sedlex does not touch the concrete syntax of the language: lexer specifications are written in source file which comply with the standard grammar of OCaml programs. sedlex reuse the syntax for pattern matching in order to describe lexers (regular expressions are encoded within OCaml patterns). A nice consequence is that your editor (vi, emacs, ...) won't get confused (indentation, coloring) and you don't need to learn new priority rules. Moreover, sedlex is compatible with any front-end parsing technology: it works fine even if you use camlp4 or camlp5, with the standard or revised syntax.
sedlex adds a new kind of expression to OCaml: lexer definitions. The syntax for the new construction is:
match%sedlex lexbuf with
| R1 -> e1
...
| Rn -> en
| _ -> def
or:
[%sedlex match lexbuf with
| R1 -> e1
...
| Rn -> en
| _ -> def
]
(The first vertical bar is optional as in any OCaml pattern matching. Guard expressions are not allowed.)
where:
Sedlexing.lexbuf
.Unlike ocamllex, lexers work on stream of Unicode codepoints, not bytes.
The actions can call functions from the Sedlexing module to extract (parts of) the matched lexeme, in the desired encoding.
Regular expressions are syntactically OCaml patterns:
"...."
(string constant): recognize the specified string'....'
(character constant) : recognize the specified characteri
(integer constant) : recognize the specified codepoint'...' .. '...'
: character rangei1 .. i2
: range between two codepointsR1 | R2
: alternationR, R2, ..., Rn
: concatenationStar R
: Kleene star (0 or more repetition)Plus R
: equivalent to R, R*
Opt R
: equivalent to ("" | R)
Rep (R, n)
: equivalent to R{n}
Rep (R, n .. m)
: equivalent to R{n, m}
Chars "..."
: recognize any character in the stringCompl R
: assume that R is a single-character length regexp (see below)
and recognize the complement setSub (R1,R2)
: assume that R is a single-character length regexp (see below)
and recognize the set of items in R1
but not in R2
("subtract")Intersect (R1,R2)
: assume that R
is a single-character length regexp (see
below) and recognize the set of items which are in both R1
and R2
lid
(lowercase identifier) : reference a named regexp (see below)A single-character length regexp is a regexp which does not contain (after expansion of references) concatenation, Star, Plus, Opt or string constants with a length different from one.
Note:
It is possible to define named regular expressions with the following construction, that can appear in place of a structure item:
let lid = [%sedlex.regexp? R]
where lid is the regexp name to be defined and R its definition. The scope of the "lid" regular expression is the rest of the structure, after the definition.
The same syntax can be used for local binding:
let lid = [%sedlex.regexp? R] in
body
The scope of "lid" is the body expression.
sedlex provides a set of predefined regexps:
See the interface of the Sedlexing module for a description of how to create lexbuf values (from strings, stream or channels encoded in Latin1, utf8 or utf16, or from integer arrays or streams representing Unicode code points).
It is possible to work with a custom implementation for lex buffers. To do this, you just have to ensure that a module called Sedlexing is in scope of your lexer specifications, and that it defines at least the following functions: start, next, mark, backtrack. See the interface of the Sedlexing module for more information.
The quick way:
opam install sedlex
Otherwise, the first thing to do is to compile and install sedlex. You need a recent version of OCaml and jbuilder.
make
If you have findlib, you can use it to install and use sedlex. The name of the findlib package is "sedlex".
Installation (after "make"):
make install
Compilation of OCaml files with lexer specifications:
ocamlfind ocamlc -c -package sedlex my_file.ml
When linking, you must also include the sedlex package:
ocamlfind ocamlc -o my_prog -linkpkg -package sedlex my_file.cmo
There is also a sedlex.ppx subpackage containing the code of the ppx filter. This can be used to build custom drivers (combining several ppx transformations in a single process).
You can use sedlex without findlib. To compile, you need to run the source file through -ppx rewriter ppx_sedlex. Moreover, you need to link the application with the runtime support library for sedlex (sedlexing.cma / sedlexing.cmxa).
FAQs
An OCaml lexer generator for Unicode
The npm package bs-sedlex receives a total of 1 weekly downloads. As such, bs-sedlex popularity was classified as not popular.
We found that bs-sedlex demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.