Commit Graph

29 Commits

Author SHA1 Message Date
Yuya Nishihara
9e9d73bc11 parser: move unescape helper from templater
revset and fileset have a similar problem, so let's make it a common helper
function.
2015-09-10 23:25:10 +09:00
Gregory Szorc
a87fcbe79d parser: use absolute_import 2015-08-08 19:44:05 -07:00
Yuya Nishihara
6cb504f763 parser: take suffix action if no infix action is defined
If no infix action is defined, a suffix action isn't ambiguous, so it should
be taken no matter if the next token can be an operand. This is exactly the
same flow as prefix/primary handling.

This change has no effect now because all suffix tokens have infix actions.
2015-07-06 22:01:41 +09:00
Yuya Nishihara
43ae52143a parser: reorder infix/suffix handling to be similar to prefix/primary flow
It can be exactly the same flow as the prefix/primary handling. A suffix
action is accepted only if the next token never starts new term.
2015-07-06 21:55:55 +09:00
Yuya Nishihara
cdaa060788 parser: resolve ambiguity where both prefix and primary actions are defined
If both actions are defined, a primary-expression action is accepted only if
the next token never starts new term. For example,

  parsed as primary expression:
  ":"   # next token 'end' has no action
  "(:)" # next token ')' has no action
  ":+y" # next token '+' is infix operator

  parsed as prefix operator:
  ":y"  # next token 'y' is primary expression
  ":-y" # next token '-' is prefix operator

This is mostly the same resolution as the infix/suffix rules.
2015-07-05 12:09:27 +09:00
Yuya Nishihara
b4caf94446 parser: separate actions for primary expression and prefix operator
This will allow us to define both a primary expression, ":", and a prefix
operator, ":y". The ambiguity will be resolved by the next patch.

Prefix actions in elements table are adjusted as follows:

  original prefix      primary  prefix
  -----------------    -------- -----------------
  ("group", 1, ")") -> n/a      ("group", 1, ")")
  ("negate", 19)    -> n/a      ("negate", 19)
  ("symbol",)       -> "symbol" n/a
2015-07-05 12:02:13 +09:00
Yuya Nishihara
718c23ab58 parser: extract function that tests if next token may start new term
Future patches will separate primary expression and prefix operator actions.
This function will be used to resolve ambiguity of them.

This is a step to remove the old-style revexpr parser. We need both ":" and
":y" operators for backward compatibility.
2015-07-05 11:54:14 +09:00
Yuya Nishihara
c84ce8d445 parser: factor out function that parses right-hand side of prefix/infix ops
These two had common pattern. The significant difference was just a result
expression:

  prefix: (op-name, rhs)
  infix:  (op-name, lhs, rhs)
2015-07-05 18:09:15 +09:00
Yuya Nishihara
8905d3395c parser: remove unused parameter 'pos' from _match()
This backs out 58030471e557. The issue spotted by that changeset was addressed
earlier by a50a014eb0ba.
2015-07-05 17:50:35 +09:00
Yuya Nishihara
4645c24be5 parser: fill invalid infix and suffix actions by None
This can simplify the expansion of (prefix, infix, suffix) actions.
2015-07-05 11:17:22 +09:00
Yuya Nishihara
d1927459b6 revset: add function to build dict of positional and keyword arguments
Keyword arguments will be convenient for functions that will take more than
one optional or boolean flags. For example,

  file(pattern[, subrepos=false])
  subrepo([[pattern], status])

Because I don't think all functions should accept key=value syntax, getkwargs()
does not support variadic functions such as 'ancestor(*changeset)'.

The core logic is placed in the parser module because keyword arguments will
be more useful in the templater, where functions take more options. Test cases
will be added by the next patch.
2015-06-27 17:25:01 +09:00
Yuya Nishihara
5747b2c8e6 parser: update documentation about tokenizer and elements 2015-06-21 00:56:09 +09:00
Yuya Nishihara
fe462ed8ac parser: accept iterator of tokens instead of tokenizer function and program
This can simplify the interface of parse() function. Our tokenizer tends to
have optional arguments other than the message to be parsed.

Before this patch, the "lookup" argument existed only for the revset, and the
templater had to pack [program, start, end] to be passed to its tokenizer.
2015-06-21 00:49:26 +09:00
Yuya Nishihara
ca51f820ee parser: add helper to reduce nesting of chained infix operations
This will be used to avoid stack overflow caused by chained 'or' operations
in revset.
2015-04-26 18:05:23 +09:00
Yuya Nishihara
1ec56bf564 parser: extract closure of prettyformat() to a top-level function
There was no capture until I added 'leafnodes' argument.
2015-05-06 10:17:41 +09:00
Yuya Nishihara
09759e9679 parser: move prettyformat() function from revset module
I want to use it in doctests that I'll add by future patches. Also, it can
be used in "hg debugfileset" command.
2015-04-26 22:20:03 +09:00
Pierre-Yves David
5ec3f86b27 parsers: use 'next' instead of try/except
This get rid of another StopIteration abomination. The change in self.current
value is supposed to not matter as nobody should be calling '_advance' after
that (as per Matt wisdom).
2015-05-18 12:27:15 -05:00
Matt Mackall
39f29cd5bc parser: allow passing a lookup function to a tokenizer
This will allow us to dynamically handle hyphenated symbols in revsets.
2014-03-18 17:17:23 -05:00
timeless@mozdev.org
023e023a87 en-us: labeled 2012-08-17 13:58:18 -07:00
Mads Kiilerich
473bcd3ed1 parsers: fix localization markup of parser errors 2011-06-21 00:17:52 +02:00
Bernhard Leiner
baf797018e revset: report a parse error if a revset is not parsed completely (issue2654) 2011-03-16 23:09:14 +01:00
Matt Mackall
0b9296f805 templater: use the parser.py parser to extend the templater syntax 2010-12-20 12:09:00 -06:00
Julian Cowley
96da4ff949 parser: fix URL to effbot 2010-06-11 01:35:38 -10:00
Matt Mackall
8de0daaafc parser: improve infix error checking
(spotted by timeless)
2010-06-19 17:56:52 -05:00
Peter Arrenbrecht
e4f22f6bc6 parser: fix missing param in _match 2010-06-08 16:27:59 +02:00
Dirkjan Ochtman
64bb18f0dd cleanups: undefined variables 2010-06-08 09:30:45 +02:00
Matt Mackall
a963622643 revset: raise ParseError exceptions 2010-06-04 20:57:52 -05:00
Matt Mackall
96ee2ad35a revset: add support for prefix and suffix versions of : and :: 2010-06-02 14:07:46 -05:00
Matt Mackall
f9905b5aeb revset: introduce basic parser 2010-06-01 11:18:57 -05:00