import {Grammar} from "@cranq/bipt-parser"; import {ChunkType} from "../types/ChunkType"; export const grammar: Grammar = { // Full-string [ChunkType.About]: { headExpr: "^about\\s*$" }, [ChunkType.ChildNode]: { headExpr: "^child\\s+${NodeDecl}\\s*$", childRules: [ ChunkType.About, ChunkType.Comment, ChunkType.NodeParam, ChunkType.NodeParams ] }, [ChunkType.ChildNodes]: { headExpr: "^children\\s*$", childRules: [ ChunkType.ChildNodesItem ] }, [ChunkType.ChildNodesItem]: { headExpr: "^${NodeDecl}\\s*$", childRules: [ ChunkType.About, ChunkType.Comment, ChunkType.NodeParam, ChunkType.NodeParams ] }, [ChunkType.Dependencies]: { headExpr: "^use\\s*$", childRules: [ ChunkType.DependenciesItem ] }, [ChunkType.DependenciesItem]: { headExpr: "^${String}\\s*$" }, [ChunkType.Dependency]: { headExpr: "^use\\s+${String}\\s*$" }, [ChunkType.Comment]: { headExpr: "^#\s*${Any}$" }, [ChunkType.Connection]: { headExpr: "^connect\\s+${ConnectionBody}\\s*$", childRules: [ ChunkType.About, ChunkType.Comment ] }, [ChunkType.Connections]: { headExpr: "^connect\\s*$", childRules: [ ChunkType.ConnectionsItem ] }, [ChunkType.ConnectionsItem]: { headExpr: "^${ConnectionBody}\\s*$", childRules: [ ChunkType.About, ChunkType.Comment ] }, [ChunkType.Include]: { headExpr: "^include\\s+${String}\\s*$" }, [ChunkType.Node]: { headExpr: "^(?:main|(?:${Export}\\s+)?node\\s+${Identifier})\\s*$", childRules: [ ChunkType.About, ChunkType.Comment, ChunkType.NodeImpl, ChunkType.Port, ChunkType.Ports ] }, [ChunkType.NodeCode]: { headExpr: "^(?:${SpreadOp}\\s*)?(?:${BuiltinCode}|${Identifier})\\s*$" }, [ChunkType.NodeImpl]: { headExpr: "^in\\s+(?:${BuiltinTarget}|${Runtime})\\s*$", childRules: [ ChunkType.ChildNode, ChunkType.ChildNodes, ChunkType.Connection, ChunkType.Connections, ChunkType.Dependencies, ChunkType.Dependency, ChunkType.NodeCode, ChunkType.PortExposure, ChunkType.PortExposures ] }, [ChunkType.NodeParam]: { headExpr: "^param\\s+${VarAssignment}\\s*$", childRules: [ ChunkType.About, ChunkType.Comment ] }, [ChunkType.NodeParams]: { headExpr: "^params\\s*$", childRules: [ ChunkType.NodeParamsItem ] }, [ChunkType.NodeParamsItem]: { headExpr: "^${VarAssignment}\\s*$", childRules: [ ChunkType.About, ChunkType.Comment ] }, [ChunkType.Port]: { headExpr: "^${PortDirection}\\s+${PortDecl}\\s*$", childRules: [ ChunkType.About, ChunkType.Comment, ChunkType.PortDomain ] }, [ChunkType.PortDomain]: { headExpr: "^domain\\s+${Identifier}\\s*$", childRules: [ ChunkType.About, ChunkType.Comment ] }, [ChunkType.PortExposure]: { headExpr: "^expose\\s+${PortExposureBody}\\s*$", childRules: [ ChunkType.About, ChunkType.Comment ] }, [ChunkType.PortExposures]: { headExpr: "^expose\\s*$", childRules: [ ChunkType.PortExposuresItem ] }, [ChunkType.PortExposuresItem]: { headExpr: "^${PortExposureBody}\\s*$", childRules: [ ChunkType.About, ChunkType.Comment ] }, [ChunkType.Ports]: { headExpr: "^${PortsDirection}\\s*$", childRules: [ ChunkType.PortsItem ] }, [ChunkType.PortsItem]: { headExpr: "^${PortDecl}\\s*$", childRules: [ ChunkType.About, ChunkType.Comment, ChunkType.PortDomain ] }, [ChunkType.Script]: { headExpr: "", childRules: [ ChunkType.Include, ChunkType.Node, ChunkType.Type ] }, [ChunkType.Type]: { // TODO: Change "Any" to "Type" headExpr: "^(?:${Export}\\s+)?type\\s+${Identifier}\\s*=(?:\\s*${Any})?\\s*$", childRules: [ ChunkType.About, ChunkType.Comment ] }, // Includes [ChunkType.Any]: { headExpr: ".*" }, [ChunkType.BuiltinCode]: { headExpr: "init|cleanup" }, [ChunkType.BuiltinTarget]: { headExpr: "all|other" }, [ChunkType.BuiltinType]: { headExpr: "string|number|boolean|true|false|null|any|never" }, [ChunkType.ChildPort]: { headExpr: "${Identifier}\\s*\\.\\s*${ChildPortDirection}\\s*\\.\\s*${Identifier}" }, [ChunkType.ChildPortDirection]: { headExpr: "in|out" }, [ChunkType.ConnectionBody]: { headExpr: "${ChildPort}\\s+and\\s+${ChildPort}" }, [ChunkType.Export]: { headExpr: "export" }, [ChunkType.Identifier]: { headExpr: "\\((?:[^)]|\\\\\\))+\\)" }, [ChunkType.NodeDecl]: { headExpr: "${Identifier}\\s*:\\s*${Identifier}" }, [ChunkType.PortDecl]: { headExpr: "(?:${SpreadOp}\\s*)?${VarDecl}" }, [ChunkType.PortDirection]: { headExpr: "input|output" }, [ChunkType.PortExposureBody]: { headExpr: "${ChildPort}\\s+as\\s+${Identifier}" }, [ChunkType.PortsDirection]: { headExpr: "inputs|outputs" }, [ChunkType.Runtime]: { headExpr: "es6|node|browser|python3" }, [ChunkType.SpreadOp]: { headExpr: "\\.\\.\\." }, [ChunkType.String]: { headExpr: "\"(?:\\\\[\"bfnrt\\/\\\\]|\\\\u[a-fA-F0-9]{4}|[^\"\\\\])*\"" }, [ChunkType.VarAssignment]: { // TODO: Change "Any" to "Json"? headExpr: "${Identifier}\\s*=(?:\\s*${Any})?" }, [ChunkType.VarDecl]: { headExpr: "${Identifier}\\s*:\\s*${Any}" } };