forked from GitHub/gf-core
Use Happy grammar for imports extraction instead of hand made shallow crapy grammar
This commit is contained in:
@@ -32,6 +32,20 @@ separator Transfer "" ;--%
|
||||
TransferIn. Transfer ::= "(" "transfer" "in" Open ")" ; --%
|
||||
TransferOut. Transfer ::= "(" "transfer" "out" Open ")" ; --%
|
||||
|
||||
-- the module header
|
||||
|
||||
MModule2. ModHeader ::= ComplMod ModType "=" ModHeaderBody ;
|
||||
|
||||
MBody2. ModHeaderBody ::= Extend Opens ;
|
||||
MNoBody2. ModHeaderBody ::= [Included] ;
|
||||
MWith2. ModHeaderBody ::= Included "with" [Open] ;
|
||||
MWithBody2. ModHeaderBody ::= Included "with" [Open] "**" Opens ;
|
||||
MWithE2. ModHeaderBody ::= [Included] "**" Included "with" [Open] ;
|
||||
MWithEBody2. ModHeaderBody ::= [Included] "**" Included "with" [Open] "**" Opens ;
|
||||
|
||||
MReuse2. ModHeaderBody ::= "reuse" PIdent ; --%
|
||||
MUnion2. ModHeaderBody ::= "union" [Included] ;--%
|
||||
|
||||
-- the individual modules
|
||||
|
||||
MModule. ModDef ::= ComplMod ModType "=" ModBody ;
|
||||
|
||||
11362
src/GF/Source/ParGF.hs
11362
src/GF/Source/ParGF.hs
File diff suppressed because one or more lines are too long
@@ -1,7 +1,7 @@
|
||||
-- This Happy file was machine-generated by the BNF converter
|
||||
{
|
||||
{-# OPTIONS -fno-warn-incomplete-patterns -fno-warn-overlapping-patterns #-}
|
||||
module GF.Source.ParGF (pGrammar, pModDef, pOldGrammar, pExp, myLexer) where --H
|
||||
module GF.Source.ParGF (pGrammar, pModDef, pOldGrammar, pExp, pModHeader, myLexer) where --H
|
||||
import GF.Source.AbsGF --H
|
||||
import GF.Source.LexGF --H
|
||||
import GF.Infra.Ident --H
|
||||
@@ -12,6 +12,7 @@ import GF.Data.ErrM --H
|
||||
%name pModDef ModDef
|
||||
%name pOldGrammar OldGrammar
|
||||
%name pExp Exp
|
||||
%partial pModHeader ModHeader
|
||||
|
||||
-- no lexer declaration
|
||||
%monad { Err } { thenM } { returnM }
|
||||
@@ -38,6 +39,7 @@ import GF.Data.ErrM --H
|
||||
'<' { PT _ (TS "<") }
|
||||
'>' { PT _ (TS ">") }
|
||||
'@' { PT _ (TS "@") }
|
||||
'#' { PT _ (TS "#") }
|
||||
'!' { PT _ (TS "!") }
|
||||
'*' { PT _ (TS "*") }
|
||||
'+' { PT _ (TS "+") }
|
||||
@@ -94,21 +96,21 @@ import GF.Data.ErrM --H
|
||||
'where' { PT _ (TS "where") }
|
||||
'with' { PT _ (TS "with") }
|
||||
|
||||
L_ident { PT _ (TV $$) }
|
||||
L_integ { PT _ (TI $$) }
|
||||
L_quoted { PT _ (TL $$) }
|
||||
L_doubl { PT _ (TD $$) }
|
||||
L_LString { PT _ (T_LString $$) }
|
||||
L_PIdent { PT _ (T_PIdent _) }
|
||||
L_err { _ }
|
||||
|
||||
|
||||
%%
|
||||
|
||||
Ident :: { Ident } : L_ident { identC $1 } --H
|
||||
Integer :: { Integer } : L_integ { (read $1) :: Integer }
|
||||
String :: { String } : L_quoted { $1 }
|
||||
Double :: { Double } : L_doubl { (read $1) :: Double }
|
||||
LString :: { LString} : L_LString { LString ($1)}
|
||||
PIdent :: { PIdent} : L_PIdent { PIdent (mkPosToken $1)}
|
||||
|
||||
Grammar :: { Grammar }
|
||||
Grammar : ListModDef { Gr (reverse $1) }
|
||||
@@ -121,12 +123,12 @@ ListModDef : {- empty -} { [] }
|
||||
|
||||
ModDef :: { ModDef }
|
||||
ModDef : ModDef ';' { $1 }
|
||||
| 'grammar' Ident '=' '{' 'abstract' '=' Ident ';' ListConcSpec '}' { MMain $2 $7 $9 }
|
||||
| 'grammar' PIdent '=' '{' 'abstract' '=' PIdent ';' ListConcSpec '}' { MMain $2 $7 $9 }
|
||||
| ComplMod ModType '=' ModBody { MModule $1 $2 $4 }
|
||||
|
||||
|
||||
ConcSpec :: { ConcSpec }
|
||||
ConcSpec : Ident '=' ConcExp { ConcSpec $1 $3 }
|
||||
ConcSpec : PIdent '=' ConcExp { ConcSpec $1 $3 }
|
||||
|
||||
|
||||
ListConcSpec :: { [ConcSpec] }
|
||||
@@ -136,7 +138,7 @@ ListConcSpec : {- empty -} { [] }
|
||||
|
||||
|
||||
ConcExp :: { ConcExp }
|
||||
ConcExp : Ident ListTransfer { ConcExp $1 (reverse $2) }
|
||||
ConcExp : PIdent ListTransfer { ConcExp $1 (reverse $2) }
|
||||
|
||||
|
||||
ListTransfer :: { [Transfer] }
|
||||
@@ -149,13 +151,28 @@ Transfer : '(' 'transfer' 'in' Open ')' { TransferIn $4 }
|
||||
| '(' 'transfer' 'out' Open ')' { TransferOut $4 }
|
||||
|
||||
|
||||
ModHeader :: { ModDef }
|
||||
ModHeader : ComplMod ModType '=' ModHeaderBody { MModule $1 $2 $4 }
|
||||
|
||||
|
||||
ModHeaderBody :: { ModBody }
|
||||
ModHeaderBody : Extend Opens { MBody $1 $2 [] }
|
||||
| ListIncluded { MNoBody $1 }
|
||||
| Included 'with' ListOpen { MWith $1 $3 }
|
||||
| Included 'with' ListOpen '**' Opens { MWithBody $1 $3 $5 [] }
|
||||
| ListIncluded '**' Included 'with' ListOpen { MWithE $1 $3 $5 }
|
||||
| ListIncluded '**' Included 'with' ListOpen '**' Opens { MWithEBody $1 $3 $5 $7 [] }
|
||||
| 'reuse' PIdent { MReuse $2 }
|
||||
| 'union' ListIncluded { MUnion $2 }
|
||||
|
||||
|
||||
ModType :: { ModType }
|
||||
ModType : 'abstract' Ident { MTAbstract $2 }
|
||||
| 'resource' Ident { MTResource $2 }
|
||||
| 'interface' Ident { MTInterface $2 }
|
||||
| 'concrete' Ident 'of' Ident { MTConcrete $2 $4 }
|
||||
| 'instance' Ident 'of' Ident { MTInstance $2 $4 }
|
||||
| 'transfer' Ident ':' Open '->' Open { MTTransfer $2 $4 $6 }
|
||||
ModType : 'abstract' PIdent { MTAbstract $2 }
|
||||
| 'resource' PIdent { MTResource $2 }
|
||||
| 'interface' PIdent { MTInterface $2 }
|
||||
| 'concrete' PIdent 'of' PIdent { MTConcrete $2 $4 }
|
||||
| 'instance' PIdent 'of' PIdent { MTInstance $2 $4 }
|
||||
| 'transfer' PIdent ':' Open '->' Open { MTTransfer $2 $4 $6 }
|
||||
|
||||
|
||||
ModBody :: { ModBody }
|
||||
@@ -165,7 +182,7 @@ ModBody : Extend Opens '{' ListTopDef '}' { MBody $1 $2 (reverse $4) }
|
||||
| Included 'with' ListOpen '**' Opens '{' ListTopDef '}' { MWithBody $1 $3 $5 (reverse $7) }
|
||||
| ListIncluded '**' Included 'with' ListOpen { MWithE $1 $3 $5 }
|
||||
| ListIncluded '**' Included 'with' ListOpen '**' Opens '{' ListTopDef '}' { MWithEBody $1 $3 $5 $7 (reverse $9) }
|
||||
| 'reuse' Ident { MReuse $2 }
|
||||
| 'reuse' PIdent { MReuse $2 }
|
||||
| 'union' ListIncluded { MUnion $2 }
|
||||
|
||||
|
||||
@@ -191,9 +208,9 @@ Opens : {- empty -} { NoOpens }
|
||||
|
||||
|
||||
Open :: { Open }
|
||||
Open : Ident { OName $1 }
|
||||
| '(' QualOpen Ident ')' { OQualQO $2 $3 }
|
||||
| '(' QualOpen Ident '=' Ident ')' { OQual $2 $3 $5 }
|
||||
Open : PIdent { OName $1 }
|
||||
| '(' QualOpen PIdent ')' { OQualQO $2 $3 }
|
||||
| '(' QualOpen PIdent '=' PIdent ')' { OQual $2 $3 $5 }
|
||||
|
||||
|
||||
ComplMod :: { ComplMod }
|
||||
@@ -214,9 +231,9 @@ ListIncluded : {- empty -} { [] }
|
||||
|
||||
|
||||
Included :: { Included }
|
||||
Included : Ident { IAll $1 }
|
||||
| Ident '[' ListIdent ']' { ISome $1 $3 }
|
||||
| Ident '-' '[' ListIdent ']' { IMinus $1 $4 }
|
||||
Included : PIdent { IAll $1 }
|
||||
| PIdent '[' ListPIdent ']' { ISome $1 $3 }
|
||||
| PIdent '-' '[' ListPIdent ']' { IMinus $1 $4 }
|
||||
|
||||
|
||||
Def :: { Def }
|
||||
@@ -244,28 +261,28 @@ TopDef : 'cat' ListCatDef { DefCat $2 }
|
||||
| 'printname' ListPrintDef { DefPrintOld $2 }
|
||||
| 'lintype' ListDef { DefLintype $2 }
|
||||
| 'pattern' ListDef { DefPattern $2 }
|
||||
| 'package' Ident '=' '{' ListTopDef '}' ';' { DefPackage $2 (reverse $5) }
|
||||
| 'package' PIdent '=' '{' ListTopDef '}' ';' { DefPackage $2 (reverse $5) }
|
||||
| 'var' ListDef { DefVars $2 }
|
||||
| 'tokenizer' Ident ';' { DefTokenizer $2 }
|
||||
| 'tokenizer' PIdent ';' { DefTokenizer $2 }
|
||||
|
||||
|
||||
CatDef :: { CatDef }
|
||||
CatDef : Ident ListDDecl { SimpleCatDef $1 (reverse $2) }
|
||||
| '[' Ident ListDDecl ']' { ListCatDef $2 (reverse $3) }
|
||||
| '[' Ident ListDDecl ']' '{' Integer '}' { ListSizeCatDef $2 (reverse $3) $6 }
|
||||
CatDef : PIdent ListDDecl { SimpleCatDef $1 (reverse $2) }
|
||||
| '[' PIdent ListDDecl ']' { ListCatDef $2 (reverse $3) }
|
||||
| '[' PIdent ListDDecl ']' '{' Integer '}' { ListSizeCatDef $2 (reverse $3) $6 }
|
||||
|
||||
|
||||
FunDef :: { FunDef }
|
||||
FunDef : ListIdent ':' Exp { FunDef $1 $3 }
|
||||
FunDef : ListPIdent ':' Exp { FunDef $1 $3 }
|
||||
|
||||
|
||||
DataDef :: { DataDef }
|
||||
DataDef : Ident '=' ListDataConstr { DataDef $1 $3 }
|
||||
DataDef : PIdent '=' ListDataConstr { DataDef $1 $3 }
|
||||
|
||||
|
||||
DataConstr :: { DataConstr }
|
||||
DataConstr : Ident { DataId $1 }
|
||||
| Ident '.' Ident { DataQId $1 $3 }
|
||||
DataConstr : PIdent { DataId $1 }
|
||||
| PIdent '.' PIdent { DataQId $1 $3 }
|
||||
|
||||
|
||||
ListDataConstr :: { [DataConstr] }
|
||||
@@ -275,13 +292,13 @@ ListDataConstr : {- empty -} { [] }
|
||||
|
||||
|
||||
ParDef :: { ParDef }
|
||||
ParDef : Ident '=' ListParConstr { ParDefDir $1 $3 }
|
||||
| Ident '=' '(' 'in' Ident ')' { ParDefIndir $1 $5 }
|
||||
| Ident { ParDefAbs $1 }
|
||||
ParDef : PIdent '=' ListParConstr { ParDefDir $1 $3 }
|
||||
| PIdent '=' '(' 'in' PIdent ')' { ParDefIndir $1 $5 }
|
||||
| PIdent { ParDefAbs $1 }
|
||||
|
||||
|
||||
ParConstr :: { ParConstr }
|
||||
ParConstr : Ident ListDDecl { ParConstr $1 (reverse $2) }
|
||||
ParConstr : PIdent ListDDecl { ParConstr $1 (reverse $2) }
|
||||
|
||||
|
||||
PrintDef :: { PrintDef }
|
||||
@@ -289,7 +306,7 @@ PrintDef : ListName '=' Exp { PrintDef $1 $3 }
|
||||
|
||||
|
||||
FlagDef :: { FlagDef }
|
||||
FlagDef : Ident '=' Ident { FlagDef $1 $3 }
|
||||
FlagDef : PIdent '=' PIdent { FlagDef $1 $3 }
|
||||
|
||||
|
||||
ListDef :: { [Def] }
|
||||
@@ -333,14 +350,14 @@ ListParConstr : {- empty -} { [] }
|
||||
| ParConstr '|' ListParConstr { (:) $1 $3 }
|
||||
|
||||
|
||||
ListIdent :: { [Ident] }
|
||||
ListIdent : Ident { (:[]) $1 }
|
||||
| Ident ',' ListIdent { (:) $1 $3 }
|
||||
ListPIdent :: { [PIdent] }
|
||||
ListPIdent : PIdent { (:[]) $1 }
|
||||
| PIdent ',' ListPIdent { (:) $1 $3 }
|
||||
|
||||
|
||||
Name :: { Name }
|
||||
Name : Ident { IdentName $1 }
|
||||
| '[' Ident ']' { ListName $2 }
|
||||
Name : PIdent { IdentName $1 }
|
||||
| '[' PIdent ']' { ListName $2 }
|
||||
|
||||
|
||||
ListName :: { [Name] }
|
||||
@@ -349,9 +366,9 @@ ListName : Name { (:[]) $1 }
|
||||
|
||||
|
||||
LocDef :: { LocDef }
|
||||
LocDef : ListIdent ':' Exp { LDDecl $1 $3 }
|
||||
| ListIdent '=' Exp { LDDef $1 $3 }
|
||||
| ListIdent ':' Exp '=' Exp { LDFull $1 $3 $5 }
|
||||
LocDef : ListPIdent ':' Exp { LDDecl $1 $3 }
|
||||
| ListPIdent '=' Exp { LDDef $1 $3 }
|
||||
| ListPIdent ':' Exp '=' Exp { LDFull $1 $3 $5 }
|
||||
|
||||
|
||||
ListLocDef :: { [LocDef] }
|
||||
@@ -361,9 +378,9 @@ ListLocDef : {- empty -} { [] }
|
||||
|
||||
|
||||
Exp6 :: { Exp }
|
||||
Exp6 : Ident { EIdent $1 }
|
||||
| '{' Ident '}' { EConstr $2 }
|
||||
| '%' Ident '%' { ECons $2 }
|
||||
Exp6 : PIdent { EIdent $1 }
|
||||
| '{' PIdent '}' { EConstr $2 }
|
||||
| '%' PIdent '%' { ECons $2 }
|
||||
| Sort { ESort $1 }
|
||||
| String { EString $1 }
|
||||
| Integer { EInt $1 }
|
||||
@@ -371,11 +388,11 @@ Exp6 : Ident { EIdent $1 }
|
||||
| '?' { EMeta }
|
||||
| '[' ']' { EEmpty }
|
||||
| 'data' { EData }
|
||||
| '[' Ident Exps ']' { EList $2 $3 }
|
||||
| '[' PIdent Exps ']' { EList $2 $3 }
|
||||
| '[' String ']' { EStrings $2 }
|
||||
| '{' ListLocDef '}' { ERecord $2 }
|
||||
| '<' ListTupleComp '>' { ETuple $2 }
|
||||
| '(' 'in' Ident ')' { EIndir $3 }
|
||||
| '(' 'in' PIdent ')' { EIndir $3 }
|
||||
| '<' Exp ':' Exp '>' { ETyped $2 $4 }
|
||||
| '(' Exp ')' { $2 }
|
||||
| LString { ELString $1 }
|
||||
@@ -383,8 +400,8 @@ Exp6 : Ident { EIdent $1 }
|
||||
|
||||
Exp5 :: { Exp }
|
||||
Exp5 : Exp5 '.' Label { EProj $1 $3 }
|
||||
| '{' Ident '.' Ident '}' { EQConstr $2 $4 }
|
||||
| '%' Ident '.' Ident { EQCons $2 $4 }
|
||||
| '{' PIdent '.' PIdent '}' { EQConstr $2 $4 }
|
||||
| '%' PIdent '.' PIdent { EQCons $2 $4 }
|
||||
| Exp6 { $1 }
|
||||
|
||||
|
||||
@@ -397,9 +414,11 @@ Exp4 : Exp4 Exp5 { EApp $1 $2 }
|
||||
| 'variants' '{' ListExp '}' { EVariants $3 }
|
||||
| 'pre' '{' Exp ';' ListAltern '}' { EPre $3 $5 }
|
||||
| 'strs' '{' ListExp '}' { EStrs $3 }
|
||||
| Ident '@' Exp6 { EConAt $1 $3 }
|
||||
| PIdent '@' Exp6 { EConAt $1 $3 }
|
||||
| '#' Patt2 { EPatt $2 }
|
||||
| 'pattern' Exp5 { EPattType $2 }
|
||||
| Exp5 { $1 }
|
||||
| 'Lin' Ident { ELin $2 }
|
||||
| 'Lin' PIdent { ELin $2 }
|
||||
|
||||
|
||||
Exp3 :: { Exp }
|
||||
@@ -444,10 +463,14 @@ Exps : {- empty -} { NilExp }
|
||||
|
||||
|
||||
Patt2 :: { Patt }
|
||||
Patt2 : '_' { PW }
|
||||
| Ident { PV $1 }
|
||||
| '{' Ident '}' { PCon $2 }
|
||||
| Ident '.' Ident { PQ $1 $3 }
|
||||
Patt2 : '?' { PChar }
|
||||
| '[' String ']' { PChars $2 }
|
||||
| '#' PIdent { PMacro $2 }
|
||||
| '#' PIdent '.' PIdent { PM $2 $4 }
|
||||
| '_' { PW }
|
||||
| PIdent { PV $1 }
|
||||
| '{' PIdent '}' { PCon $2 }
|
||||
| PIdent '.' PIdent { PQ $1 $3 }
|
||||
| Integer { PInt $1 }
|
||||
| Double { PFloat $1 }
|
||||
| String { PStr $1 }
|
||||
@@ -457,10 +480,10 @@ Patt2 : '_' { PW }
|
||||
|
||||
|
||||
Patt1 :: { Patt }
|
||||
Patt1 : Ident ListPatt { PC $1 $2 }
|
||||
| Ident '.' Ident ListPatt { PQC $1 $3 $4 }
|
||||
Patt1 : PIdent ListPatt { PC $1 $2 }
|
||||
| PIdent '.' PIdent ListPatt { PQC $1 $3 $4 }
|
||||
| Patt2 '*' { PRep $1 }
|
||||
| Ident '@' Patt2 { PAs $1 $3 }
|
||||
| PIdent '@' Patt2 { PAs $1 $3 }
|
||||
| '-' Patt2 { PNeg $2 }
|
||||
| Patt2 { $1 }
|
||||
|
||||
@@ -472,11 +495,11 @@ Patt : Patt '|' Patt1 { PDisj $1 $3 }
|
||||
|
||||
|
||||
PattAss :: { PattAss }
|
||||
PattAss : ListIdent '=' Patt { PA $1 $3 }
|
||||
PattAss : ListPIdent '=' Patt { PA $1 $3 }
|
||||
|
||||
|
||||
Label :: { Label }
|
||||
Label : Ident { LIdent $1 }
|
||||
Label : PIdent { LIdent $1 }
|
||||
| '$' Integer { LVar $2 }
|
||||
|
||||
|
||||
@@ -500,7 +523,7 @@ ListPatt : Patt2 { (:[]) $1 }
|
||||
|
||||
|
||||
Bind :: { Bind }
|
||||
Bind : Ident { BIdent $1 }
|
||||
Bind : PIdent { BIdent $1 }
|
||||
| '_' { BWild }
|
||||
|
||||
|
||||
@@ -585,11 +608,11 @@ Include : {- empty -} { NoIncl }
|
||||
|
||||
FileName :: { FileName }
|
||||
FileName : String { FString $1 }
|
||||
| Ident { FIdent $1 }
|
||||
| PIdent { FIdent $1 }
|
||||
| '/' FileName { FSlash $2 }
|
||||
| '.' FileName { FDot $2 }
|
||||
| '-' FileName { FMinus $2 }
|
||||
| Ident FileName { FAddId $1 $2 }
|
||||
| PIdent FileName { FAddId $1 $2 }
|
||||
|
||||
|
||||
ListFileName :: { [FileName] }
|
||||
|
||||
Reference in New Issue
Block a user