<commit_before>﻿using System.Collections.Generic;
using System.Linq;
using csly.whileLang.model;
using sly.lexer;
using sly.parser.generator;
using sly.parser.parser;

namespace csly.indentedWhileLang.parser
{
    public class IndentedWhileParserGeneric
    {
        #region COMPARISON OPERATIONS

        [Operation((int) IndentedWhileTokenGeneric.LESSER, Affix.InFix, Associativity.Right, 50)]
        [Operation((int) IndentedWhileTokenGeneric.GREATER, Affix.InFix, Associativity.Right, 50)]
        [Operation((int) IndentedWhileTokenGeneric.EQUALS, Affix.InFix, Associativity.Right, 50)]
        [Operation((int) IndentedWhileTokenGeneric.DIFFERENT, Affix.InFix, Associativity.Right, 50)]
        public WhileAST binaryComparisonExpression(WhileAST left, Token<IndentedWhileTokenGeneric> operatorToken,
            WhileAST right)
        {
            var oper = BinaryOperator.ADD;

            switch (operatorToken.TokenID)
            {
                case IndentedWhileTokenGeneric.LESSER:
                {
                    oper = BinaryOperator.LESSER;
                    break;
                }
                case IndentedWhileTokenGeneric.GREATER:
                {
                    oper = BinaryOperator.GREATER;
                    break;
                }
                case IndentedWhileTokenGeneric.EQUALS:
                {
                    oper = BinaryOperator.EQUALS;
                    break;
                }
                case IndentedWhileTokenGeneric.DIFFERENT:
                {
                    oper = BinaryOperator.DIFFERENT;
                    break;
                }
            }

            var operation = new BinaryOperation(left as Expression, oper, right as Expression);
            return operation;
        }

        #endregion

        #region STRING OPERATIONS

        [Operation((int) IndentedWhileTokenGeneric.CONCAT, Affix.InFix, Associativity.Right, 10)]
        public WhileAST binaryStringExpression(WhileAST left, Token<IndentedWhileTokenGeneric> operatorToken, WhileAST right)
        {
            var oper = BinaryOperator.CONCAT;
            var operation = new BinaryOperation(left as Expression, oper, right as Expression);
            return operation;
        }

        #endregion

        
        [Production("program: sequence")]
        public WhileAST program(WhileAST prog)
        {
            return prog;
        }
        
        #region statements
       

        [Production("block : INDENT[d] sequence UINDENT[d]")]
        public WhileAST sequenceStatements(SequenceStatement seq)
        {
            return seq;
        }

        [Production("sequence: statementInBlock*")]
        public WhileAST sequence(List<WhileAST> list)
        {
            var statements = list.Cast<Statement>().ToList();
            var seq = new SequenceStatement(statements); 
            return seq;
        }

        [Production("statementInBlock : basicStatement SEMICOLON[d]")]
        public WhileAST basicStatementInBlock(WhileAST basic)
        {
            return basic;
        }
        
        [Production("statementInBlock : [ifthenelse | while]")]<commit_msg>better indented while language<commit_after>﻿using System.Collections.Generic;
using System.Linq;
using csly.whileLang.model;
using sly.lexer;
using sly.parser.generator;
using sly.parser.parser;

namespace csly.indentedWhileLang.parser
{
    public class IndentedWhileParserGeneric
    {
        #region COMPARISON OPERATIONS

        [Operation((int) IndentedWhileTokenGeneric.LESSER, Affix.InFix, Associativity.Right, 50)]
        [Operation((int) IndentedWhileTokenGeneric.GREATER, Affix.InFix, Associativity.Right, 50)]
        [Operation((int) IndentedWhileTokenGeneric.EQUALS, Affix.InFix, Associativity.Right, 50)]
        [Operation((int) IndentedWhileTokenGeneric.DIFFERENT, Affix.InFix, Associativity.Right, 50)]
        public WhileAST binaryComparisonExpression(WhileAST left, Token<IndentedWhileTokenGeneric> operatorToken,
            WhileAST right)
        {
            var oper = BinaryOperator.ADD;

            switch (operatorToken.TokenID)
            {
                case IndentedWhileTokenGeneric.LESSER:
                {
                    oper = BinaryOperator.LESSER;
                    break;
                }
                case IndentedWhileTokenGeneric.GREATER:
                {
                    oper = BinaryOperator.GREATER;
                    break;
                }
                case IndentedWhileTokenGeneric.EQUALS:
                {
                    oper = BinaryOperator.EQUALS;
                    break;
                }
                case IndentedWhileTokenGeneric.DIFFERENT:
                {
                    oper = BinaryOperator.DIFFERENT;
                    break;
                }
            }

            var operation = new BinaryOperation(left as Expression, oper, right as Expression);
            return operation;
        }

        #endregion

        #region STRING OPERATIONS

        [Operation((int) IndentedWhileTokenGeneric.CONCAT, Affix.InFix, Associativity.Right, 10)]
        public WhileAST binaryStringExpression(WhileAST left, Token<IndentedWhileTokenGeneric> operatorToken, WhileAST right)
        {
            var oper = BinaryOperator.CONCAT;
            var operation = new BinaryOperation(left as Expression, oper, right as Expression);
            return operation;
        }

        #endregion

        
        [Production("program: sequence")]
        public WhileAST program(WhileAST prog)
        {
            return prog;
        }
        
        #region statements
       

        [Production("block : INDENT[d] sequence UINDENT[d]")]
        public WhileAST sequenceStatements(SequenceStatement seq)
        {
            return seq;
        }

        [Production("sequence: statementInBlock*")]
        public WhileAST sequence(List<WhileAST> list)
        {
            var statements = list.Cast<Statement>().ToList();
            var seq = new SequenceStatement(statements); 
            return seq;
        }

        [Production("statementInBlock : basicStatement SEMICOLON[d]")]
        public WhileAST basicStatementInBlock(WhileAST basic)
        {
            return basic;
        }
        
        [Production("statementInBlock : [ifthenelse | while | block]")]
{'fraction_non_alphanumeric': 0.07658436861141689, 'fraction_numerical': 0.0031451486082717407, 'mean_word_length': 1.867448151487827, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5560906', 'n_tokens_mistral': 1666, 'n_tokens_neox': 1532, 'n_words': 333}