piv

package
v1.0.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 11, 2021 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Overview

Package piv provides the PiView object for the full GUI view of the interactive parser (pi) system.

Index

Constants

View Source
const (
	LexRulesIdx = iota
	ParseRulesIdx
	StructViewIdx
	AstOutIdx
	MainTabsIdx
)

These are then the fixed indices of the different elements in the splitview

Variables

View Source
var KiT_PiView = kit.Types.AddType(&PiView{}, PiViewProps)
View Source
var KiT_ProjPrefs = kit.Types.AddType(&ProjPrefs{}, nil)
View Source
var PiViewProps = ki.Props{
	"EnumType:Flag":    gi.KiT_NodeFlags,
	"background-color": &gi.Prefs.Colors.Background,
	"color":            &gi.Prefs.Colors.Font,
	"max-width":        -1,
	"max-height":       -1,
	"#title": ki.Props{
		"max-width":        -1,
		"horizontal-align": gist.AlignCenter,
		"vertical-align":   gist.AlignTop,
	},
	"ToolBar": ki.PropSlice{
		{"SaveProj", ki.Props{
			"shortcut": gi.KeyFunMenuSave,
			"label":    "Save Project",
			"desc":     "Save GoPi project file to standard JSON-formatted file",
			"updtfunc": giv.ActionUpdateFunc(func(pvi interface{}, act *gi.Action) {
				pv := pvi.(*PiView)
				act.SetActiveState(pv.Prefs.ProjFile != "")
			}),
		}},
		{"sep-parse", ki.BlankProp{}},
		{"OpenParser", ki.Props{
			"label": "Open Parser...",
			"icon":  "file-open",
			"desc":  "Open lexer and parser rules from standard JSON-formatted file",
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"default-field": "Prefs.ParserFile",
					"ext":           ".pi",
				}},
			},
		}},
		{"SaveParser", ki.Props{
			"icon": "file-save",
			"desc": "Save lexer and parser rules from file standard JSON-formatted file",
			"updtfunc": giv.ActionUpdateFunc(func(pvi interface{}, act *gi.Action) {
				pv := pvi.(*PiView)
				act.SetActiveStateUpdt(pv.Prefs.ParserFile != "")
			}),
		}},
		{"SaveParserAs", ki.Props{
			"label": "Save Parser As...",
			"icon":  "file-save",
			"desc":  "Save As lexer and parser rules from file standard JSON-formatted file",
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"default-field": "Prefs.ParserFile",
					"ext":           ".pi",
				}},
			},
		}},
		{"sep-file", ki.BlankProp{}},
		{"OpenTest", ki.Props{
			"label": "Open Test",
			"icon":  "file-open",
			"desc":  "Open test file",
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"default-field": "Prefs.TestFile",
				}},
			},
		}},
		{"SaveTestAs", ki.Props{
			"label": "Save Test As",
			"icon":  "file-save",
			"desc":  "Save current test file as",
			"Args": ki.PropSlice{
				{"File Name", ki.Props{
					"default-field": "Prefs.TestFile",
				}},
			},
		}},
		{"sep-lex", ki.BlankProp{}},
		{"LexInit", ki.Props{
			"icon": "update",
			"desc": "Init / restart lexer",
		}},
		{"LexNext", ki.Props{
			"icon": "play",
			"desc": "do next single step of lexing",
		}},
		{"LexNextLine", ki.Props{
			"icon": "play",
			"desc": "do next line of lexing",
		}},
		{"LexAll", ki.Props{
			"icon": "fast-fwd",
			"desc": "do all remaining lexing",
		}},
		{"sep-passtwo", ki.BlankProp{}},
		{"EditPassTwo", ki.Props{
			"icon": "edit",
			"desc": "edit the settings of the PassTwo -- second pass after lexing",
		}},
		{"PassTwo", ki.Props{
			"icon": "play",
			"desc": "perform second pass after lexing -- computes nesting depth globally and finds EOS tokens",
		}},
		{"sep-parse", ki.BlankProp{}},
		{"EditTrace", ki.Props{
			"icon": "edit",
			"desc": "edit the parse tracing options for seeing how the parsing process is working",
		}},
		{"ParseInit", ki.Props{
			"icon": "update",
			"desc": "initialize parser -- this also performs lexing, PassTwo, assuming that is all working",
		}},
		{"ParseNext", ki.Props{
			"icon": "play",
			"desc": "do next step of parsing",
		}},
		{"ParseAll", ki.Props{
			"icon": "fast-fwd",
			"desc": "do remaining parsing",
		}},
		{"ViewParseState", ki.Props{
			"icon": "edit",
			"desc": "view the parser state, including symbols recorded etc",
		}},
	},
	"MainMenu": ki.PropSlice{
		{"AppMenu", ki.BlankProp{}},
		{"File", ki.PropSlice{
			{"OpenRecent", ki.Props{
				"submenu": &SavedPaths,
				"Args": ki.PropSlice{
					{"File Name", ki.Props{}},
				},
			}},
			{"OpenProj", ki.Props{
				"shortcut": gi.KeyFunMenuOpen,
				"label":    "Open Project...",
				"desc":     "open a GoPi project that has full settings",
				"Args": ki.PropSlice{
					{"File Name", ki.Props{
						"default-field": "Prefs.ProjFile",
						"ext":           ".pip",
					}},
				},
			}},
			{"NewProj", ki.Props{
				"shortcut": gi.KeyFunMenuNew,
				"label":    "New Project...",
				"desc":     "create a new project",
			}},
			{"SaveProj", ki.Props{
				"shortcut": gi.KeyFunMenuSave,
				"label":    "Save Project",
				"desc":     "Save GoPi project file to standard JSON-formatted file",
				"updtfunc": giv.ActionUpdateFunc(func(pvi interface{}, act *gi.Action) {
					pv := pvi.(*PiView)
					act.SetActiveState(pv.Prefs.ProjFile != "")
				}),
			}},
			{"SaveProjAs", ki.Props{
				"shortcut": gi.KeyFunMenuSaveAs,
				"label":    "Save Project As...",
				"desc":     "Save GoPi project to file standard JSON-formatted file",
				"Args": ki.PropSlice{
					{"File Name", ki.Props{
						"default-field": "Prefs.ProjFile",
						"ext":           ".pip",
					}},
				},
			}},
			{"sep-parse", ki.BlankProp{}},
			{"OpenParser", ki.Props{
				"shortcut": gi.KeyFunMenuOpenAlt1,
				"label":    "Open Parser...",
				"desc":     "Open lexer and parser rules from standard JSON-formatted file",
				"Args": ki.PropSlice{
					{"File Name", ki.Props{
						"default-field": "Prefs.ParserFile",
						"ext":           ".pi",
					}},
				},
			}},
			{"SaveParser", ki.Props{
				"shortcut": gi.KeyFunMenuSaveAlt,
				"desc":     "Save lexer and parser rules to file standard JSON-formatted file",
				"updtfunc": giv.ActionUpdateFunc(func(pvi interface{}, act *gi.Action) {
					pv := pvi.(*PiView)
					act.SetActiveState(pv.Prefs.ParserFile != "")
				}),
			}},
			{"SaveParserAs", ki.Props{
				"label": "Save Parser As...",
				"desc":  "Save As lexer and parser rules to file standard JSON-formatted file",
				"Args": ki.PropSlice{
					{"File Name", ki.Props{
						"default-field": "Prefs.ParserFile",
						"ext":           ".pi",
					}},
				},
			}},
			{"sep-close", ki.BlankProp{}},
			{"Close Window", ki.BlankProp{}},
			{"OpenConsoleTab", ki.Props{}},
		}},
		{"Edit", "Copy Cut Paste"},
		{"Window", "Windows"},
	},
}
View Source
var SavedPaths gi.FilePaths

SavedPaths is a slice of strings that are file paths

View Source
var SavedPathsFileName = "gopi_saved_paths.json"

SavedPathsFileName is the name of the saved file paths file in GoPi prefs directory

Functions

func InitPrefs

func InitPrefs()

InitPrefs is the overall init at startup for PiView project

func OpenPaths

func OpenPaths()

OpenPaths loads the active SavedPaths from prefs dir

func QuitReq

func QuitReq() bool

QuitReq is called when user tries to quit the app -- we go through all open main windows and look for gide windows and call their CloseWindowReq functions!

func SavePaths

func SavePaths()

SavePaths saves the active SavedPaths to prefs dir

Types

type PiView

type PiView struct {
	gi.Frame
	Parser        pi.Parser    `desc:"the parser we are viewing"`
	Prefs         ProjPrefs    `desc:"project preferences -- this IS the project file"`
	Changed       bool         `json:"-" desc:"has the root changed?  we receive update signals from root for changes"`
	FileState     pi.FileState `json:"-" desc:"our own dedicated filestate for controlled parsing"`
	TestBuf       giv.TextBuf  `json:"-" desc:"test file buffer"`
	OutBuf        giv.TextBuf  `json:"-" desc:"output buffer -- shows all errors, tracing"`
	LexBuf        giv.TextBuf  `json:"-" desc:"buffer of lexified tokens"`
	ParseBuf      giv.TextBuf  `json:"-" desc:"buffer of parse info"`
	KeySeq1       key.Chord    `desc:"first key in sequence if needs2 key pressed"`
	OutMonRunning bool         `json:"-" desc:"is the output monitor running?"`
	OutMonMu      sync.Mutex   `json:"-" desc:"mutex for updating, checking output monitor run status"`
}

PiView provides the interactive GUI view for constructing and testing the lexer and parser

func NewPiView

func NewPiView() (*gi.Window, *PiView)

NewPiView creates a new PiView window

func (*PiView) ApplyPrefs

func (pv *PiView) ApplyPrefs()

ApplyPrefs applies project-level prefs (e.g., after opening)

func (*PiView) AstTree

func (pv *PiView) AstTree() *giv.TreeView

AstTree returns the Ast output tree view

func (*PiView) AstTreeToEnd

func (pv *PiView) AstTreeToEnd()

AstTreeToEnd

func (*PiView) CloseWindowReq

func (pv *PiView) CloseWindowReq() bool

CloseWindowReq is called when user tries to close window -- we automatically save the project if it already exists (no harm), and prompt to save open files -- if this returns true, then it is OK to close -- otherwise not

func (*PiView) Config added in v0.5.8

func (pv *PiView) Config()

Config configures the view

func (*PiView) ConfigSplitView

func (pv *PiView) ConfigSplitView()

ConfigSplitView configures the SplitView.

func (*PiView) ConfigStatusBar

func (pv *PiView) ConfigStatusBar()

ConfigStatusBar configures statusbar with label

func (*PiView) ConfigTextView

func (pv *PiView) ConfigTextView(ly *gi.Layout, out bool) *giv.TextView

ConfigTextView configures text view

func (*PiView) ConfigToolbar

func (pv *PiView) ConfigToolbar()

ConfigToolbar adds a PiView toolbar.

func (*PiView) ConnectEvents2D

func (ge *PiView) ConnectEvents2D()

func (*PiView) CurPanel

func (pv *PiView) CurPanel() int

CurPanel returns the splitter panel that currently has keyboard focus

func (*PiView) EditPassTwo

func (pv *PiView) EditPassTwo()

EditPassTwo shows the PassTwo settings to edit -- does nest depth and finds the EOS end-of-statements

func (*PiView) EditTrace

func (pv *PiView) EditTrace()

EditTrace shows the parse.Trace options for detailed tracing output

func (*PiView) FileNodeClosed

func (pv *PiView) FileNodeClosed(fn *giv.FileNode, tvn *giv.FileTreeView)

func (*PiView) FileNodeOpened

func (pv *PiView) FileNodeOpened(fn *giv.FileNode, tvn *giv.FileTreeView)

func (*PiView) FocusNextPanel

func (pv *PiView) FocusNextPanel()

FocusNextPanel moves the keyboard focus to the next panel to the right

func (*PiView) FocusOnPanel

func (pv *PiView) FocusOnPanel(panel int) bool

FocusOnPanel moves keyboard focus to given panel -- returns false if nothing at that tab

func (*PiView) FocusPrevPanel

func (pv *PiView) FocusPrevPanel()

FocusPrevPanel moves the keyboard focus to the previous panel to the left

func (*PiView) GetPrefs

func (pv *PiView) GetPrefs()

GetPrefs gets the current values of things for prefs

func (*PiView) IsConfiged added in v0.5.8

func (pv *PiView) IsConfiged() bool

IsConfiged returns true if the view is fully configured

func (*PiView) IsEmpty

func (pv *PiView) IsEmpty() bool

IsEmpty returns true if current project is empty

func (*PiView) KeyChordEvent

func (ge *PiView) KeyChordEvent()

func (*PiView) LexAll

func (pv *PiView) LexAll()

LexAll does all remaining lexing until end or error

func (*PiView) LexInit

func (pv *PiView) LexInit()

LexInit initializes / restarts lexing process for current test file

func (*PiView) LexNext

func (pv *PiView) LexNext() *lex.Rule

LexNext does next step of lexing

func (*PiView) LexNextLine

func (pv *PiView) LexNextLine() *lex.Rule

LexLine does next line of lexing

func (*PiView) LexStopped

func (pv *PiView) LexStopped()

LexStopped tells the user why the lexer stopped

func (*PiView) LexTree

func (pv *PiView) LexTree() *giv.TreeView

LexTree returns the lex rules tree view

func (*PiView) MainTabByName

func (pv *PiView) MainTabByName(label string) gi.Node2D

MainTabByName returns a MainTabs (first set of tabs) tab with given name

func (*PiView) MainTabByNameTry added in v0.5.7

func (pv *PiView) MainTabByNameTry(label string) (gi.Node2D, error)

MainTabByNameTry returns a MainTabs (first set of tabs) tab with given name, err if not found

func (*PiView) MainTabTextViewByName

func (pv *PiView) MainTabTextViewByName(tabnm string) (*giv.TextView, bool)

MainTabTextViewByName returns the textview for given main tab, if it exists

func (*PiView) MainTabs

func (pv *PiView) MainTabs() *gi.TabView

MainTabs returns the main TabView

func (*PiView) MonitorOut

func (pv *PiView) MonitorOut()

MonitorOut sets up the OutBuf monitor -- must call as separate goroutine using go

func (*PiView) NewProj

func (pv *PiView) NewProj() (*gi.Window, *PiView)

NewProj makes a new project in a new window

func (*PiView) OpenConsoleTab

func (pv *PiView) OpenConsoleTab()

OpenConsoleTab opens a main tab displaying console output (stdout, stderr)

func (*PiView) OpenLexTab

func (pv *PiView) OpenLexTab()

OpenLexTab opens a main tab displaying lexer output

func (*PiView) OpenOutTab

func (pv *PiView) OpenOutTab()

OpenOutTab opens a main tab displaying all output

func (*PiView) OpenParseTab

func (pv *PiView) OpenParseTab()

OpenParseTab opens a main tab displaying parser output

func (*PiView) OpenParser

func (pv *PiView) OpenParser(filename gi.FileName)

OpenParser opens lexer and parser rules to current filename, in a standard JSON-formatted file

func (*PiView) OpenProj

func (pv *PiView) OpenProj(filename gi.FileName) *PiView

OpenProj opens lexer and parser rules to current filename, in a standard JSON-formatted file if current is not empty, opens in a new window

func (*PiView) OpenRecent

func (pv *PiView) OpenRecent(filename gi.FileName)

OpenRecent opens a recently-used project

func (*PiView) OpenTest

func (pv *PiView) OpenTest(filename gi.FileName)

OpenTest opens test file

func (*PiView) OpenTestTextTab

func (pv *PiView) OpenTestTextTab()

OpenTestTextTab opens a main tab displaying test text

func (*PiView) ParseAll

func (pv *PiView) ParseAll()

ParseAll does all remaining lexing until end or error

func (*PiView) ParseInit

func (pv *PiView) ParseInit()

ParseInit initializes / restarts lexing process for current test file

func (*PiView) ParseNext

func (pv *PiView) ParseNext() *parse.Rule

ParseNext does next step of lexing

func (*PiView) ParseStopped

func (pv *PiView) ParseStopped()

ParseStopped tells the user why the lexer stopped

func (*PiView) ParseTree

func (pv *PiView) ParseTree() *giv.TreeView

ParseTree returns the parse rules tree view

func (*PiView) PassTwo

func (pv *PiView) PassTwo()

PassTwo does the second pass after lexing, per current settings

func (*PiView) PiViewKeys

func (ge *PiView) PiViewKeys(kt *key.ChordEvent)

func (*PiView) RecycleMainTab added in v0.5.11

func (pv *PiView) RecycleMainTab(label string, typ reflect.Type, sel bool) gi.Node2D

RecycleMainTab returns a MainTabs (first set of tabs) tab with given name, first by looking for an existing one, and if not found, making a new one with widget of given type. if sel, then select it. returns widget

