├── work ├── crates │ ├── derive │ │ ├── src │ │ │ ├── token │ │ │ │ ├── ucd.rs │ │ │ │ ├── mod.rs │ │ │ │ └── opt.rs │ │ │ ├── utils │ │ │ │ ├── report.rs │ │ │ │ ├── predictable.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── symbol.rs │ │ │ │ ├── multimap.rs │ │ │ │ └── facade.rs │ │ │ ├── feature │ │ │ │ └── mod.rs │ │ │ └── node │ │ │ │ ├── mod.rs │ │ │ │ └── generics.rs │ │ ├── readme.md │ │ └── Cargo.toml │ ├── tests │ │ ├── bench-ops.gif │ │ ├── criterion.toml │ │ ├── bench.sh │ │ ├── src │ │ │ ├── lines.rs │ │ │ └── logos.rs │ │ └── Cargo.toml │ ├── ucd │ │ ├── run.sh │ │ ├── Cargo.toml │ │ └── src │ │ │ └── download.rs │ ├── main │ │ ├── src │ │ │ ├── units │ │ │ │ ├── mutable │ │ │ │ │ └── mod.rs │ │ │ │ ├── mod.rs │ │ │ │ └── storage │ │ │ │ │ ├── mod.rs │ │ │ │ │ └── refs.rs │ │ │ ├── format │ │ │ │ └── mod.rs │ │ │ ├── sync │ │ │ │ ├── mod.rs │ │ │ │ ├── markers.rs │ │ │ │ └── lazy.rs │ │ │ ├── arena │ │ │ │ └── mod.rs │ │ │ ├── syntax │ │ │ │ └── mod.rs │ │ │ ├── lexis │ │ │ │ ├── mod.rs │ │ │ │ └── chunks.rs │ │ │ └── analysis │ │ │ │ └── mod.rs │ │ └── Cargo.toml │ └── examples │ │ ├── src │ │ ├── lib.rs │ │ ├── shared_semantics │ │ │ ├── lexis.rs │ │ │ └── syntax.rs │ │ ├── json_formatter │ │ │ └── mod.rs │ │ ├── chain_analysis │ │ │ └── lexis.rs │ │ ├── expr_parser │ │ │ ├── lexis.rs │ │ │ ├── mod.rs │ │ │ └── syntax.rs │ │ ├── json_grammar │ │ │ ├── mod.rs │ │ │ └── lexis.rs │ │ └── json_highlight │ │ │ ├── mod.rs │ │ │ └── highlighter.rs │ │ └── Cargo.toml ├── logo.jpg ├── logo.png ├── book │ ├── src │ │ ├── syntax │ │ │ ├── syntax.md │ │ │ ├── hand-written-parsers.md │ │ │ └── syntax-tree.md │ │ ├── lexis │ │ │ ├── lexis.md │ │ │ └── site-references.md │ │ ├── SUMMARY.md │ │ ├── semantics │ │ │ ├── code-diagnostics.md │ │ │ ├── side-effects.md │ │ │ └── partition-into-scopes.md │ │ ├── introduction.md │ │ └── code-formatters │ │ │ └── code-formatters.md │ └── book.toml ├── Cargo.toml └── rustfmt.toml └── .github ├── PULL_REQUEST_TEMPLATE.md └── workflows └── deploy-user-guide.yml /work/crates/derive/src/token/ucd.rs: -------------------------------------------------------------------------------- 1 | ../../../main/src/lexis/ucd.rs -------------------------------------------------------------------------------- /work/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eliah-Lakhin/lady-deirdre/HEAD/work/logo.jpg -------------------------------------------------------------------------------- /work/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eliah-Lakhin/lady-deirdre/HEAD/work/logo.png -------------------------------------------------------------------------------- /work/crates/tests/bench-ops.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eliah-Lakhin/lady-deirdre/HEAD/work/crates/tests/bench-ops.gif -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | [//]: # (Summary of the changes.) 2 | 3 | --- 4 | 5 | [//]: # (To contribute to this repository, you must agree to the terms and) 6 | [//]: # (conditions of the General License Agreement. By contributing to the) 7 | [//]: # (repository, you confirm that you are granting an exclusive license) 8 | [//]: # (to your changes to the author of the original work.) 9 | [//]: # () 10 | [//]: # (Please include the following statement at the end of the Pull Request) 11 | [//]: # (description to confirm your acceptance of these terms, and put your) 12 | [//]: # (signature. You can use your name as a signature.) 13 | 14 | I agree to the terms and conditions of the 15 | [General License Agreement](https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md) 16 | and I grant an exclusive license to my changes in this Pull Request to Ilya Lakhin. 17 | 18 | (your signature) 19 | -------------------------------------------------------------------------------- /.github/workflows/deploy-user-guide.yml: -------------------------------------------------------------------------------- 1 | name: Deploy User Guide 2 | 3 | on: 4 | push: 5 | paths: [ "work/book/**" ] 6 | branches: 7 | - master 8 | 9 | jobs: 10 | deploy: 11 | runs-on: ubuntu-latest 12 | permissions: 13 | contents: write 14 | pull-requests: write 15 | steps: 16 | - uses: actions/checkout@v4 17 | with: 18 | fetch-depth: 0 19 | - name: Install 20 | run: | 21 | mkdir book 22 | curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.40/mdbook-v0.4.40-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./book 23 | echo `pwd`/book >> $GITHUB_PATH 24 | - name: Deploy 25 | run: | 26 | cd work/book 27 | mdbook build 28 | git worktree add gh-pages 29 | git config user.name "deploy-user-guide" 30 | git config user.email "" 31 | cd gh-pages 32 | git update-ref -d refs/heads/gh-pages 33 | rm -rf * 34 | mv ../output/* . 35 | echo "lady-deirdre.lakhin.com" > CNAME 36 | git add . 37 | git commit -m "Deploy User Guide $GITHUB_SHA to gh-pages" 38 | git push --force --set-upstream origin gh-pages 39 | -------------------------------------------------------------------------------- /work/crates/derive/src/utils/report.rs: -------------------------------------------------------------------------------- 1 | macro_rules! error { 2 | ($span:expr, $message:expr, $( $args:tt)*) => { 3 | syn::Error::new($span, format!($message, $($args)*)) 4 | }; 5 | } 6 | 7 | macro_rules! expect_some { 8 | ($unwrapped:expr, $message:expr, $( $args:tt)*) => {(match $unwrapped { 9 | Some(inner) => inner, 10 | None =>panic!("{}", $crate::utils::error_message!($message, $($args)*)) 11 | })}; 12 | } 13 | 14 | macro_rules! null { 15 | () => { 16 | $crate::utils::system_panic!("Automata with Null transition.") 17 | }; 18 | } 19 | 20 | macro_rules! system_panic { 21 | ($message:expr) => { 22 | panic!("{}", $crate::utils::error_message!($message)) 23 | }; 24 | ($message:expr, $($args:tt)*) => { 25 | panic!("{}", $crate::utils::error_message!($message, $($args)*)) 26 | }; 27 | } 28 | 29 | macro_rules! error_message ( 30 | ($message:expr) => { 31 | format!( 32 | r#" 33 | !! LADY DEIRDRE INTERNAL ERROR 34 | !! 35 | !! This is a bug. 36 | !! If you see this message, please open an Issue: https://github.com/Eliah-Lakhin/lady-deirdre/issues 37 | !! 38 | !! Message: {} 39 | !! File: {} 40 | !! Line: {} 41 | !! Column: {} 42 | "#, 43 | $message, 44 | file!(), 45 | line!(), 46 | column!(), 47 | ) 48 | }; 49 | 50 | ($message:expr, $($args:tt)*) => { 51 | $crate::utils::error_message!(format!($message, $($args)*)) 52 | }; 53 | ); 54 | 55 | pub(crate) use error; 56 | pub(crate) use error_message; 57 | pub(crate) use expect_some; 58 | pub(crate) use null; 59 | pub(crate) use system_panic; 60 | -------------------------------------------------------------------------------- /work/book/src/syntax/syntax.md: -------------------------------------------------------------------------------- 1 | 34 | 35 | # Syntax 36 | 37 | The next stage of source code analysis after lexical scanning is syntax parsing. 38 | 39 | The input for syntax parser is stream of tokens produced during the 40 | lexical scanning or incremental rescanning stage. 41 | 42 | Syntax parsing, and especially incremental reparsing, is a more complex process 43 | that includes error recovery and other features. However, you will find many 44 | similarities between the lexical scanning and syntax parsing APIs of Lady 45 | Deirdre. 46 | 47 | The output of the syntax parser is a syntax tree, which is used in the semantic 48 | analysis stage. 49 | -------------------------------------------------------------------------------- /work/book/src/syntax/hand-written-parsers.md: -------------------------------------------------------------------------------- 1 | 34 | 35 | # Hand-Written Parsers 36 | 37 | The following chapters cover more advanced topics, providing an in-depth 38 | exploration of the anatomy of Lady Deirdre's parsers. They will guide you on how 39 | to override parsers generated by the Node macro with manually implemented parse 40 | functions. 41 | 42 | One common case where you might want to implement the parse procedure manually 43 | is infix expression parsing. Infix expressions usually require left recursion, 44 | which cannot be directly expressed in terms of LL(1) grammars. 45 | 46 | These chapters will guide you through 47 | the [Expr Parser](https://github.com/Eliah-Lakhin/lady-deirdre/tree/f350aaed30373a67694c3aba4d2cfd9874c2a656/work/crates/examples/src/expr_parser) 48 | example. This example demonstrates how to parse boolean expressions 49 | (e.g., `(true | false) & true`) using the Pratt algorithm. 50 | -------------------------------------------------------------------------------- /work/book/src/lexis/lexis.md: -------------------------------------------------------------------------------- 1 | 34 | 35 | # Lexis 36 | 37 | Lexical scanning is the initial stage of source code text analysis. 38 | 39 | During this process, the scanner iterates through the characters of 40 | a Unicode string, establishing token boundaries and associating each scanned 41 | fragment, delimited by these boundaries, with a corresponding token instance. 42 | 43 | The lexical scanner is a simple program that implements finite-state automata, 44 | always looking at most one character ahead. Consequently, the scanner can 45 | be restarted at any character of the text, which is particularly beneficial for 46 | incremental rescanning. For instance, when an end user modifies a specific 47 | portion of the source code text, the scanner restarts before the altered 48 | fragment, eventually converging to the state of the tail of the text. 49 | 50 | The resulting token stream serves as input for the syntax parser. 51 | -------------------------------------------------------------------------------- /work/crates/tests/criterion.toml: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # This file is part of "Lady Deirdre", a compiler front-end foundation # 3 | # technology. # 4 | # # 5 | # This work is proprietary software with source-available code. # 6 | # # 7 | # To copy, use, distribute, or contribute to this work, you must agree to # 8 | # the terms of the General License Agreement: # 9 | # # 10 | # https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md # 11 | # # 12 | # The agreement grants a Basic Commercial License, allowing you to use # 13 | # this work in non-commercial and limited commercial products with a total # 14 | # gross revenue cap. To remove this commercial limit for one of your # 15 | # products, you must acquire a Full Commercial License. # 16 | # # 17 | # If you contribute to the source code, documentation, or related materials, # 18 | # you must grant me an exclusive license to these contributions. # 19 | # Contributions are governed by the "Contributions" section of the General # 20 | # License Agreement. # 21 | # # 22 | # Copying the work in parts is strictly forbidden, except as permitted # 23 | # under the General License Agreement. # 24 | # # 25 | # If you do not or cannot agree to the terms of this Agreement, # 26 | # do not use this work. # 27 | # # 28 | # This work is provided "as is", without any warranties, express or implied, # 29 | # except where such disclaimers are legally invalid. # 30 | # # 31 | # Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). # 32 | # All rights reserved. # 33 | ################################################################################ 34 | 35 | criterion_home = "./criterion" 36 | -------------------------------------------------------------------------------- /work/Cargo.toml: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # This file is part of "Lady Deirdre", a compiler front-end foundation # 3 | # technology. # 4 | # # 5 | # This work is proprietary software with source-available code. # 6 | # # 7 | # To copy, use, distribute, or contribute to this work, you must agree to # 8 | # the terms of the General License Agreement: # 9 | # # 10 | # https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md # 11 | # # 12 | # The agreement grants a Basic Commercial License, allowing you to use # 13 | # this work in non-commercial and limited commercial products with a total # 14 | # gross revenue cap. To remove this commercial limit for one of your # 15 | # products, you must acquire a Full Commercial License. # 16 | # # 17 | # If you contribute to the source code, documentation, or related materials, # 18 | # you must grant me an exclusive license to these contributions. # 19 | # Contributions are governed by the "Contributions" section of the General # 20 | # License Agreement. # 21 | # # 22 | # Copying the work in parts is strictly forbidden, except as permitted # 23 | # under the General License Agreement. # 24 | # # 25 | # If you do not or cannot agree to the terms of this Agreement, # 26 | # do not use this work. # 27 | # # 28 | # This work is provided "as is", without any warranties, express or implied, # 29 | # except where such disclaimers are legally invalid. # 30 | # # 31 | # Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). # 32 | # All rights reserved. # 33 | ################################################################################ 34 | 35 | [workspace] 36 | resolver = "2" 37 | members = ["crates/*"] 38 | -------------------------------------------------------------------------------- /work/crates/derive/src/feature/mod.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | mod input; 36 | mod output; 37 | 38 | pub use crate::feature::input::FeatureInput; 39 | -------------------------------------------------------------------------------- /work/rustfmt.toml: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # This file is part of "Lady Deirdre", a compiler front-end foundation # 3 | # technology. # 4 | # # 5 | # This work is proprietary software with source-available code. # 6 | # # 7 | # To copy, use, distribute, or contribute to this work, you must agree to # 8 | # the terms of the General License Agreement: # 9 | # # 10 | # https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md # 11 | # # 12 | # The agreement grants a Basic Commercial License, allowing you to use # 13 | # this work in non-commercial and limited commercial products with a total # 14 | # gross revenue cap. To remove this commercial limit for one of your # 15 | # products, you must acquire a Full Commercial License. # 16 | # # 17 | # If you contribute to the source code, documentation, or related materials, # 18 | # you must grant me an exclusive license to these contributions. # 19 | # Contributions are governed by the "Contributions" section of the General # 20 | # License Agreement. # 21 | # # 22 | # Copying the work in parts is strictly forbidden, except as permitted # 23 | # under the General License Agreement. # 24 | # # 25 | # If you do not or cannot agree to the terms of this Agreement, # 26 | # do not use this work. # 27 | # # 28 | # This work is provided "as is", without any warranties, express or implied, # 29 | # except where such disclaimers are legally invalid. # 30 | # # 31 | # Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). # 32 | # All rights reserved. # 33 | ################################################################################ 34 | 35 | imports_granularity = "Crate" 36 | group_imports = "StdExternalCrate" 37 | imports_layout = "HorizontalVertical" 38 | -------------------------------------------------------------------------------- /work/crates/ucd/run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ################################################################################ 4 | # This file is part of "Lady Deirdre", a compiler front-end foundation # 5 | # technology. # 6 | # # 7 | # This work is proprietary software with source-available code. # 8 | # # 9 | # To copy, use, distribute, or contribute to this work, you must agree to # 10 | # the terms of the General License Agreement: # 11 | # # 12 | # https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md # 13 | # # 14 | # The agreement grants a Basic Commercial License, allowing you to use # 15 | # this work in non-commercial and limited commercial products with a total # 16 | # gross revenue cap. To remove this commercial limit for one of your # 17 | # products, you must acquire a Full Commercial License. # 18 | # # 19 | # If you contribute to the source code, documentation, or related materials, # 20 | # you must grant me an exclusive license to these contributions. # 21 | # Contributions are governed by the "Contributions" section of the General # 22 | # License Agreement. # 23 | # # 24 | # Copying the work in parts is strictly forbidden, except as permitted # 25 | # under the General License Agreement. # 26 | # # 27 | # If you do not or cannot agree to the terms of this Agreement, # 28 | # do not use this work. # 29 | # # 30 | # This work is provided "as is", without any warranties, express or implied, # 31 | # except where such disclaimers are legally invalid. # 32 | # # 33 | # Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). # 34 | # All rights reserved. # 35 | ################################################################################ 36 | 37 | rm -rf downloads 38 | rm -f ucd_gen.txt 39 | cargo run -- download && cargo run -- generate 40 | -------------------------------------------------------------------------------- /work/crates/main/src/units/mutable/mod.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | pub(crate) mod unit; 36 | pub(crate) mod watcher; 37 | 38 | mod cursor; 39 | mod iters; 40 | mod lexis; 41 | mod syntax; 42 | -------------------------------------------------------------------------------- /work/crates/derive/readme.md: -------------------------------------------------------------------------------- 1 | 34 | 35 | # Lady Deirdre Macros Crate 36 | 37 | This is a helper crate for the [main crate](https://crates.io/crates/lady-deirdre) 38 | of Lady Deirdre, compiler front-end foundation technology. 39 | 40 | The derive macros in this crate offer default implementations for 41 | the Token (lexical scanner), Node (syntax parser), and Feature (semantic object) 42 | traits used by the main crate. 43 | 44 | ## Links 45 | 46 | - [Source Code](https://github.com/Eliah-Lakhin/lady-deirdre) 47 | - [Main Crate](https://crates.io/crates/lady-deirdre) 48 | - [API Documentation](https://docs.rs/lady-deirdre) 49 | - [User Guide](https://lady-deirdre.lakhin.com/) 50 | - [Examples](https://github.com/Eliah-Lakhin/lady-deirdre/tree/master/work/crates/examples) 51 | - [License Agreement](https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md) 52 | 53 | ## Copyright 54 | 55 | This work is proprietary software with source-available code. 56 | 57 | To copy, use, distribute, or contribute to this work, you must agree to the 58 | terms and conditions of the [General License Agreement](https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md). 59 | 60 | For an explanation of the licensing terms, see the 61 | [F.A.Q.](https://github.com/Eliah-Lakhin/lady-deirdre/tree/master/FAQ.md) 62 | 63 | Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). All rights reserved. 64 | 65 | -------------------------------------------------------------------------------- /work/crates/derive/src/token/mod.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | mod automata; 36 | mod chars; 37 | mod input; 38 | mod opt; 39 | mod output; 40 | mod regex; 41 | mod ucd; 42 | mod variant; 43 | 44 | pub use crate::token::input::TokenInput; 45 | -------------------------------------------------------------------------------- /work/crates/tests/bench.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ################################################################################ 4 | # This file is part of "Lady Deirdre", a compiler front-end foundation # 5 | # technology. # 6 | # # 7 | # This work is proprietary software with source-available code. # 8 | # # 9 | # To copy, use, distribute, or contribute to this work, you must agree to # 10 | # the terms of the General License Agreement: # 11 | # # 12 | # https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md # 13 | # # 14 | # The agreement grants a Basic Commercial License, allowing you to use # 15 | # this work in non-commercial and limited commercial products with a total # 16 | # gross revenue cap. To remove this commercial limit for one of your # 17 | # products, you must acquire a Full Commercial License. # 18 | # # 19 | # If you contribute to the source code, documentation, or related materials, # 20 | # you must grant me an exclusive license to these contributions. # 21 | # Contributions are governed by the "Contributions" section of the General # 22 | # License Agreement. # 23 | # # 24 | # Copying the work in parts is strictly forbidden, except as permitted # 25 | # under the General License Agreement. # 26 | # # 27 | # If you do not or cannot agree to the terms of this Agreement, # 28 | # do not use this work. # 29 | # # 30 | # This work is provided "as is", without any warranties, express or implied, # 31 | # except where such disclaimers are legally invalid. # 32 | # # 33 | # Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). # 34 | # All rights reserved. # 35 | ################################################################################ 36 | 37 | #Setup: 38 | #cargo install cargo-criterion 39 | #cargo install criterion-table 40 | 41 | cargo criterion --message-format=json > criterion.json 42 | cat criterion.json | criterion-table > readme.md 43 | -------------------------------------------------------------------------------- /work/crates/examples/src/lib.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | //TODO check warnings regularly 36 | #![allow(warnings)] 37 | 38 | pub mod chain_analysis; 39 | pub mod expr_parser; 40 | pub mod json_formatter; 41 | pub mod json_grammar; 42 | pub mod json_highlight; 43 | pub mod shared_semantics; 44 | -------------------------------------------------------------------------------- /work/book/book.toml: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # This file is part of "Lady Deirdre", a compiler front-end foundation # 3 | # technology. # 4 | # # 5 | # This work is proprietary software with source-available code. # 6 | # # 7 | # To copy, use, distribute, or contribute to this work, you must agree to # 8 | # the terms of the General License Agreement: # 9 | # # 10 | # https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md # 11 | # # 12 | # The agreement grants a Basic Commercial License, allowing you to use # 13 | # this work in non-commercial and limited commercial products with a total # 14 | # gross revenue cap. To remove this commercial limit for one of your # 15 | # products, you must acquire a Full Commercial License. # 16 | # # 17 | # If you contribute to the source code, documentation, or related materials, # 18 | # you must grant me an exclusive license to these contributions. # 19 | # Contributions are governed by the "Contributions" section of the General # 20 | # License Agreement. # 21 | # # 22 | # Copying the work in parts is strictly forbidden, except as permitted # 23 | # under the General License Agreement. # 24 | # # 25 | # If you do not or cannot agree to the terms of this Agreement, # 26 | # do not use this work. # 27 | # # 28 | # This work is provided "as is", without any warranties, express or implied, # 29 | # except where such disclaimers are legally invalid. # 30 | # # 31 | # Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). # 32 | # All rights reserved. # 33 | ################################################################################ 34 | 35 | [book] 36 | authors = ["Ilya Lakhin (Илья Александрович Лахин) "] 37 | language = "en" 38 | multilingual = false 39 | src = "src" 40 | title = "The Lady Deirdre Guide" 41 | 42 | [build] 43 | build-dir = "output" 44 | create-missing = false 45 | -------------------------------------------------------------------------------- /work/crates/main/src/format/mod.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | mod printer; 36 | mod snippet; 37 | mod terminal; 38 | 39 | pub use crate::format::{ 40 | printer::{PrettyPrintConfig, PrettyPrinter}, 41 | snippet::{AnnotationPriority, Highlighter, Snippet, SnippetConfig, SnippetFormatter}, 42 | terminal::{Color, Style, TerminalString}, 43 | }; 44 | -------------------------------------------------------------------------------- /work/crates/derive/src/node/mod.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | mod automata; 36 | mod constructor; 37 | mod generics; 38 | mod globals; 39 | mod index; 40 | mod inheritance; 41 | mod input; 42 | mod leftmost; 43 | mod output; 44 | mod recovery; 45 | mod regex; 46 | mod rule; 47 | mod token; 48 | mod variables; 49 | mod variant; 50 | 51 | pub use crate::node::input::NodeInput; 52 | -------------------------------------------------------------------------------- /work/crates/main/src/units/mod.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | pub(super) mod document; 36 | pub(super) mod immutable; 37 | pub(super) mod mutable; 38 | pub(super) mod unit; 39 | 40 | mod storage; 41 | 42 | pub use crate::units::{ 43 | document::Document, 44 | immutable::ImmutableUnit, 45 | mutable::{ 46 | unit::MutableUnit, 47 | watcher::{DebugWatcher, VoidWatcher, Watcher}, 48 | }, 49 | unit::{CompilationUnit, Lexis, Syntax}, 50 | }; 51 | -------------------------------------------------------------------------------- /work/crates/main/src/sync/mod.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | mod lazy; 36 | mod markers; 37 | mod shared; 38 | mod table; 39 | mod trigger; 40 | 41 | pub use crate::sync::{ 42 | lazy::Lazy, 43 | markers::SyncBuildHasher, 44 | shared::Shared, 45 | table::{ 46 | Table, 47 | TableDrain, 48 | TableEntry, 49 | TableIntoIter, 50 | TableOccupiedEntry, 51 | TableReadGuard, 52 | TableVacantEntry, 53 | TableWriteGuard, 54 | }, 55 | trigger::Trigger, 56 | }; 57 | -------------------------------------------------------------------------------- /work/crates/main/src/arena/mod.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | mod entry; 36 | mod id; 37 | mod repo; 38 | 39 | pub(crate) use crate::arena::id::SubId; 40 | pub use crate::arena::{ 41 | entry::{Entry, EntryIndex, EntryVersion, NIL_ENTRY}, 42 | id::{Id, Identifiable}, 43 | repo::{ 44 | Repo, 45 | RepoEntriesIntoIter, 46 | RepoEntriesIter, 47 | RepoEnumIntoIter, 48 | RepoEnumIter, 49 | RepoEnumIterMut, 50 | RepoIntoIter, 51 | RepoIter, 52 | RepoIterMut, 53 | }, 54 | }; 55 | -------------------------------------------------------------------------------- /work/crates/derive/src/utils/predictable.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | use std::{collections::hash_map::DefaultHasher, hash::BuildHasher}; 36 | 37 | #[derive(Default, Clone)] 38 | pub struct PredictableHasher; 39 | 40 | impl BuildHasher for PredictableHasher { 41 | type Hasher = DefaultHasher; 42 | 43 | #[inline(always)] 44 | fn build_hasher(&self) -> Self::Hasher { 45 | DefaultHasher::new() 46 | } 47 | } 48 | 49 | pub trait PredictableCollection { 50 | fn empty() -> Self; 51 | 52 | fn with_capacity(capacity: usize) -> Self; 53 | } 54 | -------------------------------------------------------------------------------- /work/crates/main/src/sync/markers.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | use std::hash::BuildHasher; 36 | 37 | /// A marker-trait for a "standard" BuildHasher. 38 | /// 39 | /// This marker-trait is automatically implemented for all types which can be 40 | /// created from the default constructor and shared between threads. 41 | /// 42 | /// In particular, the standard [RandomState](std::hash::RandomState) and 43 | /// the family are all SyncBuildHashers. 44 | pub trait SyncBuildHasher: BuildHasher + Clone + Default + Send + Sync + 'static {} 45 | 46 | impl SyncBuildHasher for S {} 47 | -------------------------------------------------------------------------------- /work/crates/main/src/units/storage/mod.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | mod branch; 36 | mod cache; 37 | mod child; 38 | mod item; 39 | mod nesting; 40 | mod page; 41 | mod refs; 42 | mod spread; 43 | mod string; 44 | mod tree; 45 | 46 | pub(crate) use crate::units::storage::{ 47 | cache::Cache, 48 | child::ChildCursor, 49 | refs::TreeRefs, 50 | tree::Tree, 51 | }; 52 | use crate::{lexis::CHUNK_SIZE, units::storage::spread::capacity}; 53 | 54 | const BRANCH_B: usize = 6; 55 | const BRANCH_CAP: usize = capacity(BRANCH_B); 56 | 57 | const PAGE_B: usize = 16; 58 | const PAGE_CAP: usize = capacity(PAGE_B); 59 | 60 | const STRING_INLINE: usize = PAGE_CAP * CHUNK_SIZE; 61 | -------------------------------------------------------------------------------- /work/crates/examples/src/shared_semantics/lexis.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | use lady_deirdre::lexis::Token; 36 | 37 | #[derive(Token, Clone, Copy, PartialEq, Eq)] 38 | #[repr(u8)] 39 | pub enum SharedSemanticsToken { 40 | EOI = 0, 41 | 42 | Mismatch = 1, 43 | 44 | #[rule(['a'..'z'] ['a'..'z', '0'..'9', '_']*)] 45 | #[describe("ident")] 46 | Ident, 47 | 48 | #[rule(['0'..'9']+)] 49 | #[describe("number")] 50 | Num, 51 | 52 | #[rule("=")] 53 | #[describe("=")] 54 | Assign, 55 | 56 | #[rule("::")] 57 | #[describe("::")] 58 | DoubleColon, 59 | 60 | #[rule(";")] 61 | #[describe(";")] 62 | Semicolon, 63 | 64 | #[rule([' ', '\t', '\n', '\x0c', '\r']+)] 65 | Whitespace, 66 | } 67 | -------------------------------------------------------------------------------- /work/crates/examples/src/json_formatter/mod.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | pub mod formatter; 36 | 37 | #[cfg(test)] 38 | mod tests { 39 | use crate::json_formatter::formatter::format_json; 40 | 41 | #[test] 42 | fn test_json_formatter() { 43 | static INPUT: &'static str = r#"{ 44 | "foo": 45 | [1, 2, 3, 4, 5, 46 | 6, 7, 8, 9], 47 | "bar": { "a": true, "b": false, 48 | "c": null, "d": "string" 49 | } 50 | }"#; 51 | 52 | static OUTPUT: &'static str = r#"{ 53 | "foo": [1, 2, 3, 4, 5, 6, 7, 8, 9], 54 | "bar": { "a": true, "b": false, "c": null, "d": "string" } 55 | }"#; 56 | 57 | assert_eq!(format_json(INPUT), OUTPUT); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /work/crates/examples/src/chain_analysis/lexis.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | use lady_deirdre::lexis::Token; 36 | 37 | #[derive(Token, Clone, Copy, PartialEq, Eq)] 38 | #[repr(u8)] 39 | pub enum ChainToken { 40 | EOI = 0, 41 | 42 | Mismatch = 1, 43 | 44 | #[rule(['0'..'9']+)] 45 | #[describe("number")] 46 | Num, 47 | 48 | #[rule(['a'..'z']+)] 49 | #[describe("ident")] 50 | Ident, 51 | 52 | #[rule("=")] 53 | #[describe("=")] 54 | Assign, 55 | 56 | #[rule(";")] 57 | #[describe(";")] 58 | Semicolon, 59 | 60 | #[rule('{')] 61 | #[describe("{")] 62 | BraceOpen, 63 | 64 | #[rule('}')] 65 | #[describe("}")] 66 | BraceClose, 67 | 68 | #[rule([' ', '\t', '\n', '\x0c', '\r']+)] 69 | Whitespace, 70 | } 71 | -------------------------------------------------------------------------------- /work/crates/examples/src/expr_parser/lexis.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | use lady_deirdre::lexis::Token; 36 | 37 | #[derive(Token, Clone, Copy, PartialEq, Eq)] 38 | #[repr(u8)] 39 | pub enum BoolToken { 40 | EOI = 0, 41 | 42 | Mismatch = 1, 43 | 44 | #[rule("true")] 45 | #[describe("operand", "true")] 46 | True, 47 | 48 | #[rule("false")] 49 | #[describe("operand", "false")] 50 | False, 51 | 52 | #[rule('(')] 53 | #[describe("(")] 54 | ParenOpen, 55 | 56 | #[rule(')')] 57 | #[describe(")")] 58 | ParenClose, 59 | 60 | #[rule('&')] 61 | #[describe("operator", "&")] 62 | And, 63 | 64 | #[rule('|')] 65 | #[describe("operator", "|")] 66 | Or, 67 | 68 | #[rule([' ', '\t', '\n', '\x0c', '\r']+)] 69 | Whitespace, 70 | } 71 | -------------------------------------------------------------------------------- /work/crates/examples/src/json_grammar/mod.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | pub mod lexis; 36 | pub mod syntax; 37 | 38 | #[cfg(test)] 39 | mod tests { 40 | use lady_deirdre::{ 41 | syntax::{Node, SyntaxTree}, 42 | units::Document, 43 | }; 44 | 45 | use crate::json_grammar::syntax::JsonNode; 46 | 47 | #[test] 48 | fn test_json_parser() { 49 | static INPUT: &'static str = r#"{ 50 | "foo": [1, 2, 3], 51 | "bar": { 52 | "a": true, 53 | "b": false, 54 | "c": null, 55 | "d": "string" 56 | } 57 | }"#; 58 | 59 | JsonNode::debug(INPUT); 60 | 61 | let doc = Document::::new_immutable(INPUT); 62 | 63 | assert!(doc.errors().next().is_none()); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /work/crates/main/Cargo.toml: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # This file is part of "Lady Deirdre", a compiler front-end foundation # 3 | # technology. # 4 | # # 5 | # This work is proprietary software with source-available code. # 6 | # # 7 | # To copy, use, distribute, or contribute to this work, you must agree to # 8 | # the terms of the General License Agreement: # 9 | # # 10 | # https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md # 11 | # # 12 | # The agreement grants a Basic Commercial License, allowing you to use # 13 | # this work in non-commercial and limited commercial products with a total # 14 | # gross revenue cap. To remove this commercial limit for one of your # 15 | # products, you must acquire a Full Commercial License. # 16 | # # 17 | # If you contribute to the source code, documentation, or related materials, # 18 | # you must grant me an exclusive license to these contributions. # 19 | # Contributions are governed by the "Contributions" section of the General # 20 | # License Agreement. # 21 | # # 22 | # Copying the work in parts is strictly forbidden, except as permitted # 23 | # under the General License Agreement. # 24 | # # 25 | # If you do not or cannot agree to the terms of this Agreement, # 26 | # do not use this work. # 27 | # # 28 | # This work is provided "as is", without any warranties, express or implied, # 29 | # except where such disclaimers are legally invalid. # 30 | # # 31 | # Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). # 32 | # All rights reserved. # 33 | ################################################################################ 34 | 35 | [package] 36 | name = "lady-deirdre" 37 | version = "2.2.0" 38 | authors = ["Ilya Lakhin (Илья Александрович Лахин) "] 39 | edition = "2021" 40 | description = "Compiler front-end foundation technology. Main Crate." 41 | keywords = ["parsing", "parser", "incremental", "compiler", "editor"] 42 | categories = ["compilers", "data-structures", "wasm", "parsing", "text-editors"] 43 | readme = "../../../README.md" 44 | license-file = "../../../EULA.md" 45 | documentation = "https://docs.rs/lady-deirdre" 46 | repository = "https://github.com/Eliah-Lakhin/lady-deirdre" 47 | rust-version = "1.79" 48 | publish = true 49 | autobins = false 50 | autoexamples = false 51 | autotests = false 52 | autobenches = false 53 | 54 | [dependencies.lady-deirdre-derive] 55 | version = "2.2" 56 | path = "../derive" 57 | -------------------------------------------------------------------------------- /work/crates/ucd/Cargo.toml: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # This file is part of "Lady Deirdre", a compiler front-end foundation # 3 | # technology. # 4 | # # 5 | # This work is proprietary software with source-available code. # 6 | # # 7 | # To copy, use, distribute, or contribute to this work, you must agree to # 8 | # the terms of the General License Agreement: # 9 | # # 10 | # https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md # 11 | # # 12 | # The agreement grants a Basic Commercial License, allowing you to use # 13 | # this work in non-commercial and limited commercial products with a total # 14 | # gross revenue cap. To remove this commercial limit for one of your # 15 | # products, you must acquire a Full Commercial License. # 16 | # # 17 | # If you contribute to the source code, documentation, or related materials, # 18 | # you must grant me an exclusive license to these contributions. # 19 | # Contributions are governed by the "Contributions" section of the General # 20 | # License Agreement. # 21 | # # 22 | # Copying the work in parts is strictly forbidden, except as permitted # 23 | # under the General License Agreement. # 24 | # # 25 | # If you do not or cannot agree to the terms of this Agreement, # 26 | # do not use this work. # 27 | # # 28 | # This work is provided "as is", without any warranties, express or implied, # 29 | # except where such disclaimers are legally invalid. # 30 | # # 31 | # Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). # 32 | # All rights reserved. # 33 | ################################################################################ 34 | 35 | [package] 36 | name = "lady-deirdre-ucd-generator" 37 | version = "0.0.0" 38 | authors = ["Ilya Lakhin (Илья Александрович Лахин) "] 39 | edition = "2021" 40 | description = "Compiler front-end foundation technology. UCD generator crate." 41 | keywords = ["parsing", "parser", "incremental", "compiler", "editor"] 42 | categories = ["compilers", "data-structures", "no-std", "parsing", "text-editors"] 43 | license-file = "../../../EULA.md" 44 | documentation = "https://docs.rs/lady-deirdre" 45 | repository = "https://github.com/Eliah-Lakhin/lady-deirdre" 46 | rust-version = "1.79" 47 | publish = false 48 | autobins = true 49 | autoexamples = false 50 | autotests = false 51 | autobenches = false 52 | 53 | [dependencies.ahash] 54 | version = "0.8" 55 | 56 | [dependencies.ucd-parse] 57 | version = "0.1" -------------------------------------------------------------------------------- /work/book/src/SUMMARY.md: -------------------------------------------------------------------------------- 1 | 34 | 35 | - [Introduction](introduction.md) 36 | 37 | - [Overview](overview.md) 38 | 39 | - [Lexis](lexis/lexis.md) 40 | - [Lexical Grammar](lexis/lexical-grammar.md) 41 | - [Scanning Process](lexis/scanning-process.md) 42 | - [Code Inspection](lexis/code-inspection.md) 43 | - [Token References](lexis/token-references.md) 44 | - [Site References](lexis/site-references.md) 45 | 46 | - [Syntax](syntax/syntax.md) 47 | - [Syntax Grammar](syntax/syntax-grammar.md) 48 | - [Error Recovering](syntax/error-recovering.md) 49 | - [Debugging](syntax/debugging.md) 50 | - [Syntax Tree](syntax/syntax-tree.md) 51 | - [Node References](syntax/node-references.md) 52 | - [Tree Inspection](syntax/tree-inspection.md) 53 | - [Hand-Written Parsers](syntax/hand-written-parsers.md) 54 | - [Overriding a Parser](syntax/overriding-a-parser.md) 55 | - [Syntax Session](syntax/syntax-session.md) 56 | - [Pratt's Algorithm](syntax/pratts-algorithm.md) 57 | 58 | - [Documents](documents.md) 59 | 60 | - [Semantics](semantics/semantics.md) 61 | - [Partition Into Scopes](semantics/partition-into-scopes.md) 62 | - [Grammar Setup](semantics/grammar-setup.md) 63 | - [Semantic Graph](semantics/semantic-graph.md) 64 | - [Incremental Computations](semantics/incremental-computations.md) 65 | - [Side Effects](semantics/side-effects.md) 66 | - [Scope Access](semantics/scope-access.md) 67 | - [Granularity](semantics/granularity.md) 68 | - [The Analyzer](semantics/the-analyzer.md) 69 | - [Tasks Management](semantics/tasks-management.md) 70 | - [Multi-File Analysis](semantics/multi-file-analysis.md) 71 | - [Language Server Design](semantics/language-server-design.md) 72 | - [Configuration Issues](semantics/configuration-issues.md) 73 | - [Code Diagnostics](semantics/code-diagnostics.md) 74 | - [Tree Index](semantics/tree-index.md) 75 | 76 | - [Code Formatters](code-formatters/code-formatters.md) 77 | - [Pretty Printer](code-formatters/pretty-printer.md) 78 | 79 | - [Snippets](snippets.md) 80 | -------------------------------------------------------------------------------- /work/crates/examples/Cargo.toml: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # This file is part of "Lady Deirdre", a compiler front-end foundation # 3 | # technology. # 4 | # # 5 | # This work is proprietary software with source-available code. # 6 | # # 7 | # To copy, use, distribute, or contribute to this work, you must agree to # 8 | # the terms of the General License Agreement: # 9 | # # 10 | # https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md # 11 | # # 12 | # The agreement grants a Basic Commercial License, allowing you to use # 13 | # this work in non-commercial and limited commercial products with a total # 14 | # gross revenue cap. To remove this commercial limit for one of your # 15 | # products, you must acquire a Full Commercial License. # 16 | # # 17 | # If you contribute to the source code, documentation, or related materials, # 18 | # you must grant me an exclusive license to these contributions. # 19 | # Contributions are governed by the "Contributions" section of the General # 20 | # License Agreement. # 21 | # # 22 | # Copying the work in parts is strictly forbidden, except as permitted # 23 | # under the General License Agreement. # 24 | # # 25 | # If you do not or cannot agree to the terms of this Agreement, # 26 | # do not use this work. # 27 | # # 28 | # This work is provided "as is", without any warranties, express or implied, # 29 | # except where such disclaimers are legally invalid. # 30 | # # 31 | # Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). # 32 | # All rights reserved. # 33 | ################################################################################ 34 | 35 | [package] 36 | name = "lady-deirdre-examples" 37 | version = "0.0.0" 38 | authors = ["Ilya Lakhin (Илья Александрович Лахин) "] 39 | edition = "2021" 40 | description = "Compiler front-end foundation technology. Examples crate." 41 | keywords = ["parsing", "parser", "incremental", "compiler", "editor"] 42 | categories = ["compilers", "data-structures", "no-std", "parsing", "text-editors"] 43 | readme = "./readme.md" 44 | license-file = "../../../EULA.md" 45 | documentation = "https://docs.rs/lady-deirdre" 46 | repository = "https://github.com/Eliah-Lakhin/lady-deirdre" 47 | rust-version = "1.79" 48 | publish = false 49 | autobins = false 50 | autoexamples = false 51 | autotests = false 52 | autobenches = false 53 | 54 | [dependencies.lady-deirdre] 55 | path = "../main" 56 | 57 | [dependencies.log] 58 | version = "0.4" 59 | -------------------------------------------------------------------------------- /work/book/src/semantics/code-diagnostics.md: -------------------------------------------------------------------------------- 1 | 34 | 35 | # Code Diagnostics 36 | 37 | While most end attributes of the semantic graph aim to infer specific semantic 38 | facts about particular syntax tree nodes, code diagnostics (semantic errors and 39 | warnings) are intended to be collected from the entire syntax tree. 40 | 41 | To tackle this issue and improve the incremental nature of code diagnostics, you 42 | can gather local diagnostic messages within scopes by iterating through scope 43 | nodes and their attributes, potentially containing diagnostic issues. These 44 | issues can then be collected into the hash set of the scope's diagnostics 45 | attribute. 46 | 47 | Subsequently, in the root node's global diagnostics attribute, you can iterate 48 | through all local diagnostic attributes of scopes and aggregate their values 49 | into a single set, wrapping it into 50 | a [Shared](https://docs.rs/lady-deirdre/2.2.0/lady_deirdre/sync/struct.Shared.html) 51 | structure for efficient cloning. Furthermore, you can enhance the final 52 | diagnostics set with syntax errors from the normal compilation unit by directly 53 | reading them from the document[^syntaxerror]. 54 | 55 | The resulting global diagnostics attribute would indirectly depend on the 56 | majority of the semantic graph. Despite potential optimizations by the validator 57 | due to granularity, querying this attribute could still be computationally 58 | intensive in edge cases. To mitigate this, the language server could 59 | periodically examine this attribute with a low-priority analysis task. 60 | 61 | Moreover, when utilizing 62 | the [Attr::snapshot](https://docs.rs/lady-deirdre/2.2.0/lady_deirdre/analysis/struct.Attr.html#method.snapshot) 63 | function to retrieve a copy of the current diagnostics sets, you can leverage 64 | the version number of the attribute value to determine whether this set needs to 65 | be republished to the client. 66 | 67 | [^syntaxerror]: The [Document::errors](https://docs.rs/lady-deirdre/2.2.0/lady_deirdre/syntax/trait.SyntaxTree.html#method.errors) 68 | function would provide you with an iterator over all syntax errors within the 69 | compilation unit. 70 | -------------------------------------------------------------------------------- /work/crates/examples/src/expr_parser/mod.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | pub mod lexis; 36 | pub mod parser; 37 | pub mod syntax; 38 | 39 | #[cfg(test)] 40 | mod tests { 41 | use lady_deirdre::{ 42 | syntax::SyntaxTree, 43 | units::{CompilationUnit, Document}, 44 | }; 45 | 46 | use crate::expr_parser::syntax::BoolNode; 47 | 48 | #[test] 49 | fn test_expression_parser() { 50 | let doc = Document::::new_immutable("true & false & (true | false) & true"); 51 | 52 | println!("{:#?}", doc.display(&doc.root_node_ref())); 53 | 54 | assert!(doc.errors().next().is_none()); 55 | } 56 | 57 | #[test] 58 | fn test_expression_recovery() { 59 | let doc = Document::::new_immutable("(false true) & tru | false"); 60 | 61 | println!("{:#?}", doc.display(&doc.root_node_ref())); 62 | 63 | for error in doc.errors() { 64 | println!("{:#}", error.display(&doc)); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /work/book/src/introduction.md: -------------------------------------------------------------------------------- 1 | 34 | 35 | # Introduction 36 | 37 | Lady Deirdre Logo 38 | 39 | Lady Deirdre is a framework that helps you develop front-end code analysis 40 | tools, such as code editor language extensions, programming language compilers 41 | and interpreters, and even new code editors. 42 | 43 | This guide will explain the main concepts of the API and walk you through the 44 | steps of developing an analysis tool. 45 | 46 | The book assumes that you already have some experience with the Rust programming 47 | language and that you understand the core concepts of classical compilers: 48 | lexical scanners, syntax parsers, regular expressions, context-free grammars, 49 | etc. 50 | 51 | If you have prior experience with code editor plugin development and 52 | the [LSP](https://microsoft.github.io/language-server-protocol/) protocol in 53 | particular, it will certainly help you understand the material but is not 54 | strictly required. The book will provide you with a brief overview of 55 | the core concepts behind these tools. 56 | 57 | ## Links 58 | 59 | - [Source Code](https://github.com/Eliah-Lakhin/lady-deirdre) 60 | - [Main Crate](https://crates.io/crates/lady-deirdre) 61 | - [API Documentation](https://docs.rs/lady-deirdre) 62 | - [User Guide](https://lady-deirdre.lakhin.com/) 63 | - [Examples](https://github.com/Eliah-Lakhin/lady-deirdre/tree/f350aaed30373a67694c3aba4d2cfd9874c2a656/work/crates/examples) 64 | - [License Agreement](https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md) 65 | 66 | ## Copyright 67 | 68 | This work is proprietary software with source-available code. 69 | 70 | To copy, use, distribute, or contribute to this work, you must agree to the 71 | terms and conditions of the [General License Agreement](https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md). 72 | 73 | For an explanation of the licensing terms, see the 74 | [F.A.Q.](https://github.com/Eliah-Lakhin/lady-deirdre/tree/master/FAQ.md) 75 | 76 | Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). All rights reserved. 77 | -------------------------------------------------------------------------------- /work/crates/derive/src/utils/mod.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | mod automata; 36 | mod context; 37 | mod description; 38 | mod deterministic; 39 | mod dump; 40 | mod expression; 41 | mod facade; 42 | mod map; 43 | mod predictable; 44 | mod report; 45 | mod set; 46 | mod transitions; 47 | 48 | pub(crate) use report::{error, error_message, expect_some, null, system_panic}; 49 | 50 | pub use crate::utils::{ 51 | automata::Automata, 52 | context::{AutomataContext, AutomataTerminal, State, Strategy}, 53 | description::Description, 54 | dump::Dump, 55 | expression::{Applicability, Expression, ExpressionOperand, ExpressionOperator}, 56 | facade::Facade, 57 | map::Map, 58 | predictable::PredictableCollection, 59 | set::{Set, SetImpl}, 60 | }; 61 | 62 | pub mod dump_kw { 63 | syn::custom_keyword!(output); 64 | syn::custom_keyword!(trivia); 65 | syn::custom_keyword!(meta); 66 | syn::custom_keyword!(dry); 67 | syn::custom_keyword!(decl); 68 | syn::custom_keyword!(dump); 69 | } 70 | -------------------------------------------------------------------------------- /work/crates/main/src/syntax/mod.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | mod captures; 36 | mod error; 37 | mod immutable; 38 | mod morphism; 39 | mod node; 40 | mod observer; 41 | mod parse; 42 | mod recovery; 43 | mod rule; 44 | mod session; 45 | mod tree; 46 | mod void; 47 | 48 | pub(crate) use crate::syntax::void::is_void_syntax; 49 | pub use crate::syntax::{ 50 | captures::{Capture, CaptureIntoIter, CapturesIter, ChildrenIter, Key}, 51 | error::{ErrorRef, SyntaxError, SyntaxErrorFormat, NIL_ERROR_REF}, 52 | immutable::ImmutableSyntaxTree, 53 | morphism::{PolyRef, PolyVariant, RefKind}, 54 | node::{AbstractNode, Node, NodeRef, NIL_NODE_REF}, 55 | observer::{DebugObserver, Observer, VoidObserver}, 56 | parse::{ParseBlank, ParseNode, ParseNodeChild, ParseToken, ParseTree}, 57 | recovery::{Recovery, RecoveryResult, UNLIMITED_RECOVERY}, 58 | rule::{NodeRule, NodeSet, EMPTY_NODE_SET, NON_RULE, ROOT_RULE}, 59 | session::SyntaxSession, 60 | tree::{ErrorIter, NodeIter, SyntaxTree, Visitor}, 61 | void::VoidSyntax, 62 | }; 63 | -------------------------------------------------------------------------------- /work/crates/main/src/units/storage/refs.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | use crate::{ 36 | arena::{Id, Repo}, 37 | syntax::{Node, SyntaxError}, 38 | units::storage::child::ChildCursor, 39 | }; 40 | 41 | pub(crate) struct TreeRefs { 42 | pub(crate) id: Id, 43 | pub(crate) chunks: Repo>, 44 | pub(crate) nodes: Repo, 45 | pub(crate) errors: Repo, 46 | } 47 | 48 | impl TreeRefs { 49 | #[inline(always)] 50 | pub(crate) fn new(id: Id) -> Self { 51 | Self { 52 | id, 53 | chunks: Repo::new(), 54 | nodes: Repo::new(), 55 | errors: Repo::new(), 56 | } 57 | } 58 | 59 | #[inline(always)] 60 | pub(crate) fn with_capacity(id: Id, mut capacity: usize) -> Self { 61 | capacity = (capacity + 1).next_power_of_two(); 62 | 63 | Self { 64 | id, 65 | chunks: Repo::with_capacity(capacity), 66 | nodes: Repo::new(), 67 | errors: Repo::new(), 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /work/book/src/semantics/side-effects.md: -------------------------------------------------------------------------------- 1 | 34 | 35 | # Side Effects 36 | 37 | Typically, implementations of 38 | attribute's [Computable](https://docs.rs/lady-deirdre/2.2.0/lady_deirdre/analysis/trait.Computable.html) 39 | functions should be free of side effects: their results should not rely on the 40 | external environment state, and non-input attributes should be independent from 41 | changes in the syntax and lexical structure of the compilation units. 42 | 43 | If the implementation has side effects that cannot be avoided, you have two ways 44 | to overcome the limitations of the validation procedure: 45 | 46 | 1. You can invalidate any attribute manually using 47 | the [Attr::invalidate](https://docs.rs/lady-deirdre/2.2.0/lady_deirdre/analysis/struct.Attr.html#method.invalidate) 48 | function if you are aware that the external environment state has changed. 49 | 50 | 2. Inside the computable function implementation, you can use 51 | the [Context::subscribe](https://docs.rs/lady-deirdre/2.2.0/lady_deirdre/analysis/struct.AttrContext.html#method.subscribe) 52 | function to subscribe this attribute to the Analyzer-wide event that could be 53 | triggered independently for bulk invalidation of the semantic graph 54 | attributes subscribed to a specific event. The event object that you would 55 | pass to this function is an arbitrary user-defined value of a numeric 56 | type[^builtinevenets]. 57 | 58 | Both methods should be used conservatively as they could potentially impact the 59 | incremental capabilities of the framework. 60 | 61 | However, one scenario where you might find these mechanisms useful is when your 62 | compiler manages several Analyzers of distinct programming languages that 63 | logically build up a single compilation project. Within this setup, changes in 64 | the state of one Analyzer could be propagated to some attributes of another 65 | Analyzer's setup. 66 | 67 | [^builtinevenets]: There are a couple of built-in events as well, such as 68 | the [DOC_UPDATED_EVENT](https://docs.rs/lady-deirdre/2.2.0/lady_deirdre/analysis/constant.DOC_UPDATED_EVENT.html), 69 | which denotes document-wide edits within the specified document regardless of 70 | the scopes. However, the majority of the value range is available for 71 | user-defined events. 72 | -------------------------------------------------------------------------------- /work/crates/derive/Cargo.toml: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # This file is part of "Lady Deirdre", a compiler front-end foundation # 3 | # technology. # 4 | # # 5 | # This work is proprietary software with source-available code. # 6 | # # 7 | # To copy, use, distribute, or contribute to this work, you must agree to # 8 | # the terms of the General License Agreement: # 9 | # # 10 | # https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md # 11 | # # 12 | # The agreement grants a Basic Commercial License, allowing you to use # 13 | # this work in non-commercial and limited commercial products with a total # 14 | # gross revenue cap. To remove this commercial limit for one of your # 15 | # products, you must acquire a Full Commercial License. # 16 | # # 17 | # If you contribute to the source code, documentation, or related materials, # 18 | # you must grant me an exclusive license to these contributions. # 19 | # Contributions are governed by the "Contributions" section of the General # 20 | # License Agreement. # 21 | # # 22 | # Copying the work in parts is strictly forbidden, except as permitted # 23 | # under the General License Agreement. # 24 | # # 25 | # If you do not or cannot agree to the terms of this Agreement, # 26 | # do not use this work. # 27 | # # 28 | # This work is provided "as is", without any warranties, express or implied, # 29 | # except where such disclaimers are legally invalid. # 30 | # # 31 | # Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). # 32 | # All rights reserved. # 33 | ################################################################################ 34 | 35 | [package] 36 | name = "lady-deirdre-derive" 37 | version = "2.2.0" 38 | authors = ["Ilya Lakhin (Илья Александрович Лахин) "] 39 | edition = "2021" 40 | description = "Compiler front-end foundation technology. Macro crate." 41 | keywords = ["parsing", "parser", "incremental", "compiler", "editor"] 42 | categories = ["compilers", "data-structures", "wasm", "parsing", "text-editors"] 43 | readme = "./readme.md" 44 | license-file = "../../../EULA.md" 45 | documentation = "https://docs.rs/lady-deirdre" 46 | repository = "https://github.com/Eliah-Lakhin/lady-deirdre" 47 | rust-version = "1.79" 48 | publish = true 49 | autobins = false 50 | autoexamples = false 51 | autotests = false 52 | autobenches = false 53 | 54 | [lib] 55 | proc-macro = true 56 | 57 | [dependencies.proc-macro2] 58 | version = "1.0" 59 | 60 | [dependencies.syn] 61 | version = "2.0" 62 | features = ["default", "full", "extra-traits"] 63 | 64 | [dependencies.quote] 65 | version = "1.0" 66 | 67 | [dependencies.prettyplease] 68 | version = "0.2" 69 | 70 | [dependencies.convert_case] 71 | version = "0.6" 72 | -------------------------------------------------------------------------------- /work/crates/main/src/lexis/mod.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | mod buffer; 36 | mod chunks; 37 | mod code; 38 | mod cursor; 39 | mod lines; 40 | mod position; 41 | mod rule; 42 | mod scanners; 43 | mod session; 44 | mod site; 45 | mod span; 46 | mod token; 47 | mod ucd; 48 | 49 | pub(crate) const CHUNK_SIZE: Length = 5; 50 | 51 | pub(crate) use crate::lexis::site::SiteRefInner; 52 | pub use crate::lexis::{ 53 | buffer::TokenBuffer, 54 | chunks::Chunk, 55 | code::{ChunkIter, SourceCode}, 56 | cursor::TokenCursor, 57 | lines::LineIndex, 58 | position::{Column, Line, Position}, 59 | rule::{TokenRule, TokenSet, EMPTY_TOKEN_SET, EOI, FULL_TOKEN_SET, MISMATCH}, 60 | scanners::{ 61 | ChunkIndicesScanner, 62 | ChunkScanner, 63 | Scannable, 64 | TokenIndicesScanner, 65 | TokenScanner, 66 | TokenStream, 67 | }, 68 | session::LexisSession, 69 | site::{ByteIndex, Length, Site, SiteRef, ToSite, NIL_SITE_REF}, 70 | span::{PositionSpan, SiteRefSpan, SiteSpan, ToSpan}, 71 | token::{Token, TokenCount, TokenRef, NIL_TOKEN_REF}, 72 | ucd::{Char, CharProperties}, 73 | }; 74 | -------------------------------------------------------------------------------- /work/crates/examples/src/json_grammar/lexis.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | use lady_deirdre::lexis::Token; 36 | 37 | #[derive(Token, Clone, Copy, PartialEq, Eq, Debug)] 38 | #[define(DEC = ['0'..'9'])] 39 | #[define(HEX = DEC | ['A'..'F'])] 40 | #[define(POSITIVE = ['1'..'9'] DEC*)] 41 | #[define(ESCAPE = '\\' ( 42 | | ['"', '\\', '/', 'b', 'f', 'n', 'r', 't'] 43 | | ('u' HEX HEX HEX HEX) 44 | ))] 45 | #[lookback(2)] 46 | #[repr(u8)] 47 | pub enum JsonToken { 48 | EOI = 0, 49 | 50 | Mismatch = 1, 51 | 52 | #[rule("true")] 53 | True, 54 | 55 | #[rule("false")] 56 | False, 57 | 58 | #[rule("null")] 59 | Null, 60 | 61 | #[rule('{')] 62 | BraceOpen, 63 | 64 | #[rule('}')] 65 | BraceClose, 66 | 67 | #[rule('[')] 68 | BracketOpen, 69 | 70 | #[rule(']')] 71 | BracketClose, 72 | 73 | #[rule(',')] 74 | Comma, 75 | 76 | #[rule(':')] 77 | Colon, 78 | 79 | #[rule('"' (ESCAPE | ^['"', '\\'])* '"')] 80 | String, 81 | 82 | #[rule('-'? ('0' | POSITIVE) ('.' DEC+)? (['e', 'E'] ['-', '+']? DEC+)?)] 83 | Number, 84 | 85 | #[rule([' ', '\t', '\n', '\x0c', '\r']+)] 86 | Whitespace, 87 | } 88 | -------------------------------------------------------------------------------- /work/book/src/lexis/site-references.md: -------------------------------------------------------------------------------- 1 | 34 | 35 | # Site References 36 | 37 | The [Site](https://docs.rs/lady-deirdre/2.2.0/lady_deirdre/lexis/type.Site.html) 38 | index, which represents the absolute offset of a Unicode character in the source 39 | code text, cannot reliably address a token's absolute offset after source code 40 | edits. This is because the token could be shifted left or right, or it could 41 | disappear during incremental rescanning, depending on the bounds of the edit. 42 | 43 | In contrast, 44 | [TokenRef::site](https://docs.rs/lady-deirdre/2.2.0/lady_deirdre/lexis/struct.TokenRef.html#method.site) 45 | returns the absolute offset of the beginning of the token's string fragment at 46 | the time of the call. In other words, this function returns an updated absolute 47 | offset of the token after an edit operation, provided the incremental rescanner 48 | did not remove the token during rescanning. 49 | 50 | This allows for addressing a token's character bounds relative to changes in the 51 | source code. 52 | 53 | The [SiteRef](https://docs.rs/lady-deirdre/2.2.0/lady_deirdre/lexis/struct.SiteRef.html) 54 | helper object (backed by the TokenRef under the hood) addresses token bounds. 55 | Specifically, this object addresses either the beginning of the token or the end 56 | of the source code. 57 | 58 | [ToSite](https://docs.rs/lady-deirdre/2.2.0/lady_deirdre/lexis/trait.ToSite.html) 59 | implements the ToSite trait, so it can be used as a valid bound of a range span. 60 | 61 | ```rust,noplayground 62 | use lady_deirdre::{ 63 | lexis::{SiteRef, SourceCode, TokenCursor}, 64 | syntax::VoidSyntax, 65 | units::Document, 66 | }; 67 | 68 | let mut doc = Document::>::new_mutable("foo [bar] baz"); 69 | 70 | let brackets_start: SiteRef = doc.cursor(..).site_ref(2); 71 | let brackets_end: SiteRef = doc.cursor(..).site_ref(5); 72 | 73 | assert_eq!(doc.substring(brackets_start..brackets_end), "[bar]"); 74 | 75 | // Rewriting "bar" to "12345". 76 | doc.write(5..8, "12345"); 77 | 78 | assert_eq!(doc.substring(brackets_start..brackets_end), "[12345]"); 79 | ``` 80 | 81 | Similar to TokenRef, the SiteRef interface has a 82 | special [nil](https://docs.rs/lady-deirdre/2.2.0/lady_deirdre/lexis/struct.SiteRef.html#method.nil) 83 | value and 84 | the [is_nil](https://docs.rs/lady-deirdre/2.2.0/lady_deirdre/lexis/struct.SiteRef.html#method.is_nil) 85 | test function. 86 | -------------------------------------------------------------------------------- /work/crates/derive/src/token/opt.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | use syn::parse::{Parse, ParseStream}; 36 | 37 | use crate::utils::Strategy; 38 | 39 | #[derive(Clone, Copy, Debug)] 40 | pub(super) enum Opt { 41 | Flat, 42 | Deep, 43 | } 44 | 45 | impl Default for Opt { 46 | #[inline(always)] 47 | fn default() -> Self { 48 | match cfg!(debug_assertions) { 49 | true => Self::Flat, 50 | false => Self::Deep, 51 | } 52 | } 53 | } 54 | 55 | impl Parse for Opt { 56 | fn parse(input: ParseStream) -> syn::Result { 57 | let lookahead = input.lookahead1(); 58 | 59 | if lookahead.peek(opt_kw::flat) { 60 | let _ = input.parse::()?; 61 | return Ok(Self::Flat); 62 | } 63 | 64 | if lookahead.peek(opt_kw::deep) { 65 | let _ = input.parse::()?; 66 | return Ok(Self::Deep); 67 | } 68 | 69 | return Err(lookahead.error()); 70 | } 71 | } 72 | 73 | impl Opt { 74 | #[inline(always)] 75 | pub(super) fn into_strategy(self) -> Strategy { 76 | match self { 77 | Self::Flat => Strategy::DETERMINIZE, 78 | Self::Deep => Strategy::CANONICALIZE, 79 | } 80 | } 81 | } 82 | 83 | mod opt_kw { 84 | syn::custom_keyword!(flat); 85 | syn::custom_keyword!(deep); 86 | } 87 | -------------------------------------------------------------------------------- /work/crates/main/src/analysis/mod.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | mod analyzer; 36 | mod attribute; 37 | mod compute; 38 | mod database; 39 | mod entry; 40 | mod error; 41 | mod grammar; 42 | mod lock; 43 | mod manager; 44 | mod scope; 45 | mod slot; 46 | mod tasks; 47 | 48 | pub use crate::analysis::{ 49 | analyzer::{Analyzer, AnalyzerConfig}, 50 | attribute::{Attr, AttrRef, NIL_ATTR_REF}, 51 | compute::{AttrContext, AttrReadGuard, Computable, SharedComputable, SlotReadGuard}, 52 | database::Revision, 53 | entry::{ 54 | DocumentReadGuard, 55 | Event, 56 | CUSTOM_EVENT_START_RANGE, 57 | DOC_ADDED_EVENT, 58 | DOC_ERRORS_EVENT, 59 | DOC_REMOVED_EVENT, 60 | DOC_UPDATED_EVENT, 61 | }, 62 | error::{AnalysisError, AnalysisResult, AnalysisResultEx}, 63 | grammar::{ 64 | AbstractFeature, 65 | Classifier, 66 | Feature, 67 | Grammar, 68 | Initializer, 69 | Invalidator, 70 | Semantics, 71 | VoidClassifier, 72 | VoidFeature, 73 | }, 74 | manager::{TaskHandle, TaskPriority, TriggerHandle}, 75 | scope::{Scope, ScopeAttr}, 76 | slot::{Slot, SlotRef, NIL_SLOT_REF}, 77 | tasks::{ 78 | AbstractTask, 79 | AnalysisTask, 80 | ExclusiveTask, 81 | MutationAccess, 82 | MutationTask, 83 | SemanticAccess, 84 | }, 85 | }; 86 | -------------------------------------------------------------------------------- /work/crates/derive/src/node/generics.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | use syn::{ 36 | punctuated::Punctuated, 37 | spanned::Spanned, 38 | GenericParam, 39 | Generics, 40 | Lifetime, 41 | LifetimeParam, 42 | }; 43 | 44 | pub(super) struct ParserGenerics { 45 | pub(super) ty: Generics, 46 | pub(super) func: Generics, 47 | pub(super) code: Lifetime, 48 | } 49 | 50 | impl ParserGenerics { 51 | pub(super) fn new(generics: Generics) -> Self { 52 | let code = { 53 | let mut candidate = String::from("'code"); 54 | 55 | 'outer: loop { 56 | for lifetime_def in generics.lifetimes() { 57 | if candidate == lifetime_def.lifetime.ident.to_string() { 58 | candidate.push('_'); 59 | continue 'outer; 60 | } 61 | } 62 | 63 | break; 64 | } 65 | 66 | Lifetime::new(candidate.as_str(), generics.span()) 67 | }; 68 | 69 | let mut func = generics.clone(); 70 | 71 | func.params.insert( 72 | 0, 73 | GenericParam::Lifetime(LifetimeParam { 74 | attrs: Vec::new(), 75 | lifetime: code.clone(), 76 | colon_token: None, 77 | bounds: Punctuated::new(), 78 | }), 79 | ); 80 | 81 | ParserGenerics { 82 | ty: generics, 83 | func, 84 | code, 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /work/crates/tests/src/lines.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | use lady_deirdre::lexis::{Length, LexisSession, Token, TokenRule}; 36 | 37 | #[derive(Clone, Copy, PartialEq, Eq)] 38 | #[repr(u8)] 39 | pub enum LineToken { 40 | EOI = 0, 41 | Mismatch = 1, 42 | Line = 2, 43 | } 44 | 45 | impl Token for LineToken { 46 | const LOOKBACK: Length = 1; 47 | 48 | #[inline(always)] 49 | fn scan(session: &mut impl LexisSession) -> Self { 50 | let mut byte = session.advance(); 51 | 52 | if byte == b'\n' { 53 | unsafe { session.submit() }; 54 | return Self::Line; 55 | } 56 | 57 | if byte == 0xFF { 58 | return Self::Mismatch; 59 | } 60 | 61 | loop { 62 | byte = session.advance(); 63 | 64 | if byte == b'\n' || byte == 0xFF { 65 | unsafe { session.submit() }; 66 | break; 67 | } 68 | } 69 | 70 | Self::Line 71 | } 72 | 73 | #[inline(always)] 74 | fn eoi() -> Self { 75 | Self::EOI 76 | } 77 | 78 | #[inline(always)] 79 | fn mismatch() -> Self { 80 | Self::Mismatch 81 | } 82 | 83 | #[inline(always)] 84 | fn rule(self) -> TokenRule { 85 | self as u8 86 | } 87 | 88 | #[inline(always)] 89 | fn rule_name(_rule: TokenRule) -> Option<&'static str> { 90 | None 91 | } 92 | 93 | #[inline(always)] 94 | fn rule_description(_rule: TokenRule, _verbose: bool) -> Option<&'static str> { 95 | None 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /work/crates/examples/src/json_highlight/mod.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | pub mod highlighter; 36 | 37 | #[cfg(test)] 38 | mod tests { 39 | use lady_deirdre::{format::AnnotationPriority, lexis::Position, units::Document}; 40 | 41 | use crate::json_highlight::highlighter::JsonSnippet; 42 | 43 | #[test] 44 | fn test_snippet() { 45 | static INPUT: &'static str = r#" 46 | { 47 | "foo": [1, 2, 3], 48 | "bar": { 49 | "a": true, 50 | "b": false, 51 | "c": null, 52 | "d": "string" 53 | } 54 | } 55 | "#; 56 | 57 | let doc = Document::new_immutable(INPUT); 58 | 59 | println!( 60 | "{:#}", 61 | JsonSnippet { 62 | doc: &doc, 63 | annotation: Vec::new(), 64 | } 65 | ); 66 | 67 | println!( 68 | "{:#}", 69 | JsonSnippet { 70 | doc: &doc, 71 | annotation: vec![ 72 | ( 73 | Position::new(3, 20)..Position::new(3, 29), 74 | AnnotationPriority::Secondary, 75 | "Annotation message." 76 | ), 77 | ( 78 | Position::new(10, 9)..Position::new(10, 10), 79 | AnnotationPriority::Primary, 80 | "Another message." 81 | ) 82 | ], 83 | } 84 | ); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /work/book/src/code-formatters/code-formatters.md: -------------------------------------------------------------------------------- 1 | 34 | 35 | # Code Formatters 36 | 37 | Many programming language compilers and language support extensions of code 38 | editors typically include code formatting programs. These programs take the 39 | source code text as input and bring it to a canonical format according to the 40 | code formatting rules. 41 | 42 | Code formatting presents a challenging problem that must consider both canonical 43 | formatting rules and the original intentions of the code author, such as 44 | preserving empty lines between code fragments and retaining code comments on 45 | their respective lines. 46 | 47 | Lady Deirdre offers two tools to aid in implementing the code formatter: 48 | 49 | 1. The 50 | [ParseTree](https://docs.rs/lady-deirdre/2.2.0/lady_deirdre/syntax/struct.ParseTree.html) 51 | builder constructs a concrete parsing tree. Unlike abstract syntax trees, it 52 | intentionally preserves all original source code whitespaces and comments. 53 | 2. The 54 | [PrettyPrinter](https://docs.rs/lady-deirdre/2.2.0/lady_deirdre/format/struct.PrettyPrinter.html) 55 | tool automatically decides on splitting the text into lines and determines 56 | line indentation to ensure that the final lines are aligned according to the 57 | predefined maximum line length. 58 | 59 | The parse tree builder utilizes the same syntax parser defined within the Node 60 | derive macro. However, unlike the Document or ImmutableSyntaxTree parsers, this 61 | parser preserves all tokens and trivia nodes, such as comments, in the concrete 62 | parse tree. While the structure of the output concrete parse tree resembles the 63 | syntax tree in terms of node structural nesting, the parse tree nodes include 64 | all possibly omitted children of the syntax tree grammar, regardless of 65 | capturing rules. 66 | 67 | Nodes of the parse tree comprehensively cover the original source code without 68 | gaps or overlaps. Consequently, the original source code text can be fully 69 | reconstructed by traversing the tree. To simplify tree traversing, parse tree 70 | nodes are owned by their parents. 71 | 72 | The source code text is expected to be provided to the parse tree builder, and 73 | the concrete parse tree is then used as input for the formatting tool. During 74 | tree traversal, your program interprets the lexis and tree nesting of the 75 | source code in accordance with your programming language formatting rules, 76 | considering the concrete tree configuration. It then feeds the source code 77 | tokens into the syntax-unaware Pretty Printer. The printer generates the final 78 | output string. 79 | 80 | The [Json Formatter](https://github.com/Eliah-Lakhin/lady-deirdre/tree/f350aaed30373a67694c3aba4d2cfd9874c2a656/work/crates/examples/src/json_formatter) 81 | example demonstrates the basic usage of both tools. 82 | -------------------------------------------------------------------------------- /work/crates/derive/src/utils/symbol.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | use std::{ 36 | cmp::Ordering, 37 | fmt::{Display, Formatter}, 38 | }; 39 | 40 | use crate::utils::Set; 41 | 42 | #[derive(Clone, Copy, PartialEq, Eq, Hash)] 43 | pub(super) enum Symbol { 44 | Null, 45 | Terminal(T), 46 | } 47 | 48 | impl Display for Symbol 49 | where 50 | T: Display, 51 | { 52 | #[inline] 53 | fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result { 54 | match self { 55 | Self::Null => formatter.write_str("Null"), 56 | Self::Terminal(t) => Display::fmt(t, formatter), 57 | } 58 | } 59 | } 60 | 61 | impl Ord for Symbol 62 | where 63 | T: Ord, 64 | { 65 | #[inline] 66 | fn cmp(&self, other: &Self) -> Ordering { 67 | match (self, other) { 68 | (Self::Null, Self::Null) => Ordering::Equal, 69 | (Self::Null, Self::Terminal(_)) => Ordering::Less, 70 | (Self::Terminal(_), Self::Null) => Ordering::Greater, 71 | (Self::Terminal(a), Self::Terminal(b)) => a.cmp(b), 72 | } 73 | } 74 | } 75 | 76 | impl PartialOrd for Symbol 77 | where 78 | T: Ord, 79 | { 80 | #[inline(always)] 81 | fn partial_cmp(&self, other: &Self) -> Option { 82 | Some(self.cmp(other)) 83 | } 84 | } 85 | 86 | impl Symbol { 87 | #[inline] 88 | pub(super) fn is_null(&self) -> bool { 89 | match self { 90 | Self::Null => true, 91 | _ => false, 92 | } 93 | } 94 | } 95 | 96 | pub type TerminalSet = Set; 97 | 98 | pub(super) type Alphabet = Set>; 99 | -------------------------------------------------------------------------------- /work/crates/ucd/src/download.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | use std::{ 36 | fs::{create_dir_all, write}, 37 | path::Path, 38 | process::{exit, Command}, 39 | }; 40 | 41 | use crate::{UCD_DOWNLOADS_DIR, UCD_RESOURCES, UCD_URL}; 42 | 43 | pub(super) fn download() { 44 | println!("Downloading UCD data..."); 45 | 46 | let downloads_dir = Path::new(UCD_DOWNLOADS_DIR); 47 | 48 | if downloads_dir.exists() { 49 | eprintln!( 50 | "Downloads dir {downloads_dir:?} already exists. Delete this directory manually.", 51 | ); 52 | exit(1); 53 | } 54 | 55 | if let Err(error) = create_dir_all(downloads_dir) { 56 | eprintln!("Failed to created downloads dir {downloads_dir:?}: {error}"); 57 | exit(1); 58 | } 59 | 60 | println!("Downloads dir {downloads_dir:?} created."); 61 | 62 | for resource in UCD_RESOURCES { 63 | let url = UCD_URL.to_owned() + resource; 64 | 65 | let output = match Command::new("curl").arg(&url).output() { 66 | Ok(output) => output, 67 | 68 | Err(error) => { 69 | eprintln!("Curl failed to fetch {url:?}: {error}",); 70 | exit(1); 71 | } 72 | }; 73 | 74 | let file_name = downloads_dir.join(resource); 75 | 76 | match write(file_name.as_path(), output.stdout) { 77 | Ok(()) => { 78 | println!("Remote file {url} saved to {file_name:?}."); 79 | } 80 | 81 | Err(error) => { 82 | eprintln!("Field to save remote file {url} to {file_name:?}: {error}"); 83 | exit(1); 84 | } 85 | }; 86 | } 87 | 88 | println!("UCD data downloading finished."); 89 | } 90 | -------------------------------------------------------------------------------- /work/crates/tests/Cargo.toml: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # This file is part of "Lady Deirdre", a compiler front-end foundation # 3 | # technology. # 4 | # # 5 | # This work is proprietary software with source-available code. # 6 | # # 7 | # To copy, use, distribute, or contribute to this work, you must agree to # 8 | # the terms of the General License Agreement: # 9 | # # 10 | # https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md # 11 | # # 12 | # The agreement grants a Basic Commercial License, allowing you to use # 13 | # this work in non-commercial and limited commercial products with a total # 14 | # gross revenue cap. To remove this commercial limit for one of your # 15 | # products, you must acquire a Full Commercial License. # 16 | # # 17 | # If you contribute to the source code, documentation, or related materials, # 18 | # you must grant me an exclusive license to these contributions. # 19 | # Contributions are governed by the "Contributions" section of the General # 20 | # License Agreement. # 21 | # # 22 | # Copying the work in parts is strictly forbidden, except as permitted # 23 | # under the General License Agreement. # 24 | # # 25 | # If you do not or cannot agree to the terms of this Agreement, # 26 | # do not use this work. # 27 | # # 28 | # This work is provided "as is", without any warranties, express or implied, # 29 | # except where such disclaimers are legally invalid. # 30 | # # 31 | # Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). # 32 | # All rights reserved. # 33 | ################################################################################ 34 | 35 | [package] 36 | name = "lady-deirdre-tests" 37 | version = "0.0.0" 38 | authors = ["Ilya Lakhin (Илья Александрович Лахин) "] 39 | edition = "2021" 40 | description = "Compiler front-end foundation technology. Examples crate." 41 | keywords = ["parsing", "parser", "incremental", "compiler", "editor"] 42 | categories = ["compilers", "data-structures", "no-std", "parsing", "text-editors"] 43 | readme = "./readme.md" 44 | license-file = "../../../EULA.md" 45 | documentation = "https://docs.rs/lady-deirdre" 46 | repository = "https://github.com/Eliah-Lakhin/lady-deirdre" 47 | rust-version = "1.79" 48 | publish = false 49 | autobins = false 50 | autoexamples = false 51 | autotests = false 52 | autobenches = false 53 | 54 | [[bin]] 55 | name = "visualize" 56 | path = "./src/visualize.rs" 57 | 58 | [[bench]] 59 | name = "benches" 60 | harness = false 61 | 62 | [dependencies.lady-deirdre] 63 | path = "../main" 64 | 65 | [dependencies.lady-deirdre-examples] 66 | path = "../examples" 67 | 68 | [dependencies.rand] 69 | version = "0.8" 70 | 71 | [dependencies.petname] 72 | version = "2.0" 73 | 74 | [dependencies.criterion] 75 | version = "0.5" 76 | 77 | [dependencies.dirs] 78 | version = "6.0" 79 | 80 | [dependencies.serde] 81 | version = "1.0" 82 | 83 | [dependencies.serde_json] 84 | version = "1.0" 85 | 86 | [dependencies.nom] 87 | version = "8.0.0" 88 | 89 | [dependencies.tree-sitter] 90 | version = "0.25" 91 | 92 | [dependencies.tree-sitter-json] 93 | version = "0.24" 94 | 95 | [dependencies.ropey] 96 | version = "2.0.0-beta.1" 97 | features = ["metric_chars"] 98 | 99 | [dependencies.logos] 100 | version = "0.15" -------------------------------------------------------------------------------- /work/crates/tests/src/logos.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | use lady_deirdre_examples::json_grammar::lexis::JsonToken; 36 | use logos::Logos; 37 | 38 | #[derive(Logos, Clone, Copy, PartialEq, Eq, Debug)] 39 | pub enum LogosJsonToken { 40 | #[token("true")] 41 | True, 42 | 43 | #[token("false")] 44 | False, 45 | 46 | #[token("null")] 47 | Null, 48 | 49 | #[token("{")] 50 | BraceOpen, 51 | 52 | #[token("}")] 53 | BraceClose, 54 | 55 | #[token("[")] 56 | BracketOpen, 57 | 58 | #[token("]")] 59 | BracketClose, 60 | 61 | #[token(",")] 62 | Comma, 63 | 64 | #[token(":")] 65 | Colon, 66 | 67 | #[regex(r#""([^"\\]|\\["\\bnfrt]|u[a-fA-F0-9]{4})*""#)] 68 | String, 69 | 70 | #[regex(r"-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?")] 71 | Number, 72 | 73 | #[regex(r"[ \t\r\n\f]+")] 74 | Whitespace, 75 | } 76 | 77 | impl LogosJsonToken { 78 | pub fn into_ld(self) -> JsonToken { 79 | match self { 80 | LogosJsonToken::True => JsonToken::True, 81 | LogosJsonToken::False => JsonToken::False, 82 | LogosJsonToken::Null => JsonToken::Null, 83 | LogosJsonToken::BraceOpen => JsonToken::BraceOpen, 84 | LogosJsonToken::BraceClose => JsonToken::BraceClose, 85 | LogosJsonToken::BracketOpen => JsonToken::BracketOpen, 86 | LogosJsonToken::BracketClose => JsonToken::BracketClose, 87 | LogosJsonToken::Comma => JsonToken::Comma, 88 | LogosJsonToken::Colon => JsonToken::Colon, 89 | LogosJsonToken::String => JsonToken::String, 90 | LogosJsonToken::Number => JsonToken::Number, 91 | LogosJsonToken::Whitespace => JsonToken::Whitespace, 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /work/book/src/syntax/syntax-tree.md: -------------------------------------------------------------------------------- 1 | 34 | 35 | # Syntax Tree 36 | 37 | The syntax API shares many similarities with the lexis API architecture: 38 | 39 | 1. The syntax grammar, implemented by 40 | the [Node](https://docs.rs/lady-deirdre/2.2.0/lady_deirdre/syntax/trait.Node.html) 41 | type, is distinct from the syntax tree manager responsible for actual parsing 42 | and storage of the syntax tree. 43 | 2. The syntax tree manager implements 44 | the [SyntaxTree](https://docs.rs/lady-deirdre/2.2.0/lady_deirdre/syntax/trait.SyntaxTree.html) 45 | trait, providing access to the parsed syntax tree through its functions. 46 | 3. There are several syntax manager implementations with distinct sets of 47 | features and performance characteristics. 48 | 4. Individual nodes within the syntax tree are addressed using 49 | the [NodeRef](https://docs.rs/lady-deirdre/2.2.0/lady_deirdre/syntax/struct.NodeRef.html) 50 | referential object, which points to concrete node instances owned by the 51 | syntax tree manager. 52 | 53 | The simplest implementation of the syntax tree manager is 54 | the [ImmutableSyntaxTree](https://docs.rs/lady-deirdre/2.2.0/lady_deirdre/syntax/struct.ImmutableSyntaxTree.html), 55 | which performs one-time parsing without incremental reparsing capabilities but 56 | has the fastest computation performance. 57 | 58 | This object accepts a token cursor providing access to the input stream. For 59 | example, you can obtain this cursor from the TokenBuffer. 60 | 61 | ```rust,noplayground 62 | use lady_deirdre::{ 63 | lexis::{SourceCode, TokenBuffer}, 64 | syntax::{ImmutableSyntaxTree, SyntaxTree}, 65 | }; 66 | 67 | let tokens = TokenBuffer::::from(r#"{ 68 | "foo": true, 69 | "bar": [123, null] 70 | }"#); 71 | 72 | // Parsing the entire set of tokens in the token buffer. 73 | let tree = ImmutableSyntaxTree::::parse(tokens.cursor(..)); 74 | 75 | // Ensuring that the ImmutableSyntaxTree successfully parsed 76 | // the input stream without syntax errors. 77 | assert!(tree.errors().next().is_none()); 78 | ``` 79 | 80 | The above code is verbose because it requires manual setup of the TokenBuffer 81 | and its token cursor. 82 | 83 | More commonly, we can utilize the 84 | immutable [Document](https://docs.rs/lady-deirdre/2.2.0/lady_deirdre/units/enum.Document.html), 85 | which is backed by the TokenBuffer and ImmutableSyntaxTree under the hood. 86 | Through this object, we can directly scan and parse the source code text. This 87 | object implements both the SourceCode and SyntaxTree traits, allowing us to 88 | access the lexical structure of the compilation unit as well. 89 | 90 | ```rust,noplayground 91 | use lady_deirdre::{syntax::SyntaxTree, units::Document}; 92 | 93 | let doc = Document::::new_immutable(r#"{ 94 | "foo": true, 95 | "bar": [123, null] 96 | }"#); 97 | 98 | assert!(doc.errors().next().is_none()); 99 | ``` 100 | -------------------------------------------------------------------------------- /work/crates/examples/src/json_highlight/highlighter.rs: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // This file is part of "Lady Deirdre", a compiler front-end foundation // 3 | // technology. // 4 | // // 5 | // This work is proprietary software with source-available code. // 6 | // // 7 | // To copy, use, distribute, or contribute to this work, you must agree to // 8 | // the terms of the General License Agreement: // 9 | // // 10 | // https://github.com/Eliah-Lakhin/lady-deirdre/blob/master/EULA.md // 11 | // // 12 | // The agreement grants a Basic Commercial License, allowing you to use // 13 | // this work in non-commercial and limited commercial products with a total // 14 | // gross revenue cap. To remove this commercial limit for one of your // 15 | // products, you must acquire a Full Commercial License. // 16 | // // 17 | // If you contribute to the source code, documentation, or related materials, // 18 | // you must grant me an exclusive license to these contributions. // 19 | // Contributions are governed by the "Contributions" section of the General // 20 | // License Agreement. // 21 | // // 22 | // Copying the work in parts is strictly forbidden, except as permitted // 23 | // under the General License Agreement. // 24 | // // 25 | // If you do not or cannot agree to the terms of this Agreement, // 26 | // do not use this work. // 27 | // // 28 | // This work is provided "as is", without any warranties, express or implied, // 29 | // except where such disclaimers are legally invalid. // 30 | // // 31 | // Copyright (c) 2024 Ilya Lakhin (Илья Александрович Лахин). // 32 | // All rights reserved. // 33 | //////////////////////////////////////////////////////////////////////////////// 34 | 35 | use std::fmt::{Display, Formatter}; 36 | 37 | use lady_deirdre::{ 38 | format::{AnnotationPriority, Highlighter, SnippetFormatter, Style}, 39 | lexis::PositionSpan, 40 | units::Document, 41 | }; 42 | 43 | use crate::json_grammar::{lexis::JsonToken, syntax::JsonNode}; 44 | 45 | pub struct JsonSnippet<'a> { 46 | pub doc: &'a Document, 47 | pub annotation: Vec<(PositionSpan, AnnotationPriority, &'static str)>, 48 | } 49 | 50 | impl<'a> Display for JsonSnippet<'a> { 51 | fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result { 52 | let mut snippet = formatter.snippet(self.doc); 53 | 54 | snippet 55 | .set_caption("Header text") 56 | .set_summary("Footer text.") 57 | .set_highlighter(JsonHighlighter); 58 | 59 | for (span, priority, message) in &self.annotation { 60 | snippet.annotate(span, *priority, *message); 61 | } 62 | 63 | snippet.finish() 64 | } 65 | } 66 | 67 | pub struct JsonHighlighter; 68 | 69 | impl Highlighter for JsonHighlighter { 70 | fn token_style(&mut self, dim: bool, token: JsonToken) -> Option