mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
Include concrete syntax flags in generated JS.
This commit is contained in:
@@ -282,7 +282,8 @@ function Concrete(abstr) {
|
|||||||
this.parser = undefined;
|
this.parser = undefined;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
function GFConcrete(rules, parser) {
|
function GFConcrete(flags, rules, parser) {
|
||||||
|
this.flags = flags;
|
||||||
this.rules = rules;
|
this.rules = rules;
|
||||||
if (parser) {
|
if (parser) {
|
||||||
this.parser = parser;
|
this.parser = parser;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -14,6 +14,7 @@ import Control.Monad (mplus)
|
|||||||
import Data.Array (Array)
|
import Data.Array (Array)
|
||||||
import qualified Data.Array as Array
|
import qualified Data.Array as Array
|
||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromMaybe)
|
||||||
|
import Data.Map (Map)
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
|
|
||||||
pgf2js :: PGF -> String
|
pgf2js :: PGF -> String
|
||||||
@@ -38,9 +39,10 @@ absdef2js (f,(typ,_)) =
|
|||||||
|
|
||||||
concrete2js :: String -> String -> (CId,Concr) -> JS.Property
|
concrete2js :: String -> String -> (CId,Concr) -> JS.Property
|
||||||
concrete2js start n (c, cnc) =
|
concrete2js start n (c, cnc) =
|
||||||
JS.Prop l (new "GFConcrete" ([(JS.EObj $ ((map (cncdef2js n (prCId c)) ds) ++ litslins))] ++
|
JS.Prop l (new "GFConcrete" ([flags,(JS.EObj $ ((map (cncdef2js n (prCId c)) ds) ++ litslins))] ++
|
||||||
maybe [] (parser2js start) (parser cnc)))
|
maybe [] (parser2js start) (parser cnc)))
|
||||||
where
|
where
|
||||||
|
flags = mapToJSObj JS.EStr $ cflags cnc
|
||||||
l = JS.IdentPropName (JS.Ident (prCId c))
|
l = JS.IdentPropName (JS.Ident (prCId c))
|
||||||
ds = concatMap Map.assocs [lins cnc, opers cnc, lindefs cnc]
|
ds = concatMap Map.assocs [lins cnc, opers cnc, lindefs cnc]
|
||||||
litslins = [JS.Prop (JS.StringPropName "Int") (JS.EFun [children] [JS.SReturn $ new "Arr" [JS.EIndex (JS.EVar children) (JS.EInt 0)]]),
|
litslins = [JS.Prop (JS.StringPropName "Int") (JS.EFun [children] [JS.SReturn $ new "Arr" [JS.EIndex (JS.EVar children) (JS.EInt 0)]]),
|
||||||
@@ -115,3 +117,6 @@ sym2js (FSymTok t) = new "Terminal" [JS.EStr t]
|
|||||||
|
|
||||||
new :: String -> [JS.Expr] -> JS.Expr
|
new :: String -> [JS.Expr] -> JS.Expr
|
||||||
new f xs = JS.ENew (JS.Ident f) xs
|
new f xs = JS.ENew (JS.Ident f) xs
|
||||||
|
|
||||||
|
mapToJSObj :: (a -> JS.Expr) -> Map CId a -> JS.Expr
|
||||||
|
mapToJSObj f m = JS.EObj [ JS.Prop (JS.IdentPropName (JS.Ident (prCId k))) (f v) | (k,v) <- Map.toList m ]
|
||||||
|
|||||||
Reference in New Issue
Block a user