Code Monkey home page Code Monkey logo

javascriptix's People

Contributors

iqltd avatar

Watchers

 avatar  avatar

Forkers

waffle-iron

javascriptix's Issues

Perform sequence brace expansion

3.5.1 "A sequence expression takes the form {x..y[..incr]}, where x and y are either integers
or single characters, and incr, an optional increment, is an integer. When integers are
supplied, the expression expands to each number between x and y, inclusive. Supplied
integers may be prefixed with ‘0’ to force each term to have the same width. When either
x or y begins with a zero, the shell attempts to force all generated terms to contain the
same number of digits, zero-padding where necessary. When characters are supplied, the
expression expands to each character lexicographically between x and y, inclusive, using the
default C locale. Note that both x and y must be of the same type. When the increment
is supplied, it is used as the difference between each term. The default increment is 1 or -1
as appropriate."

Perform indirect parameter expansion or nameref expansion

3.5.3 "If the first character of parameter is an exclamation point (!), and parameter is not a
nameref, it introduces a level of variable indirection. Bash uses the value of the variable
formed from the rest of parameter as the name of the variable; this variable is then expanded
and that value is used in the rest of the substitution, rather than the value of parameter
itself. This is known as indirect expansion. If parameter is a nameref, this expands to
the name of the variable referenced by parameter instead of performing the complete indi-
rect expansion. The exceptions to this are the expansions of $ { !prefix* } and $ { !name[@] }
described below. The exclamation point must immediately follow the left brace in order to
introduce indirection."

Run functions

3.3 "Shell functions are a way to group commands for later execution using a single name for
the group. They are executed just like a "regular" command. When the name of a shell
function is used as a simple command name, the list of commands associated with that
function name is executed. Shell functions are executed in the current shell context; no new
process is created to interpret them."

Break list of commands in individual commands

3.2.3 "A list is a sequence of one or more pipelines separated by one of the operators ‘;’, ‘&’,
‘&&’, or ‘||’, and optionally terminated by one of ‘;’, ‘&’, or a newline.
Of these list operators, ‘&&’ and ‘||’ have equal precedence, followed by ‘;’ and ‘&’, which
have equal precedence."

Identify comments

3.1.3 "In a non-interactive shell, or an interactive shell in which the interactive_comments option to the shopt builtin is enabled (see Section 4.3.2 [The Shopt Builtin], page 64), a word beginning with ‘#’ causes that word and all remaining characters on that line to be ignored. An interactive shell without the interactive_comments option enabled does not allow comments. The interactive_comments option is on by default in interactive shells. See Section 6.3 [Interactive Shells], page 85, for a description of what makes a shell interactive."

Manage exit status in functions

3.3 "The exit status of a function definition is zero unless a syntax error occurs or a readonly
function with the same name already exists. When executed, the exit status of a function
is the exit status of the last command executed in the body."

Show shell symbol

Show the shell symbol ("$") at the command line. Show it in the results after the command is entered.

Perform basic parameter expansion

3.5.3 "The basic form of parameter expansion is $ { parameter } . The value of parameter is
substituted. The parameter is a shell parameter as described above (see Section 3.4 [Shell
Parameters], page 18) or an array reference (see Section 6.7 [Arrays], page 91). The braces
are required when parameter is a positional parameter with more than one digit, or when
parameter is followed by a character that is not to be interpreted as part of its name."

j$.bash.interpret - support different kind of commands

Prepare the grounds for supporting different kind of commands: shell functions, shell builtins, executables. Decide how to detect what kind of command it is, how to interpret it accordingly, and show the correct error message on fail.

Add user and group

Add a dummy object representing the default group, containing the group name and the group ID. Add a dummy object representing the default user, containing the username, password, the user ID, the group ID, home directory and the default shell.

Perform tilde expansion

3.5.2 "~ The value of $HOME
~/foo $HOME/foo
~fred/foo
The subdirectory foo of the home directory of the user fred
~+/foo $PWD/foo
-/foo ${OLDPWD-’-’}/foo
~N The string that would be displayed by ‘dirs +N’
~+N The string that would be displayed by ‘dirs +N’
~-N The string that would be displayed by ‘dirs -N’"

Identify functions

3.3 "Functions are declared using this syntax:
name () compound-command [ redirections ]
or
function name [()] compound-command [ redirections ]
This defines a shell function named name. The reserved word function is optional. If the function reserved word is supplied, the parentheses are optional. The body of the function is the compound command compound-command (see Section 3.2.4 [Compound Commands], page 9). That command is usually a list enclosed between { and } , but may be any compound command listed above, with one exception: If the function reserved word is used, but the parentheses are not supplied, the braces are required. compound-command is executed whenever name is specified as the name of a command."

