Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
magicseteditor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
magicseteditor
Commits
dbb4bcac
Commit
dbb4bcac
authored
Mar 18, 2007
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Keyword parameters in the text are processed, placeholders are inserted
parent
6dfa6a4f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
24 deletions
+48
-24
data/magic.mse-game/game
data/magic.mse-game/game
+1
-0
src/data/keyword.cpp
src/data/keyword.cpp
+35
-17
src/data/keyword.hpp
src/data/keyword.hpp
+7
-3
src/gui/control/card_editor.cpp
src/gui/control/card_editor.cpp
+5
-4
No files found.
data/magic.mse-game/game
View file @
dbb4bcac
...
...
@@ -807,6 +807,7 @@ keyword parameter type:
name: cost
#insert as: word
match: [XYZ0-9WUBRGS/]+|[^(.,\n]|([XYZ0-9WUBRGS/]+,)?[^(.,\n]*
script: "<sym-auto>{input}</sym-auto>" # TODO : DEBUG
keyword parameter type:
name: number
match: [XYZ0-9]+
...
...
src/data/keyword.cpp
View file @
dbb4bcac
...
...
@@ -116,7 +116,7 @@ void KeywordExpansion::prepare(const vector<KeywordParamP>& param_types, bool fo
if
(
!
force
&&
matchRe
.
IsValid
())
return
;
parameters
.
clear
();
// Prepare regex
// String regex
;
String
regex
=
_
(
"("
)
;
vector
<
KeywordParamP
>::
const_iterator
param
=
parameters
.
begin
();
// Parse the 'match' string
for
(
size_t
i
=
0
;
i
<
match
.
size
()
;)
{
...
...
@@ -126,24 +126,26 @@ void KeywordExpansion::prepare(const vector<KeywordParamP>& param_types, bool fo
size_t
start
=
skip_tag
(
match
,
i
),
end
=
match_close_tag
(
match
,
i
);
String
type
=
match
.
substr
(
start
,
end
-
start
);
// find parameter type 'type'
KeywordParam
*
p
=
nullptr
;
KeywordParam
P
p
;
FOR_EACH_CONST
(
pt
,
param_types
)
{
if
(
pt
->
name
==
type
)
{
p
=
pt
.
get
()
;
p
=
pt
;
break
;
}
}
if
(
!
p
)
{
throw
InternalError
(
_
(
"Unknown keyword parameter type: "
)
+
type
);
}
parameters
.
push_back
(
p
);
// modify regex
regex
+=
_
(
"
("
)
+
make_non_capturing
(
p
->
match
)
+
_
(
")
"
);
regex
+=
_
(
"
)("
)
+
make_non_capturing
(
p
->
match
)
+
_
(
")?(
"
);
i
=
skip_tag
(
match
,
end
);
}
else
{
regex
+=
regex_escape
(
c
);
i
++
;
}
}
regex
+=
_
(
")"
);
if
(
!
matchRe
.
Compile
(
regex
,
wxRE_ADVANCED
))
{
throw
InternalError
(
_
(
"Error creating match regex"
));
}
...
...
@@ -275,7 +277,7 @@ void closure(vector<KeywordTrie*>& state) {
}
}
//
DEBUG
#ifdef _
DEBUG
void
dump
(
int
i
,
KeywordTrie
*
t
)
{
FOR_EACH
(
c
,
t
->
children
)
{
wxLogDebug
(
String
(
i
,
_
(
' '
))
+
c
.
first
+
_
(
" "
)
+
String
::
Format
(
_
(
"%p"
),
c
.
second
));
...
...
@@ -286,19 +288,18 @@ void dump(int i, KeywordTrie* t) {
if
(
t
->
on_any_star
!=
t
)
dump
(
i
+
2
,
t
->
on_any_star
);
}
}
#endif
String
KeywordDatabase
::
expand
(
const
String
&
text
,
const
ScriptValueP
&
expand_default
,
const
ScriptValueP
&
combine_script
,
Context
&
ctx
)
const
{
// DEBUG: dump db
//dump(0, root);
assert
(
combine_script
);
// Remove all old reminder texts
String
s
=
remove_tag_contents
(
text
,
_
(
"<atom-reminder>"
));
s
=
remove_tag_contents
(
s
,
_
(
"<atom-keyword>"
));
// OLD, TODO: REMOVEME
s
=
remove_tag_contents
(
s
,
_
(
"<atom-kwpph>"
));
s
=
remove_tag
(
s
,
_
(
"<keyword-param"
));
String
untagged
=
untag_no_escape
(
s
);
...
...
@@ -345,7 +346,6 @@ String KeywordDatabase::expand(const String& text,
map
<
Char
,
KeywordTrie
*>::
const_iterator
it
=
kt
->
children
.
find
(
c
);
if
(
it
!=
kt
->
children
.
end
())
{
next
.
push_back
(
it
->
second
);
wxLogDebug
(
c
+
String
(
_
(
" -> "
))
+
String
::
Format
(
_
(
"%p"
),
it
->
second
));
}
}
// next becomes current
...
...
@@ -369,17 +369,35 @@ String KeywordDatabase::expand(const String& text,
end
=
untagged_to_index
(
s
,
start_u
+
len_u
,
true
);
result
+=
s
.
substr
(
0
,
start
);
// Set parameters in context
// Split the keyword, set parameters in context
String
total
;
// the total keyword
size_t
match_count
=
kw
->
matchRe
.
GetMatchCount
();
assert
(
match_count
-
1
==
1
+
2
*
kw
->
parameters
.
size
());
for
(
size_t
j
=
1
;
j
<
match_count
;
++
j
)
{
// j = odd -> text
// j = even -> parameter #(j/2)
size_t
start_u
,
len_u
;
kw
->
matchRe
.
GetMatch
(
&
start_u
,
&
len_u
,
j
);
String
param
=
untagged
.
substr
(
start_u
,
len_u
);
if
(
j
-
1
<
kw
->
parameters
.
size
()
&&
kw
->
parameters
[
j
-
1
]
->
script
)
{
// apply parameter script
param
=
kw
->
parameters
[
j
-
1
]
->
script
.
invoke
(
ctx
)
->
toString
();
size_t
part_end
=
untagged_to_index
(
s
,
start_u
+
len_u
,
true
);
String
part
=
s
.
substr
(
start
,
part_end
-
start
);
if
((
j
%
2
)
==
0
)
{
// parameter
String
param
=
untagged
.
substr
(
start_u
,
len_u
);
// untagged version
if
(
param
.
empty
())
{
// placeholder
param
=
_
(
"<atom-kwpph>"
)
+
kw
->
parameters
[
j
/
2
-
1
]
->
name
+
_
(
"</atom-kwpph>"
);
part
=
part
+
param
;
// keep tags
}
else
if
(
kw
->
parameters
[
j
/
2
-
1
]
->
script
)
{
// apply parameter script
ctx
.
setVariable
(
_
(
"input"
),
toScript
(
part
));
part
=
kw
->
parameters
[
j
/
2
-
1
]
->
script
.
invoke
(
ctx
)
->
toString
();
ctx
.
setVariable
(
_
(
"input"
),
toScript
(
part
));
param
=
kw
->
parameters
[
j
/
2
-
1
]
->
script
.
invoke
(
ctx
)
->
toString
();
}
ctx
.
setVariable
(
String
(
_
(
"param"
))
<<
(
int
)(
j
/
2
),
toScript
(
param
));
}
ctx
.
setVariable
(
String
(
_
(
"param"
))
<<
(
int
)
j
,
toScript
(
param
));
total
+=
part
;
start
=
part_end
;
}
ctx
.
setVariable
(
_
(
"mode"
),
toScript
(
kw
->
mode
));
...
...
@@ -394,14 +412,14 @@ String KeywordDatabase::expand(const String& text,
// Combine keyword & reminder with result
if
(
expand
)
{
String
reminder
=
kw
->
reminder
.
invoke
(
ctx
)
->
toString
();
ctx
.
setVariable
(
_
(
"keyword"
),
toScript
(
s
.
substr
(
start
,
end
-
start
)
));
ctx
.
setVariable
(
_
(
"keyword"
),
toScript
(
total
));
ctx
.
setVariable
(
_
(
"reminder"
),
toScript
(
reminder
));
result
+=
_
(
"<kw-"
);
result
+=
expand_type
;
result
+=
_
(
">"
);
result
+=
combine_script
->
eval
(
ctx
)
->
toString
();
result
+=
_
(
"</kw-"
);
result
+=
expand_type
;
result
+=
_
(
">"
);
}
else
{
result
+=
_
(
"<kw-"
);
result
+=
expand_type
;
result
+=
_
(
">"
);
result
+=
s
.
substr
(
start
,
end
-
start
)
;
result
+=
total
;
result
+=
_
(
"</kw-"
);
result
+=
expand_type
;
result
+=
_
(
">"
);
}
...
...
src/data/keyword.hpp
View file @
dbb4bcac
...
...
@@ -50,11 +50,15 @@ class KeywordExpansion {
public:
String
match
;
///< String to match, <param> tags are used for parameters
vector
<
KeywordParamP
>
parameters
;
///< The types of parameters
wxRegEx
matchRe
;
///< Regular expression to match and split parameters, automatically generated
StringScript
reminder
;
///< Reminder text of the keyword
String
mode
;
///< Mode of use, can be used by scripts (only gives the name)
// . Default is the mode of the Keyword.
String
regex
;
//TODO REMOVE
/// Regular expression to match and split parameters, automatically generated.
/** The regex has exactly 2 * parameters.size() + 1 captures (excluding the entire match, caputure 0),
* captures 1,3,... capture the plain text of the match string
* captures 2,4,... capture the parameters
*/
wxRegEx
matchRe
;
//% . Default is the mode of the Keyword.
/// Prepare the expansion: (re)generate matchRe and the list of parameters.
/** Throws when there is an error in the input
...
...
src/gui/control/card_editor.cpp
View file @
dbb4bcac
...
...
@@ -35,10 +35,11 @@ ValueViewerP DataEditor::makeViewer(const StyleP& style) {
// ----------------------------------------------------------------------------- : Utility for ValueViewers
bool
DataEditor
::
drawBorders
()
const
{
return
!
nativeLook
()
&&
settings
.
stylesheetSettingsFor
(
*
set
->
stylesheetFor
(
card
)).
card_borders
();
return
!
nativeLook
()
&&
settings
.
stylesheetSettingsFor
(
*
set
->
stylesheetFor
(
card
)).
card_borders
();
}
bool
DataEditor
::
drawEditing
()
const
{
return
true
;
return
FindFocus
()
==
this
;
}
wxPen
DataEditor
::
borderPen
(
bool
active
)
const
{
...
...
@@ -47,7 +48,7 @@ wxPen DataEditor::borderPen(bool active) const {
}
ValueViewer
*
DataEditor
::
focusedViewer
()
const
{
return
current_viewe
r
;
return
FindFocus
()
==
this
?
current_viewer
:
nullpt
r
;
}
// ----------------------------------------------------------------------------- : Selection
...
...
@@ -276,7 +277,7 @@ void DataEditor::onContextMenu(wxContextMenuEvent& ev) {
if
(
current_editor
)
{
IconMenu
m
;
m
.
Append
(
wxID_CUT
,
_
(
"cut"
),
_
(
"Cu&t"
),
_
(
"Move the selected text to the clipboard"
));
m
.
Append
(
wxID_COPY
,
_
(
"copy"
),
_
(
"&Copy"
),
_
(
"Place the selected text on the clipboard"
));
m
.
Append
(
wxID_COPY
,
_
(
"copy"
),
_
(
"&Copy"
),
_
(
"Place the selected text on the clipboard"
));
m
.
Append
(
wxID_PASTE
,
_
(
"paste"
),
_
(
"&Paste"
),
_
(
"Inserts the text from the clipboard"
));
m
.
Enable
(
wxID_CUT
,
canCut
());
m
.
Enable
(
wxID_COPY
,
canCopy
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment