-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example: ```proto message A { message B {} } message B { message A { message C {} } A.B item = 1; A.C local = 2; } ```
- Loading branch information
1 parent
1207457
commit a04d052
Showing
17 changed files
with
1,077 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { isString } from '@whisklabs/typeguards'; | ||
|
||
import { Parser } from '../parser'; | ||
import { MakeOuts } from './generator'; | ||
import { checkDublicate, safeString } from './utils'; | ||
|
||
export function collectEmuns(pack: string, out: MakeOuts, items: Parser.Enum[]) { | ||
for (const msg of items) { | ||
enu(`${pack}_${msg.name}`, out, msg); | ||
} | ||
} | ||
|
||
function enu(pack: string, out: MakeOuts, item: Parser.Enum) { | ||
const eName = safeString(pack); | ||
out.enumsList.add(eName); | ||
checkDublicate(eName, out, `${pack}.${item.name}`); | ||
} | ||
|
||
export function collectMessages(pack: string, out: MakeOuts, items: Parser.Message[], parent?: string) { | ||
for (const msg of items) { | ||
const newPack = `${parent ?? pack}_${msg.name}`; | ||
message(pack, out, msg, parent); | ||
if (msg.messages.length > 0) { | ||
collectMessages(pack, out, msg.messages, newPack); | ||
} | ||
} | ||
} | ||
|
||
function message(pack: string, out: MakeOuts, item: Parser.Message, parent?: string) { | ||
const base = `${safeString(parent ?? pack)}_${safeString(item.name)}`; | ||
collectEmuns(base, out, item.enums); | ||
const baseName = safeString(base); | ||
const packName = `${pack}.${item.name}`; | ||
checkDublicate(baseName, out, `${isString(parent) ? `${parent}.` : ''}${packName}`); | ||
} | ||
|
||
export function collectServices(pack: string, out: MakeOuts, items: Parser.Service[] = []) { | ||
for (const msg of items) { | ||
service(pack, out, msg); | ||
} | ||
} | ||
|
||
function service(pack: string, out: MakeOuts, item: Parser.Service) { | ||
for (const msg of item.methods) { | ||
method(pack, out, msg, item); | ||
} | ||
} | ||
|
||
export function method(pack: string, out: MakeOuts, item: Parser.Method, serv: Parser.Service) { | ||
const sName = `${safeString(pack)}_${serv.name}_${item.name}`; | ||
checkDublicate(sName, out, `${pack}.${serv.name}.${item.name}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.