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

gramlib parses illegal input for recursive rules #4330

Closed
vicuna opened this issue Jun 25, 2007 · 1 comment
Closed

gramlib parses illegal input for recursive rules #4330

vicuna opened this issue Jun 25, 2007 · 1 comment

Comments

@vicuna
Copy link

vicuna commented Jun 25, 2007

Original bug ID: 4330
Reporter: brunodefraine
Assigned to: ertai
Status: closed (set by ertai on 2008-10-03T15:13:05Z)
Resolution: fixed
Priority: normal
Severity: major
Version: 3.10.0
Fixed in version: 3.11+dev
Category: -for Camlp4 use https://github.com/ocaml/camlp4/issues

Bug description

When defining a recursive rule for a binary operator, gramlib accepts input that illegally ommits a right operand.

For example, with the following grammar definition:

open Camlp4.PreCast ;

value a = Gram.Entry.mk "a" ;
value a_eoi = Gram.Entry.mk "a_eoi" ;

EXTEND Gram
a: [[ "one" -> 1 | x = a; "plus"; y = a -> x+y ]];
a_eoi: [[ x = a; `EOI -> x ]];
END ;

and the following function:

value parse_string entry s =
try
Gram.parse_string entry (Loc.mk "") s
with [ Loc.Exc_located loc exn ->
begin
print_endline (Loc.to_string loc);
print_endline (Printexc.to_string exn);
failwith "Syntax Error"
end ] ;

The following is correct:

parse_string a_eoi "one plus one" ;

  • : int = 2

While all of the following inputs should be rejected because they are not legal according to the grammar:

parse_string a_eoi "one plus" ;

  • : int = 1

parse_string a_eoi "one plus plus" ;

  • : int = 1

parse_string a_eoi "one plus one plus" ;

  • : int = 2

parse_string a_eoi "one plus one plus plus" ;

  • : int = 2

Curiously, you may only repeat the operator twice. If you specify it three times, gramlib complains.

parse_string a_eoi "one plus plus plus" ;

File "", line 1, characters 9-13
Stream.Error("EOI expected after [a] (in [a_eoi])")
Exception: Failure "Syntax Error".

parse_string a_eoi "one plus one plus plus plus" ;

File "", line 1, characters 18-22
Stream.Error("EOI expected after [a] (in [a_eoi])")
Exception: Failure "Syntax Error".

Additional information

Tested with Ocaml 3.10.0 on Mac OS X.

File attachments

@vicuna
Copy link
Author

vicuna commented Oct 3, 2008

Comment author: ertai

Thank for the report(s) this bug is now fixed in the CVS HEAD version.

NOTE: #4603, #4330, #4551, #4513 are all the same bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant