Print the target of an outlink - hyperlink

According to the DOORS Reference Manual, this code will print the source module identification of an inlink:
Object o = current
string srcModName
for srcModName in o<-"*" do print srcModName "\n"
This does work, however what I'm trying to do is print the target module identification of an outlink. I thought simply switching o<- to o-> would do the trick, but it doesn't. Does anyone know why, and how to fix this?

Not sure why that doesn't work but this does:
Object o = current
string tgtMod
Link l
for l in o -> "*" do
{
tgtMod = target(l)
print tgtMod "\n"
}

It doesn't work simply because there is no loop construct with that signature. All you have to work with is what's listed in the DXL Reference Manual.
EDIT: I forgot to mention though that Steve's answer is the way to do it if you just want the name of the target module.

Related

How do you get strip RTF formatting and get actual string value using DXL in DOORS?

I am trying to get the values in "ID" column of DOORS and I am currently doing this
string ostr=richtext_identifier(o)
When I try to print ostr, in some modules I get just the ID(which is what I want). But in other modules I will get values like "{\rtf1\ansi\ansicpg1256\deff0\nouicompat{\fonttbl{\f0\fnil\fcharset0 Times New Roman;}{\f1\froman\fcharset0 Times New Roman;}} {*\generator Riched20 10.0.17134}\viewkind4\uc1 \pard\f0\fs20\lang1033 SS_\f1\fs24 100\par } " This is the RTF value and I am wondering what the best way is to strip this formatting and get just the value.
Perhaps there is another way to go about this that I am not thinking of as well. Any help would be appreciated.
So the ID column of DOORS is actually a composite- DOORS builds it out of the Module level attribute 'Prefix' and the Object level attribute 'Absolute Number'.
If you wish to grab this value in the future, I would do the following (using your variables)
string ostr = ( module ( o ) )."Prefix" o."Absolute Number" ""
This is opposed to the following, which (despite seeming to be a valid attribute in the insert column dialog) WILL NOT WORK.
string ostr = o."Object Identifier" ""
Hope this helps!
Comment response: You should not need the module name for the code to work. I tested the following successfully on DOORS 9.6.1.10:
Object o = current
string ostr = ( module ( o ) )."Prefix" o."Absolute Number" ""
print ostr
Another solution is to use the identifier function, which takes an Object as input parameter, and returns the identifier as a plain (not RTF) string:
Declaration
string identifier(Object o)
Operation
Returns the identifier, which is a combination of absolute number and module prefix, of object o as a string.
The optimal solution somewhat depends on your underlying requirement for retrieving the object ID.

Retrieve all Outlinks in Doors DXL

I used dxl code to retrieve all outlinks and it works ok .
But it seems it retrieve just some links and neglect others , and i don't know why !
here is code snippet
Object o
string label
Module m = read(planSpecReportPath_inDoors)
Link outLink
for o in m do
{
for outLink in o -> "*" do
{
parentModName = target(outLink)
iTarget= targetAbsNo(outLink)
can any one tell me what is general solution to get all outlinks ? and what is i am missing ?
thanks
first of all, for clarity's sake I though I should mention that your comment says your script gets all outlinks to current modules, but the script you posted will only retrieve outlinks from the module at path planSpecReportPath_inDoors. You can change the script to work for the current module by modifying your code to the following:
Module m = current Module
Secondly, if I understand your question and comment correctly, you want to cycle through each outlink in a module, including the outlinks from previous baselines right? this can be done with a fairly simple script:
Module baselineM = null
Module m = read(planSpecReportPath_inDoors)
Object o = null
Link outLink = null
Baseline b = null
for b in all m do
{
// Load the current baseline and display it
baselineM = load(m, b, true)
for o in entire(m) do
{
for outLink in o -> "*" do
{
parentModName = target(outLink)
iTarget= targetAbsNo(outLink)
// Whatever else you want to do with each link
}
}
}
Basically, you would need to cycle through each baseline individually, then cycle through all of the objects in that baseline, then cycle through each link. I hope that answers your question!

What do I need to add to use monadUserState with alex when parsing?

I am trying to write a program that will understand a language where embedded comments are allowed. Such as:
/* Here's a comment
/* This comment is further embedded */ second comment is closed
Must close first comment */
This should be recognized as a comment (and as such not stop at the first */ it sees unless it has only seen 1 comment opening prior).
This would be an easy issue to fix in C, I could simply have a counter that incremented when it saw comment opens and decrements when it sees a comment close. If the counter is at 0, we're in "code section".
However, without having state in Haskell, it's a little more challenging.
I've read up on monadUserState which supposedly allows to keep track of a state for this exact type of parsing. However, I can't find very much reading material on it aside from the tutorial page on alex.
When I try to compile it gives the error
templates\wrappers.hs:213:16: Not in scope: `alexEOF`
It should be noted that I directly changed from the "basic" wrapper to the "monadUserState" without changing my code (I don't know what to add in order to use it). It says that this must be initialized in the user code:
data AlexState = AlexState {
alex_pos :: !AlexPosn, -- position at current input location
alex_inp :: String, -- the current input
alex_chr :: !Char, -- the character before the input
alex_bytes :: [Byte], -- rest of the bytes for the current char
alex_scd :: !Int, -- the current startcode
alex_ust :: AlexUserState -- AlexUserState will be defined in the user program
}
I'm a bit of a lexxing noob and I'm not at all sure what I should be adding here to make it at least compile... then I can worry about the logic of the thing.
Update: Working example available here: http://lpaste.net/119212
The file "tiger.x" (link) in the alex github repo contains an example of how to track embedded comments using the monadUserState wrapper.
Well, unfortunately that example doesn't compile but the ideas there should work.
Basically, these lines perform embedded comment processing:
<0> "/*" { enterNewComment `andBegin` state_comment }
<state_comment> "/*" { embedComment }
<state_comment> "*/" { unembedComment }
<state_comment> . ;
<state_comment> \n { skip }
As for alexEOF, the idea is to add an EOF token to your token data type:
data Tokens = ... | EOF
and define alexEOF as:
alexEOF = return EOF
See the file tests/tokens_monadUserState_bytestring.x in the alex repo for an example of this.

how to understand this vim script?

The following is vim script from a vim plugin:
vim's syntax is a bit strange:
!exists("*s:SetVals"), why their is a starmark before s:?
function!, why there is a ! character?
&iskeyword, is this a variable, if yes, where it is defined?
what is s: and g:, what is the difference between them?
why let should be used? such as let &dictionary = g:pydiction_location, can i change it to be &dictionary = g:pydiction_location?
if !exists("*s:SetVals")
function! s:SetVals()
" Save and change any config values we need.
" Temporarily change isk to treat periods and opening
" parenthesis as part of a keyword -- so we can complete
" python modules and functions:
let s:pydiction_save_isk = &iskeyword
setlocal iskeyword +=.,(
" Save any current dictionaries the user has set:
let s:pydiction_save_dictions = &dictionary
" Temporarily use only pydiction's dictionary:
let &dictionary = g:pydiction_location
" Save the ins-completion options the user has set:
let s:pydiction_save_cot = &completeopt
" Have the completion menu show up for one or more matches:
let &completeopt = "menu,menuone"
" Set the popup menu height:
let s:pydiction_save_pumheight = &pumheight
if !exists('g:pydiction_menu_height')
let g:pydiction_menu_height = 15
endif
let &pumheight = g:pydiction_menu_height
return ''
endfunction
endif
1. !exists("*s:SetVals"), why their is a starmark before
s:?
The asterisk is special syntax for exists function, and it means that we are checking if there's an existing function called SetVals. The option iskeyword could be checked with exists("&iskeyword") and the ex command echo with exists(":echo")
See :h exists(
2. function!, why there is a ! character?
The exclamation point means that the function is to be replaced if it already exists.
See :h user-functions
3. &iskeyword, is this a variable, if yes, where it is defined?
That is a vim option. You can check if it's set with :set iskeyword?
4. what is s: and g:, what is the difference between them?
These define the scope of the following symbol. s: means that the symbol is local to the script, while g: means that the symbol will be global.
See :h internal-variables and for s: see :h script-variable
5. why let should be used? such as let &dictionary =
g:pydiction_location, can i change it to be &dictionary =
g:pydiction_location?
Vimscript is one of the languages that require variables to be declared with a keyword. I don't think there's a way to declare variables more easily than with let.
I can answer on a few of those but i'll start with a general comment inspired by your recent questions.
The answers to most of your questions are laid out very clearly in Vim's awesomely exhaustive documentation. If you are serious about using Vim you must know how to use it. Start with :help and read carefully. It pays. Trust me.
You can find the answer to all these subquestions in :help expression.
!exists("*s:SetVals"), why their is a starmark before s:?
See :help exists().
function!, why there is a ! character?
Without an exclamation mark, Vim won't replace the previous definition if you re-source your script.
&iskeyword, is this a variable, if yes, where it is defined?
That's how you test the value of a vim option in a script. See :help iskeyword.
what is s: and g:, what is the difference between them?
These are namespaces. See :help internal-variables
why let should be used? such as let &dictionary = g:pydiction_location, can I change it to be &dictionary = g:pydiction_location?
No you can't, :let is how you define or update a variable. Get used to it.
See :help eval.txt. It describes most of vimscript syntax.

What's with PCALL or is Wowwiki wrong?

This is a WoW (World of Warcraft) lua script question. Not many of these get asked here but I have no where to turn and Stackoverflow is the programmer oasis for answers.
Question:
Wowwiki states that the 2nd, 3rd, 4th arguments are your calling functions 1st, 2nd, 3rd arguments. I don't find this to be true. I find that the 3rd, 4th, 5th arguments end up being the 1st, 2nd, 3rd arguments.
Link: http://www.wowwiki.com/API_pcall
Function:
function myTest(arg1)
return arg1 .. 10;
end
Problem:
local retOK, ret1 = pcall(myTest,"string value");
when I try the sample I get an error of "trying to perform concatenate on local 'arg1' (a nil value)". If I change the code to:
local retOK, ret1 = pcall(myTest,"string value", "bob");
then I get the output of "bob10". Where does the 2nd argument go and what is it for?
More Testing:
function BobsToolbox:RunTest()
local test1, value1 = pcall(BobsToolbox.Test1, "string value");
SharpDeck:Print("Test1: " .. tostring(test1) .. " Value: " .. tostring(value1));
end
function BobsToolbox:Test1(arg1)
return arg1 .. "10";
end
Results: attempt to concatenate local 'arg1' (a nil value)
function BobsToolbox:RunTest()
local test1, value1 = pcall(Test1, "string value");
SharpDeck:Print("Test1: " .. tostring(test1) .. " Value: " .. tostring(value1));
end
function Test1(arg1)
return arg1 .. "10";
end
Results: string value10
I am new to lua and I can't understand why these are different.
New Question:
The following code works but why?
function BobsToolbox:RunTest()
local test1, value1 = pcall(BobsToolbox.Test1, "string value");
SharpDeck:Print("Test1: " .. tostring(test1) .. " Value: " .. tostring(value1));
end
function BobsToolbox.Test1(arg1)
return arg1 .. "10";
end
What's the difference between the following: ("." vs ":")
function BobsToolbox.Test1(arg1)
function BobsToolbox:Test1(arg1)
Lua Documentation:
http://www.lua.org/pil/16.html
This use of a self parameter is a central point in any object-oriented language. Most OO languages have this mechanism partially hidden from the programmer, so that she does not have to declare this parameter (although she still can use the word self or this inside a method). Lua can also hide this parameter, using the colon operator. We can rewrite the previous method definition as
function Account:withdraw (v)
self.balance = self.balance - v
end
and the method call as
a:withdraw(100.00)
The effect of the colon is to add an extra hidden parameter in a method definition and to add an extra argument in a method call. The colon is only a syntactic facility, although a convenient one; there is nothing really new here. We can define a function with the dot syntax and call it with the colon syntax, or vice-versa, as long as we handle the extra parameter correctly:
Account = { balance=0,
withdraw = function (self, v)
self.balance = self.balance - v
end
}
function Account:deposit (v)
self.balance = self.balance + v
end
Account.deposit(Account, 200.00)
Account:withdraw(100.00)
Possible Conclusion:
With this in mind I assume that when calling a ":" function using "pcall" you must supply the "self" argument.
Related: There are nice live code editors for WoW. I used to use LuaSlinger, but turns out that's no longer developed and the developer recommends Hack instead.
However, what you might be encountering here is that the colon method-call syntax is just syntax sugar, ditto for method definitions, IIRC. Basically, if you do foo:bar("quux!"), where foo is an object, you are in reality just doing foo.bar(foo, "quux!").
Hope that helps!
Well, I don't think WoWWiki is wrong. Here is the code I am using:
function myTest(arg1) return arg1 .. 10; end
local retOK, ret1 = pcall(myTest,"string value");
DEFAULT_CHAT_FRAME:AddMessage(ret1);
local retOK, ret1 = pcall(myTest,"string value", "bob");
DEFAULT_CHAT_FRAME:AddMessage(ret1);
Here is the output I get in my General chat box:
string value10
string value10
How are you trying your sample code? I just pasted my code into an existing mod lua file and made sure that mod was enabled in the addons window before selecting my character and logging in. I made a few changes to the source lua file and typed:
/console reloadui
To try the new changes and have the results output to my screen. I don't have much advice to offer you, because I haven't done much work with WoW addons. Have you tried this code in a blank addon to make sure nothing else is interfering? Have you actually tried the code in game? If you can provide any more information or want me to try anything else, let me know!
Update: Decided to try a few more tests. Here are the tests (with the same function):
local retOK, ret1 = pcall(myTest,"");
DEFAULT_CHAT_FRAME:AddMessage(ret1);
local retOK, ret1 = pcall(myTest, nil, "bob");
DEFAULT_CHAT_FRAME:AddMessage(ret1);
And the results:
10
attempt to concatenate local 'arg1' (a nil value)
It's interesting that the error I see when arg1 is nil is slightly different than the error you see. I'd be interested in knowing how you are testing your code. Or maybe you didn't copy the error down verbatim? I guess you could also try clearing out your WTF folder and disabling the rest of your addons to test this function. If it makes a difference, then you can enable them one a time until you find the problem.

Resources