Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4057436
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:57:11+00:00 2026-05-20T14:57:11+00:00

I am messing around writing a toy programming language in OCaml with ocamllex, and

  • 0

I am messing around writing a toy programming language in OCaml with ocamllex, and was trying to make the language sensitive to indentation changes, python-style, but am having a problem matching the beginning of a line with ocamllex’s regex rules. I am used to using ^ to match the beginning of a line, but in OCaml that is the string concat operator. Google searches haven’t been turning up much for me unfortunately 🙁 Anyone know how this would work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T14:57:11+00:00Added an answer on May 20, 2026 at 2:57 pm

    I’m not sure if there is explicit support for zero-length matching symbols (like ^ in Perl-style regular expressions, which matches a position rather than a substring). However, you should be able to let your lexer turn newlines into an explicit token, something like this:

    parser.mly

    %token EOL
    %token <int> EOLWS
    % other stuff here
    %%
    main:
        EOL stmt                { MyStmtDataType(0, $2) }
      | EOLWS stmt              { MyStmtDataType($1 - 1, $2) }
     ;
    

    lexer.mll

    {
     open Parser
     exception Eof
    }
    rule token = parse
        [' ' '\t']           { token lexbuf }     (* skip other blanks *)
      | ['\n'][' ']+ as lxm  { EOLWS(String.length(lxm)) }
      | ['\n']               { EOL }
      (* ... *)
    

    This is untested, but the general idea is:

    • Treat newlines as staetment ‘starters’
    • Measure whitespace that immediately follows the newline and pass its length as an int

    Caveat: you will need to preprocess your input to start with a single \n if it doesn’t contain one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've started messing around with Google App Engine, writing Python. I love Visual Studio
I am messing around with a toy interpreter in Java and I was considering
I am messing around with Doctrine (version 1.0.3) to see if would make a
I have been messing around with writing some stored procedures in .NET code with
Been messing around with Hibernate and PostgreSQL trying to get it to work as
I've been writing a parser for PHP and while messing around with some third-party
Messing around with some CSS trying to learn some stuff as I haven't done
Messing around with 'extension functions' for the List module. (I spent quite a while
I was messing around with RhinoMocks this morning and couldn't run my tests because
I'm messing around with some C code using floats, and I'm getting 1.#INF00, -1.#IND00

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.