diff options
Diffstat (limited to 'src/yuescript/yue_parser.cpp')
| -rw-r--r-- | src/yuescript/yue_parser.cpp | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index fccb6fb..cbba115 100644 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp | |||
| @@ -232,27 +232,43 @@ YueParser::YueParser() { | |||
| 232 | KeyName = SelfItem | Name | UnicodeName; | 232 | KeyName = SelfItem | Name | UnicodeName; |
| 233 | VarArg = "..."; | 233 | VarArg = "..."; |
| 234 | 234 | ||
| 235 | check_indent = pl::user(plain_space, [](const item_t& item) { | 235 | auto getIndent = [](const item_t& item) -> int { |
| 236 | if (item.begin->m_it == item.end->m_it) return 0; | ||
| 237 | State* st = reinterpret_cast<State*>(item.user_data); | ||
| 238 | bool useTab = false; | ||
| 239 | if (st->useTab) { | ||
| 240 | useTab = st->useTab.value(); | ||
| 241 | } else { | ||
| 242 | useTab = *item.begin->m_it == '\t'; | ||
| 243 | st->useTab = useTab; | ||
| 244 | } | ||
| 236 | int indent = 0; | 245 | int indent = 0; |
| 237 | for (input_it i = item.begin->m_it; i != item.end->m_it; ++i) { | 246 | if (useTab) { |
| 238 | switch (*i) { | 247 | for (input_it i = item.begin->m_it; i != item.end->m_it; ++i) { |
| 239 | case ' ': indent++; break; | 248 | switch (*i) { |
| 240 | case '\t': indent += 4; break; | 249 | case '\t': indent += 4; break; |
| 250 | default: throw ParserError("can not mix the use of tabs and spaces as indents"sv, item.begin); break; | ||
| 251 | } | ||
| 252 | } | ||
| 253 | } else { | ||
| 254 | for (input_it i = item.begin->m_it; i != item.end->m_it; ++i) { | ||
| 255 | switch (*i) { | ||
| 256 | case ' ': indent++; break; | ||
| 257 | default: throw ParserError("can not mix the use of tabs and spaces as indents"sv, item.begin); break; | ||
| 258 | } | ||
| 241 | } | 259 | } |
| 242 | } | 260 | } |
| 261 | return indent; | ||
| 262 | }; | ||
| 263 | |||
| 264 | check_indent = pl::user(plain_space, [getIndent](const item_t& item) { | ||
| 243 | State* st = reinterpret_cast<State*>(item.user_data); | 265 | State* st = reinterpret_cast<State*>(item.user_data); |
| 244 | return st->indents.top() == indent; | 266 | return st->indents.top() == getIndent(item); |
| 245 | }); | 267 | }); |
| 246 | check_indent_match = and_(check_indent); | 268 | check_indent_match = and_(check_indent); |
| 247 | 269 | ||
| 248 | advance = pl::user(plain_space, [](const item_t& item) { | 270 | advance = pl::user(plain_space, [getIndent](const item_t& item) { |
| 249 | int indent = 0; | 271 | int indent = getIndent(item); |
| 250 | for (input_it i = item.begin->m_it; i != item.end->m_it; ++i) { | ||
| 251 | switch (*i) { | ||
| 252 | case ' ': indent++; break; | ||
| 253 | case '\t': indent += 4; break; | ||
| 254 | } | ||
| 255 | } | ||
| 256 | State* st = reinterpret_cast<State*>(item.user_data); | 272 | State* st = reinterpret_cast<State*>(item.user_data); |
| 257 | int top = st->indents.top(); | 273 | int top = st->indents.top(); |
| 258 | if (top != -1 && indent > top) { | 274 | if (top != -1 && indent > top) { |
| @@ -921,7 +937,7 @@ YueParser::YueParser() { | |||
| 921 | MacroInPlace = '$' >> space >> "->" >> space >> Body; | 937 | MacroInPlace = '$' >> space >> "->" >> space >> Body; |
| 922 | 938 | ||
| 923 | NameList = Seperator >> Variable >> *(space >> ',' >> space >> Variable); | 939 | NameList = Seperator >> Variable >> *(space >> ',' >> space >> Variable); |
| 924 | NameOrDestructure = Variable | TableLit | Comprehension; | 940 | NameOrDestructure = Variable | TableLit | Comprehension | SimpleTable; |
| 925 | AssignableNameList = Seperator >> NameOrDestructure >> *(space >> ',' >> space >> NameOrDestructure); | 941 | AssignableNameList = Seperator >> NameOrDestructure >> *(space >> ',' >> space >> NameOrDestructure); |
| 926 | 942 | ||
| 927 | FnArrowBack = '<' >> set("-="); | 943 | FnArrowBack = '<' >> set("-="); |
