Commit c781e458 authored by Yann Régis-Gianas's avatar Yann Régis-Gianas
Browse files

Syntax: Every producer must be named.

   If the programmer did not provide a name [_i] is used (where [i] is
   the producer's position in the right hand side).

   This syntax modification actually simplifies the code:
   - There is no more on-the-fly naming of unnamed arguments.
   - Inlining is no more restricted to semantic actions that do not use $i.

   The patch is large because:
   - This change has an impact on many modules.
   - The expected results of the bench had to be updated.
parent 943020b3
...@@ -15,18 +15,18 @@ open Syntax.Raw ...@@ -15,18 +15,18 @@ open Syntax.Raw
%% %%
expr: expr:
| VAR | _1 = VAR
{ EVar $1 } { ( EVar _1 )}
| CONST | _1 = CONST
{ EConst $1 } { ( EConst _1 )}
| expr PLUS expr | _1 = expr _2 = PLUS _3 = expr
{ EAdd ($1, $3) } { ( EAdd (_1, _3) )}
| FAIL | _1 = FAIL
{ EFail } { ( EFail )}
declarations: declarations:
| VAR EQUAL expr EOF | _1 = VAR _2 = EQUAL _3 = expr _4 = EOF
{ D ($1, $3, Suspension.create (fun () -> !ParserFix.declarations())) } { ( D (_1, _3, Suspension.create (fun () -> !ParserFix.declarations())) )}
%% %%
......
...@@ -35,101 +35,101 @@ open Mm.Raw ...@@ -35,101 +35,101 @@ open Mm.Raw
%% %%
atomic_expression: atomic_expression:
| LIDENT | _1 = LIDENT
{ EVar $1 } { ( EVar _1 )}
| LCURLY record_fields RCURLY | _1 = LCURLY _2 = record_fields _3 = RCURLY
{ ERecord $2 } { ( ERecord _2 )}
| atomic_expression DOT LIDENT | _1 = atomic_expression _2 = DOT _3 = LIDENT
{ ERecordSelection ($1, $3) } { ( ERecordSelection (_1, _3) )}
| MIXIN components END | _1 = MIXIN _2 = components _3 = END
{ let _, input, output = $2 in { ( let _, input, output = _2 in
EStructure (input, output) } EStructure (input, output) )}
| LPAREN expression RPAREN | _1 = LPAREN _2 = expression _3 = RPAREN
{ $2 } { ( _2 )}
unary_expression: unary_expression:
| atomic_expression | _1 = atomic_expression
{ $1 } { ( _1 )}
| CLOSE unary_expression | _1 = CLOSE _2 = unary_expression
{ EClose $2 } { ( EClose _2 )}
| DELETE fields IN unary_expression | _1 = DELETE _2 = fields _3 = IN _4 = unary_expression
{ EDeletion ($4, $2) } { ( EDeletion (_4, _2) )}
| FAKE LIDENT DEPENDS ON LIDENT IN unary_expression | _1 = FAKE _2 = LIDENT _3 = DEPENDS _4 = ON _5 = LIDENT _6 = IN _7 = unary_expression
{ EFakeDependency ($7, $2, $5) } { ( EFakeDependency (_7, _2, _5) )}
summand_expression: summand_expression:
| unary_expression | _1 = unary_expression
{ $1 } { ( _1 )}
| summand_expression PLUS unary_expression | _1 = summand_expression _2 = PLUS _3 = unary_expression
{ EComposition ($1, $3) } { ( EComposition (_1, _3) )}
expression: expression:
| summand_expression | _1 = summand_expression
{ $1 } { ( _1 )}
| LET REC bindings IN expression | _1 = LET _2 = REC _3 = bindings _4 = IN _5 = expression
{ ELetRec (List.rev $3, $5) } { ( ELetRec (List.rev _3, _5) )}
bindings: bindings:
| binding | _1 = binding
{ [ $1 ] } { ( [ _1 ] )}
| bindings AND binding | _1 = bindings _2 = AND _3 = binding
{ $3 :: $1 } { ( _3 :: _1 )}
binding: binding:
| LIDENT EQUAL expression | _1 = LIDENT _2 = EQUAL _3 = expression
{ ($1, $3) } { ( (_1, _3) )}
toplevel: toplevel:
| expression EOF | _1 = expression _2 = EOF
{ $1 } { ( _1 )}
record_fields: record_fields:
| |
{ StringMap.empty } { ( StringMap.empty )}
| record_fields VAL LIDENT EQUAL expression | _1 = record_fields _2 = VAL _3 = LIDENT _4 = EQUAL _5 = expression
{ StringMap.add $3 $5 $1 } { ( StringMap.add _3 _5 _1 )}
components: components:
| |
{ 0, StringMap.empty, (StringMap.empty, []) } { ( 0, StringMap.empty, (StringMap.empty, []) )}
| components VAL lident_pun dependencies EQUAL expression | _1 = components _2 = VAL _3 = lident_pun _4 = dependencies _5 = EQUAL _6 = expression
{ let xname, iname = $3 in { ( let xname, iname = _3 in
let i, input, (fields, anonymous) = $1 in let i, input, (fields, anonymous) = _1 in
let fields = StringMap.add xname ($4, iname, $6, Mm.KStructMember i) fields in let fields = StringMap.add xname (_4, iname, _6, Mm.KStructMember i) fields in
i+1, input, (fields, anonymous) } i+1, input, (fields, anonymous) )}
| components VAL WILDCARD AS LIDENT dependencies EQUAL expression | _1 = components _2 = VAL _3 = WILDCARD _4 = AS _5 = LIDENT _6 = dependencies _7 = EQUAL _8 = expression
{ let i, input, (fields, anonymous) = $1 in { ( let i, input, (fields, anonymous) = _1 in
let anonymous = ($6, $5, $8, Mm.KStructMember i) :: anonymous in let anonymous = (_6, _5, _8, Mm.KStructMember i) :: anonymous in
i+1, input, (fields, anonymous) } i+1, input, (fields, anonymous) )}
| components VAL lident_pun | _1 = components _2 = VAL _3 = lident_pun
{ let xname, iname = $3 in { ( let xname, iname = _3 in
let i, input, output = $1 in let i, input, output = _1 in
let input = StringMap.add xname iname input in let input = StringMap.add xname iname input in
i+1, input, output } i+1, input, output )}
lident_pun: lident_pun:
| LIDENT AS LIDENT | _1 = LIDENT _2 = AS _3 = LIDENT
{ $1, $3 } { ( _1, _3 )}
| LIDENT | _1 = LIDENT
{ $1, $1 } { ( _1, _1 )}
fields: fields:
| |
{ StringSet.empty } { ( StringSet.empty )}
| fields LIDENT | _1 = fields _2 = LIDENT
{ StringSet.add $2 $1 } { ( StringSet.add _2 _1 )}
dependencies: dependencies:
| |
{ [] } { ( [] )}
| LSQUARE variables RSQUARE | _1 = LSQUARE _2 = variables _3 = RSQUARE
{ $2 } { ( _2 )}
variables: variables:
| |
{ [] } { ( [] )}
| variables LIDENT | _1 = variables _2 = LIDENT
{ $2 :: $1 } { ( _2 :: _1 )}
%% %%
......
...@@ -32,134 +32,134 @@ open Fsub.Raw ...@@ -32,134 +32,134 @@ open Fsub.Raw
%% %%
toplevel: toplevel:
| EOF | _1 = EOF
{ TopEOF } { ( TopEOF )}
| Term SEMI toplevel | _1 = Term _2 = SEMI _3 = toplevel
{ TopEval ($1, $3) } { ( TopEval (_1, _3) )}
| UCID TyBinder SEMI toplevel | _1 = UCID _2 = TyBinder _3 = SEMI _4 = toplevel
{ TopTypeBind ($1, $2, $4) } { ( TopTypeBind (_1, _2, _4) )}
| LCID Binder SEMI toplevel | _1 = LCID _2 = Binder _3 = SEMI _4 = toplevel
{ TopTermBind ($1, $2, $4) } { ( TopTermBind (_1, _2, _4) )}
Binder: Binder:
| COLON Type | _1 = COLON _2 = Type
{ $2 } { ( _2 )}
Type: Type:
| ArrowType | _1 = ArrowType
{ $1 } { ( _1 )}
| ALL UCID OType DOT Type | _1 = ALL _2 = UCID _3 = OType _4 = DOT _5 = Type
{ TForall ($2, $3, $5) } { ( TForall (_2, _3, _5) )}
AType: AType:
| LPAREN Type RPAREN | _1 = LPAREN _2 = Type _3 = RPAREN
{ $2 } { ( _2 )}
| UCID | _1 = UCID
{ TVar $1 } { ( TVar _1 )}
| TTOP | _1 = TTOP
{ TTop } { ( TTop )}
| LCURLY FieldTypes RCURLY | _1 = LCURLY _2 = FieldTypes _3 = RCURLY
{ TRecord $2 } { ( TRecord _2 )}
TyBinder: TyBinder:
| |
{ TTop } { ( TTop )}
| LEQ Type | _1 = LEQ _2 = Type
{ $2 } { ( _2 )}
ArrowType: ArrowType:
| AType ARROW ArrowType | _1 = AType _2 = ARROW _3 = ArrowType
{ TArrow ($1, $3) } { ( TArrow (_1, _3) )}
| AType | _1 = AType
{ $1 } { ( _1 )}
Term: Term:
| AppTerm | _1 = AppTerm
{ $1 } { ( _1 )}
| LAMBDA LCID COLON Type DOT Term | _1 = LAMBDA _2 = LCID _3 = COLON _4 = Type _5 = DOT _6 = Term
{ EAbs ($2, $4, $6) } { ( EAbs (_2, _4, _6) )}
| LET Pattern EQ Term IN Term | _1 = LET _2 = Pattern _3 = EQ _4 = Term _5 = IN _6 = Term
{ ELet ($2, $4, $6) } { ( ELet (_2, _4, _6) )}
| LAMBDA UCID OType DOT Term | _1 = LAMBDA _2 = UCID _3 = OType _4 = DOT _5 = Term
{ ETyAbs ($2, $3, $5) } { ( ETyAbs (_2, _3, _5) )}
AppTerm: AppTerm:
| PathTerm | _1 = PathTerm
{ $1 } { ( _1 )}
| AppTerm PathTerm | _1 = AppTerm _2 = PathTerm
{ EApp ($1, $2) } { ( EApp (_1, _2) )}
| AppTerm LSQUARE Type RSQUARE | _1 = AppTerm _2 = LSQUARE _3 = Type _4 = RSQUARE
{ ETyApp ($1, $3) } { ( ETyApp (_1, _3) )}
PathTerm: PathTerm:
| PathTerm DOT LCID | _1 = PathTerm _2 = DOT _3 = LCID
{ EProj ($1, $3) } { ( EProj (_1, _3) )}
| ATerm | _1 = ATerm
{ $1 } { ( _1 )}
FieldTypes: FieldTypes:
| |
{ StringMap.empty } { ( StringMap.empty )}
| NEFieldTypes | _1 = NEFieldTypes
{ $1 } { ( _1 )}
NEFieldTypes: NEFieldTypes:
| LCID COLON Type | _1 = LCID _2 = COLON _3 = Type
{ StringMap.singleton $1 $3 } { ( StringMap.singleton _1 _3 )}
| LCID COLON Type COMMA NEFieldTypes | _1 = LCID _2 = COLON _3 = Type _4 = COMMA _5 = NEFieldTypes
{ StringMap.add $1 $3 $5 } { ( StringMap.add _1 _3 _5 )}
TermSeq: TermSeq:
| Term | _1 = Term
{ $1 } { ( _1 )}
| Term SEMI TermSeq | _1 = Term _2 = SEMI _3 = TermSeq
{ ELet (PWildcard, $1, $3) } { ( ELet (PWildcard, _1, _3) )}
ATerm: ATerm:
| LPAREN TermSeq RPAREN | _1 = LPAREN _2 = TermSeq _3 = RPAREN
{ $2 } { ( _2 )}
| LCID | _1 = LCID
{ EVar $1 } { ( EVar _1 )}
| LCURLY Fields RCURLY | _1 = LCURLY _2 = Fields _3 = RCURLY
{ ERecord $2 } { ( ERecord _2 )}
Fields: Fields:
| |
{ StringMap.empty } { ( StringMap.empty )}
| NEFields | _1 = NEFields
{ $1 } { ( _1 )}
NEFields: NEFields:
| LCID EQ Term | _1 = LCID _2 = EQ _3 = Term
{ StringMap.singleton $1 $3 } { ( StringMap.singleton _1 _3 )}
| LCID EQ Term COMMA NEFields | _1 = LCID _2 = EQ _3 = Term _4 = COMMA _5 = NEFields
{ StringMap.add $1 $3 $5 } { ( StringMap.add _1 _3 _5 )}
OType: OType:
| |
{ TTop} { ( TTop)}
| LEQ Type | _1 = LEQ _2 = Type
{ $2 } { ( _2 )}
Pattern: Pattern:
| USCORE | _1 = USCORE
{ PWildcard } { ( PWildcard )}
| LCID COLON Type | _1 = LCID _2 = COLON _3 = Type
{ PVar ($1, $3) } { ( PVar (_1, _3) )}
| LCURLY PatFields RCURLY | _1 = LCURLY _2 = PatFields _3 = RCURLY
{ PRecord $2 } { ( PRecord _2 )}
PatFields: PatFields:
| |
{ StringMap.empty } { ( StringMap.empty )}
| NEPatFields | _1 = NEPatFields
{ $1 } { ( _1 )}
NEPatFields: NEPatFields:
| LCID EQ Pattern | _1 = LCID _2 = EQ _3 = Pattern
{ StringMap.singleton $1 $3 } { ( StringMap.singleton _1 _3 )}
| LCID EQ Pattern COMMA NEPatFields | _1 = LCID _2 = EQ _3 = Pattern _4 = COMMA _5 = NEPatFields
{ StringMap.add $1 $3 $5 } { ( StringMap.add _1 _3 _5 )}
%% %%
......
...@@ -56,234 +56,234 @@ open Syntax ...@@ -56,234 +56,234 @@ open Syntax
%% %%
typevar: typevar:
| QUOTE LID | _1 = QUOTE _2 = LID
{ $2 } { ( _2 )}
typevars: typevars:
| typevar | _1 = typevar
{ [ $1 ] } { ( [ _1 ] )}
| typevars COMMA typevar | _1 = typevars _2 = COMMA _3 = typevar
{ $3 :: $1 } { ( _3 :: _1 )}
params: params:
| |
{ [] } { ( [] )}
| typevar | _1 = typevar
{ [ $1 ] } { ( [ _1 ] )}
| LPAREN typevars RPAREN | _1 = LPAREN _2 = typevars _3 = RPAREN
{ List.rev $2 } { ( List.rev _2 )}
params_and_set_current: params_and_set_current:
| params | _1 = params
{ let params = $1 in { ( let params = _1 in
current_params := params; current_params := params;
params } params )}
identifier: identifier:
| LID | _1 = LID
{ $1 } { ( _1 )}
| UID DOT identifier | _1 = UID _2 = DOT _3 = identifier
{ let (pos1, _, id1) = $1 { ( let (pos1, _, id1) = _1
and (_, pos2, id2) = $3 in and (_, pos2, id2) = _3 in
(pos1, pos2, id1 ^ "." ^ id2) } (pos1, pos2, id1 ^ "." ^ id2) )}
container: container:
| |
{ None } { ( None )}
| identifier | _1 = identifier
{ Some $1 } { ( Some _1 )}
expfactor: expfactor:
| ATOM LID | _1 = ATOM _2 = LID
{ EAtom $2 } { ( EAtom _2 )}
| OCAML | _1 = OCAML
{ EEscape $1 } { ( EEscape _1 )}
| params LID container | _1 = params _2 = LID _3 = container
{ ETypRef ($3, $1, $2) } { ( ETypRef (_3, _1, _2) )}
| LANGLE params LID RANGLE | _1 = LANGLE _2 = params _3 = LID _4 = RANGLE
{ EAbstraction ($2, $3) } { ( EAbstraction (_2, _3) )}
| LANGLE LPAREN LID BINDS sorts RPAREN patrhs RANGLE | _1 = LANGLE _2 = LPAREN _3 = LID _4 = BINDS _5 = sorts _6 = RPAREN _7 = patrhs _8 = RANGLE
{ inline_defs := DeclPatType (!current_params, $3, $5, $7) :: !inline_defs; { ( inline_defs := DeclPatType (!current_params, _3, _5, _7) :: !inline_defs;
EAbstraction (!current_params, $3) } EAbstraction (!current_params, _3) )}
| ATOM error | _1 = ATOM _2 = error
{ error 2 "\"atom\" should be followed by a sort (a lowercase identifier)" } { ( error 2 "\"atom\" should be followed by a sort (a lowercase identifier)" )}
| LANGLE error | _1 = LANGLE _2 = error
{ error 2 "The contents of an abstraction should be either\n\ { ( error 2 "The contents of an abstraction should be either\n\
a (possibly parameterized) pattern type identifier or\n\ a (possibly parameterized) pattern type identifier or\n\
an inline pattern type definition." } an inline pattern type definition." )}
| INNER | _1 = INNER
{ error 1 "\"inner\" does not make sense in an expression type." } { ( error 1 "\"inner\" does not make sense in an expression type." )}
| OUTER | _1 = OUTER
{ error 1 "\"outer\" does not make sense in an expression type." } { ( error 1 "\"outer\" does not make sense in an expression type." )}
| NEUTRAL | _1 = NEUTRAL
{ error 1 "\"neutral\" does not make sense in an expression type." } { ( error 1 "\"neutral\" does not make sense in an expression type." )}
| error | _1 = error
{ error 1 "Invalid expression factor." } { ( error 1 "Invalid expression factor." )}
patfactor: patfactor:
| ATOM LID | _1 = ATOM _2 = LID
{ PAtom $2 } { ( PAtom _2 )}
| OCAML | _1 = OCAML
{ PEscape $1 } { ( PEscape _1 )}
| params LID container | _1 = params _2 = LID _3 = container
{ PTypRef (MRef, $3, $1, $2) } { ( PTypRef (MRef, _3, _1, _2) )}
| patmodifier params LID container | _1 = patmodifier _2 = params _3 = LID _4 = container
{ PTypRef ($1, $4, $2, $3) } { ( PTypRef (_1, _4, _2, _3) )}
| ATOM error | _1 = ATOM _2 = error
{ error 2 "\"atom\" should be followed by a sort (a lowercase identifier)" } { ( error 2 "\"atom\" should be followed by a sort (a lowercase identifier)" )}
| patmodifier error | _1 = patmodifier _2 = error
{ error 2 "\"inner\", \"outer\", and \"neutral\" should be followed by a\n(possibly parameterized) type identifier." } { ( error 2 "\"inner\", \"outer\", and \"neutral\" should be followed by a\n(possibly parameterized) type identifier." )}
| LANGLE | _1 = LANGLE
{ error 1 "An abstraction does not make sense in a pattern type." } { ( error 1 "An abstraction does not make sense in a pattern type." )}
| error | _1 = error
{ error 1 "Invalid pattern factor." } { ( error 1 "Invalid pattern factor." )}
patmodifier: patmodifier:
| INNER | _1 = INNER
{ MInner } { ( MInner )}
| OUTER | _1 = OUTER