/* Python whitespace handling: A block has the same indentation as previously Whitespace is ignored in grouping primitives (e.g. '()', '{}', '[]', etc.) */ ometa Python <: Parser { wsNoNL = (~'\n' space)*:spaces -> spaces.join(''), wsToEnd = wsNoNL '\n', initWS = wsToEnd+ wsNoNL blockLine :indent :x = initWS:currIndent ?(indent == currIndent) apply(x, indent):r -> r block :x = wsNoNL apply(x, ''):r -> [r] | initWS:indent apply(x, indent):r (blockLine(indent, x))*:others -> [r].concat(others) pythonToken :ws :tok = apply(ws) seq(tok) expr :ws = expr(ws):first pythonToken(ws, '+') expr(ws):second stmt = expr(`wsNoNL):result -> [`expr_stmt, result] | lexpr(`wsNoNL):lexpr pythonToken(`wsNoNL, '=') expr(`wsNoNL):value -> [`assign_stmt, lexpr, value] | pythonKeyword(`wsNoNL, 'if) expr(`wsNoNL):condition }