import { StreamLanguage } from '@codemirror/language';
import type { ProjectEditorLanguageId } from '../project-language';
import { simpleParser, wordSet } from './common';

const python = simpleParser({ keywords: wordSet('and as assert async await break class continue def del elif else except False finally for from global if import in is lambda None nonlocal not or pass raise return True try while with yield match case'), types: wordSet('int float str bool bytes list tuple dict set object type'), hashComment: true });
const php = simpleParser({ keywords: wordSet('abstract and array as break callable case catch class clone const continue declare default do echo else elseif empty enddeclare endfor endforeach endif endswitch endwhile eval exit extends final finally fn for foreach function global goto if implements include include_once instanceof insteadof interface isset list match namespace new or print private protected public readonly require require_once return static switch throw trait try unset use var while xor yield'), lineComment: '//', hashComment: true, blockComment: ['/*','*/'], variablePrefix: /^\$[A-Za-z_]\w*/u });
const shell = simpleParser({ keywords: wordSet('if then else elif fi for while until do done case esac function in select time coproc export local readonly declare typeset unset source'), hashComment: true, variablePrefix: /^\$\{?[A-Za-z_][A-Za-z0-9_]*\}?/u });
const r = simpleParser({ keywords: wordSet('if else repeat while function for in next break TRUE FALSE NULL Inf NaN NA'), hashComment: true });
const ruby = simpleParser({ keywords: wordSet('BEGIN END alias and begin break case class def defined do else elsif end ensure false for if in module next nil not or redo rescue retry return self super then true undef unless until when while yield'), hashComment: true });

export function projectScriptingLanguage(id: ProjectEditorLanguageId) {
  return StreamLanguage.define(id === 'python' ? python : id === 'php' ? php : id === 'shell' ? shell : id === 'r' ? r : ruby);
}
