Page 1 of 1

Unwrapping IMPORT aliasses

Posted: Fri Oct 21, 2016 8:19 am
by Robert
The Menu Commands "Source", "Interface", & "Documentation" unwrap item aliases, which is a very useful feature.

The Menu Command "Info->Global Variables" does not, which is both inconsistent and unhelpful.

I guess it should be easy to implement this feature by copying the procedure "CheckModName" from DevReferences, or DevBrowser, to DevDebug. (Maybe it would be better not to have three copies of the same procedure?)

Re: Unwrapping IMPORT aliasses

Posted: Fri Oct 21, 2016 2:37 pm
by Robert
Below are the additions I tried in Module DevDebug. It seems to work fine, but the different values of the CONSTant "module" was a bit of a trap!
"CheckModName" is new (actually copied from elsewhere). "GetMod" has one new line.

Code: Select all

	PROCEDURE CheckModName (VAR mod: TextMappers.String; t: TextModels.Model);
		CONST module = 101;		(*  Overrides global definition !! *)
		VAR s: TextMappers.Scanner;
	BEGIN
		s.ConnectTo(t); s.SetPos(0); Scan(s);
		IF s.type = module THEN
			Scan(s);
			WHILE (s.type # TextMappers.eot) & (s.type # import) DO Scan(s) END;
			WHILE (s.type # TextMappers.eot) & (s.type # semicolon)
					& ((s.type # TextMappers.string) OR (s.string # mod)) DO Scan(s) END;
			IF s.type = TextMappers.string THEN
				Scan(s);
				IF s.type = becomes THEN
					Scan(s);
					IF s.type = TextMappers.string THEN
						mod := s.string$
					END
				END
			END
		END
	END CheckModName;

	PROCEDURE GetMod (VAR mod: Kernel.Module);
		VAR c: TextControllers.Controller; s: TextMappers.Scanner; beg, end: INTEGER; res: INTEGER; n: Kernel.Utf8Name;
	BEGIN
		mod := NIL;
		c := TextControllers.Focus();
		IF (c # NIL) & c.HasSelection() THEN
			c.GetSelection(beg, end);
			s.ConnectTo(c.text); s.SetPos(beg); s.Scan;
			IF s.type = TextMappers.string THEN
CheckModName(s.string, c.text);
				Strings.StringToUtf8(s.string, n, res); mod := Kernel.ThisMod(n$);
				IF mod = NIL THEN
					Dialog.ShowParamMsg("#Dev:ModuleNotFound", s.string, "", "");
				END				
			ELSE Dialog.ShowMsg("#Dev:NoModuleNameSelected")
			END
		ELSE Dialog.ShowMsg("#Dev:NoSelectionFound")
		END
	END GetMod;

Re: Unwrapping IMPORT aliasses

Posted: Fri Oct 21, 2016 3:44 pm
by Josef Templ
I think this is an improvement.
If the code can be reused it would even be a simplification.

Is there any lower level module where the common code could be put for reuse?

- Josef

Re: Unwrapping IMPORT aliasses

Posted: Fri Oct 21, 2016 5:12 pm
by Robert
Josef Templ wrote:Is there any lower level module where the common code could be put for reuse?
The obvious question ... I haven't had any time to investigate!

Actually I would like it to be exported (and documented!), as it would be useful in some of my private tools.

Re: Unwrapping IMPORT aliasses

Posted: Sun Oct 23, 2016 11:07 am
by Robert
The only obvious place to put the common code (without a new Module) is in TextMappers.

One would also want to move the duplicated copies of the procedure "Scan". The copies of Scan in DevReferences & DevBrowser are identical; the copy in DevDebug is different (bigger). One could easily make a dual purpose version (with an input BOOLEAN to configure it).

I'm not sure what the best thing to suggest is.


On second thoughts, maybe it is best to export these two procedres from DevReferences, and have DevBrowser & DevDebug import DevReferences?

Re: Unwrapping IMPORT aliasses

Posted: Tue Oct 25, 2016 3:06 pm
by Josef Templ
Shouldn't this also be applied to DevDependencies?
Even if it is a pretty useless tool, for the sake of completeness
it should be considered, I think.

DevReferences looks like a good place to export from.

- Josef

Re: Unwrapping IMPORT aliasses

Posted: Thu Mar 30, 2017 2:56 am
by Ivan Denisov