Skip to content

Commit

Permalink
0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspwr authored Dec 9, 2022
2 parents e19ab23 + 3df1a57 commit 6c7b756
Show file tree
Hide file tree
Showing 16 changed files with 154 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lia"
version = "0.2.1"
version = "0.2.2"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pkgname=lia
pkgver=0.2.1
pkgver=0.2.2
pkgrel=1
makedepends=('rust' 'cargo')
arch=('i686' 'x86_64' 'armv6h' 'armv7h')
Expand Down
12 changes: 7 additions & 5 deletions docs.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# LiA 0.2.1
# LiA 0.2.2

>⚠️This is the documentation for version 0.2.1. This is only an early version and is still in development. Do not expect any of these features to stay the same in future versions. Additionally, the compiler has not been thoroughly tested and may not work as expected. If you find any bugs or have any suggestions please open an issue or pull request on the [GitHub repository](https://github.com/jaspwr/LiA).
>⚠️This is the documentation for version 0.2.2. This is only an early version and is still in development. Do not expect any of these features to stay the same in future versions. Additionally, the compiler has not been thoroughly tested and may not work as expected. If you find any bugs or have any suggestions please open an issue or pull request on the [GitHub repository](https://github.com/jaspwr/LiA).
Most TeX is valid in LiA so you are able to write LaTeX as normal however with the addition of the features listed below.

Expand Down Expand Up @@ -60,6 +60,8 @@ Consumes remainder of line.
| `#* title` | `\section*{title}` |
| `##* title` | `\subsection*{title}` |
| `###* title` | `\subsubsection*{title}` |


Consumes remainder of line. For multiline enclose the section title in `{}`.

-------------------
Expand Down Expand Up @@ -124,7 +126,7 @@ List items consume the remainder of the line. For multiline enclose list item co

Any word annotated with a `@` will be treated as a variable.
#### Referencing variables
> ⚠️ As of version 0.2.1, variables with computed arguments can not be used before they are defined. This will be fixed in future versions.
> ⚠️ As of version 0.2.2, variables with computed arguments can not be used before they are defined. This will be fixed in future versions.
| LiA | TeX |
|--------------------------|--------------------------|
Expand Down Expand Up @@ -197,7 +199,7 @@ eq* {
The content inside the equation expression uses a separate syntax to more easily
represent mathematical expressions. The content will be parsed and converted to
LaTeX. Most TeX commands should work as normal.
> ⚠️ As of version 0.2.1, TeX commands can be separated from their arguments by fractions. This can be solved by encasing the command in `{}`. This will be fixed in future versions.
> ⚠️ As of version 0.2.2, TeX commands can be separated from their arguments by fractions. This can be solved by encasing the command in `{}`. This will be fixed in future versions.
#### General expressions
##### Lia

Expand Down Expand Up @@ -279,7 +281,7 @@ eq* {
### Version specification
The variable `@LIAVERSION` is reserved for specifying the version that the document is written in. If you specify a version, the document will be compiled with that version of the compiler otherwise it will use the latest version. It is recommended to specify a version to ensure that your document will compile correctly in the future. Always specify the version as the first line of the document.
```tex
@LIAVERSION = 0.2.1
@LIAVERSION = 0.2.2
```

## Document structure
Expand Down
11 changes: 2 additions & 9 deletions src/grammar/binary_additive_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::ast::*;
use crate::typed_value::TypedValue;
use crate::at_expression::AtExpToken;

use super::token_from_list;
use super::{token_from_list, check_either_side_for_opers};

enum Operation {
Add,
Expand Down Expand Up @@ -62,14 +62,7 @@ pub fn parse(tokens: &Vec<AtExpToken>, start: i32) -> Result<OpAstNode, String>
((add && !(token_from_list(tokens, start + 3).is_opertor_or_keyword("-") || (token_from_list(tokens, start - 1).is_opertor_or_keyword("-"))))
|| sub) &&
token_from_list(tokens, start + 2).is_ast_node() &&
!(token_from_list(tokens, start - 1).is_opertor_or_keyword("*")
|| token_from_list(tokens, start - 1).is_opertor_or_keyword("/")
|| token_from_list(tokens, start - 1).is_opertor_or_keyword("%")
|| token_from_list(tokens, start - 1).is_opertor_or_keyword("^")) &&
!(token_from_list(tokens, start + 3).is_opertor_or_keyword("*")
|| token_from_list(tokens, start + 3).is_opertor_or_keyword("/")
|| token_from_list(tokens, start + 3).is_opertor_or_keyword("%")
|| token_from_list(tokens, start + 3).is_opertor_or_keyword("^"))
!check_either_side_for_opers(tokens, start, 3, vec!["*", "/", "%", "^"])
{

Ok(Some((Rc::new(BinaryAdditiveExpression {
Expand Down
9 changes: 3 additions & 6 deletions src/grammar/binary_multiplicative_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::ast::*;
use crate::at_expression::AtExpToken;
use crate::typed_value::TypedValue;

use super::token_from_list;
use super::{token_from_list, check_either_side_for_opers};

enum Operation {
Mul,
Expand Down Expand Up @@ -80,12 +80,9 @@ pub fn parse(tokens: &Vec<AtExpToken>, start: i32) -> Result<OpAstNode, String>
if token_from_list(tokens, start).is_ast_node() &&
(mul || div || _mod) &&
token_from_list(tokens, start + 2).is_ast_node() &&
!token_from_list(tokens, start - 1).is_opertor_or_keyword("^") &&
!token_from_list(tokens, start + 3).is_opertor_or_keyword("^")
!check_either_side_for_opers(tokens, start, 3, vec!["^"])
{
if mul &&
(token_from_list(tokens, start + 3).is_opertor_or_keyword("/")
|| token_from_list(tokens, start - 1).is_opertor_or_keyword("/")) {
if mul && check_either_side_for_opers(tokens, start, 3, vec!["/"]) {
return Ok(None);
}
Ok(Some((Rc::new(BinaryMultiplicativeExpression {
Expand Down
14 changes: 14 additions & 0 deletions src/grammar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,18 @@ pub fn token_from_list(tokens: &Vec<AtExpToken>, pos: i32) -> AtExpToken {
} else {
tokens[pos as usize].clone()
}
}

pub fn check_either_side_for_opers(tokens: &Vec<AtExpToken>, pos: i32, len: i32, operators: Vec<&str>) -> bool {
for operator in operators {
if check_either_side_for_oper_single(tokens, pos, len, operator) {
return true;
}
}
false
}

pub fn check_either_side_for_oper_single(tokens: &Vec<AtExpToken>, pos: i32, len: i32, operator: &str) -> bool {
token_from_list(tokens, pos - 1).is_opertor_or_keyword(operator)
|| token_from_list(tokens, pos + len).is_opertor_or_keyword(operator)
}
17 changes: 3 additions & 14 deletions src/grammar/text_node_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use crate::grammar::token_from_list;
use crate::typed_value::TypedValue;
use crate::at_expression::AtExpToken;

use super::check_either_side_for_opers;

pub struct TextNodePair {
children: (AtExpToken, AtExpToken),
}
Expand Down Expand Up @@ -36,24 +38,11 @@ impl AstNode for TextNodePair {
pub fn parse(tokens: &Vec<AtExpToken>, start: i32) -> Result<OpAstNode, String> {
if token_from_list(tokens, start).is_ast_node() &&
token_from_list(tokens, start + 1).is_ast_node() &&
// Should refactor but it works for now.
!token_from_list(tokens, start + 2).is_opertor_or_keyword("+") &&
!token_from_list(tokens, start - 1).is_opertor_or_keyword("+") &&
!token_from_list(tokens, start + 2).is_opertor_or_keyword("-") &&
!token_from_list(tokens, start - 1).is_opertor_or_keyword("-") &&
!token_from_list(tokens, start + 2).is_opertor_or_keyword("*") &&
!token_from_list(tokens, start - 1).is_opertor_or_keyword("*") &&
!token_from_list(tokens, start + 2).is_opertor_or_keyword("/") &&
!token_from_list(tokens, start - 1).is_opertor_or_keyword("/") &&
!token_from_list(tokens, start + 2).is_opertor_or_keyword("%") &&
!token_from_list(tokens, start - 1).is_opertor_or_keyword("%") &&
!token_from_list(tokens, start + 2).is_opertor_or_keyword("^") &&
!token_from_list(tokens, start - 1).is_opertor_or_keyword("^")
!check_either_side_for_opers(tokens, start, 2, vec!["+", "-", "*", "/", "%", "^"])
{
Ok(Some((Rc::new(TextNodePair { children:
(token_from_list(tokens, start).clone(), token_from_list(tokens, start + 1).clone())
}), 2)))

} else {
Ok(None)
}
Expand Down
16 changes: 15 additions & 1 deletion src/parser_modules/markdown_style_enumerated_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,26 @@ use crate::tokeniser::TokenList;

#[derive(Default)]
pub struct LiaMardownEnumListParser {
initial_indentation_depth: usize
initial_indentation_depth: usize,
not_start_of_line: bool
}

#[allow(unused)]
impl NodeParser for LiaMardownEnumListParser {
fn is_opener(&mut self, token: &Token, identation: i32, other_doc_locations: &mut CompilerGlobals) -> bool {
if !other_doc_locations.feature_status_list.enumerated_lists.is_supported() { return false; }
if let Token::Newline = token {
self.not_start_of_line = false;
return false;
} else {
if (!self.not_start_of_line) {
if let Token::Whitespace(_) = token {} else {
self.not_start_of_line = true;
}
} else {
return false;
}
}
match token {
Token::Nothing(text, _) => { if is_list_number(text.to_string()) {
self.initial_indentation_depth = identation as usize;
Expand Down Expand Up @@ -120,5 +133,6 @@ fn append_closer(inner_nodes: &mut Vec<Token>) {

fn is_list_number(text: String) -> bool {
if !text.ends_with('.') { return false; }
if !text.starts_with(|c: char| c.is_numeric()) { return false; }
text.chars().all(|c| c.is_numeric() || c == '.')
}
23 changes: 23 additions & 0 deletions tests/equations.lia
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,27 @@ eq* {

eq {
hi {HI_2}/2 \a{2}{2} \int^x_y
}eq{}

eq {
f(x) = {sin(x)} / {cos{x}} -> b^{2^2_i} +- -+ <= >= < > != b-ab s in (a) inf 1 * b / c b / b + 2 - (2+ 2)/ 2
}

eq {\text{tall} [[1], [2], [3], [8123 + 3]]



}

@fn = a => {
eq{@a^2 = @(a^2)}
}

eq { }
eq{1}
eq{asjdhk}
eq{+2}
eq{ }
eq{

}
29 changes: 29 additions & 0 deletions tests/equations_out.tex
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
\newcommand{\fn}[2]{
\begin{equation}
#1^2 = #2
\end{equation}
}


\begin{document}
\[
x = \left(\frac{1}{2} + 2^3\right) + \alpha
Expand Down Expand Up @@ -27,5 +34,27 @@

\begin{equation}
hi \frac{{HI_2}}{2} \a{2}{2} \int^x_y
\end{equation}\begin{equation}\end{equation}

\begin{equation}
f \left(x\right) = \frac{{\sin \left(x\right)}}{{\cos{x}}} \rightarrow b^{2^2_i} \pm \mp \le \ge < > \ne b - ab s in \left(a\right) \infty 1 \times \frac{b}{c} \frac{b}{b} + 2 - \frac{\left(2 + 2\right)}{2}
\end{equation}

\begin{equation}
\text{tall} \begin{pmatrix} 1 \\ 2 \\ 3 \\ 8123 + 3 \end{pmatrix}
\end{equation}


\begin{equation}\end{equation}
\begin{equation}
1
\end{equation}
\begin{equation}
asjdhk
\end{equation}
\begin{equation}
+2
\end{equation}
\begin{equation}\end{equation}
\begin{equation}\end{equation}
\end{document}
3 changes: 3 additions & 0 deletions tests/functions.lia
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@
@meow(4, 4.2)
@meow(cat1, cat1)


@hi(moew)
@convolutedexpression=()=>{@(20 + 5894 / 2 * 3 + ((4) *3) % 2 -212309128309.23423423)}
@unaries = a => {@a eq{~~} @(-2 + +3 -a * + +3 / + - + - -2)}
@concat(🐈, 🐈)
@concat(🐈, 🐈)
@multiply(2.3, 2.3)
@multiply(1, 88)
@convolutedexpression()
@unaries(7)

@math()

Expand Down
7 changes: 7 additions & 0 deletions tests/functions_out.tex
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,26 @@
\newcommand{\convolutedexpression}[1]{
#1
}
\newcommand{\unaries}[2]{
#1 \begin{equation}
\approx
\end{equation} #2
}


\begin{document}
\section{cat document with fucntions !!}
\meow{4}{4.2}{0}{4}{8.2}
\meow{cat1}{cat1}{0}{4}{cat1cat1}


\hi{moew}
\concat{🐈}{🐈}{🐈 🐈text text teeeeeeeeeeeeeeexxxxxxxxxxxxxxxxxxxtttttttttt}
\concat{🐈}{🐈}{🐈 🐈text text teeeeeeeeeeeeeeexxxxxxxxxxxxxxxxxxxtttttttttt}
\multiply{2.3}{2.3}{5.289999999999999}
\multiply{1}{88}{88}
\convolutedexpression{-212309119448.23422}
\unaries{7}{11.5}

\math{4}
\end{document}
20 changes: 17 additions & 3 deletions tests/general.lia
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env center🐱 {
* List item
*List item
* List item
*inner most
*inner most *
* List item 🐱
* {List

Expand All @@ -18,7 +18,7 @@ env center🐱 {


🐱}
* a
* a*
* a
}

Expand All @@ -37,4 +37,18 @@ env center🐱 {
1. num
3223428349. num
1234243. num
a
a *
a use
a 1.
a ##
a *a
a use a
a 2222. sin
a ###text
**it* ***bf***
* **it * a *** a\*\*\* *** a **a*****

1 . this should not be a list
1. this should

\documentclass{xyz}
Loading

0 comments on commit 6c7b756

Please sign in to comment.