Exemplo n.º 1
0
        // input: text after "Plural-Forms:" (e.g. "nplurals=2; plural=(n != 1);"),
        // if s == 0, creates default handler
        // returns 0 if error
        public static PluralFormsCalculator Make(string str)
        {
            PluralFormsCalculator calculator = new PluralFormsCalculator();

            if (str != null)
            {
                PluralFormsScanner scanner = new PluralFormsScanner(str);
                PluralFormsParser  p       = new PluralFormsParser(scanner);
                if (!p.Parse(calculator))
                {
                    return(null);
                }
            }
            return(calculator);
        }
Exemplo n.º 2
0
        public bool Parse(PluralFormsCalculator calculator)
        {
            if (Token.TokenType != PluralFormsToken.Type.Nplurals)
            {
                return(false);
            }
            if (!NextToken())
            {
                return(false);
            }
            if (Token.TokenType != PluralFormsToken.Type.Assign)
            {
                return(false);
            }
            if (!NextToken())
            {
                return(false);
            }
            if (Token.TokenType != PluralFormsToken.Type.Number)
            {
                return(false);
            }
            int nplurals = Token.Number;

            if (!NextToken())
            {
                return(false);
            }
            if (Token.TokenType != PluralFormsToken.Type.Semicolon)
            {
                return(false);
            }
            if (!NextToken())
            {
                return(false);
            }
            if (Token.TokenType != PluralFormsToken.Type.Plural)
            {
                return(false);
            }
            if (!NextToken())
            {
                return(false);
            }
            if (Token.TokenType != PluralFormsToken.Type.Assign)
            {
                return(false);
            }
            if (!NextToken())
            {
                return(false);
            }
            PluralFormsNode plural = ParsePlural();

            if (plural == null)
            {
                return(false);
            }
            if (Token.TokenType != PluralFormsToken.Type.Semicolon)
            {
                return(false);
            }
            if (!NextToken())
            {
                return(false);
            }
            if (Token.TokenType != PluralFormsToken.Type.Eof)
            {
                return(false);
            }
            calculator.Init(nplurals, plural);
            return(true);
        }
Exemplo n.º 3
0
		public bool Parse (PluralFormsCalculator calculator)
		{
			if (Token.TokenType != PluralFormsToken.Type.Nplurals)
				return false;
			if (! NextToken ())
				return false;
			if (Token.TokenType != PluralFormsToken.Type.Assign)
				return false;
			if (! NextToken ())
				return false;
			if (Token.TokenType != PluralFormsToken.Type.Number)
				return false;
			int nplurals = Token.Number;
			if (! NextToken ())
				return false;
			if (Token.TokenType != PluralFormsToken.Type.Semicolon)
				return false;
			if (! NextToken ())
				return false;
			if (Token.TokenType != PluralFormsToken.Type.Plural)
				return false;
			if (! NextToken ())
				return false;
			if (Token.TokenType != PluralFormsToken.Type.Assign)
				return false;
			if (! NextToken ())
				return false;
			PluralFormsNode plural = ParsePlural ();
			if (plural == null)
				return false;
			if (Token.TokenType != PluralFormsToken.Type.Semicolon)
				return false;
			if (! NextToken ())
				return false;
			if (Token.TokenType != PluralFormsToken.Type.Eof)
				return false;
			calculator.Init (nplurals, plural);
			return true;
		}
Exemplo n.º 4
0
		// input: text after "Plural-Forms:" (e.g. "nplurals=2; plural=(n != 1);"),
		// if s == 0, creates default handler
		// returns 0 if error
		public static PluralFormsCalculator Make (string str)
		{
			PluralFormsCalculator calculator = new PluralFormsCalculator ();
			if (str != null)
			{
				PluralFormsScanner scanner = new PluralFormsScanner (str);
				PluralFormsParser p = new PluralFormsParser (scanner);
				if (!p.Parse (calculator))
				{
					return null;
				}
			}
			return calculator;
		}