0

Coq - IP Notation

I want to create a notation for ip addresses. The following is my notation definition that works fine:

Inductive IP := ip : nat -> nat -> nat -> nat -> IP.
Notation "a . b . c . d" := (ip a b c d) (at level 100).

But when I try to use it,

Definition ex := ( 192 . 168 . 1 . 1 ).

I get the following error:

Syntax error: [constr:operconstr level 200] expected after "." (in [constr:operconstr]).

What do I have to change to fix this error.

Konstantin Weitz
  • 6,180
  • 8
  • 26
  • 43
  • I am not 100% sure but I don't think you can use the ''.'' in a notation. I tried with Notation "( a 'foo' b 'foo' c 'foo' d )" := (ip a b c d) (at level 100). Definition ex := (192 foo 168 foo 1 foo 1). (notice the additional parenthesis) and it works, but the same with ''.'' also fails. You might have to declare a new scope or something. – Vinz Mar 31 '14 at 07:23

1 Answers1

2

If you can switch from ''.'' to another symbol, it should work (take care of already existing notations and use scopes to be safe):

Inductive IP := ip : nat -> nat -> nat -> nat -> IP.
Notation "a * b * c * d" := (ip a b c d) (at level 100) : MY_scope.

Delimit Scope MY_scope with MY. 

Definition ex := ( 192 * 168 * 1 * 1 )%MY.

Depending on the symbol (for example using '','' doesn't work right away), you might want to help the parser by adding beginning/end token:

(* without the ( and ) it fails *)
Notation "( a , b , c , d )" := (ip a b c d) (at level 100) : MY_scope.

Delimit Scope MY_scope with MY. 

Definition ex := ( 192 , 168 , 1 , 1 )%MY.

If you really want to use ''.'', maybe someone on the Coq-Club mailing list can help you.

Best, V.

Vinz
  • 5,997
  • 1
  • 31
  • 52