Parse single-quoted strings

3.1.2.2 "Enclosing characters in single quotes (‘’’) preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash."

Manage local builtin

3.3 "Variables local to the function may be declared with the local builtin. These variables
are visible only to the function and the commands it invokes."

Parse escaped characters

3.1.2.1 "A non-quoted backslash ‘\’ is the Bash escape character. It preserves the literal value of
the next character that follows, with the exception of newline. If a \newline pair appears,
and the backslash itself is not quoted, the \newline is treated as a line continuation (that
is, it is removed from the input stream and effectively ignored)."

Create execution context

Create a global function returning the execution context. This execution context will contain the current user, the working directory, the environment variables (for now PATH, HOME, HOSTNAME), umask.

Implement tokenizer

Separate the input into lists of tokens (words separated by metacharacters)

Perform simple parameter substring expansion

3.5.3 "${parameter:offset}
${parameter:offset:length}
This is referred to as Substring Expansion. It expands to up to length charac-
ters of the value of parameter starting at the character specified by offset. If
parameter is ‘@’, an indexed array subscripted by ‘@’ or ‘*’, or an associative ar-
ray name, the results differ as described below. If length is omitted, it expands
to the substring of the value of parameter starting at the character specified by
offset and extending to the end of the value. length and offset are arithmetic
expressions (see Section 6.5 [Shell Arithmetic], page 89).
If offset evaluates to a number less than zero, the value is used as an offset
in characters from the end of the value of parameter. If length evaluates to a
number less than zero, it is interpreted as an offset in characters from the end of
the value of parameter rather than a number of characters, and the expansion
is the characters between offset and that result. Note that a negative offset
must be separated from the colon by at least one space to avoid being confused
with the ‘:-’ expansion.
Here are some examples illustrating substring expansion on parameters and
subscripted arrays:
$ string=01234567890abcdefgh
$ echo ${string:7}
7890abcdefgh
$ echo ${string:7:0}
$ echo ${string:7:2}
78
$ echo ${string:7:-2}
7890abcdef
$ echo ${string: -7}
bcdefgh
$ echo ${string: -7:0}
$ echo ${string: -7:2}
bc
$ echo ${string: -7:-2}
bcdef
$ set -- 01234567890abcdefgh
$ echo ${1:7}
7890abcdefgh
$ echo ${1:7:0}
$ echo ${1:7:2}
78
$ echo ${1:7:-2}
7890abcdef
$ echo ${1: -7}
bcdefgh
$ echo ${1: -7:0}
$ echo ${1: -7:2}
bc
$ echo ${1: -7:-2}
bcdef
$ array[0]=01234567890abcdefgh
$ echo ${array[0]:7}
7890abcdefgh
$ echo ${array[0]:7:0}
$ echo ${array[0]:7:2}
78
$ echo ${array[0]:7:-2}
7890abcdef
$ echo ${array[0]: -7}
bcdefgh
$ echo ${array[0]: -7:0}
$ echo ${array[0]: -7:2}
bc
$ echo ${array[0]: -7:-2}
bcdef"

Improve reusability for bins

Throwing errors doesn't seem to be the way to go for showing error messages. Try creating resusable modules instead.

Perform simple brace expansion

3.5.1 "Brace expansion is a mechanism by which arbitrary strings may be generated. This mech-
anism is similar to filename expansion (see Section 3.5.8 [Filename Expansion], page 30),
but the filenames generated need not exist. Patterns to be brace expanded take the form of
an optional preamble, followed by either a series of comma-separated strings or a sequence
expression between a pair of braces, followed by an optional postscript. The preamble is
prefixed to each string contained within the braces, and the postscript is then appended to
each resulting string, expanding left to right.
Brace expansions may be nested. The results of each expanded string are not sorted;
left to right order is preserved. For example,
bash$ echo a{d,c,b}e
ade ace abe"

Perform positional substring parameter expansion

