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
66091cd7
Commit
66091cd7
authored
Mar 09, 2012
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parser for just ScriptValues, same syntax as normal script code.
parent
e930cb36
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
131 additions
and
0 deletions
+131
-0
src/script/parser.cpp
src/script/parser.cpp
+119
-0
src/script/parser.hpp
src/script/parser.hpp
+12
-0
No files found.
src/script/parser.cpp
View file @
66091cd7
...
@@ -848,3 +848,122 @@ void parseCallArguments(TokenIterator& input, Script& script, vector<Variable>&
...
@@ -848,3 +848,122 @@ void parseCallArguments(TokenIterator& input, Script& script, vector<Variable>&
}
}
}
}
}
}
// ----------------------------------------------------------------------------- : Parsing values
ScriptValueP
parse_value
(
TokenIterator
&
input
)
{
Token
token
=
input
.
read
();
if
(
token
==
_
(
"("
))
{
// Parentheses = grouping, i.e. ignore it
ScriptValueP
a
=
parse_value
(
input
);
expectToken
(
input
,
_
(
")"
),
&
token
);
return
a
;
}
else
if
(
token
==
_
(
"["
))
{
// [] = list or map literal
ScriptCustomCollectionP
col
(
new
ScriptCustomCollection
);
Token
t
=
input
.
peek
();
while
(
t
!=
_
(
"]"
)
&&
t
!=
TOK_EOF
)
{
if
(
input
.
peek
(
2
)
==
_
(
":"
)
&&
(
t
.
type
==
TOK_NAME
||
t
.
type
==
TOK_INT
||
t
.
type
==
TOK_STRING
))
{
// name: ...
String
key
=
t
.
value
;
input
.
read
();
// skip the name
input
.
read
();
// and the :
ScriptValueP
v
=
parse_value
(
input
);
if
(
v
)
col
->
key_value
[
key
]
=
v
;
}
else
{
// implicit numbered element
ScriptValueP
v
=
parse_value
(
input
);
if
(
v
)
col
->
value
.
push_back
(
v
);
}
t
=
input
.
peek
();
if
(
t
==
_
(
","
))
{
// Comma separating the elements
input
.
read
();
t
=
input
.
peek
();
}
}
expectToken
(
input
,
_
(
"]"
),
&
token
);
return
col
;
}
else
if
(
token
==
_
(
"-"
))
{
// TODO?
throw
"TODO"
;
}
else
if
(
token
==
TOK_NAME
)
{
if
(
token
==
_
(
"true"
))
{
return
script_true
;
}
else
if
(
token
==
_
(
"false"
))
{
return
script_false
;
}
else
if
(
token
==
_
(
"nil"
))
{
return
script_nil
;
}
else
if
(
token
==
_
(
"rgb"
))
{
// rgb(r, g, b)
expectToken
(
input
,
_
(
"("
));
ScriptValueP
r
=
parse_value
(
input
);
expectToken
(
input
,
_
(
","
));
ScriptValueP
g
=
parse_value
(
input
);
expectToken
(
input
,
_
(
","
));
ScriptValueP
b
=
parse_value
(
input
);
expectToken
(
input
,
_
(
")"
));
if
(
!
r
||
!
g
||
!
b
)
return
ScriptValueP
();
return
to_script
(
wxColour
(
r
->
toInt
(),
g
->
toInt
(),
b
->
toInt
()));
}
else
if
(
token
==
_
(
"rgba"
))
{
// rgba(r, g, b, a)
expectToken
(
input
,
_
(
"("
));
ScriptValueP
r
=
parse_value
(
input
);
expectToken
(
input
,
_
(
","
));
ScriptValueP
g
=
parse_value
(
input
);
expectToken
(
input
,
_
(
","
));
ScriptValueP
b
=
parse_value
(
input
);
expectToken
(
input
,
_
(
","
));
ScriptValueP
a
=
parse_value
(
input
);
expectToken
(
input
,
_
(
")"
));
if
(
!
r
||
!
g
||
!
b
)
return
ScriptValueP
();
return
to_script
(
AColor
(
r
->
toInt
(),
g
->
toInt
(),
b
->
toInt
(),
a
->
toInt
()));
}
else
if
(
token
==
_
(
"mark_default"
))
{
expectToken
(
input
,
_
(
"("
));
ScriptValueP
a
=
parse_value
(
input
);
expectToken
(
input
,
_
(
")"
));
if
(
!
a
)
return
ScriptValueP
();
return
intrusive
(
new
ScriptDefault
(
a
));
}
else
if
(
token
==
_
(
"local_filename"
))
{
expectToken
(
input
,
_
(
"("
));
ScriptValueP
a
=
parse_value
(
input
);
expectToken
(
input
,
_
(
")"
));
if
(
!
a
)
return
ScriptValueP
();
//return intrusive(new ScriptLocalFileName(input.package,a->toString()));
return
intrusive
(
new
ScriptLocalFileName
(
nullptr
,
a
->
toString
()));
}
}
else
if
(
token
==
TOK_INT
)
{
long
l
=
0
;
token
.
value
.
ToLong
(
&
l
);
return
to_script
(
l
);
}
else
if
(
token
==
TOK_DOUBLE
)
{
double
d
=
0
;
token
.
value
.
ToDouble
(
&
d
);
return
to_script
(
d
);
}
else
if
(
token
==
TOK_STRING
)
{
return
to_script
(
token
.
value
);
}
// parse error
input
.
expected
(
_
(
"expression"
));
return
ScriptValueP
();
}
ScriptValueP
parse_value
(
const
String
&
s
,
Packaged
*
package
,
vector
<
ScriptParseError
>&
errors_out
)
{
errors_out
.
clear
();
// parse
TokenIterator
input
(
s
,
package
,
false
,
errors_out
);
ScriptValueP
value
=
parse_value
(
input
);
if
(
input
.
read
()
!=
TOK_EOF
)
{
input
.
expected
(
_
(
"end of input"
));
}
return
value
;
}
ScriptValueP
parse_value
(
const
String
&
s
,
Packaged
*
package
)
{
vector
<
ScriptParseError
>
errors
;
ScriptValueP
value
=
parse_value
(
s
,
package
,
errors
);
if
(
!
errors
.
empty
()
||
!
value
)
{
throw
ScriptParseErrors
(
errors
);
}
return
value
;
}
src/script/parser.hpp
View file @
66091cd7
...
@@ -36,5 +36,17 @@ ScriptP parse(const String& s, Packaged* package, bool string_mode, vector<Scrip
...
@@ -36,5 +36,17 @@ ScriptP parse(const String& s, Packaged* package, bool string_mode, vector<Scrip
*/
*/
ScriptP
parse
(
const
String
&
s
,
Packaged
*
package
=
nullptr
,
bool
string_mode
=
false
);
ScriptP
parse
(
const
String
&
s
,
Packaged
*
package
=
nullptr
,
bool
string_mode
=
false
);
/// Parse a String to a ScriptValue
/** Can return nullptr in case of parse errors
*/
ScriptValueP
parse_value
(
const
String
&
s
,
Packaged
*
package
,
vector
<
ScriptParseError
>&
errors_out
);
/// Parse a String to a ScriptValue
/** Throws an exception in case of parse errors
*/
ScriptValueP
parse_value
(
const
String
&
s
,
Packaged
*
package
=
nullptr
);
// ----------------------------------------------------------------------------- : EOF
// ----------------------------------------------------------------------------- : EOF
#endif
#endif
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