The include declaration imports all types, functions and constants from the specified files and their included files.
The import declaration imports only public types, functions and constants from the specified files and their included files. Public objects are defined using the pub keyword.
stringConst = "`" { unicode_char } "`" | stringDoubleConststringDoubleConst = `"` { unicode_char | uShort | uLong | escapedChar | byteVal } `"`importDecl = "import" "{" {stringConst newline} "}"includeDecl = "include" "{" {stringConst newline} "}"
Consider the visibility of objects as a table. Let there be two files.
// a.g can include or import b.gfunc afunc(i int) : return i*2pub func apubfunc(i int) : return i*3// b.gfunc bfunc(i int) : return i*4pub func bpubfunc(i int) : return i*5
Let the c.g file can import or include a.g file. You can see what functions are visible in c.g in different situations.
| include a a includes b | include a a imports b | import a a includes b | import a a imports b |
afunc | visible | visible | | |
apubfunc | visible | visible | visible | visible |
bfunc | visible | | | |
bpubfunc | visible | | visible | |
The pub declaration marks the next function, type or constants as public. They can be imported with import declaration.
pubDecl = "pub"objects = [pubDecl] (structDecl | FnDecl | ConstDecl | FunctionDecl)
The pub keyword indicates that the next function, constants, or structure will be passed when the file is imported.
pub const IOTA { // public constants. Visible when include or importMY1MY2}const IOTA*2 { // private constants. Visible only when includeMY3MY4}