Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pa_ocamllex and two arguments: Preprocessing error #2522

Closed
vicuna opened this issue Apr 28, 2004 · 2 comments
Closed

pa_ocamllex and two arguments: Preprocessing error #2522

vicuna opened this issue Apr 28, 2004 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Apr 28, 2004

Original bug ID: 2522
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Hi everybody.

I have noticed a strange behavior in the pa_ocamllex library of CamlP4.

I was using CamlP4 as preprocessor in a .ml file to have a simple
parser. Today I needed to add a new parameter to the parsing rule and I
got this error:

Failure: this is not a constructor, it cannot be applied in a pattern
Preprocessing error

To solve the problem I changed the file into a .mll file to parse it
with ocamllex and everything worked.
Thus I have compared the source code as result of the preprocessor and
ocamllex in both cases and I found that the pa_ocamllex understands the
two arguments as one argument.

Here is a sample code that reproduces the error

#use "topfind";;
#camlp4o;;
#load "pa_ocamllex.cma";;

pa_ocamllex let x = 'x';;
(* no arguments )
pa_ocamllex rule foo = parse | x { Yep } | ['\000'-'\255'] { Nope };;
(
just one argument )
pa_ocamllex rule fee fuz = parse | x { Yep(fuz) } | ['\000'-'\255'] { Nope };;
(
two arguments *)
pa_ocamllex rule bar bee buz = parse | x { Yep(bee) } | [ '\000'-'\255' ] { Nope(buz) };;

The first rule has no parameters and it is compiled correctly.
The second one, with one argument, is working fine too.
The third one gives the problem: it is understood as a function named
bar with arguments (bee buz as ...) and (lexbuf as ..).

I am working with Ocaml 3.07+2 and CamlP4 3.07+2 on Linux.

Thanks for your attention
Luca Pascali

@vicuna
Copy link
Author

vicuna commented May 7, 2004

Comment author: administrator

Hello,

I found the bug report 2522 about pa_ocamllex. The problem can be solved
by applying the following patch to camlp4/etc/pa_ocamllex.ml:

definition: [

  • [ x=LIDENT; pl = LIST0 Pcaml.patt; "=";
  • [ x=LIDENT; pl = LIST0 Pcaml.patt LEVEL "simple"; "=";
    short=[ LIDENT "parse" -> false | LIDENT "shortest" -> true ];
    OPT "|"; l = LIST0 [ r=regexp; a=action -> (r,a) ] SEP "|" ->
    { name=x ; shortest=short ; args=pl ; clauses = l } ]
    ];

Moreover, I noticed that pa_ocamllex has been removed from the build
process between OCaml 3.06 and OCaml 3.07. Has it been done on purpose ?

For Luca: note that pa_ocamllex is not really maintained. In particular,
it doesn't include new features from ocamllex (such as named capture).

-- Alain

@vicuna
Copy link
Author

vicuna commented May 13, 2004

Comment author: administrator

Fixed by MM on 2004-05-13.

@vicuna vicuna closed this as completed May 13, 2004
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant