xo-tokenizer: feat: + basic arithmetic operators
This commit is contained in:
parent
3746f32529
commit
fa335ee523
4 changed files with 23 additions and 4 deletions
|
|
@ -62,7 +62,7 @@ namespace xo {
|
||||||
|
|
||||||
/** @brief create span representing prefix up to (but not including) @p *p
|
/** @brief create span representing prefix up to (but not including) @p *p
|
||||||
**/
|
**/
|
||||||
span prefix(CharT * p) const {
|
span prefix_upto(CharT * p) const {
|
||||||
if (p <= hi_)
|
if (p <= hi_)
|
||||||
return span(lo_, p);
|
return span(lo_, p);
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -560,13 +560,13 @@ namespace xo {
|
||||||
/* no-op */
|
/* no-op */
|
||||||
return {
|
return {
|
||||||
token_type::invalid(),
|
token_type::invalid(),
|
||||||
input.prefix(ix)
|
input.prefix_upto(ix)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/* here: *ix is not whitespace */
|
/* here: *ix is not whitespace */
|
||||||
|
|
||||||
auto whitespace = input.prefix(ix);
|
auto whitespace = input.prefix_upto(ix);
|
||||||
|
|
||||||
log && log(xtag("whitespace.size", whitespace.size()));
|
log && log(xtag("whitespace.size", whitespace.size()));
|
||||||
|
|
||||||
|
|
@ -630,7 +630,7 @@ namespace xo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto token_span = input.after_prefix(whitespace).prefix(ix);
|
auto token_span = input.after_prefix(whitespace).prefix_upto(ix);
|
||||||
|
|
||||||
token tk
|
token tk
|
||||||
= (this->prefix_.empty()
|
= (this->prefix_.empty()
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,20 @@ namespace xo {
|
||||||
/** '->' **/
|
/** '->' **/
|
||||||
tk_yields,
|
tk_yields,
|
||||||
|
|
||||||
|
/** note: operators not treated as punctuation
|
||||||
|
* 'do-always' is a legal variable name,
|
||||||
|
* as is 'maybe*2', 'maybe+1', 'path/to/foo'
|
||||||
|
**/
|
||||||
|
|
||||||
|
/** operator '+' **/
|
||||||
|
tk_plus,
|
||||||
|
/** operator '-' **/
|
||||||
|
tk_minus,
|
||||||
|
/** operator '*' **/
|
||||||
|
tk_star,
|
||||||
|
/** operator '/' **/
|
||||||
|
tk_slash,
|
||||||
|
|
||||||
/** keyworkd 'type' **/
|
/** keyworkd 'type' **/
|
||||||
tk_type,
|
tk_type,
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,11 @@ namespace xo {
|
||||||
CASE(tk_assign);
|
CASE(tk_assign);
|
||||||
CASE(tk_yields);
|
CASE(tk_yields);
|
||||||
|
|
||||||
|
CASE(tk_plus);
|
||||||
|
CASE(tk_minus);
|
||||||
|
CASE(tk_star);
|
||||||
|
CASE(tk_slash);
|
||||||
|
|
||||||
CASE(tk_type);
|
CASE(tk_type);
|
||||||
CASE(tk_def);
|
CASE(tk_def);
|
||||||
CASE(tk_lambda);
|
CASE(tk_lambda);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue