# \#ocamllex

**URL:** https://discuss.ocaml.org/tag/ocamllex/317.md

[Latest](https://discuss.ocaml.org/latest.md) · [Categories](https://discuss.ocaml.org/categories.md) · [Tags](https://discuss.ocaml.org/tags.md)

---

## [\[ocamllex\] how to specify strings not matching a pattern](https://discuss.ocaml.org/t/ocamllex-how-to-specify-strings-not-matching-a-pattern/16711)

<div class="topic-metadata">

**Author:** [@v01dXYZ](https://discuss.ocaml.org/u/v01dXYZ)\
**Replies:** 1\
**Last updated:** [May 27, 2025, 10:15am UTC](https://discuss.ocaml.org/t/ocamllex-how-to-specify-strings-not-matching-a-pattern/16711 "2025-05-27T10:15:33Z")

</div>

Hello, I’m trying to implement a RestructuredText parser as a stepping stone for an OCaML implementaition of Sphinx. I’ve got a problem with implementing the inline markup especially the strong markup (eg \*\*my strongifi…

---

## [Bug with Ocamllex](https://discuss.ocaml.org/t/bug-with-ocamllex/13413)

<div class="topic-metadata">

**Author:** [@os12345678](https://discuss.ocaml.org/u/os12345678)\
**Replies:** 8\
**Last updated:** [November 14, 2023, 9:22am UTC](https://discuss.ocaml.org/t/bug-with-ocamllex/13413 "2023-11-14T09:22:40Z")

</div>

Hi all, I’ve been playing around with what i think is a bug with ocamllex. I am creating a compiler and have noticed some unusual activity with the ‘-’ operator. I have defined my set of tokens using ocamllex rule read…

---

## [Lexer rule to create multiple tokens from a match](https://discuss.ocaml.org/t/lexer-rule-to-create-multiple-tokens-from-a-match/11521)

<div class="topic-metadata">

**Author:** [@intermet](https://discuss.ocaml.org/u/intermet)\
**Replies:** 5\
**Last updated:** [February 27, 2023, 1:15pm UTC](https://discuss.ocaml.org/t/lexer-rule-to-create-multiple-tokens-from-a-match/11521 "2023-02-27T13:15:39Z")

</div>

Hi! I am writing a lexer. Typical strings to tokenize are "Push 1" "Push 1 2" I am parsing a programming language and push means pushing to the stack. "Push 1" push '1' to the stack and "Push 1 2" pushes '1' and then '…

---

## [What is this syntax in the .ml files generated by ocamllex?](https://discuss.ocaml.org/t/what-is-this-syntax-in-the-ml-files-generated-by-ocamllex/9292)

<div class="topic-metadata">

**Author:** [@anentropic](https://discuss.ocaml.org/u/anentropic)\
**Replies:** 3\
**Last updated:** [February 8, 2022, 6:41pm UTC](https://discuss.ocaml.org/t/what-is-this-syntax-in-the-ml-files-generated-by-ocamllex/9292 "2022-02-08T18:41:54Z")

</div>

When I generate an .ml file with ocamllex it has a bunch of lines like: # 21 "lib/myproj/example.ml" (where the # is actually there in the code, I’m not copy and pasting from utop) They look kind of like comments, but…

---

## [Handling blank lines in a list of values](https://discuss.ocaml.org/t/handling-blank-lines-in-a-list-of-values/9196)

<div class="topic-metadata">

**Author:** [@Richard-Degenne](https://discuss.ocaml.org/u/Richard-Degenne)\
**Replies:** 4\
**Last updated:** [January 21, 2022, 9:06pm UTC](https://discuss.ocaml.org/t/handling-blank-lines-in-a-list-of-values/9196 "2022-01-21T21:06:02Z")

</div>

Hi! I am playing around with Menhir and Ocamllex. The format I’m trying to parse is the following 1:a:b 2:c:d A list of colon-separated triples, where the first item is an integer, and the second and third are strings…

---

## [Ocamllex and menhir examples that aren't calculators](https://discuss.ocaml.org/t/ocamllex-and-menhir-examples-that-arent-calculators/8843)

<div class="topic-metadata">

**Author:** [@SeedyROM](https://discuss.ocaml.org/u/SeedyROM)\
**Replies:** 10\
**Last updated:** [November 20, 2021, 6:28pm UTC](https://discuss.ocaml.org/t/ocamllex-and-menhir-examples-that-arent-calculators/8843 "2021-11-20T18:28:24Z")

</div>

Preface: I’m currently trying to parse a very simple document format using the above tools (and probably more than one document at a time), however all the examples I seem to find are for a calculator directly evaluatin…

---

## [How to write lexer rules correctly](https://discuss.ocaml.org/t/how-to-write-lexer-rules-correctly/8161)

<div class="topic-metadata">

**Author:** [@mkp](https://discuss.ocaml.org/u/mkp)\
**Replies:** 1\
**Last updated:** [July 18, 2021, 6:01pm UTC](https://discuss.ocaml.org/t/how-to-write-lexer-rules-correctly/8161 "2021-07-18T18:01:16Z")

</div>

I’m learning how to write a parser, and I was following the calc.ml example from Chapter 13 of the manual (OCaml - Lexer and parser generators (ocamllex, ocamlyacc)). The program compiles and runs as expected. When inpu…

---

## [High-performance lexing in OCaml](https://discuss.ocaml.org/t/high-performance-lexing-in-ocaml/7552)

<div class="topic-metadata">

**Author:** [@Chet\_Murthy](https://discuss.ocaml.org/u/Chet_Murthy)\
**Replies:** 20\
**Last updated:** [April 1, 2021, 7:09pm UTC](https://discuss.ocaml.org/t/high-performance-lexing-in-ocaml/7552 "2021-04-01T19:09:25Z")

</div>

I’m in the process of writing parser for a YAML-like language, that extends JSON, and is specified in two layers: a lexical layer, and a grammatical layer. The current implementation uses sedlex + camlp5 extensible gram…

---

## [Sedlex (why not ocamllex?)](https://discuss.ocaml.org/t/sedlex-why-not-ocamllex/7528)

<div class="topic-metadata">

**Author:** [@Chet\_Murthy](https://discuss.ocaml.org/u/Chet_Murthy)\
**Replies:** 2\
**Last updated:** [March 26, 2021, 12:27pm UTC](https://discuss.ocaml.org/t/sedlex-why-not-ocamllex/7528 "2021-03-26T12:27:39Z")

</div>

I’ve been using sedlex to write a YAML parser, and it’s worked very well. Pretty much, “does what it says on the can”. But in the process, I’ve started to wonder why sedlex is different from ocamllex. A long time ago,…

---

## [Type Lexbuf explanation](https://discuss.ocaml.org/t/type-lexbuf-explanation/6406)

<div class="topic-metadata">

**Author:** [@teja\_pr](https://discuss.ocaml.org/u/teja_pr)\
**Replies:** 1\
**Last updated:** [September 12, 2020, 9:25am UTC](https://discuss.ocaml.org/t/type-lexbuf-explanation/6406 "2020-09-12T09:25:37Z")

</div>

type lexbuf = { refill\_buff : lexbuf -\> unit; mutable lex\_buffer : bytes; mutable lex\_buffer\_len : int; mutable lex\_abs\_pos : int; mutable lex\_start\_pos : int; mutable lex\_curr\_pos : int; mutabl…

---

## [Lexer rule for C# attribute/annotation](https://discuss.ocaml.org/t/lexer-rule-for-c-attribute-annotation/6264)

<div class="topic-metadata">

**Author:** [@NavnathKumbhar](https://discuss.ocaml.org/u/NavnathKumbhar)\
**Replies:** 11\
**Last updated:** [August 21, 2020, 6:47pm UTC](https://discuss.ocaml.org/t/lexer-rule-for-c-attribute-annotation/6264 "2020-08-21T18:47:44Z")

</div>

Hi, I want to create a lexer rule to capture a C# attribute. Example of C# attributes are: \[Serializable\] public class SampleClass { // Objects of this type can be serialized. } \[System.Runtime.InteropServices.Dl…

---

## [Understanding lexbuf](https://discuss.ocaml.org/t/understanding-lexbuf/4826)

<div class="topic-metadata">

**Author:** [@NavnathKumbhar](https://discuss.ocaml.org/u/NavnathKumbhar)\
**Replies:** 6\
**Last updated:** [December 6, 2019, 1:38pm UTC](https://discuss.ocaml.org/t/understanding-lexbuf/4826 "2019-12-06T13:38:51Z")

</div>

Hello, Please consider below Java annoation: @SuppressWarnings(“unchecked”) I am trying to capture this annotation using below lexer rule: let identifier\_nondigit = \['A'-'Z' 'a'-'z' '\_' '@' '$'\] let identifier = (i…

---

## [Lexer rule for C++ 11 raw string literal](https://discuss.ocaml.org/t/lexer-rule-for-c-11-raw-string-literal/4192)

<div class="topic-metadata">

**Author:** [@NavnathKumbhar](https://discuss.ocaml.org/u/NavnathKumbhar)\
**Replies:** 2\
**Last updated:** [August 7, 2019, 5:18am UTC](https://discuss.ocaml.org/t/lexer-rule-for-c-11-raw-string-literal/4192 "2019-08-07T05:18:30Z")

</div>

Hello, I am new to ocamllex lexer generators. I am trying to capture raw string literal in C++ version 11 using ocamllex. \[https://en.cppreference.com/w/cpp/language/string\_literal\] I am using below regular expression…
