├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .mailmap ├── .rustfmt.toml ├── Cargo.lock ├── Cargo.toml ├── LICENSE.md ├── README.md ├── doc ├── ast.md ├── diff.md ├── hash.md └── lua.md ├── exe ├── Cargo.toml └── src │ ├── lib.rs │ └── main.rs ├── libs ├── docvim_diff │ ├── Cargo.toml │ └── src │ │ ├── diff.rs │ │ ├── format.rs │ │ ├── histogram.rs │ │ ├── lib.rs │ │ ├── myers.rs │ │ └── ring_buffer.rs ├── docvim_lexer │ ├── Cargo.toml │ ├── build.rs │ ├── src │ │ ├── error.rs │ │ ├── lexer.rs │ │ ├── lib.rs │ │ ├── lua.rs │ │ ├── markdown.rs │ │ ├── peekable.rs │ │ └── token.rs │ └── tests │ │ ├── lua │ │ ├── mod.rs │ │ ├── snapshots.rs │ │ └── snapshots │ │ │ ├── corpus.snap │ │ │ ├── index_expressions.snap │ │ │ ├── numbers.snap │ │ │ ├── strings │ │ │ ├── double_quoted.snap │ │ │ ├── long_brackets.snap │ │ │ └── single_quoted.snap │ │ │ └── unexpected_token.snap │ │ ├── markdown │ │ ├── mod.rs │ │ ├── snapshots.rs │ │ └── snapshots │ │ │ ├── docvim.snap │ │ │ ├── ferret.snap │ │ │ ├── markdown.snap │ │ │ └── unterminated_br_tag.snap │ │ └── tests.rs ├── docvim_macros │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── docvim_parser │ ├── Cargo.toml │ ├── build.rs │ ├── src │ │ ├── error.rs │ │ ├── lib.rs │ │ ├── lua.rs │ │ ├── markdown.rs │ │ └── types.rs │ └── tests │ │ ├── lua │ │ ├── mod.rs │ │ ├── snapshots.rs │ │ └── snapshots │ │ │ ├── break │ │ │ ├── in_while.snap │ │ │ └── when_not_last.snap │ │ │ ├── comments │ │ │ ├── block.snap │ │ │ └── line.snap │ │ │ ├── complex_expression.snap │ │ │ ├── corpus.snap │ │ │ ├── do_blocks │ │ │ ├── basic.snap │ │ │ ├── empty.snap │ │ │ ├── multiple_statements.snap │ │ │ ├── nested.snap │ │ │ └── unterminated.snap │ │ │ ├── dot_expressions │ │ │ ├── basic.snap │ │ │ └── chained.snap │ │ │ ├── errors │ │ │ ├── basic.snap │ │ │ ├── nested.snap │ │ │ ├── unexpected_token.snap │ │ │ └── unterminated_list.snap │ │ │ ├── for │ │ │ ├── basic.snap │ │ │ └── with_stepexp.snap │ │ │ ├── for_in │ │ │ ├── basic.snap │ │ │ └── complex_explist.snap │ │ │ ├── function_calls │ │ │ ├── chained.snap │ │ │ ├── empty.snap │ │ │ ├── expressions.snap │ │ │ ├── multiple_arguments.snap │ │ │ ├── nested.snap │ │ │ ├── on_same_line.snap │ │ │ ├── semi_colons.snap │ │ │ ├── single_argument.snap │ │ │ ├── string_arguments.snap │ │ │ └── table_argument.snap │ │ │ ├── function_expressions │ │ │ ├── basic.snap │ │ │ ├── in_list.snap │ │ │ ├── in_table.snap │ │ │ └── with_params.snap │ │ │ ├── function_statements │ │ │ ├── basic.snap │ │ │ ├── complex.snap │ │ │ ├── empty.snap │ │ │ ├── with_args.snap │ │ │ ├── with_method.snap │ │ │ ├── with_properties.snap │ │ │ └── with_properties_and_method.snap │ │ │ ├── if_statement │ │ │ ├── basic.snap │ │ │ ├── else.snap │ │ │ ├── elseif.snap │ │ │ ├── multiple.snap │ │ │ └── nested.snap │ │ │ ├── index_expressions │ │ │ ├── basic.snap │ │ │ └── chained.snap │ │ │ ├── lexer_errors │ │ │ ├── invalid_escape_sequence.snap │ │ │ ├── invalid_operator.snap │ │ │ ├── unterminated_block_comment.snap │ │ │ ├── unterminated_escape_sequence.snap │ │ │ └── unterminated_string_literal.snap │ │ │ ├── local_declarations │ │ │ ├── arithemetic_assignment.snap │ │ │ ├── boolean_assignment.snap │ │ │ ├── double_quoted_string_assignment.snap │ │ │ ├── expression_assignment.snap │ │ │ ├── forward_declaration.snap │ │ │ ├── length_assignment.snap │ │ │ ├── long_string_assignment.snap │ │ │ ├── negation_assignment.snap │ │ │ ├── negative_assignment.snap │ │ │ ├── nil_assignment.snap │ │ │ ├── number_assignment.snap │ │ │ ├── single_quoted_string_assignment.snap │ │ │ ├── table_constructor_assignment.snap │ │ │ └── unary_not_with_name_assignment.snap │ │ │ ├── local_function_declarations │ │ │ ├── basic.snap │ │ │ ├── empty.snap │ │ │ ├── multiple_params.snap │ │ │ ├── one_param.snap │ │ │ ├── varargs.snap │ │ │ └── varargs_only.snap │ │ │ ├── method_calls │ │ │ ├── as_expressions.snap │ │ │ ├── chained.snap │ │ │ ├── empty.snap │ │ │ ├── multiple_arguments.snap │ │ │ ├── nested.snap │ │ │ ├── single_argument.snap │ │ │ ├── string_arguments.snap │ │ │ └── table_argument.snap │ │ │ ├── parens.snap │ │ │ ├── prefix_expressions │ │ │ └── mixed.snap │ │ │ ├── repeat │ │ │ └── basic.snap │ │ │ ├── return │ │ │ ├── in_function.snap │ │ │ ├── in_module.snap │ │ │ ├── in_while.snap │ │ │ └── when_not_last.snap │ │ │ ├── table_constructors │ │ │ ├── basic_multiple_fields.snap │ │ │ ├── basic_multiple_fields_trailing_comma.snap │ │ │ ├── basic_single_field.snap │ │ │ ├── brackets.snap │ │ │ ├── list.snap │ │ │ ├── nested.snap │ │ │ └── shorthand.snap │ │ │ ├── unary_expressions.snap │ │ │ └── while │ │ │ └── basic.snap │ │ └── markdown │ │ └── mod.rs └── docvim_snapshot │ ├── Cargo.toml │ ├── src │ └── lib.rs │ └── tests │ ├── snapshots.rs │ └── snapshots │ ├── invalid_sample.snap │ ├── subdirectory │ └── sample.snap │ └── valid_sample.snap ├── sample └── init.lua └── support ├── .gitignore ├── collisions.c ├── hash.c └── words.txt /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | pull_request: 7 | branches: [main] 8 | 9 | jobs: 10 | 11 | test: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v3 15 | - uses: actions-rs/toolchain@v1 16 | with: 17 | profile: minimal 18 | toolchain: stable 19 | - name: Run tests 20 | run: cargo test 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | Greg Hurrell 2 | -------------------------------------------------------------------------------- /.rustfmt.toml: -------------------------------------------------------------------------------- 1 | use_small_heuristics = "max" 2 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "docvim" 7 | version = "0.1.0" 8 | dependencies = [ 9 | "docvim_parser", 10 | ] 11 | 12 | [[package]] 13 | name = "docvim_diff" 14 | version = "0.1.0" 15 | 16 | [[package]] 17 | name = "docvim_lexer" 18 | version = "0.1.0" 19 | dependencies = [ 20 | "docvim_macros", 21 | "docvim_snapshot", 22 | ] 23 | 24 | [[package]] 25 | name = "docvim_macros" 26 | version = "0.1.0" 27 | 28 | [[package]] 29 | name = "docvim_parser" 30 | version = "0.1.0" 31 | dependencies = [ 32 | "docvim_lexer", 33 | "docvim_macros", 34 | "docvim_snapshot", 35 | ] 36 | 37 | [[package]] 38 | name = "docvim_snapshot" 39 | version = "0.1.0" 40 | dependencies = [ 41 | "docvim_diff", 42 | ] 43 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = [ 3 | "exe", 4 | "libs/*" 5 | ] 6 | resolver = "2" 7 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015-present Greg Hurrell 2 | 3 | # MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /exe/Cargo.toml: -------------------------------------------------------------------------------- 1 | [[bin]] 2 | name = "docvim" 3 | 4 | [dependencies] 5 | # docvim_lexer = { path = "../libs/docvim_lexer" } 6 | docvim_parser = { path = "../libs/docvim_parser" } 7 | 8 | [lib] 9 | 10 | [package] 11 | authors = ["Greg Hurrell "] 12 | default-run = "docvim" 13 | description = "Produces Neovim/Vim help and HTML (via Markdown) documentation" 14 | edition = "2021" 15 | license-file = "LICENSE.md" 16 | name = "docvim" 17 | version = "0.1.0" 18 | -------------------------------------------------------------------------------- /exe/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::error::Error; 2 | 3 | fn main() -> Result<(), Box> { 4 | docvim::run(std::env::args().collect()) 5 | } 6 | -------------------------------------------------------------------------------- /libs/docvim_diff/Cargo.toml: -------------------------------------------------------------------------------- 1 | [dependencies] 2 | 3 | [lib] 4 | 5 | [package] 6 | authors = ["Greg Hurrell "] 7 | edition = "2021" 8 | name = "docvim_diff" 9 | version = "0.1.0" 10 | -------------------------------------------------------------------------------- /libs/docvim_diff/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod diff; 2 | pub mod histogram; 3 | pub mod myers; 4 | 5 | mod format; 6 | mod ring_buffer; 7 | 8 | pub use format::format; 9 | -------------------------------------------------------------------------------- /libs/docvim_diff/src/ring_buffer.rs: -------------------------------------------------------------------------------- 1 | use std::ops::{Index, IndexMut}; 2 | 3 | /// The Myers paper specifies an array (`V[-MAX..MAX]`) that allows negative indices, so we 4 | /// substitute a ring buffer for that. Positive indices that exceed the capacity wrap around; 5 | /// negative indices wrap around in the opposite direction. 6 | #[derive(Clone, Debug)] 7 | pub struct RingBuffer { 8 | capacity: usize, 9 | // TODO: try and make this generic, maybe, once this is resolved: 10 | // https://github.com/rust-lang/rust/issues/52662 11 | storage: Vec, 12 | } 13 | 14 | impl RingBuffer { 15 | pub fn new(capacity: usize) -> Self { 16 | RingBuffer { capacity, storage: vec![0; capacity] } 17 | } 18 | } 19 | 20 | // Note to self: this is ridiculous; I should probably just keep two vectors. 21 | impl Index for RingBuffer { 22 | type Output = usize; 23 | 24 | fn index(&self, index: isize) -> &Self::Output { 25 | if index == 0 { 26 | &self.storage[0] 27 | } else if index > 0 { 28 | &self.storage[(index as usize) % self.capacity] 29 | } else { 30 | let offset = (index * -1) as usize; 31 | if offset <= self.capacity { 32 | &self.storage[self.capacity - offset] 33 | } else { 34 | &self.storage[self.capacity - offset % self.capacity] 35 | } 36 | } 37 | } 38 | } 39 | 40 | impl IndexMut for RingBuffer { 41 | fn index_mut(&mut self, index: isize) -> &mut Self::Output { 42 | if index == 0 { 43 | &mut self.storage[0] 44 | } else if index > 0 { 45 | &mut self.storage[(index as usize) % self.capacity] 46 | } else { 47 | let offset = (index * -1) as usize; 48 | if offset <= self.capacity { 49 | &mut self.storage[self.capacity - offset] 50 | } else { 51 | &mut self.storage[self.capacity - offset % self.capacity] 52 | } 53 | } 54 | } 55 | } 56 | 57 | #[cfg(test)] 58 | mod tests { 59 | use super::*; 60 | 61 | #[test] 62 | fn test_ring_buffer() { 63 | let mut buffer = RingBuffer::new(9); 64 | 65 | // Write values. 66 | buffer[-4] = 40; 67 | buffer[-3] = 30; 68 | buffer[-2] = 20; 69 | buffer[-1] = 10; 70 | buffer[0] = 100; 71 | buffer[1] = 1000; 72 | buffer[2] = 2000; 73 | buffer[3] = 3000; 74 | buffer[4] = 4000; 75 | 76 | // Read values. 77 | assert_eq!(buffer[-4], 40); 78 | assert_eq!(buffer[-3], 30); 79 | assert_eq!(buffer[-2], 20); 80 | assert_eq!(buffer[-1], 10); 81 | assert_eq!(buffer[0], 100); 82 | assert_eq!(buffer[1], 1000); 83 | assert_eq!(buffer[2], 2000); 84 | assert_eq!(buffer[3], 3000); 85 | assert_eq!(buffer[4], 4000); 86 | 87 | // Read values with wrap-around downwards... 88 | assert_eq!(buffer[-5], 4000); 89 | assert_eq!(buffer[-6], 3000); 90 | assert_eq!(buffer[-7], 2000); 91 | assert_eq!(buffer[-8], 1000); 92 | assert_eq!(buffer[-9], 100); 93 | assert_eq!(buffer[-10], 10); 94 | 95 | // And upwards... 96 | assert_eq!(buffer[5], 40); 97 | assert_eq!(buffer[6], 30); 98 | assert_eq!(buffer[7], 20); 99 | assert_eq!(buffer[8], 10); 100 | assert_eq!(buffer[9], 100); 101 | assert_eq!(buffer[10], 1000); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /libs/docvim_lexer/Cargo.toml: -------------------------------------------------------------------------------- 1 | [dependencies] 2 | 3 | [dev-dependencies] 4 | docvim_macros = { path = "../docvim_macros" } 5 | docvim_snapshot = { path = "../docvim_snapshot" } 6 | 7 | [lib] 8 | 9 | [package] 10 | authors = ["Greg Hurrell "] 11 | edition = "2021" 12 | name = "docvim_lexer" 13 | version = "0.1.0" 14 | -------------------------------------------------------------------------------- /libs/docvim_lexer/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("cargo:rerun-if-changed=tests/lua/snapshots"); 3 | println!("cargo:rerun-if-changed=tests/markdown/snapshots"); 4 | } 5 | -------------------------------------------------------------------------------- /libs/docvim_lexer/src/error.rs: -------------------------------------------------------------------------------- 1 | use std::error; 2 | use std::fmt; 3 | use std::fmt::Debug; 4 | use std::fmt::Display; 5 | 6 | pub trait LexerErrorKind: Clone + Copy + Debug + Display + Eq + PartialEq {} 7 | 8 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] 9 | pub struct LexerError { 10 | pub kind: T, 11 | pub line: usize, 12 | pub column: usize, 13 | } 14 | 15 | impl LexerError { 16 | pub fn new(kind: T, line: usize, column: usize) -> Self { 17 | Self { kind, line, column } 18 | } 19 | } 20 | 21 | impl fmt::Display for LexerError { 22 | fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { 23 | write!(fmt, "{} (line {}, column {})", self.kind, self.line, self.column) 24 | } 25 | } 26 | 27 | impl error::Error for LexerError {} 28 | -------------------------------------------------------------------------------- /libs/docvim_lexer/src/lexer.rs: -------------------------------------------------------------------------------- 1 | pub trait Lexer {} 2 | -------------------------------------------------------------------------------- /libs/docvim_lexer/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod error; 2 | pub mod lexer; 3 | pub mod lua; 4 | pub mod markdown; 5 | pub mod token; 6 | 7 | mod peekable; 8 | 9 | #[cfg(test)] 10 | mod tests { 11 | #[test] 12 | fn blinking_light() { 13 | assert!(true); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /libs/docvim_lexer/src/token.rs: -------------------------------------------------------------------------------- 1 | use std::fmt::Debug; 2 | 3 | pub trait TokenKind: Clone + Copy + Debug + Eq + PartialEq {} 4 | 5 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] 6 | pub struct Token { 7 | pub kind: T, 8 | pub char_start: usize, 9 | pub char_end: usize, 10 | pub byte_start: usize, 11 | pub byte_end: usize, 12 | 13 | // 1-indexed, as these are all editor-centric fields. 14 | pub column_start: usize, 15 | pub column_end: usize, 16 | pub line_start: usize, 17 | pub line_end: usize, 18 | } 19 | 20 | impl Token { 21 | pub fn new( 22 | kind: T, 23 | char_start: usize, 24 | char_end: usize, 25 | byte_start: usize, 26 | byte_end: usize, 27 | column_start: usize, 28 | column_end: usize, 29 | line_start: usize, 30 | line_end: usize, 31 | ) -> Token { 32 | Token { 33 | kind, 34 | char_start, 35 | char_end, 36 | byte_start, 37 | byte_end, 38 | column_start, 39 | column_end, 40 | line_start, 41 | line_end, 42 | } 43 | } 44 | } 45 | 46 | #[macro_export] 47 | macro_rules! make_token { 48 | ($self:expr, $kind:expr) => { 49 | Some(Ok(Token::new( 50 | $kind, 51 | $self.char_start, 52 | $self.iter.char_idx, 53 | $self.byte_start, 54 | $self.iter.byte_idx, 55 | $self.column_start, 56 | $self.iter.column_idx, 57 | $self.line_start, 58 | $self.iter.line_idx, 59 | ))) 60 | }; 61 | } 62 | -------------------------------------------------------------------------------- /libs/docvim_lexer/tests/lua/mod.rs: -------------------------------------------------------------------------------- 1 | mod snapshots; 2 | -------------------------------------------------------------------------------- /libs/docvim_lexer/tests/lua/snapshots.rs: -------------------------------------------------------------------------------- 1 | use docvim_lexer::lua::Lexer; 2 | use docvim_macros::check_snapshots; 3 | 4 | #[check_snapshots("libs/docvim_lexer/tests/lua/snapshots")] 5 | fn transform(input: &str) -> String { 6 | let mut output = vec![]; 7 | for result in Lexer::new(input).tokens { 8 | output.push(match result { 9 | Ok(token) => { 10 | format!("{:?}: {}", token, &input[token.byte_start..token.byte_end]) 11 | } 12 | 13 | // Note we stringify errors too, so that we can test bad inputs. 14 | Err(err) => err.to_string(), 15 | }); 16 | } 17 | output.join("\n") 18 | } 19 | -------------------------------------------------------------------------------- /libs/docvim_lexer/tests/lua/snapshots/index_expressions.snap: -------------------------------------------------------------------------------- 1 | foo[1000] 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | Token { kind: Name(Identifier), char_start: 0, char_end: 3, byte_start: 0, byte_end: 3, column_start: 1, column_end: 4, line_start: 1, line_end: 1 }: foo 6 | Token { kind: Punctuator(Lbracket), char_start: 3, char_end: 4, byte_start: 3, byte_end: 4, column_start: 4, column_end: 5, line_start: 1, line_end: 1 }: [ 7 | Token { kind: Literal(Number), char_start: 4, char_end: 8, byte_start: 4, byte_end: 8, column_start: 5, column_end: 9, line_start: 1, line_end: 1 }: 1000 8 | Token { kind: Punctuator(Rbracket), char_start: 8, char_end: 9, byte_start: 8, byte_end: 9, column_start: 9, column_end: 10, line_start: 1, line_end: 1 }: ] 9 | -------------------------------------------------------------------------------- /libs/docvim_lexer/tests/lua/snapshots/numbers.snap: -------------------------------------------------------------------------------- 1 | 1000 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | Token { kind: Literal(Number), char_start: 0, char_end: 4, byte_start: 0, byte_end: 4, column_start: 1, column_end: 5, line_start: 1, line_end: 1 }: 1000 6 | -------------------------------------------------------------------------------- /libs/docvim_lexer/tests/lua/snapshots/strings/double_quoted.snap: -------------------------------------------------------------------------------- 1 | "hello" 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | Token { kind: Literal(Str(DoubleQuoted)), char_start: 0, char_end: 7, byte_start: 0, byte_end: 7, column_start: 1, column_end: 8, line_start: 1, line_end: 1 }: "hello" 6 | -------------------------------------------------------------------------------- /libs/docvim_lexer/tests/lua/snapshots/strings/long_brackets.snap: -------------------------------------------------------------------------------- 1 | [[a simple one]] 2 | 3 | [=[a level 1 one]=] 4 | 5 | [==[a level 2 one]==] 6 | 7 | [===[ 8 | backslashes: \ 9 | newlines 10 | [[brackets]] 11 | ]===] 12 | 13 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 14 | 15 | Token { kind: Literal(Str(Long { level: 0 })), char_start: 0, char_end: 16, byte_start: 0, byte_end: 16, column_start: 1, column_end: 17, line_start: 1, line_end: 1 }: [[a simple one]] 16 | Token { kind: Literal(Str(Long { level: 1 })), char_start: 18, char_end: 37, byte_start: 18, byte_end: 37, column_start: 1, column_end: 20, line_start: 3, line_end: 3 }: [=[a level 1 one]=] 17 | Token { kind: Literal(Str(Long { level: 2 })), char_start: 39, char_end: 60, byte_start: 39, byte_end: 60, column_start: 1, column_end: 22, line_start: 5, line_end: 5 }: [==[a level 2 one]==] 18 | Token { kind: Literal(Str(Long { level: 3 })), char_start: 62, char_end: 116, byte_start: 62, byte_end: 116, column_start: 1, column_end: 6, line_start: 7, line_end: 11 }: [===[ 19 | backslashes: \ 20 | newlines 21 | [[brackets]] 22 | ]===] 23 | -------------------------------------------------------------------------------- /libs/docvim_lexer/tests/lua/snapshots/strings/single_quoted.snap: -------------------------------------------------------------------------------- 1 | 'goodbye' 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | Token { kind: Literal(Str(SingleQuoted)), char_start: 0, char_end: 9, byte_start: 0, byte_end: 9, column_start: 1, column_end: 10, line_start: 1, line_end: 1 }: 'goodbye' 6 | -------------------------------------------------------------------------------- /libs/docvim_lexer/tests/lua/snapshots/unexpected_token.snap: -------------------------------------------------------------------------------- 1 | local x = { 1 }} 2 | 3 | --[[ 4 | 0123456789111111 5 | 012345 6 | 7 | The unexpected token is the second curly, which starts at position 8 | (`char_start`) 15 and ends at position (`char_end`) 16. 9 | --]] 10 | 11 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 12 | 13 | Token { kind: Name(Keyword(Local)), char_start: 0, char_end: 5, byte_start: 0, byte_end: 5, column_start: 1, column_end: 6, line_start: 1, line_end: 1 }: local 14 | Token { kind: Name(Identifier), char_start: 6, char_end: 7, byte_start: 6, byte_end: 7, column_start: 7, column_end: 8, line_start: 1, line_end: 1 }: x 15 | Token { kind: Op(Assign), char_start: 8, char_end: 9, byte_start: 8, byte_end: 9, column_start: 9, column_end: 10, line_start: 1, line_end: 1 }: = 16 | Token { kind: Punctuator(Lcurly), char_start: 10, char_end: 11, byte_start: 10, byte_end: 11, column_start: 11, column_end: 12, line_start: 1, line_end: 1 }: { 17 | Token { kind: Literal(Number), char_start: 12, char_end: 13, byte_start: 12, byte_end: 13, column_start: 13, column_end: 14, line_start: 1, line_end: 1 }: 1 18 | Token { kind: Punctuator(Rcurly), char_start: 14, char_end: 15, byte_start: 14, byte_end: 15, column_start: 15, column_end: 16, line_start: 1, line_end: 1 }: } 19 | Token { kind: Punctuator(Rcurly), char_start: 15, char_end: 16, byte_start: 15, byte_end: 16, column_start: 16, column_end: 17, line_start: 1, line_end: 1 }: } 20 | Token { kind: Comment(BlockComment), char_start: 18, char_end: 185, byte_start: 18, byte_end: 185, column_start: 1, column_end: 5, line_start: 3, line_end: 9 }: --[[ 21 | 0123456789111111 22 | 012345 23 | 24 | The unexpected token is the second curly, which starts at position 25 | (`char_start`) 15 and ends at position (`char_end`) 16. 26 | --]] 27 | -------------------------------------------------------------------------------- /libs/docvim_lexer/tests/markdown/mod.rs: -------------------------------------------------------------------------------- 1 | mod snapshots; 2 | -------------------------------------------------------------------------------- /libs/docvim_lexer/tests/markdown/snapshots.rs: -------------------------------------------------------------------------------- 1 | use docvim_lexer::markdown::Lexer; 2 | use docvim_macros::check_snapshots; 3 | 4 | #[check_snapshots("libs/docvim_lexer/tests/markdown/snapshots")] 5 | fn transform(input: &str) -> String { 6 | let mut output = vec![]; 7 | for result in Lexer::new(input).tokens { 8 | output.push(match result { 9 | Ok(token) => { 10 | let text = &input[token.byte_start..token.byte_end]; 11 | 12 | // Special case whitespace-only tokens to make them more readable. 13 | let display_text = if text.trim().is_empty() { 14 | format!("\"{}\"", text.escape_default()) 15 | } else { 16 | text.to_string() 17 | }; 18 | 19 | format!("{:?}: {}", token, display_text) 20 | } 21 | 22 | // Note we stringify errors too, so that we can test bad inputs. 23 | Err(err) => err.to_string(), 24 | }); 25 | } 26 | output.join("\n") 27 | } 28 | -------------------------------------------------------------------------------- /libs/docvim_lexer/tests/markdown/snapshots/docvim.snap: -------------------------------------------------------------------------------- 1 | "docvim-flavored Markdown" tokens: 2 | 3 | Links: |something()| 4 | 5 | Link targets: *something-here* 6 | 7 | Annotations: @mappings 8 | 9 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 10 | 11 | Token { kind: Text, char_start: 0, char_end: 7, byte_start: 0, byte_end: 7, column_start: 1, column_end: 8, line_start: 1, line_end: 1 }: "docvim 12 | Token { kind: Hyphen, char_start: 7, char_end: 8, byte_start: 7, byte_end: 8, column_start: 8, column_end: 9, line_start: 1, line_end: 1 }: - 13 | Token { kind: Text, char_start: 8, char_end: 16, byte_start: 8, byte_end: 16, column_start: 9, column_end: 17, line_start: 1, line_end: 1 }: flavored 14 | Token { kind: Space, char_start: 16, char_end: 17, byte_start: 16, byte_end: 17, column_start: 17, column_end: 18, line_start: 1, line_end: 1 }: " " 15 | Token { kind: Text, char_start: 17, char_end: 26, byte_start: 17, byte_end: 26, column_start: 18, column_end: 27, line_start: 1, line_end: 1 }: Markdown" 16 | Token { kind: Space, char_start: 26, char_end: 27, byte_start: 26, byte_end: 27, column_start: 27, column_end: 28, line_start: 1, line_end: 1 }: " " 17 | Token { kind: Text, char_start: 27, char_end: 34, byte_start: 27, byte_end: 34, column_start: 28, column_end: 35, line_start: 1, line_end: 1 }: tokens: 18 | Token { kind: Newline, char_start: 34, char_end: 35, byte_start: 34, byte_end: 35, column_start: 35, column_end: 1, line_start: 1, line_end: 2 }: "\n" 19 | Token { kind: Newline, char_start: 35, char_end: 36, byte_start: 35, byte_end: 36, column_start: 1, column_end: 1, line_start: 2, line_end: 3 }: "\n" 20 | Token { kind: Text, char_start: 36, char_end: 42, byte_start: 36, byte_end: 42, column_start: 1, column_end: 7, line_start: 3, line_end: 3 }: Links: 21 | Token { kind: Space, char_start: 42, char_end: 43, byte_start: 42, byte_end: 43, column_start: 7, column_end: 8, line_start: 3, line_end: 3 }: " " 22 | Token { kind: Bar, char_start: 43, char_end: 44, byte_start: 43, byte_end: 44, column_start: 8, column_end: 9, line_start: 3, line_end: 3 }: | 23 | Token { kind: Text, char_start: 44, char_end: 53, byte_start: 44, byte_end: 53, column_start: 9, column_end: 18, line_start: 3, line_end: 3 }: something 24 | Token { kind: Lparen, char_start: 53, char_end: 54, byte_start: 53, byte_end: 54, column_start: 18, column_end: 19, line_start: 3, line_end: 3 }: ( 25 | Token { kind: Rparen, char_start: 54, char_end: 55, byte_start: 54, byte_end: 55, column_start: 19, column_end: 20, line_start: 3, line_end: 3 }: ) 26 | Token { kind: Bar, char_start: 55, char_end: 56, byte_start: 55, byte_end: 56, column_start: 20, column_end: 21, line_start: 3, line_end: 3 }: | 27 | Token { kind: Newline, char_start: 56, char_end: 57, byte_start: 56, byte_end: 57, column_start: 21, column_end: 1, line_start: 3, line_end: 4 }: "\n" 28 | Token { kind: Newline, char_start: 57, char_end: 58, byte_start: 57, byte_end: 58, column_start: 1, column_end: 1, line_start: 4, line_end: 5 }: "\n" 29 | Token { kind: Text, char_start: 58, char_end: 62, byte_start: 58, byte_end: 62, column_start: 1, column_end: 5, line_start: 5, line_end: 5 }: Link 30 | Token { kind: Space, char_start: 62, char_end: 63, byte_start: 62, byte_end: 63, column_start: 5, column_end: 6, line_start: 5, line_end: 5 }: " " 31 | Token { kind: Text, char_start: 63, char_end: 71, byte_start: 63, byte_end: 71, column_start: 6, column_end: 14, line_start: 5, line_end: 5 }: targets: 32 | Token { kind: Space, char_start: 71, char_end: 72, byte_start: 71, byte_end: 72, column_start: 14, column_end: 15, line_start: 5, line_end: 5 }: " " 33 | Token { kind: Star, char_start: 72, char_end: 73, byte_start: 72, byte_end: 73, column_start: 15, column_end: 16, line_start: 5, line_end: 5 }: * 34 | Token { kind: Text, char_start: 73, char_end: 82, byte_start: 73, byte_end: 82, column_start: 16, column_end: 25, line_start: 5, line_end: 5 }: something 35 | Token { kind: Hyphen, char_start: 82, char_end: 83, byte_start: 82, byte_end: 83, column_start: 25, column_end: 26, line_start: 5, line_end: 5 }: - 36 | Token { kind: Text, char_start: 83, char_end: 87, byte_start: 83, byte_end: 87, column_start: 26, column_end: 30, line_start: 5, line_end: 5 }: here 37 | Token { kind: Star, char_start: 87, char_end: 88, byte_start: 87, byte_end: 88, column_start: 30, column_end: 31, line_start: 5, line_end: 5 }: * 38 | Token { kind: Newline, char_start: 88, char_end: 89, byte_start: 88, byte_end: 89, column_start: 31, column_end: 1, line_start: 5, line_end: 6 }: "\n" 39 | Token { kind: Newline, char_start: 89, char_end: 90, byte_start: 89, byte_end: 90, column_start: 1, column_end: 1, line_start: 6, line_end: 7 }: "\n" 40 | Token { kind: Text, char_start: 90, char_end: 102, byte_start: 90, byte_end: 102, column_start: 1, column_end: 13, line_start: 7, line_end: 7 }: Annotations: 41 | Token { kind: Space, char_start: 102, char_end: 103, byte_start: 102, byte_end: 103, column_start: 13, column_end: 14, line_start: 7, line_end: 7 }: " " 42 | Token { kind: At, char_start: 103, char_end: 104, byte_start: 103, byte_end: 104, column_start: 14, column_end: 15, line_start: 7, line_end: 7 }: @ 43 | Token { kind: Text, char_start: 104, char_end: 112, byte_start: 104, byte_end: 112, column_start: 15, column_end: 23, line_start: 7, line_end: 7 }: mappings 44 | -------------------------------------------------------------------------------- /libs/docvim_lexer/tests/markdown/snapshots/unterminated_br_tag.snap: -------------------------------------------------------------------------------- 1 | Here is an unterminated
"] 8 | edition = "2021" 9 | name = "docvim_macros" 10 | version = "0.1.0" 11 | -------------------------------------------------------------------------------- /libs/docvim_macros/src/lib.rs: -------------------------------------------------------------------------------- 1 | use proc_macro::TokenStream; 2 | use std::fs; 3 | use std::path::PathBuf; 4 | use std::str::FromStr; 5 | 6 | /// Convenience macro for checking all snapshots relative to the current package. 7 | /// 8 | /// Brittle assumptions: 9 | /// 10 | /// - Every usage of the macro contains a root-relative path attribute to find the snapshots 11 | /// (eg. `#[check_snapshots("libs/docvim_parser/tests/snapshots")]`). 12 | /// - Every usage of the macro is attached to a function named `transform`. 13 | /// - Snapshots live in the specified directory or its subdirectories. 14 | /// - There are no symlinks under this directory. 15 | /// - Snapshots are named "$something.snap". 16 | /// - File and directory names are well-formed (eg. valid Unicode) with no spaces(!!!). 17 | /// 18 | #[proc_macro_attribute] 19 | pub fn check_snapshots(attr: TokenStream, item: TokenStream) -> TokenStream { 20 | let mut base = std::env::current_dir().expect("Could not get current directory"); 21 | let path = attr.to_string(); 22 | let path = path.trim_start_matches('"').trim_end_matches('"'); 23 | base.push(path); 24 | 25 | let mut tests = item.to_string(); 26 | 27 | fn walk(dir: &PathBuf, base: &PathBuf, tests: &mut String) { 28 | for entry in fs::read_dir(dir).expect(&format!("Could not read directory {:?}", dir)) { 29 | let entry = entry.expect("Could not access file"); 30 | let file_type = entry.file_type().expect("Could not get file type"); 31 | if file_type.is_symlink() { 32 | panic!("Found symlink"); 33 | } else if file_type.is_dir() { 34 | walk(&entry.path().to_path_buf(), &base, tests); 35 | } else { 36 | let snapshot = String::from(entry.path().to_str().expect("Invalid UTF-8 string")); 37 | let snapshot_name = String::from( 38 | entry 39 | .path() 40 | .strip_prefix(base) 41 | .expect("Base is not prefix of path") 42 | .to_str() 43 | .expect("Invalid UTF-8 string"), 44 | ); 45 | let snapshot_name = snapshot_name.replace("/", "_"); 46 | let snapshot_name = snapshot_name.trim_end_matches(".snap"); 47 | // TODO: panic if snapshot name isn't a valid function identifier; the trouble is, have to wade 48 | // deep into Unicode to actually determine that - see: 49 | // https://doc.rust-lang.org/reference/identifiers.html 50 | 51 | tests.push_str("\n"); 52 | tests.push_str("#[test]\n"); 53 | tests.push_str(&format!( 54 | "fn test_{}() -> Result<(), Box> {{\n", 55 | snapshot_name 56 | )); 57 | tests.push_str(&format!(" assert!(docvim_snapshot::check_snapshot(std::path::Path::new(r####\"{}\"####), &transform, false)?);\n", snapshot)); 58 | tests.push_str(" Ok(())\n"); 59 | tests.push_str("}\n"); 60 | } 61 | } 62 | } 63 | 64 | walk(&base, &base, &mut tests); 65 | 66 | TokenStream::from_str(&tests).expect("Could not generate token stream") 67 | } 68 | -------------------------------------------------------------------------------- /libs/docvim_parser/Cargo.toml: -------------------------------------------------------------------------------- 1 | [dependencies] 2 | docvim_lexer = { path = "../docvim_lexer" } 3 | 4 | [dev-dependencies] 5 | docvim_macros = { path = "../docvim_macros" } 6 | docvim_snapshot = { path = "../docvim_snapshot" } 7 | 8 | [lib] 9 | 10 | [package] 11 | authors = ["Greg Hurrell "] 12 | edition = "2021" 13 | name = "docvim_parser" 14 | version = "0.1.0" 15 | -------------------------------------------------------------------------------- /libs/docvim_parser/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("cargo:rerun-if-changed=tests/snapshots"); 3 | } 4 | -------------------------------------------------------------------------------- /libs/docvim_parser/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod error; 2 | 3 | mod markdown; 4 | mod lua; 5 | mod types; 6 | 7 | pub use lua::LuaParser; 8 | pub use markdown::MarkdownParser; 9 | 10 | #[cfg(test)] 11 | mod tests { 12 | #[test] 13 | fn blinking_light() { 14 | assert!(true); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /libs/docvim_parser/src/markdown.rs: -------------------------------------------------------------------------------- 1 | use crate::types::Location; 2 | 3 | // Lexer token types are imported aliased (all with a "Token" suffix) to avoid collisions with 4 | // parser node types of the same name. 5 | use docvim_lexer::markdown::HeadingKind::Heading1 as Heading1Token; 6 | use docvim_lexer::markdown::HeadingKind::Heading2 as Heading2Token; 7 | use docvim_lexer::markdown::MarkdownToken::At as AtToken; 8 | use docvim_lexer::markdown::MarkdownToken::Backtick as BacktickToken; 9 | use docvim_lexer::markdown::MarkdownToken::Bang as BangToken; 10 | use docvim_lexer::markdown::MarkdownToken::Bar as BarToken; 11 | use docvim_lexer::markdown::MarkdownToken::BlockQuote as BlockQuoteToken; 12 | use docvim_lexer::markdown::MarkdownToken::Break as BreakToken; 13 | use docvim_lexer::markdown::MarkdownToken::CodeFence as CodeFenceToken; 14 | use docvim_lexer::markdown::MarkdownToken::HorizontalRule as HorizontalRuleToken; 15 | use docvim_lexer::markdown::MarkdownToken::Hyphen as HyphenToken; 16 | use docvim_lexer::markdown::MarkdownToken::Lbracket as LbracketToken; 17 | use docvim_lexer::markdown::MarkdownToken::Lparen as LparenToken; 18 | use docvim_lexer::markdown::MarkdownToken::Newline as NewlineToken; 19 | use docvim_lexer::markdown::MarkdownToken::Rbracket as RbracketToken; 20 | use docvim_lexer::markdown::MarkdownToken::Rparen as RparenToken; 21 | use docvim_lexer::markdown::MarkdownToken::Space as SpaceToken; 22 | use docvim_lexer::markdown::MarkdownToken::Star as StarToken; 23 | use docvim_lexer::markdown::MarkdownToken::Text as TextToken; 24 | use docvim_lexer::markdown::{Lexer, MarkdownToken}; 25 | use docvim_lexer::token::Token; 26 | 27 | pub struct Project(Vec); 28 | 29 | pub struct DocBlock { 30 | pub children: Vec, 31 | } 32 | 33 | pub enum BlockElement { 34 | HorizontalRule, 35 | } 36 | 37 | //#[derive(Debug, PartialEq)] 38 | //pub struct Node<'a, T> { 39 | // pub node: T, 40 | // pub location: Location, 41 | //} 42 | 43 | pub struct MarkdownParser<'a> { 44 | lexer: Lexer<'a>, 45 | } 46 | 47 | impl<'a> MarkdownParser<'a> { 48 | pub fn new(input: &'a str) -> Self { 49 | Self { lexer: Lexer::new(input) } 50 | } 51 | 52 | pub fn parse(&mut self) -> Result { 53 | Ok(Project(vec![])) 54 | } 55 | } 56 | 57 | #[derive(Debug)] 58 | pub struct ParserError { 59 | pub line: usize, 60 | pub column: usize, 61 | } 62 | -------------------------------------------------------------------------------- /libs/docvim_parser/src/types.rs: -------------------------------------------------------------------------------- 1 | #[derive(Clone, Copy, Debug, Default, PartialEq)] 2 | pub struct Location { 3 | pub line_start: usize, 4 | pub line_end: usize, 5 | pub column_start: usize, 6 | pub column_end: usize, 7 | } 8 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/mod.rs: -------------------------------------------------------------------------------- 1 | mod snapshots; 2 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots.rs: -------------------------------------------------------------------------------- 1 | use crate::LuaParser; 2 | use docvim_macros::check_snapshots; 3 | 4 | #[check_snapshots("libs/docvim_parser/tests/lua/snapshots")] 5 | fn transform(input: &str) -> String { 6 | let mut parser = LuaParser::new(input); 7 | match parser.parse() { 8 | Ok(ast) => format!("{:#?}", ast), 9 | Err(error) => parser.pretty_error(error), 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/break/when_not_last.snap: -------------------------------------------------------------------------------- 1 | while true do 2 | break 3 | 4 | -- Syntax error, because `break` must be the last statement in a block. 5 | print("Unreachable") 6 | end 7 | 8 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 9 | 10 | | 11 | 4 | -- Syntax error, because `break` must be the last statement in a block. 12 | | ^ unexpected token at 4:3 13 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/comments/block.snap: -------------------------------------------------------------------------------- 1 | --[[ 2 | A block comment. 3 | More block comment. 4 | --]] 5 | 6 | --[[ A block comment on one line. ]] 7 | 8 | --[====[ With an arbitrary number of equals signs. ]====] 9 | 10 | return "We're done here" 11 | 12 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 13 | 14 | Block( 15 | [ 16 | Node { 17 | comments: [ 18 | Comment { 19 | kind: BlockComment, 20 | content: "--[[\n A block comment.\n More block comment.\n--]]", 21 | location: Location { 22 | line_start: 1, 23 | line_end: 4, 24 | column_start: 1, 25 | column_end: 5, 26 | }, 27 | }, 28 | Comment { 29 | kind: BlockComment, 30 | content: "--[[ A block comment on one line. ]]", 31 | location: Location { 32 | line_start: 6, 33 | line_end: 6, 34 | column_start: 1, 35 | column_end: 37, 36 | }, 37 | }, 38 | Comment { 39 | kind: BlockComment, 40 | content: "--[====[ With an arbitrary number of equals signs. ]====]", 41 | location: Location { 42 | line_start: 8, 43 | line_end: 8, 44 | column_start: 1, 45 | column_end: 58, 46 | }, 47 | }, 48 | ], 49 | node: Return( 50 | Some( 51 | [ 52 | Node { 53 | comments: [], 54 | node: CookedStr( 55 | "We're done here", 56 | ), 57 | location: Location { 58 | line_start: 10, 59 | line_end: 10, 60 | column_start: 8, 61 | column_end: 25, 62 | }, 63 | }, 64 | ], 65 | ), 66 | ), 67 | location: Location { 68 | line_start: 10, 69 | line_end: 10, 70 | column_start: 1, 71 | column_end: 25, 72 | }, 73 | }, 74 | ], 75 | ) 76 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/comments/line.snap: -------------------------------------------------------------------------------- 1 | -- A line comment. 2 | 3 | local thing = true 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [ 11 | Comment { 12 | kind: LineComment, 13 | content: "-- A line comment.\n", 14 | location: Location { 15 | line_start: 1, 16 | line_end: 2, 17 | column_start: 1, 18 | column_end: 1, 19 | }, 20 | }, 21 | ], 22 | node: LocalDeclaration { 23 | namelist: [ 24 | Name( 25 | "thing", 26 | ), 27 | ], 28 | explist: [ 29 | Node { 30 | comments: [], 31 | node: True, 32 | location: Location { 33 | line_start: 3, 34 | line_end: 3, 35 | column_start: 15, 36 | column_end: 19, 37 | }, 38 | }, 39 | ], 40 | }, 41 | location: Location { 42 | line_start: 3, 43 | line_end: 3, 44 | column_start: 1, 45 | column_end: 19, 46 | }, 47 | }, 48 | ], 49 | ) 50 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/do_blocks/basic.snap: -------------------------------------------------------------------------------- 1 | do 2 | local item = foo.bar 3 | end 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [], 11 | node: DoBlock( 12 | Block( 13 | [ 14 | Node { 15 | comments: [], 16 | node: LocalDeclaration { 17 | namelist: [ 18 | Name( 19 | "item", 20 | ), 21 | ], 22 | explist: [ 23 | Node { 24 | comments: [], 25 | node: Index { 26 | pexp: Node { 27 | comments: [], 28 | node: NamedVar( 29 | "foo", 30 | ), 31 | location: Location { 32 | line_start: 2, 33 | line_end: 2, 34 | column_start: 16, 35 | column_end: 19, 36 | }, 37 | }, 38 | kexp: Node { 39 | comments: [], 40 | node: RawStr( 41 | "bar", 42 | ), 43 | location: Location { 44 | line_start: 0, 45 | line_end: 0, 46 | column_start: 0, 47 | column_end: 0, 48 | }, 49 | }, 50 | }, 51 | location: Location { 52 | line_start: 2, 53 | line_end: 0, 54 | column_start: 16, 55 | column_end: 0, 56 | }, 57 | }, 58 | ], 59 | }, 60 | location: Location { 61 | line_start: 2, 62 | line_end: 0, 63 | column_start: 3, 64 | column_end: 0, 65 | }, 66 | }, 67 | ], 68 | ), 69 | ), 70 | location: Location { 71 | line_start: 1, 72 | line_end: 3, 73 | column_start: 1, 74 | column_end: 4, 75 | }, 76 | }, 77 | ], 78 | ) 79 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/do_blocks/empty.snap: -------------------------------------------------------------------------------- 1 | do 2 | end 3 | 4 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 5 | 6 | Block( 7 | [ 8 | Node { 9 | comments: [], 10 | node: DoBlock( 11 | Block( 12 | [], 13 | ), 14 | ), 15 | location: Location { 16 | line_start: 1, 17 | line_end: 2, 18 | column_start: 1, 19 | column_end: 4, 20 | }, 21 | }, 22 | ], 23 | ) 24 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/do_blocks/multiple_statements.snap: -------------------------------------------------------------------------------- 1 | do 2 | local foo = 'foo' 3 | local bar = 'bar' 4 | end 5 | 6 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 7 | 8 | Block( 9 | [ 10 | Node { 11 | comments: [], 12 | node: DoBlock( 13 | Block( 14 | [ 15 | Node { 16 | comments: [], 17 | node: LocalDeclaration { 18 | namelist: [ 19 | Name( 20 | "foo", 21 | ), 22 | ], 23 | explist: [ 24 | Node { 25 | comments: [], 26 | node: CookedStr( 27 | "foo", 28 | ), 29 | location: Location { 30 | line_start: 2, 31 | line_end: 2, 32 | column_start: 15, 33 | column_end: 20, 34 | }, 35 | }, 36 | ], 37 | }, 38 | location: Location { 39 | line_start: 2, 40 | line_end: 2, 41 | column_start: 3, 42 | column_end: 20, 43 | }, 44 | }, 45 | Node { 46 | comments: [], 47 | node: LocalDeclaration { 48 | namelist: [ 49 | Name( 50 | "bar", 51 | ), 52 | ], 53 | explist: [ 54 | Node { 55 | comments: [], 56 | node: CookedStr( 57 | "bar", 58 | ), 59 | location: Location { 60 | line_start: 3, 61 | line_end: 3, 62 | column_start: 15, 63 | column_end: 20, 64 | }, 65 | }, 66 | ], 67 | }, 68 | location: Location { 69 | line_start: 3, 70 | line_end: 3, 71 | column_start: 3, 72 | column_end: 20, 73 | }, 74 | }, 75 | ], 76 | ), 77 | ), 78 | location: Location { 79 | line_start: 1, 80 | line_end: 4, 81 | column_start: 1, 82 | column_end: 4, 83 | }, 84 | }, 85 | ], 86 | ) 87 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/do_blocks/nested.snap: -------------------------------------------------------------------------------- 1 | do 2 | do 3 | local one = 1 4 | end 5 | end 6 | 7 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 8 | 9 | Block( 10 | [ 11 | Node { 12 | comments: [], 13 | node: DoBlock( 14 | Block( 15 | [ 16 | Node { 17 | comments: [], 18 | node: DoBlock( 19 | Block( 20 | [ 21 | Node { 22 | comments: [], 23 | node: LocalDeclaration { 24 | namelist: [ 25 | Name( 26 | "one", 27 | ), 28 | ], 29 | explist: [ 30 | Node { 31 | comments: [], 32 | node: Number( 33 | "1", 34 | ), 35 | location: Location { 36 | line_start: 3, 37 | line_end: 3, 38 | column_start: 17, 39 | column_end: 18, 40 | }, 41 | }, 42 | ], 43 | }, 44 | location: Location { 45 | line_start: 3, 46 | line_end: 3, 47 | column_start: 5, 48 | column_end: 18, 49 | }, 50 | }, 51 | ], 52 | ), 53 | ), 54 | location: Location { 55 | line_start: 2, 56 | line_end: 4, 57 | column_start: 3, 58 | column_end: 6, 59 | }, 60 | }, 61 | ], 62 | ), 63 | ), 64 | location: Location { 65 | line_start: 1, 66 | line_end: 5, 67 | column_start: 1, 68 | column_end: 4, 69 | }, 70 | }, 71 | ], 72 | ) 73 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/do_blocks/unterminated.snap: -------------------------------------------------------------------------------- 1 | do 2 | local item = foo.bar 3 | -- Will error because of missing "end" keyword. 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | | 8 | 3 | -- Will error because of missing "end" keyword. 9 | | ^ unexpected end-of-input at 3:50 10 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/dot_expressions/basic.snap: -------------------------------------------------------------------------------- 1 | local item = foo.bar 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | Block( 6 | [ 7 | Node { 8 | comments: [], 9 | node: LocalDeclaration { 10 | namelist: [ 11 | Name( 12 | "item", 13 | ), 14 | ], 15 | explist: [ 16 | Node { 17 | comments: [], 18 | node: Index { 19 | pexp: Node { 20 | comments: [], 21 | node: NamedVar( 22 | "foo", 23 | ), 24 | location: Location { 25 | line_start: 1, 26 | line_end: 1, 27 | column_start: 14, 28 | column_end: 17, 29 | }, 30 | }, 31 | kexp: Node { 32 | comments: [], 33 | node: RawStr( 34 | "bar", 35 | ), 36 | location: Location { 37 | line_start: 0, 38 | line_end: 0, 39 | column_start: 0, 40 | column_end: 0, 41 | }, 42 | }, 43 | }, 44 | location: Location { 45 | line_start: 1, 46 | line_end: 0, 47 | column_start: 14, 48 | column_end: 0, 49 | }, 50 | }, 51 | ], 52 | }, 53 | location: Location { 54 | line_start: 1, 55 | line_end: 0, 56 | column_start: 1, 57 | column_end: 0, 58 | }, 59 | }, 60 | ], 61 | ) 62 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/dot_expressions/chained.snap: -------------------------------------------------------------------------------- 1 | local item = foo.bar.baz 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | Block( 6 | [ 7 | Node { 8 | comments: [], 9 | node: LocalDeclaration { 10 | namelist: [ 11 | Name( 12 | "item", 13 | ), 14 | ], 15 | explist: [ 16 | Node { 17 | comments: [], 18 | node: Index { 19 | pexp: Node { 20 | comments: [], 21 | node: Index { 22 | pexp: Node { 23 | comments: [], 24 | node: NamedVar( 25 | "foo", 26 | ), 27 | location: Location { 28 | line_start: 1, 29 | line_end: 1, 30 | column_start: 14, 31 | column_end: 17, 32 | }, 33 | }, 34 | kexp: Node { 35 | comments: [], 36 | node: RawStr( 37 | "bar", 38 | ), 39 | location: Location { 40 | line_start: 0, 41 | line_end: 0, 42 | column_start: 0, 43 | column_end: 0, 44 | }, 45 | }, 46 | }, 47 | location: Location { 48 | line_start: 1, 49 | line_end: 0, 50 | column_start: 14, 51 | column_end: 0, 52 | }, 53 | }, 54 | kexp: Node { 55 | comments: [], 56 | node: RawStr( 57 | "baz", 58 | ), 59 | location: Location { 60 | line_start: 0, 61 | line_end: 0, 62 | column_start: 0, 63 | column_end: 0, 64 | }, 65 | }, 66 | }, 67 | location: Location { 68 | line_start: 1, 69 | line_end: 0, 70 | column_start: 14, 71 | column_end: 0, 72 | }, 73 | }, 74 | ], 75 | }, 76 | location: Location { 77 | line_start: 1, 78 | line_end: 0, 79 | column_start: 1, 80 | column_end: 0, 81 | }, 82 | }, 83 | ], 84 | ) 85 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/errors/basic.snap: -------------------------------------------------------------------------------- 1 | function hello() 2 | if something 3 | print("forgot the then") 4 | end 5 | end 6 | 7 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 8 | 9 | | 10 | 3 | print("forgot the then") 11 | | ^ unexpected token at 3:5 12 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/errors/nested.snap: -------------------------------------------------------------------------------- 1 | function hello() 2 | if something then 3 | if another then 4 | if more then 5 | if final 6 | print("forgot the then") 7 | end 8 | end 9 | end 10 | end 11 | end 12 | 13 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 14 | 15 | | 16 | 6 | print("forgot the then") 17 | | ^ unexpected token at 6:11 18 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/errors/unexpected_token.snap: -------------------------------------------------------------------------------- 1 | local x = { 1 }} 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | 1 | local x = { 1 }} 6 | | ^ unexpected token at 1:16 7 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/errors/unterminated_list.snap: -------------------------------------------------------------------------------- 1 | local x = { 1, 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | 1 | local x = { 1, 6 | | ^ unexpected end-of-input at 1:15 7 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/for/basic.snap: -------------------------------------------------------------------------------- 1 | for i = 1, 10 do 2 | print(i) 3 | end 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [], 11 | node: For { 12 | name: Name( 13 | "i", 14 | ), 15 | startexp: Node { 16 | comments: [], 17 | node: Number( 18 | "1", 19 | ), 20 | location: Location { 21 | line_start: 1, 22 | line_end: 1, 23 | column_start: 9, 24 | column_end: 10, 25 | }, 26 | }, 27 | endexp: Node { 28 | comments: [], 29 | node: Number( 30 | "10", 31 | ), 32 | location: Location { 33 | line_start: 1, 34 | line_end: 1, 35 | column_start: 12, 36 | column_end: 14, 37 | }, 38 | }, 39 | stepexp: None, 40 | block: Block( 41 | [ 42 | Node { 43 | comments: [], 44 | node: DoBlock( 45 | Block( 46 | [ 47 | Node { 48 | comments: [], 49 | node: FunctionCallStatement { 50 | pexp: Node { 51 | comments: [], 52 | node: NamedVar( 53 | "print", 54 | ), 55 | location: Location { 56 | line_start: 2, 57 | line_end: 2, 58 | column_start: 3, 59 | column_end: 8, 60 | }, 61 | }, 62 | args: [ 63 | Node { 64 | comments: [], 65 | node: NamedVar( 66 | "i", 67 | ), 68 | location: Location { 69 | line_start: 2, 70 | line_end: 2, 71 | column_start: 9, 72 | column_end: 10, 73 | }, 74 | }, 75 | ], 76 | }, 77 | location: Location { 78 | line_start: 2, 79 | line_end: 2, 80 | column_start: 3, 81 | column_end: 11, 82 | }, 83 | }, 84 | ], 85 | ), 86 | ), 87 | location: Location { 88 | line_start: 1, 89 | line_end: 3, 90 | column_start: 15, 91 | column_end: 4, 92 | }, 93 | }, 94 | ], 95 | ), 96 | }, 97 | location: Location { 98 | line_start: 1, 99 | line_end: 3, 100 | column_start: 1, 101 | column_end: 4, 102 | }, 103 | }, 104 | ], 105 | ) 106 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/for_in/basic.snap: -------------------------------------------------------------------------------- 1 | for x, y in a, b do 2 | x(y) 3 | end 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [], 11 | node: ForIn { 12 | namelist: [ 13 | Name( 14 | "x", 15 | ), 16 | Name( 17 | "y", 18 | ), 19 | ], 20 | explist: [ 21 | Node { 22 | comments: [], 23 | node: NamedVar( 24 | "a", 25 | ), 26 | location: Location { 27 | line_start: 1, 28 | line_end: 1, 29 | column_start: 13, 30 | column_end: 14, 31 | }, 32 | }, 33 | Node { 34 | comments: [], 35 | node: NamedVar( 36 | "b", 37 | ), 38 | location: Location { 39 | line_start: 1, 40 | line_end: 1, 41 | column_start: 16, 42 | column_end: 17, 43 | }, 44 | }, 45 | ], 46 | block: Block( 47 | [ 48 | Node { 49 | comments: [], 50 | node: FunctionCallStatement { 51 | pexp: Node { 52 | comments: [], 53 | node: NamedVar( 54 | "x", 55 | ), 56 | location: Location { 57 | line_start: 2, 58 | line_end: 2, 59 | column_start: 3, 60 | column_end: 4, 61 | }, 62 | }, 63 | args: [ 64 | Node { 65 | comments: [], 66 | node: NamedVar( 67 | "y", 68 | ), 69 | location: Location { 70 | line_start: 2, 71 | line_end: 2, 72 | column_start: 5, 73 | column_end: 6, 74 | }, 75 | }, 76 | ], 77 | }, 78 | location: Location { 79 | line_start: 2, 80 | line_end: 2, 81 | column_start: 3, 82 | column_end: 7, 83 | }, 84 | }, 85 | ], 86 | ), 87 | }, 88 | location: Location { 89 | line_start: 1, 90 | line_end: 3, 91 | column_start: 1, 92 | column_end: 4, 93 | }, 94 | }, 95 | ], 96 | ) 97 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/function_calls/empty.snap: -------------------------------------------------------------------------------- 1 | calculate() 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | Block( 6 | [ 7 | Node { 8 | comments: [], 9 | node: FunctionCallStatement { 10 | pexp: Node { 11 | comments: [], 12 | node: NamedVar( 13 | "calculate", 14 | ), 15 | location: Location { 16 | line_start: 1, 17 | line_end: 1, 18 | column_start: 1, 19 | column_end: 10, 20 | }, 21 | }, 22 | args: [], 23 | }, 24 | location: Location { 25 | line_start: 1, 26 | line_end: 1, 27 | column_start: 1, 28 | column_end: 12, 29 | }, 30 | }, 31 | ], 32 | ) 33 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/function_calls/expressions.snap: -------------------------------------------------------------------------------- 1 | -- ie. function call in expression position, rather than as a standalone FunctionCallStatement 2 | 3 | local result = add(1, 2, "three") 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [ 11 | Comment { 12 | kind: LineComment, 13 | content: "-- ie. function call in expression position, rather than as a standalone FunctionCallStatement\n", 14 | location: Location { 15 | line_start: 1, 16 | line_end: 2, 17 | column_start: 1, 18 | column_end: 1, 19 | }, 20 | }, 21 | ], 22 | node: LocalDeclaration { 23 | namelist: [ 24 | Name( 25 | "result", 26 | ), 27 | ], 28 | explist: [ 29 | Node { 30 | comments: [], 31 | node: FunctionCall { 32 | pexp: Node { 33 | comments: [], 34 | node: NamedVar( 35 | "add", 36 | ), 37 | location: Location { 38 | line_start: 3, 39 | line_end: 3, 40 | column_start: 16, 41 | column_end: 19, 42 | }, 43 | }, 44 | args: [ 45 | Node { 46 | comments: [], 47 | node: Number( 48 | "1", 49 | ), 50 | location: Location { 51 | line_start: 3, 52 | line_end: 3, 53 | column_start: 20, 54 | column_end: 21, 55 | }, 56 | }, 57 | Node { 58 | comments: [], 59 | node: Number( 60 | "2", 61 | ), 62 | location: Location { 63 | line_start: 3, 64 | line_end: 3, 65 | column_start: 23, 66 | column_end: 24, 67 | }, 68 | }, 69 | Node { 70 | comments: [], 71 | node: CookedStr( 72 | "three", 73 | ), 74 | location: Location { 75 | line_start: 3, 76 | line_end: 3, 77 | column_start: 26, 78 | column_end: 33, 79 | }, 80 | }, 81 | ], 82 | }, 83 | location: Location { 84 | line_start: 3, 85 | line_end: 3, 86 | column_start: 16, 87 | column_end: 34, 88 | }, 89 | }, 90 | ], 91 | }, 92 | location: Location { 93 | line_start: 3, 94 | line_end: 3, 95 | column_start: 1, 96 | column_end: 34, 97 | }, 98 | }, 99 | ], 100 | ) 101 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/function_calls/multiple_arguments.snap: -------------------------------------------------------------------------------- 1 | add(1, 2, "three") 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | Block( 6 | [ 7 | Node { 8 | comments: [], 9 | node: FunctionCallStatement { 10 | pexp: Node { 11 | comments: [], 12 | node: NamedVar( 13 | "add", 14 | ), 15 | location: Location { 16 | line_start: 1, 17 | line_end: 1, 18 | column_start: 1, 19 | column_end: 4, 20 | }, 21 | }, 22 | args: [ 23 | Node { 24 | comments: [], 25 | node: Number( 26 | "1", 27 | ), 28 | location: Location { 29 | line_start: 1, 30 | line_end: 1, 31 | column_start: 5, 32 | column_end: 6, 33 | }, 34 | }, 35 | Node { 36 | comments: [], 37 | node: Number( 38 | "2", 39 | ), 40 | location: Location { 41 | line_start: 1, 42 | line_end: 1, 43 | column_start: 8, 44 | column_end: 9, 45 | }, 46 | }, 47 | Node { 48 | comments: [], 49 | node: CookedStr( 50 | "three", 51 | ), 52 | location: Location { 53 | line_start: 1, 54 | line_end: 1, 55 | column_start: 11, 56 | column_end: 18, 57 | }, 58 | }, 59 | ], 60 | }, 61 | location: Location { 62 | line_start: 1, 63 | line_end: 1, 64 | column_start: 1, 65 | column_end: 19, 66 | }, 67 | }, 68 | ], 69 | ) 70 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/function_calls/nested.snap: -------------------------------------------------------------------------------- 1 | calculate(intermediate(inner())) 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | Block( 6 | [ 7 | Node { 8 | comments: [], 9 | node: FunctionCallStatement { 10 | pexp: Node { 11 | comments: [], 12 | node: NamedVar( 13 | "calculate", 14 | ), 15 | location: Location { 16 | line_start: 1, 17 | line_end: 1, 18 | column_start: 1, 19 | column_end: 10, 20 | }, 21 | }, 22 | args: [ 23 | Node { 24 | comments: [], 25 | node: FunctionCall { 26 | pexp: Node { 27 | comments: [], 28 | node: NamedVar( 29 | "intermediate", 30 | ), 31 | location: Location { 32 | line_start: 1, 33 | line_end: 1, 34 | column_start: 11, 35 | column_end: 23, 36 | }, 37 | }, 38 | args: [ 39 | Node { 40 | comments: [], 41 | node: FunctionCall { 42 | pexp: Node { 43 | comments: [], 44 | node: NamedVar( 45 | "inner", 46 | ), 47 | location: Location { 48 | line_start: 1, 49 | line_end: 1, 50 | column_start: 24, 51 | column_end: 29, 52 | }, 53 | }, 54 | args: [], 55 | }, 56 | location: Location { 57 | line_start: 1, 58 | line_end: 1, 59 | column_start: 24, 60 | column_end: 31, 61 | }, 62 | }, 63 | ], 64 | }, 65 | location: Location { 66 | line_start: 1, 67 | line_end: 1, 68 | column_start: 11, 69 | column_end: 32, 70 | }, 71 | }, 72 | ], 73 | }, 74 | location: Location { 75 | line_start: 1, 76 | line_end: 1, 77 | column_start: 1, 78 | column_end: 33, 79 | }, 80 | }, 81 | ], 82 | ) 83 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/function_calls/on_same_line.snap: -------------------------------------------------------------------------------- 1 | print(1) print(2) print(3) 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | Block( 6 | [ 7 | Node { 8 | comments: [], 9 | node: FunctionCallStatement { 10 | pexp: Node { 11 | comments: [], 12 | node: NamedVar( 13 | "print", 14 | ), 15 | location: Location { 16 | line_start: 1, 17 | line_end: 1, 18 | column_start: 1, 19 | column_end: 6, 20 | }, 21 | }, 22 | args: [ 23 | Node { 24 | comments: [], 25 | node: Number( 26 | "1", 27 | ), 28 | location: Location { 29 | line_start: 1, 30 | line_end: 1, 31 | column_start: 7, 32 | column_end: 8, 33 | }, 34 | }, 35 | ], 36 | }, 37 | location: Location { 38 | line_start: 1, 39 | line_end: 1, 40 | column_start: 1, 41 | column_end: 9, 42 | }, 43 | }, 44 | Node { 45 | comments: [], 46 | node: FunctionCallStatement { 47 | pexp: Node { 48 | comments: [], 49 | node: NamedVar( 50 | "print", 51 | ), 52 | location: Location { 53 | line_start: 1, 54 | line_end: 1, 55 | column_start: 10, 56 | column_end: 15, 57 | }, 58 | }, 59 | args: [ 60 | Node { 61 | comments: [], 62 | node: Number( 63 | "2", 64 | ), 65 | location: Location { 66 | line_start: 1, 67 | line_end: 1, 68 | column_start: 16, 69 | column_end: 17, 70 | }, 71 | }, 72 | ], 73 | }, 74 | location: Location { 75 | line_start: 1, 76 | line_end: 1, 77 | column_start: 10, 78 | column_end: 18, 79 | }, 80 | }, 81 | Node { 82 | comments: [], 83 | node: FunctionCallStatement { 84 | pexp: Node { 85 | comments: [], 86 | node: NamedVar( 87 | "print", 88 | ), 89 | location: Location { 90 | line_start: 1, 91 | line_end: 1, 92 | column_start: 19, 93 | column_end: 24, 94 | }, 95 | }, 96 | args: [ 97 | Node { 98 | comments: [], 99 | node: Number( 100 | "3", 101 | ), 102 | location: Location { 103 | line_start: 1, 104 | line_end: 1, 105 | column_start: 25, 106 | column_end: 26, 107 | }, 108 | }, 109 | ], 110 | }, 111 | location: Location { 112 | line_start: 1, 113 | line_end: 1, 114 | column_start: 19, 115 | column_end: 27, 116 | }, 117 | }, 118 | ], 119 | ) 120 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/function_calls/semi_colons.snap: -------------------------------------------------------------------------------- 1 | foo(); bar(true); baz(nil); 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | Block( 6 | [ 7 | Node { 8 | comments: [], 9 | node: FunctionCallStatement { 10 | pexp: Node { 11 | comments: [], 12 | node: NamedVar( 13 | "foo", 14 | ), 15 | location: Location { 16 | line_start: 1, 17 | line_end: 1, 18 | column_start: 1, 19 | column_end: 4, 20 | }, 21 | }, 22 | args: [], 23 | }, 24 | location: Location { 25 | line_start: 1, 26 | line_end: 1, 27 | column_start: 1, 28 | column_end: 6, 29 | }, 30 | }, 31 | Node { 32 | comments: [], 33 | node: FunctionCallStatement { 34 | pexp: Node { 35 | comments: [], 36 | node: NamedVar( 37 | "bar", 38 | ), 39 | location: Location { 40 | line_start: 1, 41 | line_end: 1, 42 | column_start: 8, 43 | column_end: 11, 44 | }, 45 | }, 46 | args: [ 47 | Node { 48 | comments: [], 49 | node: True, 50 | location: Location { 51 | line_start: 1, 52 | line_end: 1, 53 | column_start: 12, 54 | column_end: 16, 55 | }, 56 | }, 57 | ], 58 | }, 59 | location: Location { 60 | line_start: 1, 61 | line_end: 1, 62 | column_start: 8, 63 | column_end: 17, 64 | }, 65 | }, 66 | Node { 67 | comments: [], 68 | node: FunctionCallStatement { 69 | pexp: Node { 70 | comments: [], 71 | node: NamedVar( 72 | "baz", 73 | ), 74 | location: Location { 75 | line_start: 1, 76 | line_end: 1, 77 | column_start: 19, 78 | column_end: 22, 79 | }, 80 | }, 81 | args: [ 82 | Node { 83 | comments: [], 84 | node: Nil, 85 | location: Location { 86 | line_start: 1, 87 | line_end: 1, 88 | column_start: 23, 89 | column_end: 26, 90 | }, 91 | }, 92 | ], 93 | }, 94 | location: Location { 95 | line_start: 1, 96 | line_end: 1, 97 | column_start: 19, 98 | column_end: 27, 99 | }, 100 | }, 101 | ], 102 | ) 103 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/function_calls/single_argument.snap: -------------------------------------------------------------------------------- 1 | len("contents") 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | Block( 6 | [ 7 | Node { 8 | comments: [], 9 | node: FunctionCallStatement { 10 | pexp: Node { 11 | comments: [], 12 | node: NamedVar( 13 | "len", 14 | ), 15 | location: Location { 16 | line_start: 1, 17 | line_end: 1, 18 | column_start: 1, 19 | column_end: 4, 20 | }, 21 | }, 22 | args: [ 23 | Node { 24 | comments: [], 25 | node: CookedStr( 26 | "contents", 27 | ), 28 | location: Location { 29 | line_start: 1, 30 | line_end: 1, 31 | column_start: 5, 32 | column_end: 15, 33 | }, 34 | }, 35 | ], 36 | }, 37 | location: Location { 38 | line_start: 1, 39 | line_end: 1, 40 | column_start: 1, 41 | column_end: 16, 42 | }, 43 | }, 44 | ], 45 | ) 46 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/function_calls/string_arguments.snap: -------------------------------------------------------------------------------- 1 | foo 'single' 2 | bar "double" 3 | baz [[long]] 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [], 11 | node: FunctionCallStatement { 12 | pexp: Node { 13 | comments: [], 14 | node: NamedVar( 15 | "foo", 16 | ), 17 | location: Location { 18 | line_start: 1, 19 | line_end: 1, 20 | column_start: 1, 21 | column_end: 4, 22 | }, 23 | }, 24 | args: [ 25 | Node { 26 | comments: [], 27 | node: CookedStr( 28 | "single", 29 | ), 30 | location: Location { 31 | line_start: 1, 32 | line_end: 1, 33 | column_start: 5, 34 | column_end: 13, 35 | }, 36 | }, 37 | ], 38 | }, 39 | location: Location { 40 | line_start: 1, 41 | line_end: 1, 42 | column_start: 1, 43 | column_end: 13, 44 | }, 45 | }, 46 | Node { 47 | comments: [], 48 | node: FunctionCallStatement { 49 | pexp: Node { 50 | comments: [], 51 | node: NamedVar( 52 | "bar", 53 | ), 54 | location: Location { 55 | line_start: 2, 56 | line_end: 2, 57 | column_start: 1, 58 | column_end: 4, 59 | }, 60 | }, 61 | args: [ 62 | Node { 63 | comments: [], 64 | node: CookedStr( 65 | "double", 66 | ), 67 | location: Location { 68 | line_start: 2, 69 | line_end: 2, 70 | column_start: 5, 71 | column_end: 13, 72 | }, 73 | }, 74 | ], 75 | }, 76 | location: Location { 77 | line_start: 2, 78 | line_end: 2, 79 | column_start: 1, 80 | column_end: 13, 81 | }, 82 | }, 83 | Node { 84 | comments: [], 85 | node: FunctionCallStatement { 86 | pexp: Node { 87 | comments: [], 88 | node: NamedVar( 89 | "baz", 90 | ), 91 | location: Location { 92 | line_start: 3, 93 | line_end: 3, 94 | column_start: 1, 95 | column_end: 4, 96 | }, 97 | }, 98 | args: [ 99 | Node { 100 | comments: [], 101 | node: RawStr( 102 | "long", 103 | ), 104 | location: Location { 105 | line_start: 3, 106 | line_end: 3, 107 | column_start: 5, 108 | column_end: 13, 109 | }, 110 | }, 111 | ], 112 | }, 113 | location: Location { 114 | line_start: 3, 115 | line_end: 3, 116 | column_start: 1, 117 | column_end: 13, 118 | }, 119 | }, 120 | ], 121 | ) 122 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/function_expressions/basic.snap: -------------------------------------------------------------------------------- 1 | local x = function() 2 | foo() 3 | end 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [], 11 | node: LocalDeclaration { 12 | namelist: [ 13 | Name( 14 | "x", 15 | ), 16 | ], 17 | explist: [ 18 | Node { 19 | comments: [], 20 | node: Function { 21 | parlist: [], 22 | varargs: false, 23 | block: Block( 24 | [ 25 | Node { 26 | comments: [], 27 | node: FunctionCallStatement { 28 | pexp: Node { 29 | comments: [], 30 | node: NamedVar( 31 | "foo", 32 | ), 33 | location: Location { 34 | line_start: 2, 35 | line_end: 2, 36 | column_start: 3, 37 | column_end: 6, 38 | }, 39 | }, 40 | args: [], 41 | }, 42 | location: Location { 43 | line_start: 2, 44 | line_end: 2, 45 | column_start: 3, 46 | column_end: 8, 47 | }, 48 | }, 49 | ], 50 | ), 51 | }, 52 | location: Location { 53 | line_start: 1, 54 | line_end: 3, 55 | column_start: 11, 56 | column_end: 4, 57 | }, 58 | }, 59 | ], 60 | }, 61 | location: Location { 62 | line_start: 1, 63 | line_end: 3, 64 | column_start: 1, 65 | column_end: 4, 66 | }, 67 | }, 68 | ], 69 | ) 70 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/function_expressions/with_params.snap: -------------------------------------------------------------------------------- 1 | local x = function(a, ...) 2 | a(...) 3 | end 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [], 11 | node: LocalDeclaration { 12 | namelist: [ 13 | Name( 14 | "x", 15 | ), 16 | ], 17 | explist: [ 18 | Node { 19 | comments: [], 20 | node: Function { 21 | parlist: [ 22 | Name( 23 | "a", 24 | ), 25 | ], 26 | varargs: true, 27 | block: Block( 28 | [ 29 | Node { 30 | comments: [], 31 | node: FunctionCallStatement { 32 | pexp: Node { 33 | comments: [], 34 | node: NamedVar( 35 | "a", 36 | ), 37 | location: Location { 38 | line_start: 2, 39 | line_end: 2, 40 | column_start: 3, 41 | column_end: 4, 42 | }, 43 | }, 44 | args: [ 45 | Node { 46 | comments: [], 47 | node: Varargs, 48 | location: Location { 49 | line_start: 2, 50 | line_end: 2, 51 | column_start: 5, 52 | column_end: 8, 53 | }, 54 | }, 55 | ], 56 | }, 57 | location: Location { 58 | line_start: 2, 59 | line_end: 2, 60 | column_start: 3, 61 | column_end: 9, 62 | }, 63 | }, 64 | ], 65 | ), 66 | }, 67 | location: Location { 68 | line_start: 1, 69 | line_end: 3, 70 | column_start: 11, 71 | column_end: 4, 72 | }, 73 | }, 74 | ], 75 | }, 76 | location: Location { 77 | line_start: 1, 78 | line_end: 3, 79 | column_start: 1, 80 | column_end: 4, 81 | }, 82 | }, 83 | ], 84 | ) 85 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/function_statements/basic.snap: -------------------------------------------------------------------------------- 1 | function simple() 2 | foo() 3 | end 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [], 11 | node: FunctionDeclaration { 12 | name: [ 13 | Name( 14 | "simple", 15 | ), 16 | ], 17 | method: None, 18 | parlist: [], 19 | varargs: false, 20 | block: Block( 21 | [ 22 | Node { 23 | comments: [], 24 | node: FunctionCallStatement { 25 | pexp: Node { 26 | comments: [], 27 | node: NamedVar( 28 | "foo", 29 | ), 30 | location: Location { 31 | line_start: 2, 32 | line_end: 2, 33 | column_start: 3, 34 | column_end: 6, 35 | }, 36 | }, 37 | args: [], 38 | }, 39 | location: Location { 40 | line_start: 2, 41 | line_end: 2, 42 | column_start: 3, 43 | column_end: 8, 44 | }, 45 | }, 46 | ], 47 | ), 48 | }, 49 | location: Location { 50 | line_start: 1, 51 | line_end: 3, 52 | column_start: 1, 53 | column_end: 4, 54 | }, 55 | }, 56 | ], 57 | ) 58 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/function_statements/complex.snap: -------------------------------------------------------------------------------- 1 | function a.b.c:d(e, f, ...) 2 | e(f)(...) 3 | end 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [], 11 | node: FunctionDeclaration { 12 | name: [ 13 | Name( 14 | "a", 15 | ), 16 | Name( 17 | "b", 18 | ), 19 | Name( 20 | "c", 21 | ), 22 | ], 23 | method: Some( 24 | Name( 25 | "d", 26 | ), 27 | ), 28 | parlist: [ 29 | Name( 30 | "e", 31 | ), 32 | Name( 33 | "f", 34 | ), 35 | ], 36 | varargs: true, 37 | block: Block( 38 | [ 39 | Node { 40 | comments: [], 41 | node: FunctionCallStatement { 42 | pexp: Node { 43 | comments: [], 44 | node: FunctionCall { 45 | pexp: Node { 46 | comments: [], 47 | node: NamedVar( 48 | "e", 49 | ), 50 | location: Location { 51 | line_start: 2, 52 | line_end: 2, 53 | column_start: 3, 54 | column_end: 4, 55 | }, 56 | }, 57 | args: [ 58 | Node { 59 | comments: [], 60 | node: NamedVar( 61 | "f", 62 | ), 63 | location: Location { 64 | line_start: 2, 65 | line_end: 2, 66 | column_start: 5, 67 | column_end: 6, 68 | }, 69 | }, 70 | ], 71 | }, 72 | location: Location { 73 | line_start: 2, 74 | line_end: 2, 75 | column_start: 3, 76 | column_end: 7, 77 | }, 78 | }, 79 | args: [ 80 | Node { 81 | comments: [], 82 | node: Varargs, 83 | location: Location { 84 | line_start: 2, 85 | line_end: 2, 86 | column_start: 8, 87 | column_end: 11, 88 | }, 89 | }, 90 | ], 91 | }, 92 | location: Location { 93 | line_start: 2, 94 | line_end: 2, 95 | column_start: 3, 96 | column_end: 12, 97 | }, 98 | }, 99 | ], 100 | ), 101 | }, 102 | location: Location { 103 | line_start: 1, 104 | line_end: 3, 105 | column_start: 1, 106 | column_end: 4, 107 | }, 108 | }, 109 | ], 110 | ) 111 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/function_statements/empty.snap: -------------------------------------------------------------------------------- 1 | function empty() 2 | end 3 | 4 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 5 | 6 | Block( 7 | [ 8 | Node { 9 | comments: [], 10 | node: FunctionDeclaration { 11 | name: [ 12 | Name( 13 | "empty", 14 | ), 15 | ], 16 | method: None, 17 | parlist: [], 18 | varargs: false, 19 | block: Block( 20 | [], 21 | ), 22 | }, 23 | location: Location { 24 | line_start: 1, 25 | line_end: 2, 26 | column_start: 1, 27 | column_end: 4, 28 | }, 29 | }, 30 | ], 31 | ) 32 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/function_statements/with_args.snap: -------------------------------------------------------------------------------- 1 | function foo(bar, baz) 2 | bar(baz) 3 | end 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [], 11 | node: FunctionDeclaration { 12 | name: [ 13 | Name( 14 | "foo", 15 | ), 16 | ], 17 | method: None, 18 | parlist: [ 19 | Name( 20 | "bar", 21 | ), 22 | Name( 23 | "baz", 24 | ), 25 | ], 26 | varargs: false, 27 | block: Block( 28 | [ 29 | Node { 30 | comments: [], 31 | node: FunctionCallStatement { 32 | pexp: Node { 33 | comments: [], 34 | node: NamedVar( 35 | "bar", 36 | ), 37 | location: Location { 38 | line_start: 2, 39 | line_end: 2, 40 | column_start: 3, 41 | column_end: 6, 42 | }, 43 | }, 44 | args: [ 45 | Node { 46 | comments: [], 47 | node: NamedVar( 48 | "baz", 49 | ), 50 | location: Location { 51 | line_start: 2, 52 | line_end: 2, 53 | column_start: 7, 54 | column_end: 10, 55 | }, 56 | }, 57 | ], 58 | }, 59 | location: Location { 60 | line_start: 2, 61 | line_end: 2, 62 | column_start: 3, 63 | column_end: 11, 64 | }, 65 | }, 66 | ], 67 | ), 68 | }, 69 | location: Location { 70 | line_start: 1, 71 | line_end: 3, 72 | column_start: 1, 73 | column_end: 4, 74 | }, 75 | }, 76 | ], 77 | ) 78 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/function_statements/with_method.snap: -------------------------------------------------------------------------------- 1 | function some:thing(a, b) 2 | a(b) 3 | end 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [], 11 | node: FunctionDeclaration { 12 | name: [ 13 | Name( 14 | "some", 15 | ), 16 | ], 17 | method: Some( 18 | Name( 19 | "thing", 20 | ), 21 | ), 22 | parlist: [ 23 | Name( 24 | "a", 25 | ), 26 | Name( 27 | "b", 28 | ), 29 | ], 30 | varargs: false, 31 | block: Block( 32 | [ 33 | Node { 34 | comments: [], 35 | node: FunctionCallStatement { 36 | pexp: Node { 37 | comments: [], 38 | node: NamedVar( 39 | "a", 40 | ), 41 | location: Location { 42 | line_start: 2, 43 | line_end: 2, 44 | column_start: 3, 45 | column_end: 4, 46 | }, 47 | }, 48 | args: [ 49 | Node { 50 | comments: [], 51 | node: NamedVar( 52 | "b", 53 | ), 54 | location: Location { 55 | line_start: 2, 56 | line_end: 2, 57 | column_start: 5, 58 | column_end: 6, 59 | }, 60 | }, 61 | ], 62 | }, 63 | location: Location { 64 | line_start: 2, 65 | line_end: 2, 66 | column_start: 3, 67 | column_end: 7, 68 | }, 69 | }, 70 | ], 71 | ), 72 | }, 73 | location: Location { 74 | line_start: 1, 75 | line_end: 3, 76 | column_start: 1, 77 | column_end: 4, 78 | }, 79 | }, 80 | ], 81 | ) 82 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/function_statements/with_properties.snap: -------------------------------------------------------------------------------- 1 | function foo.bar.baz() 2 | die() 3 | end 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [], 11 | node: FunctionDeclaration { 12 | name: [ 13 | Name( 14 | "foo", 15 | ), 16 | Name( 17 | "bar", 18 | ), 19 | Name( 20 | "baz", 21 | ), 22 | ], 23 | method: None, 24 | parlist: [], 25 | varargs: false, 26 | block: Block( 27 | [ 28 | Node { 29 | comments: [], 30 | node: FunctionCallStatement { 31 | pexp: Node { 32 | comments: [], 33 | node: NamedVar( 34 | "die", 35 | ), 36 | location: Location { 37 | line_start: 2, 38 | line_end: 2, 39 | column_start: 3, 40 | column_end: 6, 41 | }, 42 | }, 43 | args: [], 44 | }, 45 | location: Location { 46 | line_start: 2, 47 | line_end: 2, 48 | column_start: 3, 49 | column_end: 8, 50 | }, 51 | }, 52 | ], 53 | ), 54 | }, 55 | location: Location { 56 | line_start: 1, 57 | line_end: 3, 58 | column_start: 1, 59 | column_end: 4, 60 | }, 61 | }, 62 | ], 63 | ) 64 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/function_statements/with_properties_and_method.snap: -------------------------------------------------------------------------------- 1 | function a.b.c:d() 2 | yes() 3 | end 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [], 11 | node: FunctionDeclaration { 12 | name: [ 13 | Name( 14 | "a", 15 | ), 16 | Name( 17 | "b", 18 | ), 19 | Name( 20 | "c", 21 | ), 22 | ], 23 | method: Some( 24 | Name( 25 | "d", 26 | ), 27 | ), 28 | parlist: [], 29 | varargs: false, 30 | block: Block( 31 | [ 32 | Node { 33 | comments: [], 34 | node: FunctionCallStatement { 35 | pexp: Node { 36 | comments: [], 37 | node: NamedVar( 38 | "yes", 39 | ), 40 | location: Location { 41 | line_start: 2, 42 | line_end: 2, 43 | column_start: 3, 44 | column_end: 6, 45 | }, 46 | }, 47 | args: [], 48 | }, 49 | location: Location { 50 | line_start: 2, 51 | line_end: 2, 52 | column_start: 3, 53 | column_end: 8, 54 | }, 55 | }, 56 | ], 57 | ), 58 | }, 59 | location: Location { 60 | line_start: 1, 61 | line_end: 3, 62 | column_start: 1, 63 | column_end: 4, 64 | }, 65 | }, 66 | ], 67 | ) 68 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/if_statement/basic.snap: -------------------------------------------------------------------------------- 1 | if a ~= nil then 2 | a() 3 | end 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [], 11 | node: IfStatement { 12 | consequents: [ 13 | Consequent { 14 | cexp: Node { 15 | comments: [], 16 | node: Binary { 17 | lexp: Node { 18 | comments: [], 19 | node: NamedVar( 20 | "a", 21 | ), 22 | location: Location { 23 | line_start: 1, 24 | line_end: 1, 25 | column_start: 4, 26 | column_end: 5, 27 | }, 28 | }, 29 | op: Ne, 30 | rexp: Node { 31 | comments: [], 32 | node: Nil, 33 | location: Location { 34 | line_start: 1, 35 | line_end: 1, 36 | column_start: 9, 37 | column_end: 12, 38 | }, 39 | }, 40 | }, 41 | location: Location { 42 | line_start: 1, 43 | line_end: 1, 44 | column_start: 4, 45 | column_end: 12, 46 | }, 47 | }, 48 | block: Block( 49 | [ 50 | Node { 51 | comments: [], 52 | node: FunctionCallStatement { 53 | pexp: Node { 54 | comments: [], 55 | node: NamedVar( 56 | "a", 57 | ), 58 | location: Location { 59 | line_start: 2, 60 | line_end: 2, 61 | column_start: 3, 62 | column_end: 4, 63 | }, 64 | }, 65 | args: [], 66 | }, 67 | location: Location { 68 | line_start: 2, 69 | line_end: 2, 70 | column_start: 3, 71 | column_end: 6, 72 | }, 73 | }, 74 | ], 75 | ), 76 | }, 77 | ], 78 | alternate: None, 79 | }, 80 | location: Location { 81 | line_start: 1, 82 | line_end: 3, 83 | column_start: 1, 84 | column_end: 4, 85 | }, 86 | }, 87 | ], 88 | ) 89 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/index_expressions/basic.snap: -------------------------------------------------------------------------------- 1 | -- var ::= Name | prefixexp `[´ exp `]´ | prefixexp `.´ Name 2 | -- prefixexp ::= var | functioncall | `(´ exp `)´ 3 | -- functioncall ::= prefixexp args | prefixexp `:´ Name args 4 | -- args ::= `(´ [explist] `)´ | tableconstructor | String 5 | 6 | 7 | local item = list[100] 8 | 9 | -- TODO: note that index expressions can appear on the LHS too; eg: 10 | -- foo[x] = 1 11 | 12 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 13 | 14 | Block( 15 | [ 16 | Node { 17 | comments: [ 18 | Comment { 19 | kind: LineComment, 20 | content: "-- var ::= Name | prefixexp `[´ exp `]´ | prefixexp `.´ Name\n", 21 | location: Location { 22 | line_start: 1, 23 | line_end: 2, 24 | column_start: 1, 25 | column_end: 1, 26 | }, 27 | }, 28 | Comment { 29 | kind: LineComment, 30 | content: "-- prefixexp ::= var | functioncall | `(´ exp `)´\n", 31 | location: Location { 32 | line_start: 2, 33 | line_end: 3, 34 | column_start: 1, 35 | column_end: 1, 36 | }, 37 | }, 38 | Comment { 39 | kind: LineComment, 40 | content: "-- functioncall ::= prefixexp args | prefixexp `:´ Name args\n", 41 | location: Location { 42 | line_start: 3, 43 | line_end: 4, 44 | column_start: 1, 45 | column_end: 1, 46 | }, 47 | }, 48 | Comment { 49 | kind: LineComment, 50 | content: "-- args ::= `(´ [explist] `)´ | tableconstructor | String\n", 51 | location: Location { 52 | line_start: 4, 53 | line_end: 5, 54 | column_start: 1, 55 | column_end: 1, 56 | }, 57 | }, 58 | ], 59 | node: LocalDeclaration { 60 | namelist: [ 61 | Name( 62 | "item", 63 | ), 64 | ], 65 | explist: [ 66 | Node { 67 | comments: [], 68 | node: Index { 69 | pexp: Node { 70 | comments: [], 71 | node: NamedVar( 72 | "list", 73 | ), 74 | location: Location { 75 | line_start: 7, 76 | line_end: 7, 77 | column_start: 14, 78 | column_end: 18, 79 | }, 80 | }, 81 | kexp: Node { 82 | comments: [], 83 | node: Number( 84 | "100", 85 | ), 86 | location: Location { 87 | line_start: 7, 88 | line_end: 7, 89 | column_start: 19, 90 | column_end: 22, 91 | }, 92 | }, 93 | }, 94 | location: Location { 95 | line_start: 7, 96 | line_end: 7, 97 | column_start: 18, 98 | column_end: 23, 99 | }, 100 | }, 101 | ], 102 | }, 103 | location: Location { 104 | line_start: 7, 105 | line_end: 7, 106 | column_start: 1, 107 | column_end: 23, 108 | }, 109 | }, 110 | ], 111 | ) 112 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/lexer_errors/invalid_escape_sequence.snap: -------------------------------------------------------------------------------- 1 | local foo = "foo \y" 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | 1 | local foo = "foo \y" 6 | | ^ invalid escape sequence at 1:20 7 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/lexer_errors/invalid_operator.snap: -------------------------------------------------------------------------------- 1 | local equal = a === b 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | 1 | local equal = a === b 6 | | ^ invalid operator at 1:17 7 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/lexer_errors/unterminated_block_comment.snap: -------------------------------------------------------------------------------- 1 | --[[ stuff 2 | return 3 | 4 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 5 | 6 | | 7 | 2 | return 8 | | ^ unterminated block comment at 2:7 9 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/lexer_errors/unterminated_escape_sequence.snap: -------------------------------------------------------------------------------- 1 | local str = "foo\ 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | 1 | local str = "foo\ 6 | | ^ unterminated escape sequence at 1:18 7 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/lexer_errors/unterminated_string_literal.snap: -------------------------------------------------------------------------------- 1 | local str = "foo 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | 1 | local str = "foo 6 | | ^ unterminated string literal at 1:17 7 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/local_declarations/arithemetic_assignment.snap: -------------------------------------------------------------------------------- 1 | local sum = 7 + 8 2 | 3 | 4 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 5 | 6 | Block( 7 | [ 8 | Node { 9 | comments: [], 10 | node: LocalDeclaration { 11 | namelist: [ 12 | Name( 13 | "sum", 14 | ), 15 | ], 16 | explist: [ 17 | Node { 18 | comments: [], 19 | node: Binary { 20 | lexp: Node { 21 | comments: [], 22 | node: Number( 23 | "7", 24 | ), 25 | location: Location { 26 | line_start: 1, 27 | line_end: 1, 28 | column_start: 13, 29 | column_end: 14, 30 | }, 31 | }, 32 | op: Plus, 33 | rexp: Node { 34 | comments: [], 35 | node: Number( 36 | "8", 37 | ), 38 | location: Location { 39 | line_start: 1, 40 | line_end: 1, 41 | column_start: 17, 42 | column_end: 18, 43 | }, 44 | }, 45 | }, 46 | location: Location { 47 | line_start: 1, 48 | line_end: 1, 49 | column_start: 13, 50 | column_end: 18, 51 | }, 52 | }, 53 | ], 54 | }, 55 | location: Location { 56 | line_start: 1, 57 | line_end: 1, 58 | column_start: 1, 59 | column_end: 18, 60 | }, 61 | }, 62 | ], 63 | ) 64 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/local_declarations/boolean_assignment.snap: -------------------------------------------------------------------------------- 1 | local bar = false 2 | 3 | local qux = true 4 | 5 | 6 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 7 | 8 | Block( 9 | [ 10 | Node { 11 | comments: [], 12 | node: LocalDeclaration { 13 | namelist: [ 14 | Name( 15 | "bar", 16 | ), 17 | ], 18 | explist: [ 19 | Node { 20 | comments: [], 21 | node: False, 22 | location: Location { 23 | line_start: 1, 24 | line_end: 1, 25 | column_start: 13, 26 | column_end: 18, 27 | }, 28 | }, 29 | ], 30 | }, 31 | location: Location { 32 | line_start: 1, 33 | line_end: 1, 34 | column_start: 1, 35 | column_end: 18, 36 | }, 37 | }, 38 | Node { 39 | comments: [], 40 | node: LocalDeclaration { 41 | namelist: [ 42 | Name( 43 | "qux", 44 | ), 45 | ], 46 | explist: [ 47 | Node { 48 | comments: [], 49 | node: True, 50 | location: Location { 51 | line_start: 3, 52 | line_end: 3, 53 | column_start: 13, 54 | column_end: 17, 55 | }, 56 | }, 57 | ], 58 | }, 59 | location: Location { 60 | line_start: 3, 61 | line_end: 3, 62 | column_start: 1, 63 | column_end: 17, 64 | }, 65 | }, 66 | ], 67 | ) 68 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/local_declarations/double_quoted_string_assignment.snap: -------------------------------------------------------------------------------- 1 | local y = "don't say \"hello\"!" 2 | 3 | 4 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 5 | 6 | Block( 7 | [ 8 | Node { 9 | comments: [], 10 | node: LocalDeclaration { 11 | namelist: [ 12 | Name( 13 | "y", 14 | ), 15 | ], 16 | explist: [ 17 | Node { 18 | comments: [], 19 | node: CookedStr( 20 | "don't say \"hello\"!", 21 | ), 22 | location: Location { 23 | line_start: 1, 24 | line_end: 1, 25 | column_start: 11, 26 | column_end: 33, 27 | }, 28 | }, 29 | ], 30 | }, 31 | location: Location { 32 | line_start: 1, 33 | line_end: 1, 34 | column_start: 1, 35 | column_end: 33, 36 | }, 37 | }, 38 | ], 39 | ) 40 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/local_declarations/forward_declaration.snap: -------------------------------------------------------------------------------- 1 | local foo 2 | 3 | 4 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 5 | 6 | Block( 7 | [ 8 | Node { 9 | comments: [], 10 | node: LocalDeclaration { 11 | namelist: [ 12 | Name( 13 | "foo", 14 | ), 15 | ], 16 | explist: [], 17 | }, 18 | location: Location { 19 | line_start: 1, 20 | line_end: 1, 21 | column_start: 1, 22 | column_end: 10, 23 | }, 24 | }, 25 | ], 26 | ) 27 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/local_declarations/length_assignment.snap: -------------------------------------------------------------------------------- 1 | local len = #'sample' 2 | 3 | 4 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 5 | 6 | Block( 7 | [ 8 | Node { 9 | comments: [], 10 | node: LocalDeclaration { 11 | namelist: [ 12 | Name( 13 | "len", 14 | ), 15 | ], 16 | explist: [ 17 | Node { 18 | comments: [], 19 | node: Unary { 20 | exp: Node { 21 | comments: [], 22 | node: CookedStr( 23 | "sample", 24 | ), 25 | location: Location { 26 | line_start: 1, 27 | line_end: 1, 28 | column_start: 14, 29 | column_end: 22, 30 | }, 31 | }, 32 | op: Length, 33 | }, 34 | location: Location { 35 | line_start: 1, 36 | line_end: 1, 37 | column_start: 13, 38 | column_end: 22, 39 | }, 40 | }, 41 | ], 42 | }, 43 | location: Location { 44 | line_start: 1, 45 | line_end: 1, 46 | column_start: 1, 47 | column_end: 22, 48 | }, 49 | }, 50 | ], 51 | ) 52 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/local_declarations/long_string_assignment.snap: -------------------------------------------------------------------------------- 1 | local z = [[loooong]] 2 | 3 | 4 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 5 | 6 | Block( 7 | [ 8 | Node { 9 | comments: [], 10 | node: LocalDeclaration { 11 | namelist: [ 12 | Name( 13 | "z", 14 | ), 15 | ], 16 | explist: [ 17 | Node { 18 | comments: [], 19 | node: RawStr( 20 | "loooong", 21 | ), 22 | location: Location { 23 | line_start: 1, 24 | line_end: 1, 25 | column_start: 11, 26 | column_end: 22, 27 | }, 28 | }, 29 | ], 30 | }, 31 | location: Location { 32 | line_start: 1, 33 | line_end: 1, 34 | column_start: 1, 35 | column_end: 22, 36 | }, 37 | }, 38 | ], 39 | ) 40 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/local_declarations/negation_assignment.snap: -------------------------------------------------------------------------------- 1 | local neg = not true 2 | 3 | 4 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 5 | 6 | Block( 7 | [ 8 | Node { 9 | comments: [], 10 | node: LocalDeclaration { 11 | namelist: [ 12 | Name( 13 | "neg", 14 | ), 15 | ], 16 | explist: [ 17 | Node { 18 | comments: [], 19 | node: Unary { 20 | exp: Node { 21 | comments: [], 22 | node: True, 23 | location: Location { 24 | line_start: 1, 25 | line_end: 1, 26 | column_start: 17, 27 | column_end: 21, 28 | }, 29 | }, 30 | op: Not, 31 | }, 32 | location: Location { 33 | line_start: 1, 34 | line_end: 1, 35 | column_start: 13, 36 | column_end: 21, 37 | }, 38 | }, 39 | ], 40 | }, 41 | location: Location { 42 | line_start: 1, 43 | line_end: 1, 44 | column_start: 1, 45 | column_end: 21, 46 | }, 47 | }, 48 | ], 49 | ) 50 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/local_declarations/negative_assignment.snap: -------------------------------------------------------------------------------- 1 | local small = -1000 2 | 3 | 4 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 5 | 6 | Block( 7 | [ 8 | Node { 9 | comments: [], 10 | node: LocalDeclaration { 11 | namelist: [ 12 | Name( 13 | "small", 14 | ), 15 | ], 16 | explist: [ 17 | Node { 18 | comments: [], 19 | node: Unary { 20 | exp: Node { 21 | comments: [], 22 | node: Number( 23 | "1000", 24 | ), 25 | location: Location { 26 | line_start: 1, 27 | line_end: 1, 28 | column_start: 16, 29 | column_end: 20, 30 | }, 31 | }, 32 | op: Minus, 33 | }, 34 | location: Location { 35 | line_start: 1, 36 | line_end: 1, 37 | column_start: 15, 38 | column_end: 20, 39 | }, 40 | }, 41 | ], 42 | }, 43 | location: Location { 44 | line_start: 1, 45 | line_end: 1, 46 | column_start: 1, 47 | column_end: 20, 48 | }, 49 | }, 50 | ], 51 | ) 52 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/local_declarations/nil_assignment.snap: -------------------------------------------------------------------------------- 1 | local baz = nil 2 | 3 | 4 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 5 | 6 | Block( 7 | [ 8 | Node { 9 | comments: [], 10 | node: LocalDeclaration { 11 | namelist: [ 12 | Name( 13 | "baz", 14 | ), 15 | ], 16 | explist: [ 17 | Node { 18 | comments: [], 19 | node: Nil, 20 | location: Location { 21 | line_start: 1, 22 | line_end: 1, 23 | column_start: 13, 24 | column_end: 16, 25 | }, 26 | }, 27 | ], 28 | }, 29 | location: Location { 30 | line_start: 1, 31 | line_end: 1, 32 | column_start: 1, 33 | column_end: 16, 34 | }, 35 | }, 36 | ], 37 | ) 38 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/local_declarations/number_assignment.snap: -------------------------------------------------------------------------------- 1 | local w = 1 2 | 3 | 4 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 5 | 6 | Block( 7 | [ 8 | Node { 9 | comments: [], 10 | node: LocalDeclaration { 11 | namelist: [ 12 | Name( 13 | "w", 14 | ), 15 | ], 16 | explist: [ 17 | Node { 18 | comments: [], 19 | node: Number( 20 | "1", 21 | ), 22 | location: Location { 23 | line_start: 1, 24 | line_end: 1, 25 | column_start: 11, 26 | column_end: 12, 27 | }, 28 | }, 29 | ], 30 | }, 31 | location: Location { 32 | line_start: 1, 33 | line_end: 1, 34 | column_start: 1, 35 | column_end: 12, 36 | }, 37 | }, 38 | ], 39 | ) 40 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/local_declarations/single_quoted_string_assignment.snap: -------------------------------------------------------------------------------- 1 | local x = 'wat' 2 | 3 | 4 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 5 | 6 | Block( 7 | [ 8 | Node { 9 | comments: [], 10 | node: LocalDeclaration { 11 | namelist: [ 12 | Name( 13 | "x", 14 | ), 15 | ], 16 | explist: [ 17 | Node { 18 | comments: [], 19 | node: CookedStr( 20 | "wat", 21 | ), 22 | location: Location { 23 | line_start: 1, 24 | line_end: 1, 25 | column_start: 11, 26 | column_end: 16, 27 | }, 28 | }, 29 | ], 30 | }, 31 | location: Location { 32 | line_start: 1, 33 | line_end: 1, 34 | column_start: 1, 35 | column_end: 16, 36 | }, 37 | }, 38 | ], 39 | ) 40 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/local_declarations/table_constructor_assignment.snap: -------------------------------------------------------------------------------- 1 | local stuff = { ["foo"] = bar } 2 | 3 | 4 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 5 | 6 | Block( 7 | [ 8 | Node { 9 | comments: [], 10 | node: LocalDeclaration { 11 | namelist: [ 12 | Name( 13 | "stuff", 14 | ), 15 | ], 16 | explist: [ 17 | Node { 18 | comments: [], 19 | node: Table( 20 | [ 21 | Node { 22 | comments: [], 23 | node: Field { 24 | index: None, 25 | lexp: Node { 26 | comments: [], 27 | node: CookedStr( 28 | "foo", 29 | ), 30 | location: Location { 31 | line_start: 1, 32 | line_end: 1, 33 | column_start: 18, 34 | column_end: 23, 35 | }, 36 | }, 37 | rexp: Node { 38 | comments: [], 39 | node: NamedVar( 40 | "bar", 41 | ), 42 | location: Location { 43 | line_start: 1, 44 | line_end: 1, 45 | column_start: 27, 46 | column_end: 30, 47 | }, 48 | }, 49 | }, 50 | location: Location { 51 | line_start: 1, 52 | line_end: 1, 53 | column_start: 18, 54 | column_end: 30, 55 | }, 56 | }, 57 | ], 58 | ), 59 | location: Location { 60 | line_start: 1, 61 | line_end: 1, 62 | column_start: 15, 63 | column_end: 32, 64 | }, 65 | }, 66 | ], 67 | }, 68 | location: Location { 69 | line_start: 1, 70 | line_end: 1, 71 | column_start: 1, 72 | column_end: 32, 73 | }, 74 | }, 75 | ], 76 | ) 77 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/local_declarations/unary_not_with_name_assignment.snap: -------------------------------------------------------------------------------- 1 | local foo = not bar 2 | 3 | 4 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 5 | 6 | Block( 7 | [ 8 | Node { 9 | comments: [], 10 | node: LocalDeclaration { 11 | namelist: [ 12 | Name( 13 | "foo", 14 | ), 15 | ], 16 | explist: [ 17 | Node { 18 | comments: [], 19 | node: Unary { 20 | exp: Node { 21 | comments: [], 22 | node: NamedVar( 23 | "bar", 24 | ), 25 | location: Location { 26 | line_start: 1, 27 | line_end: 1, 28 | column_start: 17, 29 | column_end: 20, 30 | }, 31 | }, 32 | op: Not, 33 | }, 34 | location: Location { 35 | line_start: 1, 36 | line_end: 1, 37 | column_start: 13, 38 | column_end: 20, 39 | }, 40 | }, 41 | ], 42 | }, 43 | location: Location { 44 | line_start: 1, 45 | line_end: 1, 46 | column_start: 1, 47 | column_end: 20, 48 | }, 49 | }, 50 | ], 51 | ) 52 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/local_function_declarations/basic.snap: -------------------------------------------------------------------------------- 1 | local function secret() 2 | foo() 3 | end 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [], 11 | node: LocalFunctionDeclaration { 12 | name: Name( 13 | "secret", 14 | ), 15 | parlist: [], 16 | varargs: false, 17 | block: Block( 18 | [ 19 | Node { 20 | comments: [], 21 | node: FunctionCallStatement { 22 | pexp: Node { 23 | comments: [], 24 | node: NamedVar( 25 | "foo", 26 | ), 27 | location: Location { 28 | line_start: 2, 29 | line_end: 2, 30 | column_start: 3, 31 | column_end: 6, 32 | }, 33 | }, 34 | args: [], 35 | }, 36 | location: Location { 37 | line_start: 2, 38 | line_end: 2, 39 | column_start: 3, 40 | column_end: 8, 41 | }, 42 | }, 43 | ], 44 | ), 45 | }, 46 | location: Location { 47 | line_start: 1, 48 | line_end: 3, 49 | column_start: 1, 50 | column_end: 4, 51 | }, 52 | }, 53 | ], 54 | ) 55 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/local_function_declarations/empty.snap: -------------------------------------------------------------------------------- 1 | local function empty() 2 | end 3 | 4 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 5 | 6 | Block( 7 | [ 8 | Node { 9 | comments: [], 10 | node: LocalFunctionDeclaration { 11 | name: Name( 12 | "empty", 13 | ), 14 | parlist: [], 15 | varargs: false, 16 | block: Block( 17 | [], 18 | ), 19 | }, 20 | location: Location { 21 | line_start: 1, 22 | line_end: 2, 23 | column_start: 1, 24 | column_end: 4, 25 | }, 26 | }, 27 | ], 28 | ) 29 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/local_function_declarations/multiple_params.snap: -------------------------------------------------------------------------------- 1 | local function three(foo, bar, baz) 2 | foo(bar(baz)) 3 | end 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [], 11 | node: LocalFunctionDeclaration { 12 | name: Name( 13 | "three", 14 | ), 15 | parlist: [ 16 | Name( 17 | "foo", 18 | ), 19 | Name( 20 | "bar", 21 | ), 22 | Name( 23 | "baz", 24 | ), 25 | ], 26 | varargs: false, 27 | block: Block( 28 | [ 29 | Node { 30 | comments: [], 31 | node: FunctionCallStatement { 32 | pexp: Node { 33 | comments: [], 34 | node: NamedVar( 35 | "foo", 36 | ), 37 | location: Location { 38 | line_start: 2, 39 | line_end: 2, 40 | column_start: 3, 41 | column_end: 6, 42 | }, 43 | }, 44 | args: [ 45 | Node { 46 | comments: [], 47 | node: FunctionCall { 48 | pexp: Node { 49 | comments: [], 50 | node: NamedVar( 51 | "bar", 52 | ), 53 | location: Location { 54 | line_start: 2, 55 | line_end: 2, 56 | column_start: 7, 57 | column_end: 10, 58 | }, 59 | }, 60 | args: [ 61 | Node { 62 | comments: [], 63 | node: NamedVar( 64 | "baz", 65 | ), 66 | location: Location { 67 | line_start: 2, 68 | line_end: 2, 69 | column_start: 11, 70 | column_end: 14, 71 | }, 72 | }, 73 | ], 74 | }, 75 | location: Location { 76 | line_start: 2, 77 | line_end: 2, 78 | column_start: 7, 79 | column_end: 15, 80 | }, 81 | }, 82 | ], 83 | }, 84 | location: Location { 85 | line_start: 2, 86 | line_end: 2, 87 | column_start: 3, 88 | column_end: 16, 89 | }, 90 | }, 91 | ], 92 | ), 93 | }, 94 | location: Location { 95 | line_start: 1, 96 | line_end: 3, 97 | column_start: 1, 98 | column_end: 4, 99 | }, 100 | }, 101 | ], 102 | ) 103 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/local_function_declarations/one_param.snap: -------------------------------------------------------------------------------- 1 | local function one(foo) 2 | foo() 3 | end 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [], 11 | node: LocalFunctionDeclaration { 12 | name: Name( 13 | "one", 14 | ), 15 | parlist: [ 16 | Name( 17 | "foo", 18 | ), 19 | ], 20 | varargs: false, 21 | block: Block( 22 | [ 23 | Node { 24 | comments: [], 25 | node: FunctionCallStatement { 26 | pexp: Node { 27 | comments: [], 28 | node: NamedVar( 29 | "foo", 30 | ), 31 | location: Location { 32 | line_start: 2, 33 | line_end: 2, 34 | column_start: 3, 35 | column_end: 6, 36 | }, 37 | }, 38 | args: [], 39 | }, 40 | location: Location { 41 | line_start: 2, 42 | line_end: 2, 43 | column_start: 3, 44 | column_end: 8, 45 | }, 46 | }, 47 | ], 48 | ), 49 | }, 50 | location: Location { 51 | line_start: 1, 52 | line_end: 3, 53 | column_start: 1, 54 | column_end: 4, 55 | }, 56 | }, 57 | ], 58 | ) 59 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/local_function_declarations/varargs.snap: -------------------------------------------------------------------------------- 1 | local function add(first, second, ...) 2 | adder(first, second, ...) 3 | end 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [], 11 | node: LocalFunctionDeclaration { 12 | name: Name( 13 | "add", 14 | ), 15 | parlist: [ 16 | Name( 17 | "first", 18 | ), 19 | Name( 20 | "second", 21 | ), 22 | ], 23 | varargs: true, 24 | block: Block( 25 | [ 26 | Node { 27 | comments: [], 28 | node: FunctionCallStatement { 29 | pexp: Node { 30 | comments: [], 31 | node: NamedVar( 32 | "adder", 33 | ), 34 | location: Location { 35 | line_start: 2, 36 | line_end: 2, 37 | column_start: 3, 38 | column_end: 8, 39 | }, 40 | }, 41 | args: [ 42 | Node { 43 | comments: [], 44 | node: NamedVar( 45 | "first", 46 | ), 47 | location: Location { 48 | line_start: 2, 49 | line_end: 2, 50 | column_start: 9, 51 | column_end: 14, 52 | }, 53 | }, 54 | Node { 55 | comments: [], 56 | node: NamedVar( 57 | "second", 58 | ), 59 | location: Location { 60 | line_start: 2, 61 | line_end: 2, 62 | column_start: 16, 63 | column_end: 22, 64 | }, 65 | }, 66 | Node { 67 | comments: [], 68 | node: Varargs, 69 | location: Location { 70 | line_start: 2, 71 | line_end: 2, 72 | column_start: 24, 73 | column_end: 27, 74 | }, 75 | }, 76 | ], 77 | }, 78 | location: Location { 79 | line_start: 2, 80 | line_end: 2, 81 | column_start: 3, 82 | column_end: 28, 83 | }, 84 | }, 85 | ], 86 | ), 87 | }, 88 | location: Location { 89 | line_start: 1, 90 | line_end: 3, 91 | column_start: 1, 92 | column_end: 4, 93 | }, 94 | }, 95 | ], 96 | ) 97 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/local_function_declarations/varargs_only.snap: -------------------------------------------------------------------------------- 1 | local function debug(...) 2 | print(inspect(...)) 3 | end 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [], 11 | node: LocalFunctionDeclaration { 12 | name: Name( 13 | "debug", 14 | ), 15 | parlist: [], 16 | varargs: true, 17 | block: Block( 18 | [ 19 | Node { 20 | comments: [], 21 | node: FunctionCallStatement { 22 | pexp: Node { 23 | comments: [], 24 | node: NamedVar( 25 | "print", 26 | ), 27 | location: Location { 28 | line_start: 2, 29 | line_end: 2, 30 | column_start: 3, 31 | column_end: 8, 32 | }, 33 | }, 34 | args: [ 35 | Node { 36 | comments: [], 37 | node: FunctionCall { 38 | pexp: Node { 39 | comments: [], 40 | node: NamedVar( 41 | "inspect", 42 | ), 43 | location: Location { 44 | line_start: 2, 45 | line_end: 2, 46 | column_start: 9, 47 | column_end: 16, 48 | }, 49 | }, 50 | args: [ 51 | Node { 52 | comments: [], 53 | node: Varargs, 54 | location: Location { 55 | line_start: 2, 56 | line_end: 2, 57 | column_start: 17, 58 | column_end: 20, 59 | }, 60 | }, 61 | ], 62 | }, 63 | location: Location { 64 | line_start: 2, 65 | line_end: 2, 66 | column_start: 9, 67 | column_end: 21, 68 | }, 69 | }, 70 | ], 71 | }, 72 | location: Location { 73 | line_start: 2, 74 | line_end: 2, 75 | column_start: 3, 76 | column_end: 22, 77 | }, 78 | }, 79 | ], 80 | ), 81 | }, 82 | location: Location { 83 | line_start: 1, 84 | line_end: 3, 85 | column_start: 1, 86 | column_end: 4, 87 | }, 88 | }, 89 | ], 90 | ) 91 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/method_calls/as_expressions.snap: -------------------------------------------------------------------------------- 1 | -- ie. method call in expression position, rather than as an independent statement. 2 | 3 | local foo = bar:baz("hello", "world") 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [ 11 | Comment { 12 | kind: LineComment, 13 | content: "-- ie. method call in expression position, rather than as an independent statement.\n", 14 | location: Location { 15 | line_start: 1, 16 | line_end: 2, 17 | column_start: 1, 18 | column_end: 1, 19 | }, 20 | }, 21 | ], 22 | node: LocalDeclaration { 23 | namelist: [ 24 | Name( 25 | "foo", 26 | ), 27 | ], 28 | explist: [ 29 | Node { 30 | comments: [], 31 | node: MethodCall { 32 | pexp: Node { 33 | comments: [], 34 | node: NamedVar( 35 | "bar", 36 | ), 37 | location: Location { 38 | line_start: 3, 39 | line_end: 3, 40 | column_start: 13, 41 | column_end: 16, 42 | }, 43 | }, 44 | name: "baz", 45 | args: [ 46 | Node { 47 | comments: [], 48 | node: CookedStr( 49 | "hello", 50 | ), 51 | location: Location { 52 | line_start: 3, 53 | line_end: 3, 54 | column_start: 21, 55 | column_end: 28, 56 | }, 57 | }, 58 | Node { 59 | comments: [], 60 | node: CookedStr( 61 | "world", 62 | ), 63 | location: Location { 64 | line_start: 3, 65 | line_end: 3, 66 | column_start: 30, 67 | column_end: 37, 68 | }, 69 | }, 70 | ], 71 | }, 72 | location: Location { 73 | line_start: 3, 74 | line_end: 3, 75 | column_start: 13, 76 | column_end: 38, 77 | }, 78 | }, 79 | ], 80 | }, 81 | location: Location { 82 | line_start: 3, 83 | line_end: 3, 84 | column_start: 1, 85 | column_end: 38, 86 | }, 87 | }, 88 | ], 89 | ) 90 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/method_calls/empty.snap: -------------------------------------------------------------------------------- 1 | bar:baz() 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | Block( 6 | [ 7 | Node { 8 | comments: [], 9 | node: MethodCallStatement { 10 | pexp: Node { 11 | comments: [], 12 | node: NamedVar( 13 | "bar", 14 | ), 15 | location: Location { 16 | line_start: 1, 17 | line_end: 1, 18 | column_start: 1, 19 | column_end: 4, 20 | }, 21 | }, 22 | name: "baz", 23 | args: [], 24 | }, 25 | location: Location { 26 | line_start: 1, 27 | line_end: 1, 28 | column_start: 1, 29 | column_end: 10, 30 | }, 31 | }, 32 | ], 33 | ) 34 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/method_calls/multiple_arguments.snap: -------------------------------------------------------------------------------- 1 | bar:baz("hello", "world") 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | Block( 6 | [ 7 | Node { 8 | comments: [], 9 | node: MethodCallStatement { 10 | pexp: Node { 11 | comments: [], 12 | node: NamedVar( 13 | "bar", 14 | ), 15 | location: Location { 16 | line_start: 1, 17 | line_end: 1, 18 | column_start: 1, 19 | column_end: 4, 20 | }, 21 | }, 22 | name: "baz", 23 | args: [ 24 | Node { 25 | comments: [], 26 | node: CookedStr( 27 | "hello", 28 | ), 29 | location: Location { 30 | line_start: 1, 31 | line_end: 1, 32 | column_start: 9, 33 | column_end: 16, 34 | }, 35 | }, 36 | Node { 37 | comments: [], 38 | node: CookedStr( 39 | "world", 40 | ), 41 | location: Location { 42 | line_start: 1, 43 | line_end: 1, 44 | column_start: 18, 45 | column_end: 25, 46 | }, 47 | }, 48 | ], 49 | }, 50 | location: Location { 51 | line_start: 1, 52 | line_end: 1, 53 | column_start: 1, 54 | column_end: 26, 55 | }, 56 | }, 57 | ], 58 | ) 59 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/method_calls/nested.snap: -------------------------------------------------------------------------------- 1 | y:z(a:b(c)) 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | Block( 6 | [ 7 | Node { 8 | comments: [], 9 | node: MethodCallStatement { 10 | pexp: Node { 11 | comments: [], 12 | node: NamedVar( 13 | "y", 14 | ), 15 | location: Location { 16 | line_start: 1, 17 | line_end: 1, 18 | column_start: 1, 19 | column_end: 2, 20 | }, 21 | }, 22 | name: "z", 23 | args: [ 24 | Node { 25 | comments: [], 26 | node: MethodCall { 27 | pexp: Node { 28 | comments: [], 29 | node: NamedVar( 30 | "a", 31 | ), 32 | location: Location { 33 | line_start: 1, 34 | line_end: 1, 35 | column_start: 5, 36 | column_end: 6, 37 | }, 38 | }, 39 | name: "b", 40 | args: [ 41 | Node { 42 | comments: [], 43 | node: NamedVar( 44 | "c", 45 | ), 46 | location: Location { 47 | line_start: 1, 48 | line_end: 1, 49 | column_start: 9, 50 | column_end: 10, 51 | }, 52 | }, 53 | ], 54 | }, 55 | location: Location { 56 | line_start: 1, 57 | line_end: 1, 58 | column_start: 5, 59 | column_end: 11, 60 | }, 61 | }, 62 | ], 63 | }, 64 | location: Location { 65 | line_start: 1, 66 | line_end: 1, 67 | column_start: 1, 68 | column_end: 12, 69 | }, 70 | }, 71 | ], 72 | ) 73 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/method_calls/single_argument.snap: -------------------------------------------------------------------------------- 1 | bar:baz(nil) 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | Block( 6 | [ 7 | Node { 8 | comments: [], 9 | node: MethodCallStatement { 10 | pexp: Node { 11 | comments: [], 12 | node: NamedVar( 13 | "bar", 14 | ), 15 | location: Location { 16 | line_start: 1, 17 | line_end: 1, 18 | column_start: 1, 19 | column_end: 4, 20 | }, 21 | }, 22 | name: "baz", 23 | args: [ 24 | Node { 25 | comments: [], 26 | node: Nil, 27 | location: Location { 28 | line_start: 1, 29 | line_end: 1, 30 | column_start: 9, 31 | column_end: 12, 32 | }, 33 | }, 34 | ], 35 | }, 36 | location: Location { 37 | line_start: 1, 38 | line_end: 1, 39 | column_start: 1, 40 | column_end: 13, 41 | }, 42 | }, 43 | ], 44 | ) 45 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/method_calls/string_arguments.snap: -------------------------------------------------------------------------------- 1 | b:c 'single' 2 | e:f "double" 3 | h:i [[long]] 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [], 11 | node: MethodCallStatement { 12 | pexp: Node { 13 | comments: [], 14 | node: NamedVar( 15 | "b", 16 | ), 17 | location: Location { 18 | line_start: 1, 19 | line_end: 1, 20 | column_start: 1, 21 | column_end: 2, 22 | }, 23 | }, 24 | name: "c", 25 | args: [ 26 | Node { 27 | comments: [], 28 | node: CookedStr( 29 | "single", 30 | ), 31 | location: Location { 32 | line_start: 1, 33 | line_end: 1, 34 | column_start: 5, 35 | column_end: 13, 36 | }, 37 | }, 38 | ], 39 | }, 40 | location: Location { 41 | line_start: 1, 42 | line_end: 1, 43 | column_start: 1, 44 | column_end: 13, 45 | }, 46 | }, 47 | Node { 48 | comments: [], 49 | node: MethodCallStatement { 50 | pexp: Node { 51 | comments: [], 52 | node: NamedVar( 53 | "e", 54 | ), 55 | location: Location { 56 | line_start: 2, 57 | line_end: 2, 58 | column_start: 1, 59 | column_end: 2, 60 | }, 61 | }, 62 | name: "f", 63 | args: [ 64 | Node { 65 | comments: [], 66 | node: CookedStr( 67 | "double", 68 | ), 69 | location: Location { 70 | line_start: 2, 71 | line_end: 2, 72 | column_start: 5, 73 | column_end: 13, 74 | }, 75 | }, 76 | ], 77 | }, 78 | location: Location { 79 | line_start: 2, 80 | line_end: 2, 81 | column_start: 1, 82 | column_end: 13, 83 | }, 84 | }, 85 | Node { 86 | comments: [], 87 | node: MethodCallStatement { 88 | pexp: Node { 89 | comments: [], 90 | node: NamedVar( 91 | "h", 92 | ), 93 | location: Location { 94 | line_start: 3, 95 | line_end: 3, 96 | column_start: 1, 97 | column_end: 2, 98 | }, 99 | }, 100 | name: "i", 101 | args: [ 102 | Node { 103 | comments: [], 104 | node: RawStr( 105 | "long", 106 | ), 107 | location: Location { 108 | line_start: 3, 109 | line_end: 3, 110 | column_start: 5, 111 | column_end: 13, 112 | }, 113 | }, 114 | ], 115 | }, 116 | location: Location { 117 | line_start: 3, 118 | line_end: 3, 119 | column_start: 1, 120 | column_end: 13, 121 | }, 122 | }, 123 | ], 124 | ) 125 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/method_calls/table_argument.snap: -------------------------------------------------------------------------------- 1 | bar:baz { force = true } 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | Block( 6 | [ 7 | Node { 8 | comments: [], 9 | node: MethodCallStatement { 10 | pexp: Node { 11 | comments: [], 12 | node: NamedVar( 13 | "bar", 14 | ), 15 | location: Location { 16 | line_start: 1, 17 | line_end: 1, 18 | column_start: 1, 19 | column_end: 4, 20 | }, 21 | }, 22 | name: "baz", 23 | args: [ 24 | Node { 25 | comments: [], 26 | node: Table( 27 | [ 28 | Node { 29 | comments: [], 30 | node: Field { 31 | index: None, 32 | lexp: Node { 33 | comments: [], 34 | node: RawStr( 35 | "force", 36 | ), 37 | location: Location { 38 | line_start: 0, 39 | line_end: 0, 40 | column_start: 0, 41 | column_end: 0, 42 | }, 43 | }, 44 | rexp: Node { 45 | comments: [], 46 | node: True, 47 | location: Location { 48 | line_start: 1, 49 | line_end: 1, 50 | column_start: 19, 51 | column_end: 23, 52 | }, 53 | }, 54 | }, 55 | location: Location { 56 | line_start: 0, 57 | line_end: 1, 58 | column_start: 0, 59 | column_end: 23, 60 | }, 61 | }, 62 | ], 63 | ), 64 | location: Location { 65 | line_start: 1, 66 | line_end: 1, 67 | column_start: 9, 68 | column_end: 25, 69 | }, 70 | }, 71 | ], 72 | }, 73 | location: Location { 74 | line_start: 1, 75 | line_end: 1, 76 | column_start: 1, 77 | column_end: 25, 78 | }, 79 | }, 80 | ], 81 | ) 82 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/parens.snap: -------------------------------------------------------------------------------- 1 | local item = (100) 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | Block( 6 | [ 7 | Node { 8 | comments: [], 9 | node: LocalDeclaration { 10 | namelist: [ 11 | Name( 12 | "item", 13 | ), 14 | ], 15 | explist: [ 16 | Node { 17 | comments: [], 18 | node: Number( 19 | "100", 20 | ), 21 | location: Location { 22 | line_start: 1, 23 | line_end: 1, 24 | column_start: 15, 25 | column_end: 18, 26 | }, 27 | }, 28 | ], 29 | }, 30 | location: Location { 31 | line_start: 1, 32 | line_end: 1, 33 | column_start: 1, 34 | column_end: 18, 35 | }, 36 | }, 37 | ], 38 | ) 39 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/repeat/basic.snap: -------------------------------------------------------------------------------- 1 | repeat 2 | inc(x) 3 | until x < 100 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [], 11 | node: Repeat { 12 | block: Block( 13 | [ 14 | Node { 15 | comments: [], 16 | node: FunctionCallStatement { 17 | pexp: Node { 18 | comments: [], 19 | node: NamedVar( 20 | "inc", 21 | ), 22 | location: Location { 23 | line_start: 2, 24 | line_end: 2, 25 | column_start: 3, 26 | column_end: 6, 27 | }, 28 | }, 29 | args: [ 30 | Node { 31 | comments: [], 32 | node: NamedVar( 33 | "x", 34 | ), 35 | location: Location { 36 | line_start: 2, 37 | line_end: 2, 38 | column_start: 7, 39 | column_end: 8, 40 | }, 41 | }, 42 | ], 43 | }, 44 | location: Location { 45 | line_start: 2, 46 | line_end: 2, 47 | column_start: 3, 48 | column_end: 9, 49 | }, 50 | }, 51 | ], 52 | ), 53 | cexp: Node { 54 | comments: [], 55 | node: Binary { 56 | lexp: Node { 57 | comments: [], 58 | node: NamedVar( 59 | "x", 60 | ), 61 | location: Location { 62 | line_start: 3, 63 | line_end: 3, 64 | column_start: 7, 65 | column_end: 8, 66 | }, 67 | }, 68 | op: Lt, 69 | rexp: Node { 70 | comments: [], 71 | node: Number( 72 | "100", 73 | ), 74 | location: Location { 75 | line_start: 3, 76 | line_end: 3, 77 | column_start: 11, 78 | column_end: 14, 79 | }, 80 | }, 81 | }, 82 | location: Location { 83 | line_start: 3, 84 | line_end: 3, 85 | column_start: 7, 86 | column_end: 14, 87 | }, 88 | }, 89 | }, 90 | location: Location { 91 | line_start: 1, 92 | line_end: 3, 93 | column_start: 1, 94 | column_end: 14, 95 | }, 96 | }, 97 | ], 98 | ) 99 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/return/in_module.snap: -------------------------------------------------------------------------------- 1 | print("in a module") 2 | 3 | return true 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [], 11 | node: FunctionCallStatement { 12 | pexp: Node { 13 | comments: [], 14 | node: NamedVar( 15 | "print", 16 | ), 17 | location: Location { 18 | line_start: 1, 19 | line_end: 1, 20 | column_start: 1, 21 | column_end: 6, 22 | }, 23 | }, 24 | args: [ 25 | Node { 26 | comments: [], 27 | node: CookedStr( 28 | "in a module", 29 | ), 30 | location: Location { 31 | line_start: 1, 32 | line_end: 1, 33 | column_start: 7, 34 | column_end: 20, 35 | }, 36 | }, 37 | ], 38 | }, 39 | location: Location { 40 | line_start: 1, 41 | line_end: 1, 42 | column_start: 1, 43 | column_end: 21, 44 | }, 45 | }, 46 | Node { 47 | comments: [], 48 | node: Return( 49 | Some( 50 | [ 51 | Node { 52 | comments: [], 53 | node: True, 54 | location: Location { 55 | line_start: 3, 56 | line_end: 3, 57 | column_start: 8, 58 | column_end: 12, 59 | }, 60 | }, 61 | ], 62 | ), 63 | ), 64 | location: Location { 65 | line_start: 3, 66 | line_end: 3, 67 | column_start: 1, 68 | column_end: 12, 69 | }, 70 | }, 71 | ], 72 | ) 73 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/return/when_not_last.snap: -------------------------------------------------------------------------------- 1 | function bad() 2 | return 3 | 4 | -- Syntax error, because `return` must be the last statement in a block. 5 | print("Unreachable") 6 | end 7 | 8 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 9 | 10 | | 11 | 4 | -- Syntax error, because `return` must be the last statement in a block. 12 | | ^ unexpected token at 4:3 13 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/table_constructors/basic_single_field.snap: -------------------------------------------------------------------------------- 1 | local stuff = { one = 1 } 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | Block( 6 | [ 7 | Node { 8 | comments: [], 9 | node: LocalDeclaration { 10 | namelist: [ 11 | Name( 12 | "stuff", 13 | ), 14 | ], 15 | explist: [ 16 | Node { 17 | comments: [], 18 | node: Table( 19 | [ 20 | Node { 21 | comments: [], 22 | node: Field { 23 | index: None, 24 | lexp: Node { 25 | comments: [], 26 | node: RawStr( 27 | "one", 28 | ), 29 | location: Location { 30 | line_start: 0, 31 | line_end: 0, 32 | column_start: 0, 33 | column_end: 0, 34 | }, 35 | }, 36 | rexp: Node { 37 | comments: [], 38 | node: Number( 39 | "1", 40 | ), 41 | location: Location { 42 | line_start: 1, 43 | line_end: 1, 44 | column_start: 23, 45 | column_end: 24, 46 | }, 47 | }, 48 | }, 49 | location: Location { 50 | line_start: 0, 51 | line_end: 1, 52 | column_start: 0, 53 | column_end: 24, 54 | }, 55 | }, 56 | ], 57 | ), 58 | location: Location { 59 | line_start: 1, 60 | line_end: 1, 61 | column_start: 15, 62 | column_end: 26, 63 | }, 64 | }, 65 | ], 66 | }, 67 | location: Location { 68 | line_start: 1, 69 | line_end: 1, 70 | column_start: 1, 71 | column_end: 26, 72 | }, 73 | }, 74 | ], 75 | ) 76 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/table_constructors/brackets.snap: -------------------------------------------------------------------------------- 1 | local stuff = { ["foo"] = bar } 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | Block( 6 | [ 7 | Node { 8 | comments: [], 9 | node: LocalDeclaration { 10 | namelist: [ 11 | Name( 12 | "stuff", 13 | ), 14 | ], 15 | explist: [ 16 | Node { 17 | comments: [], 18 | node: Table( 19 | [ 20 | Node { 21 | comments: [], 22 | node: Field { 23 | index: None, 24 | lexp: Node { 25 | comments: [], 26 | node: CookedStr( 27 | "foo", 28 | ), 29 | location: Location { 30 | line_start: 1, 31 | line_end: 1, 32 | column_start: 18, 33 | column_end: 23, 34 | }, 35 | }, 36 | rexp: Node { 37 | comments: [], 38 | node: NamedVar( 39 | "bar", 40 | ), 41 | location: Location { 42 | line_start: 1, 43 | line_end: 1, 44 | column_start: 27, 45 | column_end: 30, 46 | }, 47 | }, 48 | }, 49 | location: Location { 50 | line_start: 1, 51 | line_end: 1, 52 | column_start: 18, 53 | column_end: 30, 54 | }, 55 | }, 56 | ], 57 | ), 58 | location: Location { 59 | line_start: 1, 60 | line_end: 1, 61 | column_start: 15, 62 | column_end: 32, 63 | }, 64 | }, 65 | ], 66 | }, 67 | location: Location { 68 | line_start: 1, 69 | line_end: 1, 70 | column_start: 1, 71 | column_end: 32, 72 | }, 73 | }, 74 | ], 75 | ) 76 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/table_constructors/shorthand.snap: -------------------------------------------------------------------------------- 1 | local stuff = { one } 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | Block( 6 | [ 7 | Node { 8 | comments: [], 9 | node: LocalDeclaration { 10 | namelist: [ 11 | Name( 12 | "stuff", 13 | ), 14 | ], 15 | explist: [ 16 | Node { 17 | comments: [], 18 | node: Table( 19 | [ 20 | Node { 21 | comments: [], 22 | node: Field { 23 | index: Some( 24 | 1, 25 | ), 26 | lexp: Node { 27 | comments: [], 28 | node: Nil, 29 | location: Location { 30 | line_start: 0, 31 | line_end: 0, 32 | column_start: 0, 33 | column_end: 0, 34 | }, 35 | }, 36 | rexp: Node { 37 | comments: [], 38 | node: NamedVar( 39 | "one", 40 | ), 41 | location: Location { 42 | line_start: 1, 43 | line_end: 1, 44 | column_start: 17, 45 | column_end: 20, 46 | }, 47 | }, 48 | }, 49 | location: Location { 50 | line_start: 1, 51 | line_end: 1, 52 | column_start: 17, 53 | column_end: 20, 54 | }, 55 | }, 56 | ], 57 | ), 58 | location: Location { 59 | line_start: 1, 60 | line_end: 1, 61 | column_start: 15, 62 | column_end: 22, 63 | }, 64 | }, 65 | ], 66 | }, 67 | location: Location { 68 | line_start: 1, 69 | line_end: 1, 70 | column_start: 1, 71 | column_end: 22, 72 | }, 73 | }, 74 | ], 75 | ) 76 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/unary_expressions.snap: -------------------------------------------------------------------------------- 1 | local x = not value 2 | 3 | local y = #items 4 | 5 | local z = -1000 6 | 7 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 8 | 9 | Block( 10 | [ 11 | Node { 12 | comments: [], 13 | node: LocalDeclaration { 14 | namelist: [ 15 | Name( 16 | "x", 17 | ), 18 | ], 19 | explist: [ 20 | Node { 21 | comments: [], 22 | node: Unary { 23 | exp: Node { 24 | comments: [], 25 | node: NamedVar( 26 | "value", 27 | ), 28 | location: Location { 29 | line_start: 1, 30 | line_end: 1, 31 | column_start: 15, 32 | column_end: 20, 33 | }, 34 | }, 35 | op: Not, 36 | }, 37 | location: Location { 38 | line_start: 1, 39 | line_end: 1, 40 | column_start: 11, 41 | column_end: 20, 42 | }, 43 | }, 44 | ], 45 | }, 46 | location: Location { 47 | line_start: 1, 48 | line_end: 1, 49 | column_start: 1, 50 | column_end: 20, 51 | }, 52 | }, 53 | Node { 54 | comments: [], 55 | node: LocalDeclaration { 56 | namelist: [ 57 | Name( 58 | "y", 59 | ), 60 | ], 61 | explist: [ 62 | Node { 63 | comments: [], 64 | node: Unary { 65 | exp: Node { 66 | comments: [], 67 | node: NamedVar( 68 | "items", 69 | ), 70 | location: Location { 71 | line_start: 3, 72 | line_end: 3, 73 | column_start: 12, 74 | column_end: 17, 75 | }, 76 | }, 77 | op: Length, 78 | }, 79 | location: Location { 80 | line_start: 3, 81 | line_end: 3, 82 | column_start: 11, 83 | column_end: 17, 84 | }, 85 | }, 86 | ], 87 | }, 88 | location: Location { 89 | line_start: 3, 90 | line_end: 3, 91 | column_start: 1, 92 | column_end: 17, 93 | }, 94 | }, 95 | Node { 96 | comments: [], 97 | node: LocalDeclaration { 98 | namelist: [ 99 | Name( 100 | "z", 101 | ), 102 | ], 103 | explist: [ 104 | Node { 105 | comments: [], 106 | node: Unary { 107 | exp: Node { 108 | comments: [], 109 | node: Number( 110 | "1000", 111 | ), 112 | location: Location { 113 | line_start: 5, 114 | line_end: 5, 115 | column_start: 12, 116 | column_end: 16, 117 | }, 118 | }, 119 | op: Minus, 120 | }, 121 | location: Location { 122 | line_start: 5, 123 | line_end: 5, 124 | column_start: 11, 125 | column_end: 16, 126 | }, 127 | }, 128 | ], 129 | }, 130 | location: Location { 131 | line_start: 5, 132 | line_end: 5, 133 | column_start: 1, 134 | column_end: 16, 135 | }, 136 | }, 137 | ], 138 | ) 139 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/lua/snapshots/while/basic.snap: -------------------------------------------------------------------------------- 1 | while x < 100 do 2 | inc(x) 3 | end 4 | 5 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 6 | 7 | Block( 8 | [ 9 | Node { 10 | comments: [], 11 | node: While { 12 | cexp: Node { 13 | comments: [], 14 | node: Binary { 15 | lexp: Node { 16 | comments: [], 17 | node: NamedVar( 18 | "x", 19 | ), 20 | location: Location { 21 | line_start: 1, 22 | line_end: 1, 23 | column_start: 7, 24 | column_end: 8, 25 | }, 26 | }, 27 | op: Lt, 28 | rexp: Node { 29 | comments: [], 30 | node: Number( 31 | "100", 32 | ), 33 | location: Location { 34 | line_start: 1, 35 | line_end: 1, 36 | column_start: 11, 37 | column_end: 14, 38 | }, 39 | }, 40 | }, 41 | location: Location { 42 | line_start: 1, 43 | line_end: 1, 44 | column_start: 7, 45 | column_end: 14, 46 | }, 47 | }, 48 | block: Block( 49 | [ 50 | Node { 51 | comments: [], 52 | node: FunctionCallStatement { 53 | pexp: Node { 54 | comments: [], 55 | node: NamedVar( 56 | "inc", 57 | ), 58 | location: Location { 59 | line_start: 2, 60 | line_end: 2, 61 | column_start: 3, 62 | column_end: 6, 63 | }, 64 | }, 65 | args: [ 66 | Node { 67 | comments: [], 68 | node: NamedVar( 69 | "x", 70 | ), 71 | location: Location { 72 | line_start: 2, 73 | line_end: 2, 74 | column_start: 7, 75 | column_end: 8, 76 | }, 77 | }, 78 | ], 79 | }, 80 | location: Location { 81 | line_start: 2, 82 | line_end: 2, 83 | column_start: 3, 84 | column_end: 9, 85 | }, 86 | }, 87 | ], 88 | ), 89 | }, 90 | location: Location { 91 | line_start: 1, 92 | line_end: 3, 93 | column_start: 1, 94 | column_end: 4, 95 | }, 96 | }, 97 | ], 98 | ) 99 | -------------------------------------------------------------------------------- /libs/docvim_parser/tests/markdown/mod.rs: -------------------------------------------------------------------------------- 1 | mod snapshots; 2 | -------------------------------------------------------------------------------- /libs/docvim_snapshot/Cargo.toml: -------------------------------------------------------------------------------- 1 | [dependencies] 2 | docvim_diff = { path = "../docvim_diff" } 3 | 4 | [lib] 5 | 6 | [package] 7 | authors = ["Greg Hurrell "] 8 | edition = "2021" 9 | name = "docvim_snapshot" 10 | version = "0.1.0" 11 | -------------------------------------------------------------------------------- /libs/docvim_snapshot/src/lib.rs: -------------------------------------------------------------------------------- 1 | use std::error::Error; 2 | use std::fs; 3 | use std::path::Path; 4 | 5 | use docvim_diff::format; 6 | use docvim_diff::histogram::diff; 7 | 8 | /// Divider consisting of 72 downward-pointing arrows with a blank line before and after. The 9 | /// string "OUTPUT" appears in the middle to make it easy to jump to the divider using search. 10 | const DIVIDER: &str = 11 | "\n\n↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓\n\n"; 12 | 13 | /// Environment variable that can be set (to any value) to force `check_snapshot()` to update the 14 | /// snapshot files on disk. 15 | pub const UPDATE_SNAPSHOTS: &str = "UPDATE_SNAPSHOTS"; 16 | 17 | /// Convenience macro for checking a snapshot relative to the current package. 18 | /// 19 | /// Mostly superseded by the `#[check_snapshots]` procedural macro defined in the docvim_macros 20 | /// package. 21 | #[macro_export] 22 | macro_rules! check_snapshot { 23 | ($path:expr, $callback:expr) => { 24 | docvim_snapshot::check_snapshot_relative_to_base( 25 | $path, 26 | std::env!("CARGO_MANIFEST_DIR"), 27 | $callback, 28 | false, 29 | ) 30 | }; 31 | } 32 | 33 | /// Really only used in the test_suite (ignores effect of UPDATE_SNAPSHOTS). 34 | #[macro_export] 35 | macro_rules! check_snapshot_dry_run { 36 | ($path:expr, $callback:expr) => { 37 | docvim_snapshot::check_snapshot_relative_to_base( 38 | $path, 39 | std::env!("CARGO_MANIFEST_DIR"), 40 | $callback, 41 | true, 42 | ) 43 | }; 44 | } 45 | 46 | pub fn check_snapshot_relative_to_base( 47 | path: &str, 48 | base: &str, 49 | callback: &dyn Fn(&str) -> String, 50 | dry_run: bool, 51 | ) -> Result> { 52 | let mut snapshot = Path::new(base).to_path_buf(); 53 | snapshot.push("tests/snapshots"); 54 | snapshot.push(Path::new(path)); 55 | snapshot.set_extension("snap"); 56 | check_snapshot(snapshot.as_path(), callback, dry_run) 57 | } 58 | 59 | pub fn check_snapshot( 60 | snapshot: &Path, 61 | callback: &dyn Fn(&str) -> String, 62 | dry_run: bool, 63 | ) -> Result> { 64 | // Read snapshot file. 65 | let contents = fs::read_to_string(snapshot)?; 66 | 67 | // Extract input and expected output. 68 | if let Some(divider_idx) = contents.find(DIVIDER) { 69 | let output_idx = divider_idx + DIVIDER.len(); 70 | let input = &contents[0..divider_idx]; 71 | let expected = &contents[output_idx..contents.len()]; 72 | let mut transformed = String::from(callback(&input)); 73 | if !transformed.ends_with("\n") { 74 | transformed.push('\n'); 75 | } 76 | 77 | if std::env::var_os(UPDATE_SNAPSHOTS).is_some() && !dry_run { 78 | let mut updated = String::from(input); 79 | updated.push_str(DIVIDER); 80 | updated.push_str(&transformed); 81 | fs::write(snapshot, updated)?; 82 | Ok(true) 83 | } else if expected == transformed { 84 | Ok(true) 85 | } else { 86 | let expected_lines = expected.lines().collect::>(); 87 | let transformed_lines = transformed.lines().collect::>(); 88 | 89 | // Show what change would be applied if we updated the snapshots. 90 | let ses = diff(&expected_lines, &transformed_lines); 91 | let formatted = format(ses, &expected_lines, &transformed_lines); 92 | println!("{}", formatted); 93 | 94 | println!("If output is correct, re-run with {}=1", UPDATE_SNAPSHOTS); 95 | Ok(false) 96 | } 97 | } else { 98 | // No divider found, so assume this is a new snapshot that we need to fill out. 99 | let mut input = String::from(contents); 100 | let transformed = String::from(callback(&input)); 101 | input.push_str(DIVIDER); 102 | input.push_str(&transformed); 103 | 104 | if !transformed.ends_with("\n") { 105 | input.push('\n'); 106 | } 107 | if !dry_run { 108 | fs::write(snapshot, input)?; 109 | } 110 | Ok(true) 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /libs/docvim_snapshot/tests/snapshots.rs: -------------------------------------------------------------------------------- 1 | use std::error::Error; 2 | 3 | use docvim_snapshot::{check_snapshot, check_snapshot_dry_run}; 4 | 5 | /// Demo function that uppercases its input. 6 | fn transform(input: &str) -> String { 7 | input.to_uppercase() 8 | } 9 | 10 | #[test] 11 | fn test_check_snapshot_macro_with_matching_snapshot() -> Result<(), Box> { 12 | assert!(check_snapshot!("valid_sample", &transform)?); 13 | Ok(()) 14 | } 15 | 16 | #[test] 17 | fn test_check_snapshot_macro_with_mismatching_snapshot() { 18 | // Use dry-run variant because we never want to update this snapshot, even when 19 | // UPDATE_SNAPSHOTS is set. 20 | let snapshot_mismatch = 21 | matches!(check_snapshot_dry_run!("invalid_sample", &transform), Ok(false)); 22 | 23 | assert!(snapshot_mismatch); 24 | } 25 | 26 | #[test] 27 | fn test_check_snapshot_macro_in_subdirectory() -> Result<(), Box> { 28 | assert!(check_snapshot!("subdirectory/sample", &transform)?); 29 | Ok(()) 30 | } 31 | -------------------------------------------------------------------------------- /libs/docvim_snapshot/tests/snapshots/invalid_sample.snap: -------------------------------------------------------------------------------- 1 | This string will be transformed to uppercase. 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | Transformed output won't match this, so test will fail. 6 | -------------------------------------------------------------------------------- /libs/docvim_snapshot/tests/snapshots/subdirectory/sample.snap: -------------------------------------------------------------------------------- 1 | Transforming strings to uppercase works in a subdirectory too. 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | TRANSFORMING STRINGS TO UPPERCASE WORKS IN A SUBDIRECTORY TOO. 6 | -------------------------------------------------------------------------------- /libs/docvim_snapshot/tests/snapshots/valid_sample.snap: -------------------------------------------------------------------------------- 1 | This string will be transformed to uppercase. 2 | 3 | ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ OUTPUT ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 4 | 5 | THIS STRING WILL BE TRANSFORMED TO UPPERCASE. 6 | -------------------------------------------------------------------------------- /sample/init.lua: -------------------------------------------------------------------------------- 1 | -- Example. 2 | local intro = [[hi!]] 3 | 4 | local docs = [[ 5 | Long format string here 6 | ]] 7 | 8 | local more_docs = [==[ 9 | Note this one can even include "]]" in it without terminating the string. 10 | ]==] 11 | 12 | if true then 13 | print(intro .. "world") 14 | print(docs) 15 | print(more_docs) 16 | end 17 | 18 | --[[ 19 | print('Commented-out code') 20 | --]] 21 | -------------------------------------------------------------------------------- /support/.gitignore: -------------------------------------------------------------------------------- 1 | /a.out 2 | -------------------------------------------------------------------------------- /support/collisions.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ``` 3 | * cc collisions.c 4 | * cat words.txt | ./a.out | sort -k 2 | uniq -D -f 1 | sed '$!N;s/\n/ /' 5 | * ``` 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | #define DJB2A 12 | #define DJB2A_BIG 13 | 14 | #ifdef DJB2A_BIG 15 | #include 16 | #define DJB2A_SIZE uint64_t 17 | #define HASH_FMT "%lu" 18 | #else 19 | #define DJB2A_SIZE unsigned int 20 | #define HASH_FMT "%u" 21 | #endif 22 | 23 | DJB2A_SIZE hash(const char *word) 24 | { 25 | DJB2A_SIZE hash = 5381; 26 | int c; 27 | while ((c = *word++)) { 28 | #ifdef DJB2A 29 | hash = ((hash << 5) + hash) ^ c; 30 | #else 31 | hash = ((hash << 5) + hash) + c; 32 | #endif 33 | } 34 | return hash; 35 | } 36 | 37 | int main() { 38 | char word[1024]; 39 | FILE *f = stdin; 40 | while (fscanf(f, "%1023s", word) == 1) { 41 | printf("%s " HASH_FMT "\n", word, hash(word)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /support/hash.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ``` 3 | * cc hash.c 4 | * ./a.out 5 | * ``` 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | #define DJB2A 12 | #define DJB2A_BIG 13 | 14 | #ifdef DJB2A_BIG 15 | #include 16 | #define DJB2A_SIZE uint64_t 17 | #define HASH_FMT "%lu" 18 | #else 19 | #define DJB2A_SIZE unsigned int 20 | #define HASH_FMT "%u" 21 | #endif 22 | 23 | DJB2A_SIZE hash(const char *word) 24 | { 25 | DJB2A_SIZE hash = 5381; 26 | int c; 27 | while ((c = *word++)) { 28 | #ifdef DJB2A 29 | hash = ((hash << 5) + hash) ^ c; 30 | #else 31 | hash = ((hash << 5) + hash) + c; 32 | #endif 33 | } 34 | return hash; 35 | } 36 | 37 | int main() { 38 | printf(HASH_FMT "\n", hash("hetairas")); 39 | printf(HASH_FMT "\n", hash("mentioner")); 40 | printf(HASH_FMT "\n", hash("haggadot")); 41 | printf(HASH_FMT "\n", hash("loathsomenesses")); 42 | 43 | // djb2 (32) djb2a (32) djb2 (64) djb2a (64) 44 | // 45 | // 3940087062 254653076 7572452189730070 7569463502025364 46 | // 3940087062 1605867752 249897947298854166 249788221435123944 47 | // 2567235620 379918194 7572446521911332 7569467922257778 48 | // 3968138338 379918194 2706329446310542434 10696802194950526834 49 | // 50 | // u64 Rust implementation does indeed agree with the last two columns. 51 | } 52 | --------------------------------------------------------------------------------