func (*PiView) RecycleMainTabTextView added in v0.5.11

func (pv *PiView) RecycleMainTabTextView(label string, sel bool, out bool) *giv.TextView

RecycleMainTabTextView returns a MainTabs (first set of tabs) tab with given name, first by looking for an existing one, and if not found, making a new one with a Layout and then a TextView in it. if sel, then select it. returns widget

func (*PiView) Render2D

func (pv *PiView) Render2D()

func (*PiView) SaveParser

func (pv *PiView) SaveParser()

SaveParser saves lexer and parser rules to current filename, in a standard JSON-formatted file

func (*PiView) SaveParserAs

func (pv *PiView) SaveParserAs(filename gi.FileName)

SaveParserAs saves lexer and parser rules to current filename, in a standard JSON-formatted file

func (*PiView) SaveProj

func (pv *PiView) SaveProj()

SaveProj saves project prefs to current filename, in a standard JSON-formatted file also saves the current parser

func (*PiView) SaveProjAs

func (pv *PiView) SaveProjAs(filename gi.FileName)

SaveProjAs saves lexer and parser rules to current filename, in a standard JSON-formatted file also saves the current parser

func (*PiView) SaveTestAs

func (pv *PiView) SaveTestAs(filename gi.FileName)

SaveTestAs saves the test file as..

func (*PiView) SelectLexRule

func (pv *PiView) SelectLexRule(rule *lex.Rule)

SelectLexRule selects given lex rule in Lexer

func (*PiView) SelectMainTabByName

func (pv *PiView) SelectMainTabByName(label string) gi.Node2D

SelectMainTabByName Selects given main tab, and returns all of its contents as well.

func (*PiView) SelectParseRule

func (pv *PiView) SelectParseRule(rule *parse.Rule)

SelectParseRule selects given lex rule in Parser

func (*PiView) SetChanged

func (pv *PiView) SetChanged()

func (*PiView) SetStatus

func (pv *PiView) SetStatus(msg string)

SetStatus updates the statusbar label with given message, along with other status info

func (*PiView) SplitView

func (pv *PiView) SplitView() *gi.SplitView

SplitView returns the main SplitView

func (*PiView) SplitViewConfig

func (pv *PiView) SplitViewConfig() kit.TypeAndNameList

SplitViewConfig returns a TypeAndNameList for configuring the SplitView

func (*PiView) StatusBar

func (pv *PiView) StatusBar() *gi.Frame

StatusBar returns the statusbar widget

func (*PiView) StatusLabel

func (pv *PiView) StatusLabel() *gi.Label

StatusLabel returns the statusbar label widget

func (*PiView) StructView

func (pv *PiView) StructView() *giv.StructView

StructView returns the StructView for editing rules

func (*PiView) TestTextView

func (pv *PiView) TestTextView() (*giv.TextView, bool)

TextTextView returns the textview for TestBuf TextView

func (*PiView) ToolBar

func (pv *PiView) ToolBar() *gi.ToolBar

ToolBar returns the toolbar widget

func (*PiView) UpdtLexBuf

func (pv *PiView) UpdtLexBuf()

UpdtLexBuf sets the LexBuf to current lex content

func (*PiView) UpdtParseBuf

func (pv *PiView) UpdtParseBuf()

UpdtParseBuf sets the ParseBuf to current parse rule output

func (*PiView) ViewNode

func (pv *PiView) ViewNode(tv *giv.TreeView)

ViewNode sets the StructView view to src node for given treeview

func (*PiView) ViewParseState

func (pv *PiView) ViewParseState()

ViewParseState

type ProjPrefs

type ProjPrefs struct {
	ProjFile   gi.FileName     `desc:"filename for project (i.e, these preference)"`
	ParserFile gi.FileName     `desc:"filename for parser"`
	TestFile   gi.FileName     `desc:"the file for testing"`
	TraceOpts  parse.TraceOpts `desc:"the options for tracing parsing"`
}

ProjPrefs are the preferences for saving for a project -- this IS the project file

func (*ProjPrefs) OpenJSON

func (pf *ProjPrefs) OpenJSON(filename gi.FileName) error

OpenJSON open from JSON file

func (*ProjPrefs) SaveJSON

func (pf *ProjPrefs) SaveJSON(filename gi.FileName) error

SaveJSON save to JSON file

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL