<?php
return [
'controllers' => [
'value' => [
'defaultNamespace' => '\\Bquadro\\Fos\\Controllers',
],
'readonly' => true,
],
];
namespace Bquadro\Fos\Controllers;
use Bitrix\Main\Application;
use Bitrix\Main\Engine\Controller;
class FosController extends Controller
{
public function getDefaultPreFilters(): array
{
$prefilters = [];
return $prefilters;
}
public function submitAction()
{
$request = Application::getInstance()->getContext()->getRequest();
return $request->getPostList()->toArray();
}
}
let response = await BX.ajax.runAction('bquadro:fos.foscontroller.submit', {
data: formData
})
var position = 0
const variables = []
const kw = [
'VAR', 'STRING', 'FUN', 'INT', 'FLOAT', 'CONST'
]
const operators = [
'(', ')', '=', ':', '{', '}'
]
const operatorsTypes = [
'LEFT', 'RIGHT', 'INIT', 'TYPE', 'SLEFT', 'SRIGTH'
]
function error(text) {
throw new Error(`TursLang:MainStream:${position}\n\n${text}`)
}
function tokenType(text) {
if (!isNaN(text)) return 'NUMBER'
if (operators.indexOf(text) != -1) return operatorsTypes[operators.indexOf(text)]
if (text.toLowerCase() == text && /[a-zA-Z]+/.test(text)) {
variables.push(text)
return 'VARIABLE'
}
if (text.toUpperCase() == text && kw.includes(text)) return 'KEYWORD'
error(`Unexpected identifier '${text}'`)
}
function token(text, types = null) {
const y = types == null ? tokenType(text) : types
return {
type: y,
text
}
}
function tokenize(text) {
const tokensList = []
var stringUse = false
var string = ''
for (; position < text.length; position++) {
var ch = text[position],
next = position + 1 < text.length ? text[position + 1] : ''
if (stringUse && ch != '\'') {
string += ch
continue
}
if (ch == '\'') {
stringUse = !stringUse
if (!stringUse) {
tokensList.push(token(string, 'STRING'))
string = ''
continue
}
}
if (!stringUse) {
if (ch == ' ' || operators.includes(next)) {
if (string) tokensList.push(token(string.trim()))
string = ''
} else if (operators.includes(ch)) {
tokensList.push(token(ch))
} else {
string += ch
}
}
}
if (string) tokensList.push(token(string.trim()))
return tokensList.filter(i => i.text.trim() !== '')
}
const tokens = tokenize(`
FUN print() {
}
FUN main() {
CONST: STRING hello = 'Hi!'
print(hello)
}
`)
console.log(tokens.map(token => `${token.type}: ${token.text}`).join('\n'))