https://github.com/rm-code/lua-tgf-parser
A parser for "Trivial Graph Format" (TGF) files written in Lua.
https://github.com/rm-code/lua-tgf-parser
Last synced: 2 months ago
JSON representation
A parser for "Trivial Graph Format" (TGF) files written in Lua.
- Host: GitHub
- URL: https://github.com/rm-code/lua-tgf-parser
- Owner: rm-code
- License: mit
- Created: 2016-12-18T11:32:09.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-10-21T07:40:13.000Z (about 7 years ago)
- Last Synced: 2025-01-27T12:48:07.483Z (11 months ago)
- Language: Lua
- Size: 3.91 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lua-tgf-parser
A parser for the "[Trivial Graph Format](https://en.wikipedia.org/wiki/Trivial_Graph_Format)" (TGF) written in Lua.
## Usage
Parsing an example .tgf file like this:
```tgf
1 LEFT
2 RIGHT
#
1 2 LTR
2 1 RTL
```
Would work like this:
```lua
local TGFParser = require( 'TGFParser' )
local graph = TGFParser.parse( 'example.tgf' )
for _, node in ipairs( graph.nodes ) do
print( node.id, node.label )
end
for _, edge in ipairs( graph.edges ) do
print( edge.from, edge.to, edge.label )
end
```
The above script would give you this console output:
```
1 LEFT
2 RIGHT
1 2 LTR
2 1 RTL
```