3.5.3 "If parameter is ‘@’, the result is length positional parameters beginning at offset.
A negative offset is taken relative to one greater than the greatest positional
parameter, so an offset of -1 evaluates to the last positional parameter. It is an
expansion error if length evaluates to a number less than zero.
The following examples illustrate substring expansion using positional param-
eters:
$
$
7
$
set -- 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
echo ${@:7}
8 9 0 a b c d e f g h
echo ${@:7:0}
$ echo ${@:7:2}
7 8
$ echo ${@:7:-2}
bash: -2: substring expression < 0
$ echo ${@: -7:2}
b c
$ echo ${@:0}
./bash 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
$ echo ${@:0:2}
./bash 1
$ echo ${@: -7:0}
If parameter is an indexed array name subscripted by ‘@’ or ‘*’, the result is
the length members of the array beginning with ${parameter[offset]}. A
negative offset is taken relative to one greater than the maximum index of the
specified array. It is an expansion error if length evaluates to a number less
than zero.
These examples show how you can use substring expansion with indexed arrays:
$ array=(0 1 2 3 4 5 6 7 8 9 0 a b c d e f g h)
$ echo ${array[@]:7}
7 8 9 0 a b c d e f g h
$ echo ${array[@]:7:2}
7 8
$ echo ${array[@]: -7:2}
b c
$ echo ${array[@]: -7:-2}
bash: -2: substring expression < 0
$ echo ${array[@]:0}
0 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
$ echo ${array[@]:0:2}
0 1
$ echo ${array[@]: -7:0}
Substring expansion applied to an associative array produces undefined results.
Substring indexing is zero-based unless the positional parameters are used, in
which case the indexing starts at 1 by default. If offset is 0, and the positional
parameters are used, $@ is prefixed to the list."

Parse pipes

3.2.2 "A pipeline is a sequence of one or more commands separated by one of the control operators
‘|’ or ‘|&’.
The format for a pipeline is
[time [-p]] [!] command1 [ | or |& command2 ] ...
The output of each command in the pipeline is connected via a pipe to the input of the next
command. That is, each command reads the previous command’s output. This connection
is performed before any redirections specified by the command.
If ‘|&’ is used, command1’s standard error, in addition to its standard output, is con-
nected to command2’s standard input through the pipe; it is shorthand for 2>&1 |. This
implicit redirection of the standard err"

Perform parameter conditional expansion

3.5.3 "In each of the cases below, word is subject to tilde expansion, parameter expansion,
command substitution, and arithmetic expansion.
When not performing substring expansion, using the form described below (e.g., ‘:-’),
Bash tests for a parameter that is unset or null. Omitting the colon results in a test only
for a parameter that is unset. Put another way, if the colon is included, the operator tests
for both parameter’s existence and that its value is not null; if the colon is omitted, the
operator tests only for existence.

${parameter:−word}
If parameter is unset or null, the expansion of word is substituted. Otherwise,
the value of parameter is substituted.
${parameter:=word}
If parameter is unset or null, the expansion of word is assigned to parameter.
The value of parameter is then substituted. Positional parameters and special
parameters may not be assigned to in this way.
${parameter:?word}
If parameter is null or unset, the expansion of word (or a message to that effect
if word is not present) is written to the standard error and the shell, if it is not
interactive, exits. Otherwise, the value of parameter is substituted.
${parameter:+word}
If parameter is null or"

Manage parameters to functions

3.3 "When a function is executed, the arguments to the function become the positional pa-
rameters during its execution (see Section 3.4.1 [Positional Parameters], page 19). The
special parameter ‘#’ that expands to the number of positional parameters is updated to
reflect the change. Special parameter 0 is unchanged. The first element of the FUNCNAME
variable is set to the name of the function while the function is executing."

Run background commands

3.2.3 "If a command is terminated by the control operator ‘&’, the shell executes the command
asynchronously in a subshell. This is known as executing the command in the background.
The shell does not wait for the command to finish, and the return status is 0 (true). When
job control is not active (see Chapter 7 [Job Control], page 100), the standard input for
asynchronous commands, in the absence of any explicit redirections, is redirected from
/dev/null."

Manage return builtin

3.3 "If the builtin command return is executed in a function, the function completes and
execution resumes with the next command after the function call. Any command associated
with the RETURN trap is executed before execution resumes. When a function completes,
the values of the positional parameters and the special parameter ‘#’ are restored to the
values they had prior to the function’s execution. If a numeric argument is given to return,
that is the function’s return status; otherwise the function’s return status is the exit status
of the last command executed before the return."

Rewrite tokenize as a module. Follow comments and quoting rules. Just for fun, try to make it functional.

3.1. "When the shell reads input, it proceeds through a sequence of operations. If the input indicates the beginning of a comment, the shell ignores the comment symbol (‘#’), and the rest of that line.
Otherwise, roughly speaking, the shell reads its input and divides the input into words and operators, employing the quoting rules to select which meanings to assign various words and characters."

Process commands separated by && and || accordingly

3.2.3 "and and or lists are sequences of one or more pipelines separated by the control oper-
ators ‘&&’ and ‘||’, respectively. and and or lists are executed with left associativity.
An and list has the form
command1 && command2
command2 is executed if, and only if, command1 returns an exit status of zero.
An or list has the form
command1 || command2
command2 is executed if, and only if, command1 returns a non-zero exit status.
The return status of and and or lists is the exit status of the last command executed
in the list."

Parse paths

create a function that can parse a path given. It should support both absolute and relative paths (relative to the working directory). It should ignore any surplus '/' characters.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.