import { LRParser } from '@lezer/lr'; import { LanguageSupport, LRLanguage } from '@codemirror/language'; import { CompletionSource } from '@codemirror/autocomplete'; declare const parser$2: LRParser declare const parser$1: LRParser /** A language provider for the C shell, based on the Lezer grammar in `csh.grammar`. */ declare const cshLanguage = LRLanguage.define({ name: "csh", parser: cshParser.configure({ props: [ indentNodeProp.add({ Group: delimitedIndent({ closing: "}" }), Subshell: delimitedIndent({ closing: ")" }), WhileStatement: delimitedIndent({ closing: "end" }), ForeachStatement: delimitedIndent({ closing: "end" }), SwitchStatement: delimitedIndent({ closing: "endsw" }), // `then` sits on the same line as the `if` it belongs to, so what is // indented is everything after that line. IfStatement: continuedIndent({ except: /^\s*(endif|else)\b/ }), CaseClause: continuedIndent({ except: /^\s*(case|default|endsw)\b/ }) }), foldNodeProp.add({ Group: foldInside, Subshell: foldInside, WhileStatement: foldInside, ForeachStatement: foldInside, SwitchStatement: foldInside }), styleTags({ "if then else endif": t.controlKeyword, "while foreach end repeat": t.controlKeyword, "switch case default endsw": t.controlKeyword, "set setenv unset alias": t.definitionKeyword, Label: t.labelName, Comment: t.lineComment, String: t.string, RawString: t.string, HeredocBody: t.special(t.string), Escape: t.escape, LineContinuation: t.escape, Glob: t.special(t.string), "SimpleCommand/CommandName ShortCommand/CommandName": t.function(t.variableName), VariableName: t.definition(t.variableName), SimpleExpansion: t.variableName, ParamName: t.variableName, ParamOp: t.operator, Dollar: t.variableName, // `:q` and its relatives say what to do with the word before them, // which is what an operator is. Modifier: t.operator, Number: t.number, RedirectOp: t.controlOperator, "PipeOp Background": t.controlOperator, "AndOp OrOp NotOp": t.logicOperator, "AddOp MulOp": t.arithmeticOperator, "ShiftOp BitAndOp BitXorOp BitOrOp BitNotOp": t.bitwiseOperator, "RelateOp EqualOp MatchOp": t.compareOperator, FileTestOp: t.operatorKeyword, AssignOp: t.definitionOperator, IncDecOp: t.updateOperator, // `@` is a command rather than a symbol, and reads as the arithmetic // it introduces. "@": t.definitionKeyword, '"\\""': t.string, '"${" "}" "{"': t.brace, '"(" ")"': t.paren, '"[" "]"': t.squareBracket, '";"': t.separator, Terminator: t.separator }) ] }), languageData: { commentTokens: { line: "#" }, closeBrackets: { brackets: ["(", "[", "{", "'", '"', "`"] }, indentOnInput: /^\s*(endif|end|endsw|else|breaksw|\}|\))$/ } }); /** Autocompletion for the C shell's builtins and the variables it sets. */ declare const cshCompletion = completeFromList([...builtins, ...specials]); declare const parser: LRParser /** A language provider for fish, based on the Lezer grammar in `fish.grammar`. */ declare const fishLanguage = LRLanguage.define({ name: "fish", parser: fishParser.configure({ props: [ indentNodeProp.add({ CommandSubstitution: delimitedIndent({ closing: ")" }), // Every block ends with the same word, so every block indents the same // way, which is the one thing fish made easier than the shell did. "IfStatement WhileStatement ForStatement SwitchStatement FunctionDefinition BeginBlock": continuedIndent({ except: /^\s*(end|else)\b/ }), CaseClause: continuedIndent({ except: /^\s*(case|end)\b/ }) }), foldNodeProp.add({ CommandSubstitution: foldInside, "IfStatement WhileStatement ForStatement SwitchStatement FunctionDefinition BeginBlock": foldInside }), styleTags({ "if else end": t.controlKeyword, "while for in switch case begin": t.controlKeyword, function: t.definitionKeyword, // `and`, `or` and `not` are commands rather than punctuation, and read // as the logic they are either way. "and or not": t.logicOperator, Comment: t.lineComment, String: t.string, RawString: t.string, Escape: t.escape, Glob: t.special(t.string), "SimpleCommand/CommandName": t.function(t.variableName), "FunctionDefinition/FunctionName": t.function(t.definition(t.variableName)), VariableName: t.definition(t.variableName), SimpleExpansion: t.variableName, Dollar: t.variableName, RedirectOp: t.controlOperator, "PipeOp Background": t.controlOperator, "AndOp OrOp": t.logicOperator, Terminator: t.separator, '"\\""': t.string, '"$(" "(" ")"': t.paren, "SubscriptOpen SubscriptClose": t.squareBracket }) ] }), languageData: { commentTokens: { line: "#" }, closeBrackets: { brackets: ["(", "[", "{", "'", '"'] }, indentOnInput: /^\s*(end|else|case)$/ } }); /** Autocompletion for fish's builtins and the variables it sets. */ declare const fishCompletion = completeFromList([...builtins, ...specials]); /** A language provider based on the Lezer shell parser in this package, extended with highlighting, folding and indentation information. */ declare const shellLanguage: LRLanguage; /** Autocompletion for the shell's reserved words, builtin commands and the variables it sets. */ declare const shellCompletion: CompletionSource; /** The name of a shell this package reads, or any of the aliases above. */ type Shell = "sh" | "csh" | "fish"; /** The language for one shell. `"csh"`, `"tcsh"` and `"fish"` are answered with their own grammars, and everything else with the shell command language. What a caller does with the result is the same either way. */ declare function shellLanguageFor(shell: string): LRLanguage; interface ShellConfig { /** Whose shell to read. `"sh"`, `"bash"`, `"zsh"` and `"ksh"` are all the one grammar; `"csh"`, `"tcsh"` and `"fish"` each have their own. Defaults to `"sh"`. */ shell?: Shell | string; } /** Shell language support, with completion for the builtins and the variables the shell sets. */ declare function shell(config?: ShellConfig): LanguageSupport; /** C shell support, for a caller who knows which of the grammars they want. */ declare function csh(): LanguageSupport; /** fish support, likewise. */ declare function fish(): LanguageSupport; export { csh, cshCompletion, cshLanguage, parser$1 as cshParser, fish, fishCompletion, fishLanguage, parser as fishParser, parser$2 as parser, shell, shellCompletion, shellLanguage, shellLanguageFor }; export type { Shell, ShellConfig };