lectures.alex.balgavy.eu

Lecture notes from university.
git clone git://git.alex.balgavy.eu/lectures.alex.balgavy.eu.git
Log | Files | Refs | Submodules

commit a0e3a3f81ae7c57c1e640edb1ce8f55aa2a46079
parent 3c1685fcb3f4ce9dbcbce26134596bb2add86062
Author: Alex Balgavy <alex@balgavy.eu>
Date:   Sat, 12 Jun 2021 22:46:14 +0200

Intro to programming notes

Diffstat:
Mcontent/_index.md | 1+
Acontent/cpp-notes/Abstraction.md | 7+++++++
Acontent/cpp-notes/Advice for programming in C++.md | 28++++++++++++++++++++++++++++
Acontent/cpp-notes/Basic architecture & making a program/0ab6636bda3549b4a64812acc2481f5a.png | 0
Acontent/cpp-notes/Basic architecture & making a program/d1fed7a52380407e96ccadb9a7351bc1.png | 0
Acontent/cpp-notes/Basic architecture & making a program/index.md | 21+++++++++++++++++++++
Acontent/cpp-notes/Basic functionality.md | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acontent/cpp-notes/Constants in C++.md | 11+++++++++++
Acontent/cpp-notes/Declarations, definitions, init.md | 26++++++++++++++++++++++++++
Acontent/cpp-notes/Enumerations.md | 30++++++++++++++++++++++++++++++
Acontent/cpp-notes/Functions.md | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acontent/cpp-notes/Glossary.md | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Acontent/cpp-notes/Grammars.md | 24++++++++++++++++++++++++
Acontent/cpp-notes/Header files.md | 12++++++++++++
Acontent/cpp-notes/Modular programming/6d5dc15c08d82af46e93fec41ec22f28.png | 0
Acontent/cpp-notes/Modular programming/index.md | 91+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acontent/cpp-notes/Namespaces.md | 18++++++++++++++++++
Acontent/cpp-notes/Operator overloading.md | 27+++++++++++++++++++++++++++
Acontent/cpp-notes/Randomness.md | 25+++++++++++++++++++++++++
Acontent/cpp-notes/Recursion.md | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acontent/cpp-notes/Scope.md | 15+++++++++++++++
Acontent/cpp-notes/Separate compilation.md | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acontent/cpp-notes/The Standard Library.md | 101+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acontent/cpp-notes/Tokens.md | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acontent/cpp-notes/Types.md | 11+++++++++++
Acontent/cpp-notes/Variable types & their operators/b80694855519b22b77375e2df16835bd.png | 0
Acontent/cpp-notes/Variable types & their operators/index.md | 5+++++
Acontent/cpp-notes/_index.md | 26++++++++++++++++++++++++++
Asyntaxes/Makefile/Comments.tmPreferences | 25+++++++++++++++++++++++++
Asyntaxes/Makefile/Indention Rules.tmPreferences | 14++++++++++++++
Asyntaxes/Makefile/Make Output.sublime-syntax | 13+++++++++++++
Asyntaxes/Makefile/Make.sublime-build | 16++++++++++++++++
Asyntaxes/Makefile/Makefile.sublime-settings | 3+++
Asyntaxes/Makefile/Makefile.sublime-syntax | 655+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asyntaxes/Makefile/syntax_test_makefile.mak | 954+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asyntaxes/Ruby/Comments.tmPreferences | 31+++++++++++++++++++++++++++++++
Asyntaxes/Ruby/Completion Rules.tmPreferences | 12++++++++++++
Asyntaxes/Ruby/Default.sublime-keymap | 13+++++++++++++
Asyntaxes/Ruby/Indentation Rules.tmPreferences | 47+++++++++++++++++++++++++++++++++++++++++++++++
Asyntaxes/Ruby/Ruby.sublime-build | 5+++++
Asyntaxes/Ruby/Ruby.sublime-syntax | 2204+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asyntaxes/Ruby/Snippets/#!;usr;local;bin;ruby-w.sublime-snippet | 7+++++++
Asyntaxes/Ruby/Snippets/060-ruby-if-else.sublime-snippet | 10++++++++++
Asyntaxes/Ruby/Snippets/070-ruby-if.sublime-snippet | 8++++++++
Asyntaxes/Ruby/Snippets/080-ruby-case.sublime-snippet | 9+++++++++
Asyntaxes/Ruby/Snippets/Add-'#-=-'-Marker.sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/Array.new(10)-{-i-..-}-(Arr).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/Benchmark_bmbm(__)-do-__-end.sublime-snippet | 9+++++++++
Asyntaxes/Ruby/Snippets/Dir.glob(-..-)-do-file-..-end-(Dir).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/Dir[-__-].sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/File.foreach-(-..-)-do-line-..-end-(File).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/File_open(-__-)-{-file-__-}.sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/File_read(-__-).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/Hash.new-{-hash-key-hash[key]-=-..-}-(Has).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/Marshal.dump(obj-file)-(Md).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/Marshal.load(obj)-(Ml).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/PStore_new(-__-).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/RDoc-documentation-block.sublime-snippet | 8++++++++
Asyntaxes/Ruby/Snippets/Wrap-in-Begin-Rescue-End.sublime-snippet | 11+++++++++++
Asyntaxes/Ruby/Snippets/YAML.dump(..-file)-(Yd-).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/YAML.load(file)-(Yl-).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/alias_method-..-(am).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/all-{-e-..-}-(all).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/any-{-e-..-}-(any).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/application_code-..-(app).sublime-snippet | 8++++++++
Asyntaxes/Ruby/Snippets/assert(..)-(as).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/assert_equal.sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/assert_in_delta(..)-(asid).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/assert_instance_of(..)-(asio).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/assert_kind_of(..)-(asko).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/assert_match(..)-(asm).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/assert_nil(..)-(asn).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/assert_no_match(..)-(asnm).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/assert_not_equal(..)-(asne).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/assert_not_nil(..)-(asnn).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/assert_not_same(..)-(asns).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/assert_nothing_raised(..)-{-..-}-(asnr).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/assert_nothing_thrown-{-..-}-(asnt).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/assert_operator(..)-(aso).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/assert_raise(..)-{-..-}-(asr).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/assert_respond_to(..)-(asrt).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/assert_same(..)-(ass).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/assert_send(..)-(ass).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/assert_throws(..)-{-..-}-(ast).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/attr_accessor-..-(rw).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/attr_reader-..-(r).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/attr_writer-..-(w).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/class-..-DelegateClass-..-initialize-..-end-(class).sublime-snippet | 14++++++++++++++
Asyntaxes/Ruby/Snippets/class-..-ParentClass-..-initialize-..-end.sublime-snippet | 12++++++++++++
Asyntaxes/Ruby/Snippets/class-..-Struct-..-initialize-..-end.sublime-snippet | 12++++++++++++
Asyntaxes/Ruby/Snippets/class-..-Test;;Unit;;TestCase-..-end-(tc).sublime-snippet | 14++++++++++++++
Asyntaxes/Ruby/Snippets/class-..-end-(cla).sublime-snippet | 8++++++++
Asyntaxes/Ruby/Snippets/class-..-initialize-..-end.sublime-snippet | 12++++++++++++
Asyntaxes/Ruby/Snippets/class-..-instance_methods-..-undef-..-initialize-..-end-(class).sublime-snippet | 20++++++++++++++++++++
Asyntaxes/Ruby/Snippets/class-self-__-end.sublime-snippet | 8++++++++
Asyntaxes/Ruby/Snippets/class_from_name()-(clafn).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/classify-{-e-..-}-(clas).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/collect-{-e-..-}-(col).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/deep_copy(..)-(dee).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/def-end.sublime-snippet | 8++++++++
Asyntaxes/Ruby/Snippets/def-method_missing-..-end-(mm).sublime-snippet | 8++++++++
Asyntaxes/Ruby/Snippets/def-self-..-end-(defs).sublime-snippet | 8++++++++
Asyntaxes/Ruby/Snippets/def-test_-..-end-(t).sublime-snippet | 8++++++++
Asyntaxes/Ruby/Snippets/def_delegator-..-(defd).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/def_delegators-..-(defds).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/def_initialize.sublime-snippet | 11+++++++++++
Asyntaxes/Ruby/Snippets/delete_if-{-e-..-}-(deli).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/detect-{-e-..-}-(det).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/directory().sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/do-obj-..-end-(doo).sublime-snippet | 8++++++++
Asyntaxes/Ruby/Snippets/downto(0)-{-n-..-}-(dow).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/each-{-e-..-}-(ea).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/each_byte-{-byte-..-}-(eab).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/each_char-{-chr-..-}-(eac-).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/each_cons(..)-{-group-..-}-(eac-).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/each_index-{-i-..-}-(eai).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/each_key-{-key-..-}-(eak).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/each_line-{-line-..-}-(eal).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/each_pair-{-name-val-..-}-(eap).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/each_slice-{-group-..-}-(eas).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/each_value-{-val-..-}-(eav).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/each_with_index-{-e-i-..-}-(eawi).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/elsif-___.sublime-snippet | 7+++++++
Asyntaxes/Ruby/Snippets/extend-Forwardable-(Forw).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/fetch(name)-{-key-..-}-(fet).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/fill(range)-{-i-..-}-(fil).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/find-{-e-..-}-(fin).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/find_all-{-e-..-}-(fina).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/flatten_once-(fla).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/flunk(..)-(fl).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/grep(;pattern;)-{-match-..-}-(gre).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/gsub(;..;)-{-match-..-}-(gsu).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/hash-pair-(-).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/include-Comparable-..-(Comp).sublime-snippet | 10++++++++++
Asyntaxes/Ruby/Snippets/include-Enumerable-..-(Enum).sublime-snippet | 10++++++++++
Asyntaxes/Ruby/Snippets/inject(init)-{-mem-var-..-}-(inj).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/lambda-{-args-..-}-(lam).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/loop-{-__-}.sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/map-{-e-..-}-(map).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/map_with_index-{-e-i-..-}-(mapwi).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/max-{-a-b-..-}-(max).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/min-{-a-b-..-}-(min).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/module-..-ClassMethods-..-end.sublime-snippet | 19+++++++++++++++++++
Asyntaxes/Ruby/Snippets/module-..-end.sublime-snippet | 8++++++++
Asyntaxes/Ruby/Snippets/module-..-module_function-..-end.sublime-snippet | 10++++++++++
Asyntaxes/Ruby/Snippets/namespace-__-do-__-end.sublime-snippet | 8++++++++
Asyntaxes/Ruby/Snippets/open(-path;or;url-w-)-do-doc-..-end-(ope).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/open-yield-block-({).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/option_parse-{-..-}-(optp).sublime-snippet | 32++++++++++++++++++++++++++++++++
Asyntaxes/Ruby/Snippets/partition-{-e-..-}-(par).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/path_from_here(-__-).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/randomize-(ran).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/reject-{-e-..-}-(rej).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/require-..-(req).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/require-tc_..-..-(ts).sublime-snippet | 10++++++++++
Asyntaxes/Ruby/Snippets/require_gem-__.sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/results_report(__)-{-__-}.sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/reverse_each-{-e-..-}-(rea).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/scan(;..;)-{-match-..-}-(sca).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/select-{-e-..-}-(sel).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/service_object.sublime-snippet | 19+++++++++++++++++++
Asyntaxes/Ruby/Snippets/singleton_class().sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/sort-{-a-b-..-}-(sor).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/sort_by-{-e-..-}-(sorb).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/step(2)-{-e-..-}-(ste).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/sub(;..;)-{-match-..-}-(sub).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/task-task_name-=-[-dependent-tasks]-do-__-end.sublime-snippet | 9+++++++++
Asyntaxes/Ruby/Snippets/times-{-n-..-}-(tim).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/transaction(-__-)-do-__-end.sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/unix_filter-..-(uni).sublime-snippet | 8++++++++
Asyntaxes/Ruby/Snippets/unless-(unless).sublime-snippet | 8++++++++
Asyntaxes/Ruby/Snippets/until-___-end.sublime-snippet | 8++++++++
Asyntaxes/Ruby/Snippets/untitled.sublime-snippet | 9+++++++++
Asyntaxes/Ruby/Snippets/upto(1.0;0.0)-{-n-..-}-(upt).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/usage_if()-(usai).sublime-snippet | 8++++++++
Asyntaxes/Ruby/Snippets/usage_unless()-(usau).sublime-snippet | 8++++++++
Asyntaxes/Ruby/Snippets/when.sublime-snippet | 7+++++++
Asyntaxes/Ruby/Snippets/while-___-end.sublime-snippet | 8++++++++
Asyntaxes/Ruby/Snippets/xmlread(__).sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/xpath(__)-{-__-}.sublime-snippet | 8++++++++
Asyntaxes/Ruby/Snippets/yields-RDoc-comment.sublime-snippet | 6++++++
Asyntaxes/Ruby/Snippets/zip(enums)-{-row-..-}-(zip).sublime-snippet | 6++++++
Asyntaxes/Ruby/Symbol List - Classes, Modules.tmPreferences | 19+++++++++++++++++++
Asyntaxes/Ruby/Symbol List - Methods.tmPreferences | 16++++++++++++++++
Asyntaxes/Ruby/syntax_test_ruby.rb | 1397+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
185 files changed, 7340 insertions(+), 0 deletions(-)

diff --git a/content/_index.md b/content/_index.md @@ -39,6 +39,7 @@ title = "Alex's university course notes" ## Subject notes: Year 1 +* [Introduction to Programming in C++](cpp-notes) * [Computational thinking](compthink-notes) * [Systems architecture](https://thezeroalpha.github.io/sysarch-notes) * [Physical Computing](https://thezeroalpha.github.io/physcomp-notes) diff --git a/content/cpp-notes/Abstraction.md b/content/cpp-notes/Abstraction.md @@ -0,0 +1,7 @@ ++++ +title = 'Abstraction' ++++ +# Abstraction +“Eliminate the irrelevant, amplify the essential.” + +a process of hiding details of implementation in programs and data diff --git a/content/cpp-notes/Advice for programming in C++.md b/content/cpp-notes/Advice for programming in C++.md @@ -0,0 +1,28 @@ ++++ +title = 'Advice for programming in C++' ++++ +# Advice for programming in C++ +1. When you program, you create a concrete representation of the ideas in your solution to someproblem. Let the structure of the program reflect those ideas as directly as possible: + + 1. If you can think of ‘‘it’’ as a separate idea, make it a class. + + 2. If you can think of ‘‘it’’ as a separate entity, make it an object of some class. + + 3. If two classes have a common interface, make that interface an abstract class. + + 4. If the implementations of two classes have something significant in common, make that commonality a base class. + + 5. If a class is a container of objects, make it a template. + + 6. If a function implements an algorithm for a container, make it a template function implementing the algorithm for a family of containers. + + 7. If a set of classes, templates, etc., are logically related, place them in a common namespace. + +2. When you define either a class that does not implement a mathematical entity like a matrix or acomplex number or a low-level type such as a linked list: + + 1. Don’t use global data (use members). + 2. Don’t use global functions. + 3. Don’t use public data members. + 4. Don’t use friends, except to avoid [a] or [c]. + 5. Don’t put a ‘‘type field’’ in a class; use virtual functions. + 6. Don’t use inline functions, except as a significant optimization. diff --git a/content/cpp-notes/Basic architecture & making a program/0ab6636bda3549b4a64812acc2481f5a.png b/content/cpp-notes/Basic architecture & making a program/0ab6636bda3549b4a64812acc2481f5a.png Binary files differ. diff --git a/content/cpp-notes/Basic architecture & making a program/d1fed7a52380407e96ccadb9a7351bc1.png b/content/cpp-notes/Basic architecture & making a program/d1fed7a52380407e96ccadb9a7351bc1.png Binary files differ. diff --git a/content/cpp-notes/Basic architecture & making a program/index.md b/content/cpp-notes/Basic architecture & making a program/index.md @@ -0,0 +1,21 @@ ++++ +title = 'Basic architecture & making a program' ++++ +# Basic architecture & making a program +## Von Neumann Architecture +Early computer design. + +CPU: ALU, CU with instruction register and program counter + +The CN sees memory contents in bits, 1 or 0. That's called a binary program. + +How to make binary program? +- Opt. 1: program bit by bit +- Opt. 2: compile to binary. + - C++ is a compiled language. + + ![65418c4b17ccbc237a004cfb5edfe470.png](0ab6636bda3549b4a64812acc2481f5a.png) + +- Opt. 3: interpreter that converts & executes a HLL, line-by-line + + ![adb0bda1daddad55ed78750983e9064f.png](d1fed7a52380407e96ccadb9a7351bc1.png) diff --git a/content/cpp-notes/Basic functionality.md b/content/cpp-notes/Basic functionality.md @@ -0,0 +1,81 @@ ++++ +title = 'Basic functionality' ++++ +# Basic functionality +## Variables +```cpp +int inch; +bool answer=true; +``` + +## Fundamental types +- integral: boolean (bool), character (char), integer (int) +- arithmetic: floating-point (double), integral types +- user-defined types: enumeration (enum) and classes +- absence of information (void) + +from these, you can construct: +- pointer types (int*, char*,…) +- arrays (int[], char[], …) +- reference (double&), data structures + +## Operators +- arithmetic: +, -, /, *, % +- comparison: ==, !=, <, >, <=, >= +- ‘put to’: << +- ‘get from’: >> — type accepted depends on the right-hand operand + +## Tests (conditionals) +```cpp +// simple function that asks user to proceed +bool accept() { +    cout << “Do you want to proceed (yN)?\n”; +    char answer=0; +    cin >> answer; + +    if (answer == ‘y’) return true; +    return false; +} + +// more complex function, with a switch statement +bool accept2() { +    cout << “Do you want to proceed (yN)?\n”; +    char answer=0; +    cin >> answer; +    switch (answer) { +    case ‘y’: +        return true; +    case ’n’: +        return false; +    default: +        cout << “Whatever, it’s a no.\n”; +        return false; +    } +} +``` + +## Loops +```cpp +while (condition) { +    // execute code +    // opt. increment iterator +} + +for (int i=0; i<10; i++) { +    // execute code +} +``` + +## Pointers & arrays +- array declaration: + ```cpp + char v[10];    // array of 10 chars, with 0 as lower bound + ``` +- pointer declaration: + ```cpp + char* p;    // pointer to a char element + ``` +- setting a pointer: + ```cpp + p = &v[3];    // p points to address of index 3 of array v + ``` diff --git a/content/cpp-notes/Constants in C++.md b/content/cpp-notes/Constants in C++.md @@ -0,0 +1,11 @@ ++++ +title = 'Constants in C++' ++++ +# Constants in C++ +Why? + +If you know that a value will always be the same, the compiler can use that fact for optimisations. For example — it will always have the same size in memory, so the computer can use that memory for other things. + +Two options +- `const` — declares an object as constant. Immutable once initialised. +- `constexpr` — constant at compile-time diff --git a/content/cpp-notes/Declarations, definitions, init.md b/content/cpp-notes/Declarations, definitions, init.md @@ -0,0 +1,26 @@ ++++ +title = 'Declarations, definitions, init' ++++ +# Declarations, definitions, init +Each definition is a declaration, but not each declaration is also a definition. + +## Declarations +- a declaration is a statement that introduces a name into a scope +- declare variables/functions before use +- declarations say how something can be used, not how it’s implemented +- in function declaration, named parameters are not necessary, but useful + +## Definitions +- a definition fully specifies the entity declared +- sets aside memory for the variable + +## Initialisation +ways of initialising: + +- = syntax — `double d = 2;` +- () syntax — `vector<int> v(10);` + - specifies number of elements +- {} syntax — `vector<int> v{1,2,3};` + - gives a “vector literal" + +with const, initialisation is mandatory diff --git a/content/cpp-notes/Enumerations.md b/content/cpp-notes/Enumerations.md @@ -0,0 +1,30 @@ ++++ +title = 'Enumerations' ++++ +# Enumerations +enum (enumeration) — simple user-defined type, specifying its set of values as symbolic constants + +by default, values of constants start with 0 and increment by 1 with each constant + +you can give a constant a value from which the rest is incremented + +e.g.: + +```cpp +enum class Month { + jan=1, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec +}; +``` + +conversions: + +```cpp +Mont int_to_month(int x) { + if (x < int(Month::jan) || int(Month::dec) < x) + error(“bad month”); + return Month(x); +} + +int m = 12; +Month mm = int_to_month(m); +``` diff --git a/content/cpp-notes/Functions.md b/content/cpp-notes/Functions.md @@ -0,0 +1,54 @@ ++++ +title = 'Functions' ++++ +# Functions +defined by types of input parameters, its name, type of return value, and algorithm that computes return value from input values + +example: + +```cpp +int add(int a, int b) { + return a+b; +} +``` + +when a function is called, thread of execution continues within code of function + +as soon as it returns, code that called the function continues +a function returns if: +1. It reaches a return statement +2. It reaches the end of its code block + +a void function is allowed to reach end of its code block + +a function that has a return value must reach a return statement or throw an exception + +## Parameters +parameters in declaration of function are called *formal parameters* +parameters in call of function are called *actual parameters* + +Rules of thumb: +1. Use pass-by-value for small objects +2. Use pass-by-const-reference for large objects that you don’t need to modify +3. Return a result rather than modifying parameter through reference +4. Use pass-by-reference only when you have to — when there’s no alternative + +pass-by-value: + +- copies actual parameters into formal parameters +- formal parameters in function can’t modify anything outside the function +- happens by default +- inefficient with large parameters +- `void print(vector<double> v) {}` + +pass-by-const-reference + +- passes address of values (reference) +- efficient, no copying of data +- safe, parameter is const and can’t be overwritten +- `void print(const vector<double>& v) {}` + +pass-by-reference + +- if we want to modify contents of parameters, pass by reference +- `void init(vector<double>& v) { v[2]=2; }` diff --git a/content/cpp-notes/Glossary.md b/content/cpp-notes/Glossary.md @@ -0,0 +1,52 @@ ++++ +title = 'Glossary' ++++ +# Glossary +- // — denotes a comment +- << — “put into” operator +- C++ — the language C, but improved + +- comment — documentation, only seen by the programmer and not read by the compiler + +- compiler — turns source code into object code +- compile-time error — an error caught while compiling +- cout — character output stream +- executable — a program that can run on a computer + +- function — a subprocess that has multiple parts to it (return type, name, parameters, code) + +- header — an external file with code + +- IDE — development environment that has everything, and can both compile and execute code + +- #include — make available code from other libraries (preprocessor directive) +- library — an external file with functions +- linker — ‘links’ together code compiled separately into one executable file +- main() — every C++ program needs this, the first method that is executed +- object code — compiled source code +- output — result from a program +- program — a thing you can run on your computer +- source code — text written by programmer +- statement — a single line of code +- assignment — giving a value to a variable +- cin — character input stream +- concatenation — combining two strings +- conversion — changing from one type to another +- declaration — naming something (variable, function, etc.) in a statement +- decrement — decrease value +- definition — declaration that sets aside memory for an object +- increment — increase value +- initialization — give a variable an initial value +- name — (obvious) + +- narrowing — putting a value into an object that is too small for the value (e.g. large int into a char) + +- object — region of memory with a type +- operation — something that you do to a value +- operator — +, -, /, *, ==, <=, ……... +- type — int, float, bool, double.. + +- type safety — safely converting from one type to another (initializing a variable before using it, converting correctly) + +- value — set of bits in memory, interpreted according to type +- variable — a named object diff --git a/content/cpp-notes/Grammars.md b/content/cpp-notes/Grammars.md @@ -0,0 +1,24 @@ ++++ +title = 'Grammars' ++++ +# Grammars +A grammar defines the syntax of the input. We can then write a program implementing the rules of that grammar. + +For a calculator, a grammar looks like this: + +``` +Expression: + Term + Expression “+” Term + Expression “-“ Term +Term: + Primary + Term “*” Primary + Term “/“ Primary + Term “%” Primary +Primary: + Number + “(“ Expression “)” +Number: + floating-point-literal +``` diff --git a/content/cpp-notes/Header files.md b/content/cpp-notes/Header files.md @@ -0,0 +1,12 @@ ++++ +title = 'Header files' ++++ +# Header files +- collections of declarations +- conventionally have extension .h +- #included near “head” of program + +## `#include` +- copies contents of header into program text +- for consistency, #include interface of class into file with its implementation +- handled by preprocessor (first compiler phase) — check what it does by g++ -E diff --git a/content/cpp-notes/Modular programming/6d5dc15c08d82af46e93fec41ec22f28.png b/content/cpp-notes/Modular programming/6d5dc15c08d82af46e93fec41ec22f28.png Binary files differ. diff --git a/content/cpp-notes/Modular programming/index.md b/content/cpp-notes/Modular programming/index.md @@ -0,0 +1,91 @@ ++++ +title = 'Modular programming' ++++ +# Modular programming +"Decide which modules you want; partition the program so that data is hidden within modules.” + +## Namespaces +for example, the definition for a stack. the problems to solve: + +1. Provide a user interface (functions *push* and *pop*) +2. Ensure that the representation of the stack can only be accessed through these methods +3. Ensure that the stack is initialized before its first use + +for a stack, interface could be declared and used like this: + +```cpp +namespace Stack { +    void push(char); +    char pop(); +} +void f() { +    Stack::push(‘c’); +    if (Stack::pop() != ‘c’) error(“impossible”); +} +``` + +## Separate compilation +define the interface in `stack.h`: + +```cpp +namespace Stack { +    void push(char); +    char pop(); +} +``` + +include the header file and implement the interface: + +```cpp +#include “stack.h” +namespace Stack { +    const int max_size=200; +    char v[max_size]; +    int top=0; +} + +void Stack::push(char c) { /* check for overflow and push c */ } +char Stack::pop() { /* check for underflow and pop */ } +``` + +graphically, it looks like this: + +![screenshot.png](6d5dc15c08d82af46e93fec41ec22f28.png) + +## Exception handling +in interface, define the exception (`stack.h`): + +```cpp +namespace Stack { +    ... +    class Overflow { }; +} +``` + +in implementation, throw the exception when needed (`stack.c`): + +```cpp +#include “stack.h" +namespace Stack { +    … +    void Stack::push(char c) { +        if(top==max_size) throw Overflow(); +        // push c +    } +} +``` + +use the exception capabilities in code (`user.c`): + +```cpp +#include “stack.h” +void f() { +    … +    try { +        while (true) Stack::push(‘c’); +    } +    catch (Stack::Overflow) { +        // take appropriate action +    } +} +``` diff --git a/content/cpp-notes/Namespaces.md b/content/cpp-notes/Namespaces.md @@ -0,0 +1,18 @@ ++++ +title = 'Namespaces' ++++ +# Namespaces +Scopes: global, class, function, local, statement + +Namespaces help distinguish between identical variable names from different contexts. + +## Using +using declaration: + +- `using std::string` — “when I write string, I mean std::string” +- specific to one function/class + +using directive: + +- `using namespace std` — “when you can’t find a name in this scope, look in std” +- can be dangerous, you might not get what you’re looking for diff --git a/content/cpp-notes/Operator overloading.md b/content/cpp-notes/Operator overloading.md @@ -0,0 +1,27 @@ ++++ +title = 'Operator overloading' ++++ +# Operator overloading +an operator is just a function with different syntax +you cannot define any new operators + +ex: + +```c++ +enum class Month{ + jan=1, feb, mar, apr, may, jun, jul, aug, sept, oct, nov, dec +}; + +vector<string> month_table {“January”, “February”, ..etc}; + +ostream& operator<<(ostream& os, Month m) { + return os << month_table[int(m)-1]; +} + +int main() { + Month m {Month::dec}; + cout << m; + + // returns “December” +} +``` diff --git a/content/cpp-notes/Randomness.md b/content/cpp-notes/Randomness.md @@ -0,0 +1,25 @@ ++++ +title = 'Randomness' ++++ +# Randomness +nothing really behaves randomly in a computer, everything is 100% reproducible + +but possible combinations of state often make it look as if something behaves unpredictably + +if you want real randomness, you need to observe a physical phenomenon (e.g. atmospheric noise) + +true randomness is hard to achieve, but pseudo randomness is enough most of the time + +`int rand()` +- Pseudorandom generator +- produces a sequence of numbers based on algorithm that humans can’t guess any better than by “chance” +- it’s a stateful function +- returns pseudo-random number between 0 and RAND_MAX +- included through `<iostream>` for some reason +- unless seeded, always returns same sequence of numbers + +to seed, use function: +`void srand((unsigned) int seed)` + +best to use with time: +`srand((unsigned) time(0))` diff --git a/content/cpp-notes/Recursion.md b/content/cpp-notes/Recursion.md @@ -0,0 +1,89 @@ ++++ +title = 'Recursion' ++++ +# Recursion +Recursion: when a method calls itself…how would you use that? will explain, let’s start with something everyone here knows + +Used for quicksort and divide and conquer algorithms. +Divide and conquer: +1. Divide problem into smaller ones +2. Compute subproblems recursively +3. Combine partial results to overall solution + +## Factorial — n! +Everyone here knows what the factorial is. + +Important definition — 1! = 1. may seem obvious, but very important, because lets us get definite answer for the factorial of a number. + +For this example, let’s choose a nice round number. 5. + +`5! = 120`. How do we know that? `5*4*3*2*1` + +so `5! = 120 = 5*4*3*2*1` + +but the mathematicians here know that: +- `5! = 5*4! = 5*4*3! = 5*4*3*2! = 5*4*3*2*1!. 1!=1` from definition, therefore +- `5! = 5*4*3*2*1 = 120` + + +## Java implementation — recursion + +Keep that in mind. Now, Java code which you can follow along with. Do any of you know ternary operator? No…I will write expanded. Otherwise, ternary operator. + +```cpp +public class Factorial { + public static void main(String[] args) { + System.out.println(fact(5)); + } + + public static int fact(int n) { + + // Done simply using ternary operator: + // return (n==1)? 1 : n*fact(n-1); + + if (n==1) { + return 1; // If n is 1, return 1 + } + + else { + return n*fact(n-1); // Otherwise, return n times factorial of a number one less + } + } +} +``` + +In the else statement, there is *recursion*. The method fact is calling itself. If you don’t understand what that does yet, let me show it to you. + +## Code flow explanation +Indentation shows different levels of execution within the program. + +Method main runs and asks the factorial method — what is fact5? + +``` +main: fact(5)? + +fact: +fact5 - 5*fact4 - fact4? +fact4 - 4*fact3 - fact3? +fact3 - 3*fact2 - fact2? +fact2 - 2*fact1 - fact1? +     fact1 - 1 (‘if’ part of statement runs) +fact2 - 2*1 - return 2 +fact3 - 3*2 - return 6 +fact4 - 4*6 - return 24 +fact5 - 5*24 - return 120 + +main: fact(5) = 120 +``` + +Basically, it’s just a huge stack of the method calling itself over and over again until it hits the ‘if’ part of the statement (until n is 1) and returns a specific value, and that’s passed back along the stack until you get a concrete result. That’s recursion. + +## Ruby implementation + +```ruby +def fact n +     return n==1? 1 : n*fact(n-1) +end + +puts fact(5) +``` diff --git a/content/cpp-notes/Scope.md b/content/cpp-notes/Scope.md @@ -0,0 +1,15 @@ ++++ +title = 'Scope' ++++ +# Scope +region of program text. +name is declared and valid in a scope. +scopes are nested. + +- global: text outside any other scope +- namespace: named scope nested in global scope (or another namespace) +- class: text within class +- local: between {...} of block or in function argument list +- statement: e.g. in a for statement + +scopes keep names local diff --git a/content/cpp-notes/Separate compilation.md b/content/cpp-notes/Separate compilation.md @@ -0,0 +1,67 @@ ++++ +title = 'Separate compilation' ++++ +# Separate compilation +as soon as project grows to multiple files, compilation must be managed + +files involved depend on one another, updating one causes others to be recompiled + +## make +- the first Unix tool to automate compile-and-build process +- reads a makefile, which describes dependencies +- also reads timestamps to determine which file is newest +- only re-compile the stuff that depends on a newer file + +### makefile entries +syntax is as follows: + +``` +target: *list of sources* + command of recipe steps (compilation) +``` + +has to be indented with a single tab, unless you set `.RECIPEPREFIX` like in [this article](https://tech.davis-hansson.com/p/make/). + +can set variables and use them like in bash, for example for compiler or flags + +wildcard: % (example: %.o) + +automatic variables: + +- $@ — filename of the target +- $< — filename of first prerequisite + +### phony targets +`.PHONY`: can declare a phony target so that the target is run even if a file of the same name exists in the directory. + +e.g.: + +```make +.PHONY: clean +clean: + rm *.o temp +``` + +### example: + +```make +CC=g++ +CFLAGS= -std=c++11 -stdlib=libc++ -Weverything + +all: bank + +account.o: account.h account.cpp +    $(CC) $(CFLAGS) -c account.cpp + +bank.o: bank.cpp bank.h account.o +    $(CC) $(CFLAGS) -c bank.cpp + +main.o: main.cpp bank.o +    $(CC) $(CFLAGS) -c main.cpp + +bank: bank.o main.o +    $(CC) $(CFLAGS) main.o bank.o account.o -o bank + +clean: +    rm *.o bank + ``` diff --git a/content/cpp-notes/The Standard Library.md b/content/cpp-notes/The Standard Library.md @@ -0,0 +1,101 @@ ++++ +title = 'The Standard Library' ++++ +# The Standard Library +## The minimal program +```cpp +int main() {} +``` + +Every program needs a main method. A nonzero return value indicates failure. + +## Hello world +```cpp +#include <iostream> +int main() { +    std::cout << “Hello, world!\n”; +} +``` + +## The standard library namespace + +Everything provided by the standard library needs a `std::` prefix. Either include headers and use prefix, or make everything global, such as this: + +```cpp +#include <string> // include the standard string facilities +using namespace std; // make std names available without prefix +string s=“Ignorance is bliss!” // cool, string is std::string +``` + +But making everything global is generally in poor taste. Albeit easier. + +## Output +By default, values to output are converted to a sequence of characters. +You can combine values in an obvious way: + +```cpp +void f(int i) { +    cout << “The value of i is “; +    cout << i; +    cout << “.\n”; +} +``` + +To simplify it, you can use the result of an output expression for further output: + +```cpp +void g(int i) { +    cout << “The value of i is “ << i << “.\n”; +} +``` + +## Strings +the standard library provides string concatenation, using the + operator. + +```cpp +string s3 = “Hello “ + “world.” + “\n”; +cout << s3; +``` + +you can also append to a string: + +```cpp +s1 = s1 + “\n”;    // verbose +s1 += “\n”;        // shorthand +``` + +manipulating substrings is also straightforward: + +```cpp +string name=“Niels Stroustrup”; + +string s=name.substr(6,10);    // s=“Stroustrup” — starting at 6, with a len of 10 + +name.replace(0,5,”Nicholas”);  // name becomes “Nicholas Stroustrup” +``` + +## Input +```cpp +int main() { +    string str; +    cout << “Please enter your name:\n”; +    cin >> str; +    cout << “Hello “ << str << “!\n”; +} +``` + +## Vectors +```cpp +struct Entry { +    string name; +    int number; +} + +vector<Entry> phone_book(1000);    // Initial size: 1000 +void print_entry(int i) { +    cout << phone_book[i].name << ‘ ‘ << phone_book[i].number << ‘\n’; +} +void add_entries(int n) { +    phone_book.resize(phone_book.size()+n); +} +``` diff --git a/content/cpp-notes/Tokens.md b/content/cpp-notes/Tokens.md @@ -0,0 +1,65 @@ ++++ +title = 'Tokens' ++++ +# Tokens +## What is it? +a token is a sequence of characters that represents a unit + +- float literals: 3.14, 0.274e2, 42 +- operators: +,-,*,/,% +- parentheses: () + +tokenising is the first step of a compiler run + +## Representing/storing tokens +storing as chars/strings is not handy, need to still be extracted + +predefined types from C++, but nothing that suits a token. so define own with classes. + +## Implementing tokens +token consists of kind and value. value is only used for numbers. + +```cpp +class Token { +public: + char kind; + double value; +} + +Token t,t2,t3; // declare tokens +t.kind = ‘+’;  // token 1 is a + +t2.kind=‘8’;   // indicating number +t2.value=3.14; // value +t3=t;          // copy initialisation +``` + +Now, `(1.5+4)*11` can be shown as: + +<table> +<tr> +<td>'('</td> +<td>'8'</td> +<td>'+'</td> +<td>'8'</td> +<td>')'</td> +<td>'*'</td> +<td>'8'</td> +</tr> +<tr><td></td> +<td>1.5</td><td></td> +<td>4</td><td></td><td></td> +<td>11</td></tr> +</table> + +## Using tokens +```cpp +Token get_token(); +vector<Token> toks; + +int main() { + while (cin) { + Token t=get_token(); + tok.push_back(t); + } +} +``` diff --git a/content/cpp-notes/Types.md b/content/cpp-notes/Types.md @@ -0,0 +1,11 @@ ++++ +title = 'Types' ++++ +# Types +Built-in: simple types with language-defined operations (int, char, etc.) + +User-defined (combining built-in types into larger aggregates) + +- Structs: classes with all-public data members +- Classes: abstract data types with hidden implementation/state. members are private by default +- everything in std namespace diff --git a/content/cpp-notes/Variable types & their operators/b80694855519b22b77375e2df16835bd.png b/content/cpp-notes/Variable types & their operators/b80694855519b22b77375e2df16835bd.png Binary files differ. diff --git a/content/cpp-notes/Variable types & their operators/index.md b/content/cpp-notes/Variable types & their operators/index.md @@ -0,0 +1,5 @@ ++++ +title = 'Variable types & their operators' ++++ +# Variable types & their operators +![screenshot.png](b80694855519b22b77375e2df16835bd.png) diff --git a/content/cpp-notes/_index.md b/content/cpp-notes/_index.md @@ -0,0 +1,26 @@ ++++ +title = 'Programming in C++' ++++ +# Programming in C++ +- [Basic architecture & making a program](basic-architecture-making-a-program) +- [Basic functionality](basic-functionality) +- [Types](types) +- [Variable types & their operators](variable-types-their-operators) +- [Declarations, definitions, init](declarations-definitions-init) +- [Enumerations](enumerations) +- [Functions](functions) +- [Scope](scope) +- [Operator overloading](operator-overloading) +- [Namespaces](namespaces) +- [Recursion](recursion) +- [Randomness](randomness) +- [Abstraction](abstraction) +- [Grammars](grammars) +- [Tokens](tokens) +- [Constants in C++](constants-in-c) +- [The Standard Library](the-standard-library) +- [Modular programming](modular-programming) +- [Header files](header-files) +- [Separate compilation](separate-compilation) +- [Advice for programming in C++](advice-for-programming-in-c) +- [Glossary](glossary) diff --git a/syntaxes/Makefile/Comments.tmPreferences b/syntaxes/Makefile/Comments.tmPreferences @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<plist version="1.0"> +<dict> + <key>scope</key> + <string>source.makefile</string> + <key>settings</key> + <dict> + <key>shellVariables</key> + <array> + <dict> + <key>name</key> + <string>TM_COMMENT_START</string> + <key>value</key> + <string># </string> + </dict> + <dict> + <key>name</key> + <string>TM_COMMENT_DISABLE_INDENT</string> + <key>value</key> + <string>yes</string> + </dict> + </array> + </dict> +</dict> +</plist> diff --git a/syntaxes/Makefile/Indention Rules.tmPreferences b/syntaxes/Makefile/Indention Rules.tmPreferences @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<plist version="1.0"> +<dict> + <key>scope</key> + <string>source.makefile - string - comment</string> + <key>settings</key> + <dict> + <key>increaseIndentPattern</key> + <string>^[^:]+:(?!=)|^\s*(else\s+)?ifn?(eq|def)\b|^\s*else\b</string> + <key>decreaseIndentPattern</key> + <string>^\s*(else|endif)\b</string> + </dict> +</dict> +</plist> diff --git a/syntaxes/Makefile/Make Output.sublime-syntax b/syntaxes/Makefile/Make Output.sublime-syntax @@ -0,0 +1,13 @@ +%YAML 1.2 +--- +name: Make Output +hidden: true +scope: source.build_output +contexts: + main: + - match: '^(..[^:\n]*):([0-9]+):?([0-9]+)?:? ' + scope: entity.name.filename + - match: '\b(warning|error): ' + scope: message.error + - match: '^\[.+\]$' + scope: comment diff --git a/syntaxes/Makefile/Make.sublime-build b/syntaxes/Makefile/Make.sublime-build @@ -0,0 +1,16 @@ +{ + "shell_cmd": "make", + "file_regex": "^(..[^:\n]*):([0-9]+):?([0-9]+)?:? (.*)$", + "working_dir": "${folder:${project_path:${file_path}}}", + "selector": "source.makefile", + "syntax": "Packages/Makefile/Make Output.sublime-syntax", + "keyfiles": ["Makefile", "makefile"], + + "variants": + [ + { + "name": "Clean", + "shell_cmd": "make clean" + } + ] +} diff --git a/syntaxes/Makefile/Makefile.sublime-settings b/syntaxes/Makefile/Makefile.sublime-settings @@ -0,0 +1,3 @@ +{ + "translate_tabs_to_spaces": false +} diff --git a/syntaxes/Makefile/Makefile.sublime-syntax b/syntaxes/Makefile/Makefile.sublime-syntax @@ -0,0 +1,655 @@ +%YAML 1.2 +# http://www.sublimetext.com/docs/3/syntax.html +# https://www.gnu.org/software/make/manual/make.html +--- #--------------------------------------------------------------------------- +# Converted from Makefile Improved by Kay-Uwe (Kiwi) Lorenz +# Includes a few improvement like special-target, a bit more shell command, +# better variable recognition, fix ifeq/ifneq missing highlight ... +# Rewritten by Raoul Wols on May 2017. +# +# All number references refer to the "Make manual" (see link above). +name: Makefile +file_extensions: + - make + - GNUmakefile + - makefile + - Makefile + - makefile.am + - Makefile.am + - makefile.in + - Makefile.in + - OCamlMakefile + - mak + - mk +first_line_match: |- + (?xi: + ^\#! .* \bmake\b | # shebang + ^\# \s* -\*- [^*]* makefile [^*]* -\*- # editorconfig + ) +scope: source.makefile +#------------------------------------------------------------------------------- +variables: + + varassign: (\?|\+|::?)?= + shellassign: '!=' + startdirective: ifn?(def|eq) + include: '[s-]?include' + ruleassign: :(?!=) + function_call_token_begin: \$\$?\( + + # The big "rule lookahead". What we want to do is here is detect if the + # line that we are parsing is going to define a rule. So we need to check + # if we have something of the form <rule-name> : <rule-prerequisites> + # However matters become complicated by the fact that we can have arbitrary + # variable substitutions anywhere. We try to remedy this by hacking in a + # regex that matches up to four levels of nested parentheses, and ignores + # whatever's inside the parentheses. + nps: '[^()]*' + open: '(?:\(' + close: '\))?' # ignore this invalid.illegal + just_eat: | # WARNING: INSANITY FOLLOWS! + (?x) # ignore whitespace in this regex + {{nps}} # level 0 + {{open}} # start level 1 __ + {{nps}} # level 1 _______ /*_>-< + {{open}} # start level 2 ___/ _____ \__/ / + {{nps}} # level 2 <____/ \____/ + {{open}} # start level 3 is like snek... (by Valerie Haecky) + {{nps}} # level 3 + {{open}} # start level 4 + {{nps}} # level 4 + {{close}} # end level 4 + {{nps}} # level 3 + {{close}} # end level 3 + {{nps}} # level 2 + {{open}} # start level 3 + {{nps}} # level 3 + {{open}} # start level 4 + {{nps}} # level 4 + {{close}} # end level 4 + {{nps}} # level 3 + {{close}} # end level 3 + {{nps}} # level 2 + {{close}} # end level 2 + {{nps}} # level 1 + {{open}} # start level 2 + {{nps}} # level 2 + {{open}} # start level 3 + {{nps}} # level 3 + {{open}} # start level 4 + {{nps}} # level 4 + {{close}} # end level 4 + {{nps}} # level 3 + {{close}} # end level 3 + {{nps}} # level 2 + {{open}} # start level 3 + {{nps}} # level 3 + {{open}} # start level 4 + {{nps}} # level 4 + {{close}} # end level 4 + {{nps}} # level 3 + {{close}} # end level 3 + {{nps}} # level 2 + {{open}} # start level 3 + {{nps}} # level 3 + {{open}} # start level 4 + {{nps}} # level 4 + {{close}} # end level 4 + {{nps}} # level 3 + {{close}} # end level 3 + {{nps}} # level 2 + {{close}} # end level 2 + {{nps}} # level 1 + {{close}} # end level 1 + {{nps}} # level 0 + rule_lookahead: '{{just_eat}}{{ruleassign}}{{just_eat}}' + + var_lookahead_base: '{{just_eat}}({{varassign}}|{{shellassign}}){{just_eat}}' + # Just as with rules we want to look ahead if we are going to define a var. + # However, due to the possibility of "target-specific" variables (see 6.11), + # we want to NOT match if there's a {{ruleassign}} before a {{varassign}}. + var_lookahead: (?!{{rule_lookahead}}){{var_lookahead_base}} + + first_assign_then_colon: | + (?x) + {{just_eat}} + {{varassign}} + {{just_eat}} + {{ruleassign}} + {{just_eat}} + +#------------------------------------------------------------------------------- +contexts: + + # 3.1 What Makefiles Contain + # Makefiles contain five kinds of things: explicit rules, implicit rules, + # variable definitions, directives, and comments. + main: + - include: comments + - include: variable-definitions + - match: (?={{rule_lookahead}}) + push: expect-rule + - include: variable-substitutions + - include: control-flow + - match: ^\s*(endef) + captures: + 1: invalid.illegal.stray.endef.makefile + + inside-control-flow: + - meta_scope: meta.group.makefile + - match: "'" + scope: punctuation.definition.string.begin.makefile + push: + - meta_scope: meta.string.makefile string.quoted.single.makefile + - match: "'" + scope: punctuation.definition.string.end.makefile + pop: true + - include: escape-literals + - include: line-continuation + - include: variable-substitutions + - match: '"' + scope: punctuation.definition.string.begin.makefile + push: + - meta_scope: meta.string.makefile string.quoted.double.makefile + - match: '"' + scope: punctuation.definition.string.end.makefile + pop: true + - include: escape-literals + - include: line-continuation + - include: variable-substitutions + - match: \( + scope: punctuation.section.group.begin.makefile + push: + - match: \) + scope: punctuation.section.group.end.makefile + pop: true + - include: variable-substitutions + - match: \, + scope: punctuation.separator.makefile + - match: \) + scope: invalid.illegal.stray.paren.makefile + - include: continuation-or-pop-on-line-end + + control-flow: + - match: ^\s*(vpath)\s + captures: + 1: keyword.control.vpath.makefile + push: + - include: highlight-wildcard-sign + - match: \s + set: + - meta_content_scope: meta.string.makefile string.unquoted.makefile + - include: pop-on-line-end + - include: pop-on-line-end + - match: ^\s*(vpath)$ + captures: keyword.control.vpath.makefile + - match: ^\s*({{include}})\s+ + captures: + 1: keyword.control.import.makefile + push: + - meta_content_scope: meta.string.makefile string.unquoted.makefile + - include: continuation-or-pop-on-line-end + - include: variable-substitutions + - include: comments + - match: \b{{startdirective}}\b + scope: keyword.control.conditional.makefile + push: inside-control-flow + - match: ^\s*(else)\b + captures: + 1: keyword.control.conditional.makefile + push: + - include: control-flow + - include: comments + - include: pop-on-line-end + - match: ^\s*(endif)\b + captures: + 1: keyword.control.conditional.makefile + push: + - include: comments + - include: pop-on-line-end + + highlight-percentage-sign: + - match: \% + scope: variable.language.makefile + + highlight-wildcard-sign: + - match: \* + scope: variable.language.wildcard.makefile + + expect-rule: + # Anything before the colon is part of the rule's name. + - meta_scope: meta.function.makefile entity.name.function.makefile + - include: line-continuation + - include: variable-substitutions + - include: highlight-percentage-sign + - match: (?= *::?[^=]+[!:?]?=) + set: + - match: ::? + scope: keyword.operator.assignment.makefile + set: + - include: variable-definitions + - include: variable-substitutions + - include: continuation-or-pop-on-line-end + - match: (?= *::?) + set: + - match: (::?)\s* + captures: + 1: keyword.operator.assignment.makefile + set: + - meta_content_scope: + meta.function.arguments.makefile + string.unquoted.makefile + - include: line-continuation + - include: variable-substitutions + - include: highlight-percentage-sign + - match: (?=#) + set: + - match: \# + scope: punctuation.definition.comment.makefile + set: + - meta_scope: comment.line.number-sign.makefile + - match: $ + set: recipe-junction-between-spaces-or-tabs + - match: $ + set: recipe-junction-between-spaces-or-tabs + - match: (?=\s*;) + set: + - match: ; + scope: punctuation.terminator.makefile + set: recipe-inline + + recipe-junction-between-spaces-or-tabs: + - meta_content_scope: meta.function.body.makefile + - include: comments + - match: ^\s*({{startdirective}}) + captures: + 1: keyword.control.conditional.makefile + push: + - include: inside-control-flow + - include: recipe-junction-between-spaces-or-tabs + - match: ^(?=[ ]+([-@]{1,2})?) + set: recipe-with-spaces + - match: ^(?=\t([-@]{1,2})?) + set: recipe-with-tabs + - match: ^ + pop: true + + recipe-inline: + - meta_content_scope: meta.function.body.makefile source.shell.embedded.makefile + - include: recipe-junction-between-spaces-or-tabs + - include: control-flow + - match: $ + set: recipe-junction-between-spaces-or-tabs + - include: shell-content + + recipe-with-spaces: + - meta_content_scope: meta.function.body.makefile + - match: ^([ ]+)([-@]{1,2})? + captures: + 2: constant.language.makefile + push: shell-common + - match: ^(\t)([-@]{1,2})? + captures: + 1: invalid.illegal.inconsistent.expected.spaces.makefile + 2: constant.language.makefile + - include: recipe-common + - match: ^(?![ ]+) + pop: true + + recipe-with-tabs: + - meta_content_scope: meta.function.body.makefile + - match: ^\t([-@]{1,2})? + captures: + 1: constant.language.makefile + push: shell-common + - match: ^([ ]+)([-@]{1,2})? + captures: + 1: invalid.illegal.inconsistent.expected.tab.makefile + 2: constant.language.makefile + - include: recipe-common + - match: ^(?!\t) + pop: true + + recipe-common: + - include: control-flow + - match: ^\n + + shell-common: + - meta_content_scope: source.shell.embedded.makefile + - include: pop-on-line-end + - include: shell-content + + shell-content: + - include: Packages/Makefile/Makefile Shell.sublime-syntax + apply_prototype: true + + line-continuation: + - match: (\\)([ ]*)$\n? + captures: + 1: punctuation.separator.continuation.line.makefile + # make sure to resume parsing at next line + push: + - match: (?=\S|^\s*$) + pop: true + + pop-on-line-end: + - match: $ + pop: true + + continuation-or-pop-on-line-end: + - include: line-continuation + - include: pop-on-line-end + + quoted-string: + - match: "'" + scope: punctuation.definition.string.begin.makefile + push: + - meta_include_prototype: false + - meta_scope: meta.string.makefile string.quoted.single.makefile + - match: "'" + scope: punctuation.definition.string.end.makefile + pop: true + - include: escape-literals + - include: line-continuation + - include: variable-substitutions + - match: '"' + scope: punctuation.definition.string.begin.makefile + push: + - meta_include_prototype: false + - meta_scope: meta.string.makefile string.quoted.double.makefile + - match: '"' + scope: punctuation.definition.string.end.makefile + pop: true + - include: escape-literals + - include: line-continuation + - include: variable-substitutions + + escape-literals: + - match: \\. + scope: constant.character.escape.makefile + + comments-pop-on-line-end: + - include: line-continuation + - match: $\n? + pop: true + + comments: + # This hack is here in order to circumvent false-positives for the big + # rule lookahead. For example, if this match is not present, then things + # like + # + # # A comment with a : colon + # + # will match the rule-lookahead. + - match: (?=^\s*#) + push: + - match: \# + scope: punctuation.definition.comment.makefile + set: + - meta_scope: comment.line.number-sign.makefile + - include: comments-pop-on-line-end + # This is the "normal" comment parsing logic, but not sufficient in every + # case (see above). + - match: \# + scope: punctuation.definition.comment.makefile + push: + - meta_scope: comment.line.number-sign.makefile + - include: comments-pop-on-line-end + + inside-function-call: + - meta_content_scope: meta.function-call.arguments.makefile + - match: \) + scope: keyword.other.block.end.makefile + pop: true + - match: \( + push: textual-parenthesis-balancer + - match: \, + scope: punctuation.separator.makefile + # eat escaped or unbalanced quotation marks in front of the `,` separator + # to highlight them as ordinary part of the surrounding unquoted string + - match: '\\[''""]|[''""](?=\s*,)' + - include: variable-substitutions + - include: quoted-string + + function-invocations: + - match: ({{function_call_token_begin}})(call)\s + captures: + 0: meta.function-call.makefile + 1: keyword.other.block.begin.makefile + 2: constant.language.call.makefile + push: + - meta_content_scope: + meta.function-call.makefile + variable.function.makefile + - match: (?=\)) + set: inside-function-call + - match: (?=,) + set: + - meta_content_scope: meta.function-call.makefile + - match: \, + scope: punctuation.separator.makefile + set: inside-function-call + - include: variable-substitutions + - match: ({{function_call_token_begin}})(patsubst|filter)\s + captures: + 0: meta.function-call.makefile + 1: keyword.other.block.begin.makefile + 2: support.function.builtin.makefile + push: + - meta_content_scope: meta.function-call.arguments.makefile + - include: highlight-percentage-sign + - include: inside-function-call + - match: ({{function_call_token_begin}})(wildcard)\s + captures: + 0: meta.function-call.makefile + 1: keyword.other.block.begin.makefile + 2: support.function.builtin.makefile + push: + - meta_content_scope: meta.function-call.arguments.makefile + - include: inside-function-call + - include: highlight-wildcard-sign + - match: ({{function_call_token_begin}})(info|warning|error)\s + captures: + 0: meta.function-call.makefile + 1: keyword.other.block.begin.makefile + 2: support.function.builtin.makefile + push: + - meta_content_scope: meta.function-call.arguments.makefile + - match: \) + scope: keyword.other.block.end.makefile + pop: true + - match: \( + push: textual-parenthesis-balancer + - match: \, + scope: punctuation.separator.makefile + - include: variable-substitutions + - match: | # multiline string + (?x) # ignore whitespace + ({{function_call_token_begin}}) + ( + subst| + strip| + findstring| + filter-out| + sort| + word| + wordlist| + words| + firstword| + lastword| + dir| + notdir| + suffix| + basename| + addsuffix| + addprefix| + join| + realpath| + abspath| + if| + or| + and| + foreach| + file| + value| + eval| + origin| + flavor| + guile + ) + \s + captures: + 0: meta.function-call.makefile + 1: keyword.other.block.begin.makefile + 2: support.function.builtin.makefile + push: inside-function-call + - match: ({{function_call_token_begin}})(shell)\s + captures: + 1: keyword.other.block.begin.makefile + 2: support.function.builtin.makefile + push: + - meta_content_scope: source.shell.embedded.makefile + - match: \) + scope: keyword.other.block.end.makefile + pop: true + - include: shell-content + + variable-definitions: + - match: \s*(override)\b + captures: + 1: keyword.control.makefile + set: + - match: \bdefine\b + scope: keyword.control.makefile + push: inside-define-directive-context + - include: variable-definitions + - include: continuation-or-pop-on-line-end + - match: \s*(define)\b + captures: + 1: keyword.control.makefile + push: inside-define-directive-context + - match: ^\s*(export)\b + captures: + 1: keyword.control.makefile + push: + - meta_content_scope: variable.other.makefile + - include: continuation-or-pop-on-line-end + - include: variable-substitutions + - match: (\?|\+|::?)?= + scope: keyword.operator.assignment.makefile + set: [value-to-be-defined, eat-whitespace-then-pop] + - match: (?={{var_lookahead}}|{{first_assign_then_colon}}) + push: + - meta_content_scope: variable.other.makefile + - match: (?=\s*!=) + set: + - match: '!=' + scope: keyword.operator.assignment.makefile + set: shell-common + - match: (?=\s*(!|\?|\+|::?)?=) + set: + - match: (!|\?|\+|::?)?= + scope: keyword.operator.assignment.makefile + set: [value-maybe-shellscript, eat-whitespace-then-pop] + - include: variable-substitutions + - include: continuation-or-pop-on-line-end + - include: variable-substitutions + + textual-parenthesis-balancer: + - match: \) + pop: true + - include: variable-substitutions + + eat-whitespace-then-pop: + - clear_scopes: 1 + - match: \s* + pop: true + + value-maybe-shellscript: + - match: ((?:bash|sh|zsh)\s+-c\s+)(['"`]) + captures: + 1: meta.string.makefile string.unquoted.makefile + 2: meta.string.makefile meta.interpolation.makefile punctuation.section.interpolation.begin.makefile + embed: shell-content + embed_scope: meta.string.makefile meta.interpolation.makefile source.shell.embedded.makefile + escape: (?!<\\)\2 + escape_captures: + 0: meta.string.makefile meta.interpolation.makefile punctuation.section.interpolation.end.makefile + - match: '' + set: value-to-be-defined + + value-to-be-defined: + - meta_content_scope: meta.string.makefile string.unquoted.makefile + - include: escape-literals + - match: (?=#) + set: + - match: \# + scope: punctuation.definition.comment.makefile + set: + - meta_scope: comment.line.number-sign.makefile + - include: comments-pop-on-line-end + - include: variable-substitutions + - include: continuation-or-pop-on-line-end + + inside-define-directive-context: + - meta_content_scope: variable.other.makefile + - match: (?=(!|\?|\+|::?)?=\s*\n) + set: + - match: ((!|\?|\+|::?)?=)\s*\n + captures: + 1: keyword.operator.assignment.makefile + set: inside-define-directive-value + + # Need to eat the actual newline character in order to start the + # string.unquoted scope on the next line. + - match: \n + set: inside-define-directive-value + - include: variable-substitutions + + inside-define-directive-value: + - meta_content_scope: meta.string.makefile string.unquoted.makefile + - match: ^\s*(endef)\b + captures: + 1: keyword.control.makefile + pop: true + # keep in balance with nested define statements + # see: https://github.com/sublimehq/Packages/issues/1998 + - match: ^\s*define\b + push: + - match: ^\s*endef\b + pop: true + + variable-sub-common: + - match: ':' + scope: punctuation.definition.substitution.makefile + - match: = + scope: punctuation.definition.assignment.makefile + - include: highlight-percentage-sign + - include: variable-substitutions + + variable-substitutions: + - include: function-invocations + - match: \$\$?\( + scope: keyword.other.block.begin.makefile + push: + - meta_scope: variable.parameter.makefile + - match: \) + scope: keyword.other.block.end.makefile + pop: true + - include: variable-sub-common + - match: \$\$?{ + scope: keyword.other.block.begin.makefile + push: + - meta_scope: variable.parameter.makefile + - match: \} + scope: keyword.other.block.end.makefile + pop: true + - include: variable-sub-common + - match: \$\$?[@%<?^+|*] + scope: variable.language.automatic.makefile + - match: \$\$ + scope: constant.character.escape.makefile + - match: (\$)[[:alpha:]] + captures: + 0: variable.parameter.makefile + 1: keyword.other.single-character-variable.makefile diff --git a/syntaxes/Makefile/syntax_test_makefile.mak b/syntaxes/Makefile/syntax_test_makefile.mak @@ -0,0 +1,954 @@ +# SYNTAX TEST "Packages/Makefile/Makefile.sublime-syntax" + +################################# +# 6.3.1 substitution references # +################################# + +P = Hello +# <- variable.other +# ^ keyword.operator.assignment +# ^ - string.unquoted +# ^ string.unquoted +# ^ string.unquoted +# ^ - string.unquoted + +FOO = $P +# <- variable.other +# ^ keyword.operator.assignment +# ^ keyword.other +# ^ string variable +BAR = $PATH +# <- variable.other +# ^ keyword.operator.assignment +# ^ keyword.other +# ^ string variable +# ^ string - variable + +foo := a.o b.o c.o +# <- variable +# ^^ keyword +# ^^^^^^^^^^^ string +bar := $(foo:.o=.c) +# <- variable +# ^^ keyword +# ^^ keyword.other.block.begin +# ^ punctuation +# ^ punctuation +# ^ keyword.other.block.end +bar := $(foo:%.o=%.c) +# <- variable +# ^^ keyword +# ^ - string.unquoted +# ^^ keyword.other.block.begin +# ^ punctuation +# ^ variable.language +# ^ punctuation +# ^ variable.language +# ^ keyword.other.block.end + +bar := ${foo:%.o=%.c} +# <- variable +# ^^ keyword +# ^ - string.unquoted +# ^^ keyword.other.block.begin +# ^ punctuation +# ^ variable.language +# ^ punctuation +# ^ variable.language +# ^ keyword.other.block.end + +foo = bar # a comment +# ^ - string.unquoted +# ^ string.unquoted +# ^ comment.line punctuation - string.unquoted + +foo = bar # a multiline \ + comment +# ^ comment.line + +################################# +# 6.3.2 computed variable names # +################################# + +x = $(y) +y = z +z = Hello +a := $($(x)) +sources := $($(a1)_objects:.o=.c) +dir = foo +$(dir)_sources := $(wildcard $(dir)/*.c) +# <- keyword.other.block.begin +#^ keyword.other.block.begin +# ^^ keyword.operator.assignment +# ^^ keyword.other.block.begin +# ^^ keyword.other.block.begin +# ^ keyword.other.block.end +# ^ variable.language.wildcard +# ^ keyword.other.block.end +define $(dir)_print = +# ^ keyword.control +# ^^ keyword.other.block.begin +# ^ keyword.other.block.end +# ^ keyword.operator.assignment +lpr $($(dir)_sources) +endef + +define FOO + BAR := 1 + define BAZ +# ^^^^^^ string.unquoted.makefile - keyword + X := 1 + endef +# ^^^^^^ string.unquoted.makefile - keyword +Y := 3 +endef # comment +#^^^^ keyword.control.makefile +# ^^^ comment.line.number-sign.makefile + +######################### +# 6.5 setting variables # +######################### + +FOO ?= bar + +ifeq ($(origin FOO), undefined) +FOO = bar +endif + +hash != printf '\043' +# ^ source.shell +file_list != find . -name '*.c' +# ^ source.shell + +hash := $(shell printf '\043') +# ^ support.function +# ^ source.shell +var := $(shell find . -name "*.c") +# ^ support.function +# ^ source.shell + +######################################## +# 6.6 appending more text to variables # +######################################## + +objects = main.o foo.o bar.o utils.o +objects += another.o +CFLAGS = $(includes) -O +CFLAGS += -pg # enable profiling + +############################## +# 6.7 the override directive # +############################## + +override variable = value +# ^ keyword.control +override variable := value +override variable += more text +override CFLAGS += -g +override define foo +# <-keyword +# ^ keyword +# ^ variable.other +# ^ - string.unquoted +asdf +# <- string.unquoted +endef +# <- keyword +override define foo = +# <- keyword +# ^ keyword +# ^ variable.other +# ^ keyword.operator.assignment +# ^ - string +bar +endef +override define foo ?= +# ^^ keyword.operator.assignment +# ^ - string +bar +endef +override define foo := +# ^^ keyword.operator.assignment +# ^ - string +bar +endef +# ^ keyword.control + +endef +# <- invalid.illegal.stray + +######################################## +# 6.11 target-specific variable values # +######################################## + +prog : CFLAGS = -g +# ^ keyword.operator +# ^ variable - string +# ^ keyword +# ^ - string +# ^^ string - meta.function.arguments + +######################################### +# 6.12 pattern-specific variable values # +######################################### + +lib/%.o: CFLAGS := -fPIC -g +# ^ keyword.operator +# ^ - string +# ^ string +# ^ - string +%.o: CFLAGS := -g +# ^ keyword.operator +# ^ - string +# ^^ string +# ^ - string + +# Line comment +# <- comment + +ifeq ($(shell test -r $(MAKEFILE_PATH)Makefile.Defs; echo $$?), 0) +# <- keyword.control +# ^ support.function +# ^^ variable.parameter keyword.other.block.begin +# ^^^^^^^^^^^^^ variable.parameter +# ^ variable.parameter keyword.other.block.end +# ^^^ variable.language.automatic + include $(MAKEFILE_PATH)Makefile.Defs + # <- keyword.control + # ^ - string + # ^ string + # IMPORTANT NOTE: Extra spaces are allowed and ignored at the beginning of + # the line, but the first character must not be a tab (or the value of + # .RECIPEPREFIX) — if the line begins with a tab, it will be considered a + # recipe line. +endif +# <- keyword.control + +a_objects := a.o b.o c.o +# ^ variable.other +# ^^ keyword.operator.assignment +# ^^^^^^^^^^^ string +1_objects := 1.o 2.o 3.o +# ^^^^^^^ variable.other +# ^^ keyword.operator.assignment +# ^^^^^^^^^^^ string.unquoted + +# This is NOT the start of a rule... + # A comment with a tab and with a : colon + # <- comment.line - meta.function - entity.name.function + +all: foo.o +# ^ - string +# ^ string +# ^ - string + ld a + ar b + asdf + @echo "that's, like, your opinion man!" # some movie? + asdf +# <- invalid.illegal.inconsistent.expected.spaces + +all: foo.o + ld a + ar b + asdf + @echo "that's, like, your opinion man!" # some movie? + # <- constant.language + asdf +# <- invalid.illegal.inconsistent.expected.tab + +all: foo.o # a comment +# <- meta.function entity.name.function +# ^ keyword.operator.assignment +# ^ - string +# ^ string +# ^ meta.function.arguments string.unquoted +# ^ string +# ^ comment.line. punctuation - meta.function.arguments - string.unquoted +# ^ comment.line - punctuation - meta.function.arguments - string.unquoted + rm -rf / +# <- meta.function.body + +# A make comment. +# ^ comment.line.number-sign.makefile +foo: qux + @bar # A shell comment. + # ^ comment.line.number-sign.shell + +sources := $($(a1)_objects:.o=.c) +# ^ variable +# ^^ keyword.operator +# ^^ string variable keyword.other.block.begin +# ^^ string variable variable keyword.other.block.begin +# ^^ string variable variable +# ^ string variable variable keyword.other.block.end +# ^^^^^^^^ string variable +# ^ string variable punctuation.definition +# ^^ string variable +# ^ string variable punctuation.definition +# ^^ string variable +# ^ string variable keyword.other.block.end + +.build/vernum: ../meta/version + sed -i.bak 's/.*automatically updated.*/version = "$(VER)" # automatically updated/' setup.py +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.body.makefile source.shell.embedded meta.function-call +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single - comment +# ^^^^^^ variable.parameter.makefile + +CC=g++ +#<- variable.other +# ^ keyword.operator.assignment +# ^^^ string.unquoted +CFLAGS=-c -Wall +LDFLAGS= +#<- variable.other +# ^ keyword.operator.assignment +SOURCES=main.cpp hello.cpp factorial.cpp +OBJECTS=$(SOURCES:.cpp=.o) +#<- variable.other +# ^ keyword.operator.assignment +# ^^ string.unquoted keyword.other.block.begin +# ^ string.unquoted variable.parameter punctuation.definition.substitution +# ^ string.unquoted variable.parameter punctuation.definition +# ^ string.unquoted keyword.other.block.end +EXECUTABLE=hello + +lib: foo.o bar.o lose.o win.o + ar r lib $@ + ar whatevs +# <- meta.function.body + # <- meta.function.body + # BIG NOTE: This comment is actually a shell comment, not a makefile + # comment. Everything on a recipe line is passed to the shell; even lines + # starting with a numbrer sign! It depends on the particular shell if it + # gets treated as comments, but for all intents and purposes it should. + +all: $(SOURCES) $(EXECUTABLE) +#<- entity.name.function +# ^ keyword.operator.assignment +# ^^ variable.parameter keyword.other.block.begin +# ^^^^^^^ variable.parameter +# ^ variable.parameter keyword.other.block.end +# ^^ variable.parameter keyword.other.block.begin +# ^^^^^^^^^^ variable.parameter +# ^ variable.parameter keyword.other.block.end + +export FOO=foo +# ^ keyword.control +# ^ variable.other +# ^ keyword.operator.assignment +# ^ string.unquoted + +$(EXECUTABLE): $(OBJECTS) +# <- meta.function entity.name.function + $(CC) $(LDFLAGS) $(OBJECTS) -o $@ + + +.cpp.o: a.c b.c +# <- meta.function entity.name.function + $(CC) $(CFLAGS) $< -o $@ + # ^^ meta.function.body variable.language.automatic + # ^^ meta.function.body variable.language.automatic + +FOO = some \ + line \ + continuation \ + in \ + here +# ^ string.unquoted + +# echo I am a comment \ + echo I am a comment, too! +# ^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line + +# echo I am a comment \ + echo I am a comment, too! + echo I am no comment... +# ^^^^^^^^^^^^^^^^^^^^^^^ - comment.line + +reverse = $(2) $(1) +# <- variable.other +# ^ keyword.operator.assignment +# ^^ keyword.other.block.begin +# ^ string.unquoted variable.parameter +# ^ string.unquoted +# ^^ keyword.other.block.begin +# ^ string.unquoted variable.parameter +# ^ keyword.other.block.end + +foo = $(call reverse,a,b) +# ^ constant.language.call +# ^ string.unquoted - meta.function-call.arguments +# ^ string.unquoted punctuation.separator - meta.function-call.arguments +# ^ string.unquoted meta.function-call.arguments +# ^ string.unquoted meta.function-call.arguments punctuation.separator +# ^ string.unquoted meta.function-call.arguments +# ^ string.unquoted keyword.other.block.end + +foo = $(call something) +# ^ - variable.function + +foo = $(eval $(call bar)) +# ^ support.function +# ^ constant.language +# ^ variable.function +# ^^ string.unquoted keyword.other.block.end - variable.function + +pathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH))))) +# ^^^^^^^^^ meta.function-call support.function +# ^^^^^^^^ meta.function-call.arguments meta.function-call support.function +# ^^^^^^^^^ meta.function-call.arguments meta.function-call.arguments meta.function-call support.function +# ^ meta.function-call.arguments meta.function-call.arguments meta.function-call.arguments +# ^^ keyword.other.block.begin +# ^ meta.function-call.arguments meta.function-call.arguments meta.function-call.arguments variable.parameter +# ^ keyword.other.block.end +# ^ punctuation.separator +# ^^ keyword.other.block.begin +# ^^^^^ meta.function-call.arguments meta.function-call.arguments meta.function-call.arguments meta.function-call support.function +# ^ string.unquoted +# ^ punctuation.separator +# ^ string.unquoted +# ^ punctuation.separator +# ^^ keyword.other.block.begin +# ^^^^ meta.function-call.arguments meta.function-call.arguments meta.function-call.arguments meta.function-call.arguments variable.parameter +# ^ meta.function-call.arguments meta.function-call.arguments meta.function-call.arguments meta.function-call.arguments variable.parameter keyword.other.block.end +# ^ meta.function-call.arguments meta.function-call.arguments meta.function-call.arguments keyword.other.block.end +# ^ meta.function-call.arguments meta.function-call.arguments keyword.other.block.end +# ^ meta.function-call.arguments keyword.other.block.end +# ^ keyword.other.block.end + +LS := $(call pathsearch,ls) + +-include $(MAKEFILE_PATH)Makefile.Defs +# <- keyword.control.import + +sinclude $(MAKEFILE_PATH)Makefile.Defs +# <- keyword.control.import +# ^ string.unquoted variable.parameter keyword.other.block.begin +# ^ string.unquoted variable.parameter +# ^ string.unquoted variable.parameter keyword.other.block.end + + +CC=g++ +# <- variable.other +# ^ keyword.operator.assignment +# ^ string.unquoted +SOURCES=main.cpp +SOURCES+=hello.cpp +# <- variable.other +# ^ keyword.operator.assignment +# ^ string.unquoted + +EXECUTABLE=hello + +OBJECTS=$(SOURCES:.cpp=.o) +# ^ string.unquoted.makefile variable.parameter.makefile + +all: $(SOURCES) hello.o +# <- entity.name.function.makefile +# ^ keyword.other.block.begin +# ^ variable.parameter.makefile + +$(EXECUTABLE): $(OBJECTS) +# <- keyword.other.block.begin +# ^ variable.parameter.makefile +# ^ keyword.other.block.begin +# ^ variable.parameter.makefile + @$(CC) $(LDFLAGS) $(OBJECTS) -o $@ + # <- constant.language + # ^^ variable.language.automatic + + +all: whatevs + @asdf + # <- constant.language + +all: whatevs + @asdf + @echo "Heyo!" + # <- constant.language + +export RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o \ + -name CVS -o -name .pc -o -name .hg -o -name .git \) \ + -prune -o +export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \ + --exclude CVS --exclude .pc --exclude .hg --exclude .git + +# Use spaces instead of tabs... This complicates matters. +.RECIPEPREFIX += + +help:: + @echo "Excutable is $(EXECUTABLE)" + # <- constant.language + +$(warning he:llo) +# ^ meta.function-call support.function +# ^^^ meta.function-call.arguments.makefile - punctuation +# ^ keyword.other.block.end + +all: deps + $(warning he:llo) + # ^ meta.function-call support.function + # ^^^ meta.function-call.arguments.makefile - punctuation + # ^ keyword.other.block.end +deps: + $(warning he:llo) + # ^ meta.function-call support.function + # ^^^ meta.function-call.arguments.makefile - punctuation + # ^ keyword.other.block.end +all: +# ^ meta.function entity.name.function +# ^ keyword.operator.assignment + asdf +# <- meta.function.body + +# OS detecting makefile +# http://stackoverflow.com/questions/714100/os-detecting-makefile +# +ifeq ($(OS),Windows_NT) +# ^ keyword.control + SEPARATOR = ; +# ^ variable.other +# ^ - variable.other +# ^ keyword.operator.assignment +# ^ string.unquoted + +else +# ^ keyword.control + SEPARATOR = : +# ^ variable.other +# ^ - variable.other +# ^ keyword.operator.assignment +# ^ string.unquoted +endif +# ^ keyword.control + +a_percentage_%_sign := $(SOME_C%MPLEX:SUBSTITUTI%N) +# ^ variable.other - variable.language +# ^ string.unquoted variable.parameter variable.language +# ^ punctuation +# ^ string.unquoted variable.parameter variable.language + +%.cpp: %.o +# <- meta.function entity.name.function variable.language +# ^ keyword.operator +# ^ meta.function.arguments string.unquoted variable.language + @rm -rf / + @rm -rf / + # <- meta.function.body constant.language + #^ meta.function.body - constant.language + +a = b # c +#<- variable.other +# ^ keyword.operator.assignment +# ^ string.unquoted +# ^ comment.line.number-sign punctuation.definition.comment +# ^ comment.line.number-sign + +a = b # c +#<- variable.other +# ^ keyword.operator.assignment +# ^ string.unquoted +# ^ comment.line.number-sign punctuation.definition.comment +# ^ comment.line.number-sign + +_modinst_: + @rm -rf $(MODLIB)/kernel + # <- constant.language + @rm -f $(MODLIB)/source + # <- constant.language + @mkdir -p $(MODLIB)/kernel + # <- constant.language + @ln -s `cd $(srctree) && /bin/pwd` $(MODLIB)/source + # <- constant.language + @if [ ! $(objtree) -ef $(MODLIB)/build ]; then \ + rm -f $(MODLIB)/build ; \ + ln -s $(CURDIR) $(MODLIB)/build ; \ + fi + @cp -f $(objtree)/modules.order $(MODLIB)/ + # <- constant.language + @cp -f $(objtree)/modules.builtin $(MODLIB)/ + # <- constant.language + $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst + + +$(sort $(a)): $(b) ; +# ^ keyword.operator + +%:x +# <- meta.function entity.name.function variable.language +#^ keyword.operator + rm -rf / + +a : b ; +# <- meta.function entity.name.function +# ^ keyword.operator - entity.name.function +# ^ - string.unquoted +# ^ meta.function.arguments string.unquoted +# ^ - string.unquoted +# ^ punctuation.terminator + +a : b \ + more prerequisites \ + on a third line even + # ^ meta.function.arguments string.unquoted + @rm -rf / + # <- meta.function.body constant.language + +a : b ; rm -rf / +# ^ punctuation.terminator +# ^ source.shell + +a-$(b) := c +# ^ keyword.other.block.begin +# ^ keyword.other.block.end +# ^^ keyword.operator +# ^ string.unquoted + +$(a): b +# <- keyword.other.block.begin +# ^ meta.function entity.name.function keyword.other.block.end +# ^ keyword.operator +# ^ meta.function.arguments string.unquoted + $(Q)$(MAKE) $(build)=$@ + # <- meta.function.body + # ^^ meta.function.body variable.language.automatic + +$(a:b=c) : d +# <- meta.function entity.name.function +# ^ - meta.function.arguments +# ^ meta.function.arguments + $(Q)$(MAKE) $(build)=$@ + # <- meta.function.body + # ^^ meta.function.body variable.language.automatic + +$(X:a=b) : w ; +# <- meta.function entity.name.function variable.parameter keyword.other.block.begin +# ^ keyword.operator +# ^ meta.function.arguments string.unquoted +# ^ - string.unquoted +# ^ punctuation.terminator + +$(Y:%.cpp=%.o) := $(Z) +# <- - meta.function +# ^^ keyword.operator.assignment + +$(call my_func,my_arg): deps +# <- meta.function entity.name.function +# ^ keyword.operator.assignment +# ^ - keyword.operator.assignment + rm -rf / + +$(foreach i,j,k): deps +# <- meta.function entity.name.function +# ^ keyword.operator.assignment +# ^ - keyword.operator.assignment + rm -rf / + # <- meta.function.body + +$(foreach i,$(a),$(foreach j,$(b),x)): deps +# <- meta.function entity.name.function +# ^ keyword.operator.assignment +# ^ - keyword.operator.assignment + rm -rf / + # <- meta.function.body + +include $(c) +ifneq ($(a),) +$(b): ; rm -rf / +# ^ meta.function.body source.shell + @git clone asdf + # <- meta.function.body constant.language + # ^ meta.function.body +endif + +define filechk_utsrelease.h + if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \ + echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \ + exit 1; \ + fi; \ + (echo \#define UTS_RELEASE \"$(KERNELRELEASE)\";) +endef +# <- keyword.control + +endef +# <- invalid.illegal.stray + +# meta.group.conditional balancing +ifeq ($(shell git status >/dev/null 2>&1 && echo USING_GIT),USING_GIT) + ifeq ($(shell git svn info >/dev/null 2>&1 && echo USING_GIT_SVN),USING_GIT_SVN) + # git-svn + ifeq ($(REVISION),) + REVISION := $(shell git svn find-rev git-svn) + endif + VCSTURD := $(subst $(SPACE),\ ,$(shell git rev-parse --git-dir)/refs/remotes/git-svn) + else + # plain git + ifeq ($(REVISION),) + REVISION := $(shell git describe --always HEAD) + endif + GIT_BRANCH := $(shell git symbolic-ref HEAD 2>/dev/null) + VCSTURD := $(subst $(SPACE),\ ,$(shell git rev-parse --git-dir)/$(GIT_BRANCH)) + endif +else ifeq ($(shell hg root >/dev/null 2>&1 && echo USING_HG),USING_HG) +# ^ keyword.control +# ^ keyword.control + # mercurial + ifeq ($(REVISION),) + REVISION := $(shell hg id -i) + endif + VCSTURD := $(subst $(SPACE),\ ,$(shell hg root)/.hg/dirstate) +else ifeq ($(shell svn info >/dev/null && echo USING_SVN),USING_SVN) +# ^ keyword.control +# ^ keyword.control + # subversion + ifeq ($(REVISION),) + REVISION := $(subst :,-,$(shell svnversion -n)) + endif + # This used to break the makefile syntax because we didn't properly account + # for closing parentheses in shell-strings. We now use our own quoted string + # context in the with_prototype override so that we can account for this. + # This does mean that the shell syntax looks a tiny bit different. + VCSTURD := $(addsuffix /.svn/entries, $(shell svn info | grep 'Root Path' | sed -e 's/\(.*\:\)\(.*\) /\2/')) + # ^ string.quoted.single.shell punctuation.definition.string.begin.shell + # ^ string.quoted.single.shell punctuation.definition.string.end.shell +endif +# <- keyword.control + +ifeq (0,1) + $(info zero is one) +else ifneq (1,2) + $(info one is not equal to two) +else ifeq ("asf",asdf") + $(info foo) +else ifeq (2,3) + $(info one is equal to three) +else ifeq "2" "3" + $(info asdf) +else ifeq '2' "3" + $(info asdf) +else ifeq "2" '3' + $(info asdf) +else ifeq '2' '3' + $(info asdf) +else ifdef X + $(info X is defined) +else ifndef Y + $(info Y is not defined) +endif +# <- keyword + +ifeq (0,1) + $(info asdf) +else +ifeq (0,1) + $(info asdf) +endif +# <- keyword + +a:b +ifeq (0,1) + $(info asdf) +else # some comment +# ^ comment.line + $(info asdf) +endif +# <- keyword + +# Another case where the lookahead for the colon used to fail: +ifneq ($(words $(subst :, ,$(CURDIR))), 1) +# ^ meta.function-call.arguments meta.function-call.arguments - keyword.operator + $(error main directory cannot contain spaces nor colons) +endif + +ifeq ($(shell which inkscape >/dev/null 2>&1 && echo USING_INKSCAPE),USING_INKSCAPE) +# <- keyword.control.conditional +$(FIGS)/%.pdf: $(FIGS)/%.svg ## Figures for the manuscript +# <- meta.function entity.name.function +# ^ keyword.operator.assignment +# ^ meta.function.arguments string.unquoted + # ^ comment.line - string.unquoted + inkscape -C -z --file=$< --export-pdf=$@ 2> /dev/null + # <- meta.function.body +endif +# <- keyword.control.conditional + +vpath dir/*/whatevs whatevs +# ^ keyword.control.vpath +# ^ variable.language.wildcard +# ^ string.unquoted.makefile + +vpath asdf/* +# ^ keyword.control.vpath +# ^ variable.language.wildcard +vpath +# ^ keyword.control.vpath.makefile + +# a comment check +# <- comment.line + +rule: asdf + @rm -rf / +# <- meta.function.body + +ifneq ($(REVISION),) +# ^ keyword.control.conditional +REVDEPS += revision.tex +revision.tex: $(VCSTURD) + /bin/echo '\newcommand{\Revision}'"{$(subst _,\_,$(REVISION))}" > $@ + # ^ - invalid.illegal + # ^ meta.function-call.makefile + # ^^ meta.function.body meta.function-call.arguments variable.parameter +AUXFILES += revision.aux +endif + +build_target: + @echo "${INFO_CLR}>> Building $(TARGET)...${RESTORE_CLR}${RESULT_CLR}" + # <- constant.language +ifdef WORKSPACE + @xcodebuild -sdk iphoneos -workspace "$(WORKSPACE).xcworkspace" -target "$(TARGET)" -configuration "$(CONFIG)" SYMROOT="$(BUILD_PATH)/Products" -jobs 6 build 2>/dev/null | tail -n 2 | cat && printf "${RESET_CLR}" + # <- constant.language +else + @xcodebuild -sdk iphoneos -project "$(PROJECT).xcodeproj" -target "$(TARGET)" -configuration "$(CONFIG)" CONFIGURATION_BUILD_DIR="$(BUILD_PATH)/Products" -jobs 6 build 2>/dev/null | tail -n 2 | cat && printf "${RESET_CLR}" + # <- constant.language +endif +ifndef ARDMK_DIR_MSG + $(call show_config_variable,ARDMK_DIR,[COMPUTED],(relative to $(notdir $(lastword $(MAKEFILE_LIST))))) + # ^ variable.function + # ^ support.function + # ^ support.function + # ^ - keyword.other.block.end + # ^ keyword.other.block.end +else + $(call show_config_variable,ARDMK_DIR,[USER]) + # ^ constant.language + # ^ variable.function +endif + +kselftest-merge: + $(if $(wildcard $(objtree)/.config),, $(error No .config exists, config your kernel first!)) + $(Q)$(CONFIG_SHELL) $(srctree)/scripts/kconfig/merge_config.sh \ + -m $(objtree)/.config \ + # ^ - constant.language.makefile + $(srctree)/tools/testing/selftests/*/config + +$(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig + +search: + @$(MAKE) --no-print-directory \ + -f core/core.mk $(addprefix -f,$(wildcard index/*.mk)) -f core/index.mk \ + # ^ variable.language.wildcard + search + +CC_VERSION := $(shell $(CC) -dumpversion) +$(call show_config_variable,CC_VERSION,[COMPUTED],($(CC_NAME))) +# ^ keyword.other.block.end +# ^ - keyword.other.block.end +# ^ keyword.other.block.end + +# A recipe may contain empty lines like below +help: + @echo 'Cleaning targets:' + # <- meta.function.body constant.language + + @echo ' make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build' + # <- meta.function.body constant.language + # ^ - keyword.operator.assignment + # ^ string.quoted.single.shell + @echo ' 1: warnings which may be relevant and do not occur too often' + # <- meta.function.body constant.language + # ^ - keyword.operator.assignment + @echo ' 2: warnings which occur quite often but may still be relevant' + # <- meta.function.body constant.language + +CC_VERSION := $(shell $(CC) -dumpversion) +$(call show_config_variable,CC_VERSION,[COMPUTED],($(CC_NAME))) +# ^ keyword.other.block.end +# ^ - keyword.other.block.end +# ^ keyword.other.block.end + +LIBRARIES := $(filter $(notdir $(wildcard $(HOME)/energia_sketchbook/libraries/*)), \ + $(shell sed -ne "s/^ *\# *include *[<\"]\(.*\)\.h[>\"]/\1/p" $(SOURCES))) + # ^ string.quoted.double.shell punctuation.definition.string.begin.shell + # ^ string.quoted.double.shell punctuation.definition.string.end.shell + +# FIX: https://github.com/sublimehq/Packages/issues/1941 +escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1)))) +# ^^^^^^^^ meta.function-call.makefile +# ^^^^^ meta.function-call.arguments.makefile - meta.function-call.makefile +# ^^^^^^^^ meta.function-call.arguments.makefile meta.function-call.makefile +# ^^^^^ meta.function-call.arguments.makefile meta.function-call.arguments.makefile - meta.function-call.makefile +# ^^^^^^^^ meta.function-call.arguments.makefile meta.function-call.arguments.makefile meta.function-call.makefile +# ^^^^^^^ meta.function-call.arguments.makefile meta.function-call.arguments.makefile meta.function-call.arguments.makefile - meta.function-call.makefile +# ^^^^^^^^ meta.function-call.arguments.makefile meta.function-call.arguments.makefile meta.function-call.arguments.makefile meta.function-call.makefile +# ^^^^^^^ meta.function-call.arguments.makefile meta.function-call.arguments.makefile meta.function-call.arguments.makefile meta.function-call.arguments.makefile - meta.function-call.makefile +# ^ meta.function-call.arguments.makefile meta.function-call.arguments.makefile meta.function-call.arguments.makefile keyword.other.block.end.makefile +# ^ meta.function-call.arguments.makefile meta.function-call.arguments.makefile keyword.other.block.end.makefile +# ^ meta.function-call.arguments.makefile keyword.other.block.end.makefile +# ^ keyword.other.block.end.makefile +# ^ - meta +# ^ - punctuation +# ^ punctuation.separator.makefile +# ^^ - punctuation +# ^ - punctuation +# ^ punctuation.separator.makefile +# ^^ - punctuation + +.SECONDEXPANSION: +# <- meta.function entity.name.function +# ^ keyword.operator.assignment - entity.name.function +# ^ - keyword.operator.assignment - entity.name.function +$(DO_IMPLS): $$(foreach s,$$(STEPS),$$(call $$(@)_STEP_TO_PROG,$$(s))) +# <- meta.function entity.name.function +# ^ keyword.operator.assignment - entity.name.function +# ^ - keyword.operator.assignment - entity.name.function +# ^ meta.function.arguments support.function +# ^^^^^^^^^^^^^^^^^^ variable.function +# ^ punctuation.separator + +.SECONDEXPANSION: +$(foreach i,$(DO_IMPLS),$(foreach s,$(STEPS),$(i)^$(s))): $$(call $$(word 1,$$(subst ^, ,$$(@)))_STEP_TO_PROG,$$(word 2,$$(subst ^, ,$$(@)))) +# <- meta.function entity.name.function +# ^ keyword.operator.assignment +# ^ - keyword.operator.assignment +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.function +# ^ punctuation.separator +NAME = FeedProcessorSIAC + +target2: + @# Comment Text + #^ comment - variable + @# FeedProcessorSIAC -origin CQS -decodeData "binData" + #^ comment - variable + + @# # Regular Message + #^ comment - variable + @FeedProcessorSIAC -origin CTS -decodeData "binData" + +TESTTOOL = sh -c '\ +# ^ keyword.operator.assignment.makefile +# ^^^^^^ meta.string.makefile - meta.interpolation +# ^^^ meta.string.makefile meta.interpolation.makefile +# ^^^^^^ string.unquoted.makefile +# ^ punctuation.section.interpolation.begin.makefile +# ^ source.shell.embedded punctuation.separator.continuation.line.shell - source.shell source.shell + if something; then + build_thisway $$1 $$2; + fi' TESTTOOL +# ^^^ meta.string.makefile meta.interpolation.makefile +# ^^^^^^^^^ meta.string.makefile string.unquoted.makefile - meta.interpolation +# ^^ source.shell.embedded keyword.control.conditional.end.shell - source.shell source.shell +# ^ punctuation.section.interpolation.end.makefile + + +# Fix https://github.com/sublimehq/Packages/issues/2388 +html: + $(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS) +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.body.makefile source.shell.embedded.makefile - source.shell source.shell +# ^^^^^^^^^^ meta.function-call.identifier.shell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.arguments.shell +# ^^^^^^^^^^^ variable.parameter.makefile +# ^^ variable.parameter.option.shell +# ^^^^^^^^^^^ variable.parameter.makefile +# ^^ variable.parameter.option.shell +# ^^^^^^^^^^^ variable.parameter.makefile +# ^^^^^^^^^^^^^^ variable.parameter.makefile diff --git a/syntaxes/Ruby/Comments.tmPreferences b/syntaxes/Ruby/Comments.tmPreferences @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<plist version="1.0"> +<dict> + <key>scope</key> + <string>source.ruby</string> + <key>settings</key> + <dict> + <key>shellVariables</key> + <array> + <dict> + <key>name</key> + <string>TM_COMMENT_START</string> + <key>value</key> + <string># </string> + </dict> + <dict> + <key>name</key> + <string>TM_COMMENT_START_2</string> + <key>value</key> + <string>=begin</string> + </dict> + <dict> + <key>name</key> + <string>TM_COMMENT_END_2</string> + <key>value</key> + <string>=end</string> + </dict> + </array> + </dict> +</dict> +</plist> diff --git a/syntaxes/Ruby/Completion Rules.tmPreferences b/syntaxes/Ruby/Completion Rules.tmPreferences @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<plist version="1.0"> +<dict> + <key>scope</key> + <string>source.ruby</string> + <key>settings</key> + <dict> + <key>cancelCompletion</key> + <string>^\s*(else|end|do|begin|rescue|(class|def|module|include)\s*[a-zA-Z_0-9]+)$</string> + </dict> +</dict> +</plist> diff --git a/syntaxes/Ruby/Default.sublime-keymap b/syntaxes/Ruby/Default.sublime-keymap @@ -0,0 +1,13 @@ +[ + { "keys": ["#"], "command": "insert_snippet", "args": {"contents": "#{${0:$SELECTION}}"}, "context": + [ + { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true }, + { + "operand": "(string.quoted.double.ruby | string.interpolated.ruby) - string source", + "operator": "equal", + "match_all": true, + "key": "selector" + } + ] + } +] diff --git a/syntaxes/Ruby/Indentation Rules.tmPreferences b/syntaxes/Ruby/Indentation Rules.tmPreferences @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> +<plist version="1.0"> +<dict> + <key>scope</key> + <string>source.ruby</string> + <key>settings</key> + <dict> + <key>decreaseIndentPattern</key> + <string>^\s*([}\]]|(end|rescue|ensure|else|elsif|when)\b)</string> + <key>increaseIndentPattern</key> + <string><![CDATA[(?x)^ + (\s* + ( + module|class|(?:(?:private|protected|public)\s+)?def + |unless|if|else|elsif + |case|when + |begin|rescue|ensure + |for|while|until + | + (?=.*? \b(do|begin|case|if|unless)\b ) + # the look-ahead above is to quickly discard non-candidates + ( + "(\\.|[^\\"])*+" # eat a double quoted string + | '(\\.|[^\\'])*+' # eat a single quoted string + | [^#"'] # eat all but comments and strings + )* + ( + \s (do|begin|case) + | [-+=&|*/~%^<>~](?<!\$.) \s*+ (if|unless) + ) + )\b + (?! [^;]*+ ; .*? \bend\b ) + | + ( + "(\\.|[^\\"])*+" # eat a double quoted string + | '(\\.|[^\\'])*+' # eat a single quoted string + | [^#"'] # eat all but comments and strings + )* + ( + \{ (?! [^}]*+ \} ) + | \[ (?! [^\]]*+ \] ) + ) + ).*$ + ]]></string> + </dict> +</dict> +</plist> diff --git a/syntaxes/Ruby/Ruby.sublime-build b/syntaxes/Ruby/Ruby.sublime-build @@ -0,0 +1,5 @@ +{ + "shell_cmd": "ruby \"$file\"", + "file_regex": "^(...*?):([0-9]*):?([0-9]*)", + "selector": "source.ruby" +} diff --git a/syntaxes/Ruby/Ruby.sublime-syntax b/syntaxes/Ruby/Ruby.sublime-syntax @@ -0,0 +1,2204 @@ +%YAML 1.2 +--- +name: Ruby +# TODO: unresolved issues +# +# text: +# "p << end +# print me! +# end" +# symptoms: +# not recognized as a heredoc +# solution: +# there is no way to distinguish perfectly between the << operator and the start +# of a heredoc. Currently, we require assignment to recognize a heredoc. More +# refinement is possible. +# • Heredocs with indented terminators (<<-) are always distinguishable, however. +# • Nested heredocs are not really supportable at present +# +# text: +# val?(a):p(b) +# val?'a':'b' +# symptoms: +# ':p' is recognized as a symbol.. its 2 things ':' and 'p'. +# :'b' has same problem. +# solution: +# ternary operator rule, precedence stuff, symbol rule. +# but also consider 'a.b?(:c)' ?? +file_extensions: + - rb + - Appfile + - Appraisals + - Berksfile + - Brewfile + - capfile + - cgi + - Cheffile + - config.ru + - Deliverfile + - Fastfile + - fcgi + - Gemfile + - gemspec + - Guardfile + - irbrc + - jbuilder + - Podfile + - podspec + - prawn + - pryrc + - rabl + - rake + - Rakefile + - Rantfile + - rbx + - rjs + - ruby.rail + - Scanfile + - simplecov + - Snapfile + - thor + - Thorfile + - Vagrantfile +first_line_match: |- + (?xi: + ^\#! .* \bj?ruby\b | # shebang + ^\# \s* -\*- [^*]* ruby [^*]* -\*- # editorconfig + ) +scope: source.ruby +variables: + bin_digits: (?:[01]+(?:_[01]+)*) + dec_digits: (?:\d+(?:_\d+)*) + hex_digits: (?:\h+(?:_\h+)*) + oct_digits: (?:[0-7]+(?:_[0-7]+)*) + dec_exponent: (?:[Ee][-+]?{{dec_digits}}) + heredoc_type_css: (?:[[:upper:]_]_)?CSS\b + heredoc_type_html: (?:[[:upper:]_]_)?HTML\b + heredoc_type_js: (?:[[:upper:]_]_)?(?:JS|JAVASCRIPT)\b + heredoc_type_ruby: (?:[[:upper:]_]_)?RUBY\b + heredoc_type_shell: (?:[[:upper:]_]_)?(?:SH|SHELL)\b + heredoc_type_sql: (?:[[:upper:]_]_)?SQL\b + identifier: '\b[[:alpha:]_][[:alnum:]_]*\b' + method_punctuation: '(?:[?!]|=(?![>=]))?' + method_name: '{{identifier}}{{method_punctuation}}' + path_lookahead: '(::)?({{identifier}}(\.|::))*{{identifier}}' + +contexts: + main: + - include: expressions + + expressions: + - include: constants + - include: class + - include: module + - include: invalid + - include: blocks + - include: keywords + - include: well-known-methods + - include: variables + - include: method + - include: strings + - include: comments + - include: data-section + - include: heredocs + - include: punctuation + - include: operators + - include: identifiers-accessors + + comments: + # multiline comments + - match: ^=begin + scope: punctuation.definition.comment.begin.ruby + push: + - meta_scope: comment.block.documentation.ruby + - match: ^=end + scope: punctuation.definition.comment.end.ruby + pop: true + - match: \#+ + scope: punctuation.definition.comment.ruby + push: + - meta_scope: comment.line.number-sign.ruby + - match: \n + pop: true + + class: + # Defining a class method + - match: \bclass\b(?=\s*<) + scope: keyword.declaration.class.ruby + - match: \bclass\b + scope: keyword.declaration.class.ruby + push: class-declaration + + class-declaration: + - meta_scope: meta.class.ruby + - match: '(?={{path_lookahead}})' + set: class-name + # Escape if no valid match + - match: (?=\S) + pop: true + + class-name: + - meta_content_scope: meta.class.ruby entity.name.class.ruby + - include: name-parts + - match: '' + set: class-inheritance + + class-inheritance: + - meta_content_scope: meta.class.ruby + - match: '<' + scope: punctuation.separator.inheritance.ruby + set: + - meta_content_scope: meta.class.ruby + - match: '(?={{path_lookahead}})' + set: + - meta_content_scope: meta.class.ruby entity.other.inherited-class.ruby + - include: name-parts + - match: '' + pop: true + # Escape if no valid match + - match: '(?=\S)' + pop: true + # Escape if no valid match + - match: '(?=\S)' + pop: true + + module: + - match: \bmodule\b + scope: keyword.declaration.namespace.ruby + push: module-declaration + + module-declaration: + - meta_scope: meta.namespace.ruby + - match: '(?=(::)?({{identifier}}::)*{{identifier}})' + set: + - meta_content_scope: meta.namespace.ruby entity.name.namespace.ruby + - include: name-parts + - match: '' + pop: true + # Escape if no valid match + - match: (?=\S) + pop: true + + name-parts: + - match: ({{identifier}})?(?:(::)|(\.)) + captures: + 1: support.other.namespace.ruby + 2: punctuation.accessor.double-colon.ruby + 3: punctuation.accessor.dot.ruby + - match: '{{identifier}}' + + invalid: + # else if is a common mistake carried over from other languages. it works if you put in a second end, but it’s never what you want. + - match: \belse\s+if\b + scope: invalid.deprecated.ruby + + constants: + # constant definition, handles multiple definitions on a single line 'APPLE, ORANGE= 1, 2' + - match: '\b([[:upper:]]\w*)(?=(\s*,\s*[[:upper:]]\w*)*\s*=(?![=\>]))' + scope: meta.constant.ruby entity.name.constant.ruby + # Ruby 1.9 symbols + - match: '{{identifier}}[?!]?(:)(?!:)' + scope: constant.other.symbol.ruby + captures: + 1: punctuation.definition.constant.ruby + push: try-regex + - match: '\b(nil|true|false)\b(?![?!])' + scope: constant.language.ruby + - match: '\b(__(FILE|LINE|ENCODING)__|self)\b(?![?!])' + scope: variable.language.ruby + # hexadecimal imaginary numbers: 0xAi, 0xAri + - match: '\b(0[xX])({{hex_digits}})(r?i(r)?)\b' + scope: meta.number.imaginary.hexadecimal.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + 3: constant.numeric.suffix.ruby + 4: invalid.illegal.numeric.ruby + # octal imaginary numbers: 0o1i, 0o1ri, 01i, 01ri + - match: '\b(0[oO]?)({{oct_digits}})(r?i(r)?)\b' + scope: meta.number.imaginary.octal.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + 3: constant.numeric.suffix.ruby + 4: invalid.illegal.numeric.ruby + # binary imaginary numbers: 0b1i, 0b1ri + - match: '\b(0[bB])({{bin_digits}})(r?i(r)?)\b' + scope: meta.number.imaginary.binary.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + 3: constant.numeric.suffix.ruby + 4: invalid.illegal.numeric.ruby + # decimal imaginary numbers: 0d1i, 0d1ri, 1i, 1ri, 1.1i, 1.1ri, 1e1i, 1.1e1i + - match: |- + \b(?x: + (?: + # 0d1i, 0d1ri, 1i, 1ri | 1.1i, 1.1ri + (?: (0[dD])? ({{dec_digits}}) | ({{dec_digits}} (\.) {{dec_digits}}) ) (r?i) + # 1e1i, 1.1e1i + | ({{dec_digits}} (?: (\.) {{dec_digits}} )? {{dec_exponent}}) (r)?(i) + ) (r)? + )\b + scope: meta.number.imaginary.decimal.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + 3: constant.numeric.value.ruby + 4: punctuation.separator.decimal.ruby + 5: constant.numeric.suffix.ruby + 6: constant.numeric.value.ruby + 7: punctuation.separator.decimal.ruby + 8: constant.numeric.suffix.ruby invalid.illegal.numeric.ruby + 9: constant.numeric.suffix.ruby + 10: constant.numeric.suffix.ruby invalid.illegal.numeric.ruby + # hexadecimal rational numbers: 0xAr + - match: '\b(0[xX])({{hex_digits}})(r)\b' + scope: meta.number.rational.hexadecimal.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + 3: constant.numeric.suffix.ruby + # octal rational numbers: 0o1r, 01r + - match: '\b(0[oO]?)({{oct_digits}})(r)\b' + scope: meta.number.rational.octal.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + 3: constant.numeric.suffix.ruby + # binary rational numbers: 0b1r + - match: '\b(0[bB])({{bin_digits}})(r)\b' + scope: meta.number.rational.binary.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + 3: constant.numeric.suffix.ruby + # decimal rational numbers: 0d1r, 1r, 1.1r + - match: '\b(0[dD])?({{dec_digits}}|{{dec_digits}}(\.){{dec_digits}})(r)\b' + scope: meta.number.rational.decimal.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + 3: punctuation.separator.decimal.ruby + 4: constant.numeric.suffix.ruby + # decimal floating point numbers: 1.1, 1e1, 1.1e1 + - match: '\b({{dec_digits}})(?:((\.){{dec_digits}})|((?:(\.){{dec_digits}})?{{dec_exponent}})(r)?)\b' + scope: meta.number.float.decimal.ruby + captures: + 1: constant.numeric.value.ruby + 2: constant.numeric.value.ruby + 3: punctuation.separator.decimal.ruby + 4: constant.numeric.value.ruby + 5: punctuation.separator.decimal.ruby + 6: constant.numeric.suffix.ruby invalid.illegal.numeric.rational.ruby + # hexadecimal integer numbers: 0xA + - match: '\b(0[xX])({{hex_digits}})\b' + scope: meta.number.integer.hexadecimal.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + # octal integer numbers: 0o1, 01 + - match: '\b(0[oO]?)({{oct_digits}})\b' + scope: meta.number.integer.octal.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + # binary integer numbers: 0b1 + - match: '\b(0[bB])({{bin_digits}})\b' + scope: meta.number.integer.binary.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + # decimal integer numbers: 0d1, 1 + - match: '\b(0[dD])?({{dec_digits}})\b' + scope: meta.number.integer.decimal.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + # Quoted symbols + - match: ":'" + scope: punctuation.definition.constant.ruby + push: + - meta_scope: meta.constant.ruby constant.other.symbol.single-quoted.ruby + - match: "'" + scope: punctuation.definition.constant.ruby + pop: true + - match: '\\[''\\]' + scope: constant.character.escape.ruby + - match: ':"' + scope: punctuation.definition.constant.ruby + push: + - meta_scope: meta.constant.ruby constant.other.symbol.double-quoted.ruby + - match: '"' + scope: punctuation.definition.constant.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + # Unquoted symbols + - match: |- + (?x: + (:) + ( + {{identifier}}{{method_punctuation}}| + ===?| + >[>=]?| + <[<=]?| + <=>| + [%&`/\|]| + \*\*?| + =?~| + [-+]@?| + \[\]=?| + @@?{{identifier}} + ) + ) + scope: constant.other.symbol.ruby + captures: + 1: punctuation.definition.constant.ruby + # questionmark literals + - match: ((\?)\\u)(\{) + captures: + 1: constant.character.ruby + 2: punctuation.definition.constant.ruby + 3: meta.braces.ruby punctuation.section.braces.begin.ruby + push: + - meta_scope: meta.constant.ruby + - meta_content_scope: meta.braces.ruby + - match: \} + scope: meta.braces.ruby punctuation.section.braces.end.ruby + pop: true + - match: \h{0,6} + scope: meta.number.integer.hexadecimal.ruby constant.numeric.value.ruby + - match: \S + scope: invalid.illegal.escape.ruby + - match: |- + (?x: (\?)(?: + # examples (meta control sequences): + # ?\C-a ?\M-a ?\M-\C-a ?\ca ?\M-ca + (?:\\(?:[MC]-|c)){1,2}[[:ascii:]] | + \\(?: + # examples (hex): + # ?\x1 ?\x61 + x\h{1,2}\b | + # examples (octal): + # ?\0 ?\07 ?\017 + 0[0-7]{0,2}\b | + # examples (escaped): + # ?\n ?\b ?\\ + .(?!\w) + ) | + # examples (illegal): + # ?abc ?\xAG ?\\n + # ?_a0 + ([[:alpha:]_\\]\S+)\b(?!\s*:) | + # examples (normal): + # ?a ?A ?0 + # ?* ?" ?( + # ?. ?# ?\ + [[:alnum:]_]\b(?!\s*:) | [^[:alnum:]_\s] + ) ) + scope: constant.character.ruby + captures: + 1: punctuation.definition.constant.ruby + 2: invalid.illegal.character.ruby + + blocks: + - match: \bdo\b + scope: keyword.control.block.do.ruby + push: maybe-block-parameters + - match: \{ + scope: punctuation.section.scope.ruby + push: maybe-block-parameters + + maybe-block-parameters: + - match: \| + scope: meta.block.parameters.ruby punctuation.definition.parameters.begin.ruby + set: block-parameters + - match: (?=\s*[^\s\|]) + pop: true + + block-parameters: + - meta_content_scope: meta.block.parameters.ruby + - match: \| + scope: meta.block.parameters.ruby punctuation.definition.parameters.end.ruby + set: try-regex + - match: '{{identifier}}' + scope: variable.parameter.ruby + - match: ',' + scope: punctuation.separator.ruby + - match: \* + scope: keyword.operator.splat.ruby + - match: '&' + scope: keyword.operator.ruby + - match: '(?==)' + set: + - meta_content_scope: meta.block.parameters.default-value.ruby + - match: '=' + scope: keyword.operator.assignment.ruby + set: + - meta_content_scope: meta.block.parameters.default-value.ruby + - match: '(?=[,\|])' + set: block-parameters + - include: nest-all + - include: expressions + + keywords: + # blocks + - match: \bbegin\b(?![?!]) + scope: keyword.control.block.begin.ruby + push: after-keyword + - match: \bend\b(?![?!]) + scope: keyword.control.block.end.ruby + # conditional + - match: \bcase\b(?![?!]) + scope: keyword.control.conditional.case.ruby + push: after-keyword + - match: \belse\b(?![?!]) + scope: keyword.control.conditional.if.ruby + push: after-keyword + - match: \belsif\b(?![?!]) + scope: keyword.control.conditional.elseif.ruby + push: after-keyword + - match: \bif\b(?![?!]) + scope: keyword.control.conditional.if.ruby + push: after-keyword + - match: \bthen\b(?![?!]) + scope: keyword.control.conditional.then.ruby + - match: \bunless\b(?![?!]) + scope: keyword.control.conditional.unless.ruby + push: after-keyword + - match: \bwhen\b(?![?!]) + scope: keyword.control.conditional.when.ruby + push: after-keyword + # exception + - match: \bensure\b(?![?!]) + scope: keyword.control.exception.ensure.ruby + push: after-keyword + - match: \brescue\b(?![?!]) + scope: keyword.control.exception.rescue.ruby + push: after-keyword + # loop + - match: \bfor\b(?![?!]) + scope: keyword.control.loop.for.ruby + push: after-keyword + - match: \buntil\b(?![?!]) + scope: keyword.control.loop.until.ruby + push: after-keyword + - match: \bwhile\b(?![?!]) + scope: keyword.control.loop.while.ruby + push: after-keyword + # flow + - match: \bbreak\b(?![?!]) + scope: keyword.control.flow.break.ruby + - match: \bnext\b(?![?!]) + scope: keyword.control.flow.next.ruby + - match: \bredo\b(?![?!]) + scope: keyword.control.flow.redo.ruby + - match: \bretry\b(?![?!]) + scope: keyword.control.flow.retry.ruby + - match: \breturn\b(?![?!]) + scope: keyword.control.flow.return.ruby + - match: \byield\b(?![?!]) + scope: keyword.control.flow.yield.ruby + # declarations + - match: \b(?:alias|alias_method)\b(?![?!]) + scope: keyword.declaration.alias.ruby + push: after-keyword + - match: \bundef\b(?![?!]) + scope: keyword.declaration.undef.ruby + push: after-keyword + # operators + - match: \b(?:and|not|or)\b + scope: keyword.operator.logical.ruby + push: after-keyword + - match: \bin\b(?![?!]) + scope: keyword.operator.logical.ruby + push: after-keyword + # other functions + - match: \b(?:BEGIN|END)\b(?![?!]) + scope: entity.name.function.prepocessor.ruby + - match: \b(?:defined|block_given)\? + scope: support.function.builtin.ruby + push: after-keyword + - match: \bsuper\b(?![?!]) + scope: support.function.builtin.ruby + push: after-keyword + + operators: + - match: '>>' + scope: keyword.operator.other.ruby + push: after-operator + # note: `/=` is matched in the `regexes` context + - match: <<=|&&=|\|\|=|\*\*=|[-+*&|^]=|<< + scope: keyword.operator.assignment.augmented.ruby + push: after-operator + - match: <=>|===|<=|>=|==|=~|!=|!~|<|> + scope: keyword.operator.comparison.ruby + push: after-operator + - match: \*\*|[-+*/%] + scope: keyword.operator.arithmetic.ruby + push: after-operator + - match: = + scope: keyword.operator.assignment.ruby + push: after-operator + - match: '!+|&&|\|\|' + scope: keyword.operator.logical.ruby + push: after-operator + - match: '[~&|^]' + scope: keyword.operator.bitwise.ruby + push: after-operator + - match: \? + scope: keyword.operator.conditional.ruby + push: + # Handle hash-key-lookalike of identifier: in ternary + - match: \s*{{identifier}}(:)(?!:) + captures: + 1: keyword.operator.conditional.ruby + set: after-operator + - include: after-operator + - match: :(?!:) + scope: keyword.operator.conditional.ruby + push: after-operator + - match: \.\.\.? + scope: keyword.operator.range.ruby + push: after-operator + + punctuation: + - match: => + scope: punctuation.separator.key-value.ruby + push: after-operator + - match: ',' + scope: punctuation.separator.sequence.ruby + push: after-operator + - match: ; + scope: punctuation.terminator.statement.ruby + push: after-operator + - match: \[ + scope: punctuation.section.array.ruby + push: after-operator + - match: \( + scope: punctuation.definition.group.begin.ruby + push: after-operator + # Opening { is handled by "block" context to try and detect parameters + - match: \} + scope: punctuation.section.scope.ruby + - match: \] + scope: punctuation.section.array.ruby + - match: \) + scope: punctuation.definition.group.end.ruby + + identifiers-accessors: + # This consumes class/module access to prevent issues parsing : as part + # of a ternary operator + - match: ::(?={{identifier}}{{method_punctuation}}) + scope: punctuation.accessor.double-colon.ruby + push: + - include: well-known-methods + - match: '{{identifier}}{{method_punctuation}}' + - match: '' + set: after-identifier + # This consumes attribute access so we don't need a lookbehind for . + - match: \.(?={{identifier}}{{method_punctuation}}) + scope: punctuation.accessor.dot.ruby + push: + - include: well-known-methods + - match: '{{identifier}}{{method_punctuation}}' + - match: '' + set: after-identifier + # This consumes method names ending in punctuation so we don't need a lookbehind for ?, ! or = + - match: '{{identifier}}{{method_punctuation}}' + # This consumes module/class accessor so we don't need a lookbehind for :: + push: after-identifier + - match: \. + scope: punctuation.accessor.dot.ruby + - match: '::' + scope: punctuation.accessor.double-colon.ruby + + after-identifier: + # Handles a : right after an identifier. In this case it can't be the + # beginning of a symbol, so it must be part of a ternary operator + - match: ':(?!:)' + scope: keyword.operator.conditional.ruby + pop: true + - match: '' + pop: true + + variables: + - match: '(@)[a-zA-Z_]\w*' + scope: variable.other.readwrite.instance.ruby + captures: + 1: punctuation.definition.variable.ruby + - match: '(@@)[a-zA-Z_]\w*' + scope: variable.other.readwrite.class.ruby + captures: + 1: punctuation.definition.variable.ruby + - match: '(\$)[a-zA-Z_]\w*' + scope: variable.other.readwrite.global.ruby + captures: + 1: punctuation.definition.variable.ruby + - match: '(\$)(!|@|&|`|''|\+|\d+|~|=|/|\\|,|;|\.|<|>|_|\*|\$|\?|:|"|-[0adFiIlpv])' + scope: variable.other.readwrite.global.pre-defined.ruby + captures: + 1: punctuation.definition.variable.ruby + - match: '\b(ENV)\[' + captures: + 1: variable.other.constant.ruby + push: + - meta_scope: meta.environment-variable.ruby + - match: '\]' + pop: true + - include: expressions + - match: '(::)?(\b[[:upper:]]\w*)(?=((\.|::)[[:alpha:]_]|\[))' + captures: + 1: punctuation.accessor.double-colon.ruby + 2: support.class.ruby + - match: '\b[[:upper:]]\w*\b' + scope: variable.other.constant.ruby + + well-known-methods: + # exceptions + - match: \bcatch\b(?![?!]) + scope: keyword.control.exception.catch.ruby + push: function-call-arguments + # flow + - match: \b(?:fail|raise|throw)\b(?![?!]) + scope: keyword.control.flow.throw.ruby + push: function-call-arguments + # loop + - match: \bloop\b(?![?!]) + scope: keyword.control.loop.loop.ruby + push: function-call-arguments + # other + - match: \b(initialize|new|include|extend|prepend|attr_reader|attr_writer|attr_accessor|attr|module_function|public|protected|private)\b(?![?!]) + scope: keyword.other.special-method.ruby + push: function-call-arguments + - match: \b(require|require_relative|gem)\b + scope: keyword.control.import.ruby + push: + - meta_scope: meta.require.ruby + - match: $|(?=[#}]) + pop: true + - include: expressions + # Conversion methods + - match: |- + (?x: + \b( + to_ary| + to_a| + to_c| + to_enum| + to_f| + to_hash| + to_h| + to_int| + to_io| + to_i| + to_proc| + to_r| + to_str| + to_sym| + to_s + )\b + (?![!?=]) + ) + scope: support.function.builtin.ruby + push: function-call-arguments + # Methods that may be followed by a regex + - match: |- + (?x: + \b( + gsub| + sub + )(!|\b) + | + \b( + match + )(\?|\b) + | + \b( + assert_match| + assert_no_match| + index| + rindex| + scan + )\b(?![!?=]) + ) + scope: support.function.builtin.ruby + push: function-call-arguments + # Methods from the Object class not handled elsewhere, ending in punctuation + - match: |- + (?x: + \b( + eql\?| + instance_of\?| + instance_variable_defined\?| + is_a\?| + kind_of\?| + nil\?| + respond_to\?| + respond_to_missing\?| + tainted\?| + untrusted\? + ) + ) + scope: support.function.builtin.ruby + push: function-call-arguments + # Methods from the Object class not handled elsewhere + - match: |- + (?x: + \b( + class| + clone| + define_singleton_method| + display| + dup| + enum_for| + extend| + freeze| + frozen?| + hash| + inspect| + instance_variable_get| + instance_variable_set| + instance_variables| + itself| + method| + methods| + object_id| + private_methods| + protected_methods| + public_method| + public_methods| + public_send| + remove_instance_variable| + send| + singleton_class| + singleton_method| + singleton_methods| + taint| + tap| + trust| + untaint| + untrust + )\b + (?![!?=]) + ) + scope: support.function.builtin.ruby + push: function-call-arguments + # Methods from the Kernel class not handled elsewhere, ending in punctuation + - match: |- + (?x: + \b( + autoload\?| + iterator\?| + exit! + ) + ) + scope: support.function.builtin.ruby + push: function-call-arguments + # Methods from the Kernel class not handled elsewhere + - match: |- + (?x: + \b( + Array| + Complex| + Float| + Hash| + Integer| + Rational| + String| + __callee__| + __dir__| + __method__| + abort| + at_exit| + autoload| + binding| + callcc| + caller| + caller_locations| + chomp| + chop| + eval| + exec| + exit| + fork| + format| + gets| + global_variables| + gsub| + lambda| + load| + local_variables| + open| + p| + print| + printf| + proc| + putc| + puts| + rand| + readline| + readlines| + require| + require_relative| + select| + set_trace_func| + sleep| + spawn| + sprintf| + srand| + sub| + syscall| + system| + test| + trace_var| + trap| + untrace_var| + warn + )\b + (?![!?=]) + ) + scope: support.function.builtin.ruby + push: function-call-arguments + # Methods from the Kernel class not handled elsewhere, ending in punctuation + - match: |- + (?x: + \b( + class_variable_defined\?| + const_defined\?| + include\?| + instance_methods\?| + method_defined\?| + private_method_defined\?| + protected_method_defined\?| + public_method_defined\?| + singleton_class\? + ) + ) + scope: support.function.builtin.ruby + push: function-call-arguments + # Lambda operator from the Kernel class not handled elsewhere + - match: '->' + scope: meta.function.ruby keyword.declaration.function.anonymous.ruby + push: function-call-arguments + # Methods from the Module class not handled elsewhere + - match: |- + (?x: + \b( + ancestors| + append_features| + class_eval| + class_exec| + class_variable_get| + class_variable_set| + class_variables| + const_get| + const_missing| + const_set| + constants| + define_method| + extend_object| + extended| + freeze| + included| + included_modules| + inspect| + method_added| + method_removed| + method_undefined| + module_eval| + module_exec| + name| + prepend_features| + prepended| + private_class_method| + private_constant| + private_instance_methods| + protected_instance_methods| + public_class_method| + public_constant| + public_instance_method| + public_instance_methods| + refine| + remove_class_variable| + remove_const| + remove_method| + undef_method| + using + )\b + (?![!?=]) + ) + scope: support.function.builtin.ruby + push: function-call-arguments + + function-call-arguments: + - include: try-regex + + method: + - match: \bdef\b + scope: meta.function.ruby keyword.declaration.function.ruby + push: + - meta_content_scope: meta.function.ruby + - match: '(self)(\.)({{identifier}}{{method_punctuation}}|===?|>[>=]?|<=>|<[<=]?|[%&`/\|]|\*\*?|=?~|[-+]@?|\[\]=?)' + captures: + 1: variable.language.ruby + 2: punctuation.accessor.dot.ruby + 3: entity.name.function.ruby + set: method-parameters-start + - match: '===?|>[>=]?|<=>|<[<=]?|[%&`/\|]|\*\*?|=?~|[-+]@?|\[\]=?' + scope: entity.name.function.ruby + set: method-parameters-start + - match: '(?:({{identifier}})(?:(::)|(\.)))?{{identifier}}{{method_punctuation}}' + scope: entity.name.function.ruby + captures: + 1: support.other.namespace.ruby + 2: punctuation.accessor.double-colon.ruby + 3: punctuation.accessor.dot.ruby + set: method-parameters-start + - match: '$' + pop: true + - match: '(?=\S)' + pop: true + + method-parameters-start: + - meta_content_scope: meta.function.ruby + - match: '(?=\()' + set: + - meta_content_scope: meta.function.parameters.ruby + - match: '\(' + scope: punctuation.definition.group.begin.ruby + set: method-parameters + # No parameters + - match: '(?=$|;|#)' + pop: true + # No parentheses around parameters + - match: '(?=[[:alpha:]_*])' + set: method-bare-parameters + + method-parameters: + - meta_content_scope: meta.function.parameters.ruby + - match: '\)' + scope: meta.function.parameters.ruby punctuation.definition.group.end.ruby + pop: true + - match: '{{identifier}}' + scope: variable.parameter.ruby + - include: comments + - match: ',' + scope: punctuation.separator.ruby + - match: '\*' + scope: keyword.operator.splat.ruby + - match: '&' + scope: keyword.operator.ruby + # De-structuring + - match: \( + scope: punctuation.definition.group.begin.ruby + push: + - match: \) + scope: punctuation.definition.group.end.ruby + pop: true + - match: '{{identifier}}' + scope: variable.parameter.ruby + - match: ',' + scope: punctuation.separator.ruby + - match: '\*' + scope: keyword.operator.splat.ruby + # Default values + - match: (?==) + set: + - meta_content_scope: meta.function.parameters.default-value.ruby + - match: '=' + scope: keyword.operator.assignment.ruby + set: + - meta_content_scope: meta.function.parameters.default-value.ruby + - match: '(?=[,\)])' + set: method-parameters + - include: nest-all + - include: expressions + # Keyword parameter (with default value support) + - match: (?=:) + set: + - meta_content_scope: meta.function.parameters.default-value.ruby + - match: ':' + scope: punctuation.separator.ruby + set: + - meta_content_scope: meta.function.parameters.default-value.ruby + - match: '(?=[,\)])' + set: method-parameters + - include: nest-all + - include: expressions + + # When no parentheses are placed around the parameters + method-bare-parameters: + - meta_content_scope: meta.function.parameters.ruby + - match: '(?=$|;|#)' + pop: true + - match: '{{identifier}}' + scope: variable.parameter.ruby + - match: ',' + scope: punctuation.separator.ruby + - match: '\*' + scope: keyword.operator.splat.ruby + - match: '&' + scope: keyword.operator.ruby + # Default values + - match: (?==) + set: + - meta_content_scope: meta.function.parameters.default-value.ruby + - match: '=' + scope: punctuation.operator.assignment.ruby + set: + - meta_content_scope: meta.function.parameters.default-value.ruby + - match: '(?=$|[,;])' + set: method-bare-parameters + - include: nest-all + - include: expressions + # Keyword parameter (with default value support) + - match: (?=:) + set: + - meta_content_scope: meta.function.parameters.default-value.ruby + - match: ':' + scope: punctuation.separator.ruby + set: + - meta_content_scope: meta.function.parameters.default-value.ruby + - match: '(?=$|[,;])' + set: method-bare-parameters + - include: nest-all + - include: expressions + + strings: + - include: early-strings + - include: regexes + - include: late-strings + + early-strings: + # single quoted string (does not allow interpolation) + - match: "'" + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.single.ruby + - match: "'" + scope: punctuation.definition.string.end.ruby + pop: true + - match: \\'|\\\\ + scope: constant.character.escape.ruby + - include: string-placeholder + # double quoted string (allows for interpolation) + - match: '"' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.double.ruby + - match: '"' + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: string-placeholder + # execute string (allows for interpolation) + - match: "`" + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.interpolated.ruby + - match: "`" + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + # execute string (allow for interpolation) + - match: '%x\{' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.interpolated.ruby + - match: '\}' + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-curly-i + # execute string (allow for interpolation) + - match: '%x\[' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.interpolated.ruby + - match: '\]' + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-brackets-i + # execute string (allow for interpolation) + - match: '%x\<' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.interpolated.ruby + - match: \> + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-ltgt-i + # execute string (allow for interpolation) + - match: '%x\(' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.interpolated.ruby + - match: \) + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-parens-i + # execute string (allow for interpolation) + - match: '%x([^\w])' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.interpolated.ruby + - match: \1 + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + + late-strings: + # literal capable of interpolation () + - match: '%[QW]?\(' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.upper.ruby + - match: \) + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-parens-i + # "literal capable of interpolation []" + - match: '%[QW]?\[' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.upper.ruby + - match: '\]' + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-brackets-i + # literal capable of interpolation <> + - match: '%[QW]?\<' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.upper.ruby + - match: \> + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-ltgt-i + # literal capable of interpolation -- {} + - match: '%[QW]?\{' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.double.ruby.mod + - match: '\}' + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-curly-i + # literal capable of interpolation -- wildcard + - match: '%[QW]([^\w])' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.upper.ruby + - match: \1 + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + # literal capable of interpolation -- wildcard + - match: '%([^\w\s=])' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.other.ruby + - match: \1 + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + # literal capable of interpolation () + - match: '%I\(' + scope: punctuation.definition.string.begin.ruby + push: + - match: '\w+' + scope: constant.other.symbol.ruby + - meta_scope: meta.string.ruby string.quoted.other.literal.upper.ruby + - match: \) + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-parens-i + # "literal capable of interpolation []" + - match: '%I\[' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.upper.ruby + - match: '\w+' + scope: constant.other.symbol.ruby + - match: '\]' + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-brackets-i + # literal capable of interpolation <> + - match: '%I\<' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.upper.ruby + - match: '\w+' + scope: constant.other.symbol.ruby + - match: \> + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-ltgt-i + # literal capable of interpolation -- {} + - match: '%I\{' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.double.ruby.mod + - match: '\w+' + scope: constant.other.symbol.ruby + - match: '\}' + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-curly-i + # literal capable of interpolation -- wildcard + - match: '%I([^\w])' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.upper.ruby + - match: '\w+' + scope: constant.other.symbol.ruby + - match: \1 + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + # literal incapable of interpolation -- () + - match: '%[qws]\(' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.lower.ruby + - match: \) + scope: punctuation.definition.string.end.ruby + pop: true + - match: \\\)|\\\\ + scope: constant.character.escape.ruby + - include: nest-parens + # literal incapable of interpolation -- <> + - match: '%[qws]\<' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.lower.ruby + - match: \> + scope: punctuation.definition.string.end.ruby + pop: true + - match: \\\>|\\\\ + scope: constant.character.escape.ruby + - include: nest-ltgt + # literal incapable of interpolation -- [] + - match: '%[qws]\[' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.lower.ruby + - match: '\]' + scope: punctuation.definition.string.end.ruby + pop: true + - match: '\\\]|\\\\' + scope: constant.character.escape.ruby + - include: nest-brackets + # literal incapable of interpolation -- {} + - match: '%[qws]\{' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.lower.ruby + - match: '\}' + scope: punctuation.definition.string.end.ruby + pop: true + - match: '\\\}|\\\\' + scope: constant.character.escape.ruby + - include: nest-curly + # literal incapable of interpolation -- wildcard + - match: '%[qws]([^\w])' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.lower.ruby + - match: \1 + scope: punctuation.definition.string.end.ruby + pop: true + # Cant be named because its not necessarily an escape + - match: \\. + # symbol literal incapable of interpolation -- () + - match: '%i\(' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: string.quoted.other.literal.lower.ruby + - match: '\w+' + scope: constant.other.symbol.ruby + - match: \) + scope: punctuation.definition.string.end.ruby + pop: true + - match: \\\)|\\\\ + scope: constant.character.escape.ruby + - include: nest-parens + # symbol literal incapable of interpolation -- <> + - match: '%i\<' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: string.quoted.other.literal.lower.ruby + - match: '\w+' + scope: constant.other.symbol.ruby + - match: \> + scope: punctuation.definition.string.end.ruby + pop: true + - match: \\\>|\\\\ + scope: constant.character.escape.ruby + - include: nest-ltgt + # symbol literal incapable of interpolation -- [] + - match: '%i\[' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: string.quoted.other.literal.lower.ruby + - match: '\w+' + scope: constant.other.symbol.ruby + - match: '\]' + scope: punctuation.definition.string.end.ruby + pop: true + - match: '\\\]|\\\\' + scope: constant.character.escape.ruby + - include: nest-brackets + # symbol literal incapable of interpolation -- {} + - match: '%i\{' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: string.quoted.other.literal.lower.ruby + - match: '\w+' + scope: constant.other.symbol.ruby + - match: '\}' + scope: punctuation.definition.string.end.ruby + pop: true + - match: '\\\}|\\\\' + scope: constant.character.escape.ruby + - include: nest-curly + # symbol literal incapable of interpolation -- wildcard + - match: '%i([^\w])' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: string.quoted.other.literal.lower.ruby + - match: '\w+' + scope: constant.other.symbol.ruby + - match: \1 + scope: punctuation.definition.string.end.ruby + pop: true + # Cant be named because its not necessarily an escape + - match: \\. + + after-keyword: + - include: try-regex + + after-operator: + - include: try-regex + + try-regex: + # Generally for multiline regexes, one of the %r forms below will be used, + # so we bail out if we can't find a second / on the current line + - match: \s*(/)(?=(?!=).*/) + captures: + 1: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.regexp.ruby string.regexp.classic.ruby + - match: (/)([eimnosux]*) + captures: + 1: punctuation.definition.string.end.ruby + 2: keyword.other.ruby + pop: true + - include: regex-sub + - match: '' + pop: true + + regexes: + # Needs higher precedence than regular expressions. + - match: /= + scope: keyword.operator.assignment.augmented.ruby + - match: '(?=^\s*/)' + push: try-regex + - match: (?=/\s*[^\w\(\s@"']) + push: try-regex + # regular expressions (literal) + - match: '%r\{' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.regexp.mod-r.ruby + - match: '\}[eimnosux]*' + scope: punctuation.definition.string.end.ruby + pop: true + - include: regex-sub + - include: nest-curly-r + # regular expressions (literal) + - match: '%r\[' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.regexp.mod-r.ruby + - match: '\][eimnosux]*' + scope: punctuation.definition.string.end.ruby + pop: true + - include: regex-sub + - include: nest-brackets-r + # regular expressions (literal) + - match: '%r\(' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.regexp.mod-r.ruby + - match: '\)[eimnosux]*' + scope: punctuation.definition.string.end.ruby + pop: true + - include: regex-sub + - include: nest-parens-r + # regular expressions (literal) + - match: '%r\<' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.regexp.mod-r.ruby + - match: '\>[eimnosux]*' + scope: punctuation.definition.string.end.ruby + pop: true + - include: regex-sub + - include: nest-ltgt-r + # regular expressions (literal) + - match: '%r([^\w])' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.regexp.mod-r.ruby + - match: '\1[eimnosux]*' + scope: punctuation.definition.string.end.ruby + pop: true + - include: regex-sub + + regex-sub: + - include: interpolated-ruby + - include: escaped-char + - match: '(\{)\d+(,\d+)?(\})' + scope: meta.string.ruby string.regexp.arbitrary-repetition.ruby + captures: + 1: punctuation.definition.arbitrary-repetition.ruby + 3: punctuation.definition.arbitrary-repetition.ruby + - match: '\[(?:\^?\])?' + scope: punctuation.definition.character-class.ruby + push: + - meta_scope: meta.string.ruby string.regexp.character-class.ruby + - match: '\]' + scope: punctuation.definition.character-class.ruby + pop: true + - include: escaped-char + - match: \( + scope: punctuation.definition.group.ruby + push: + - meta_scope: meta.string.ruby string.regexp.group.ruby + - match: \) + scope: punctuation.definition.group.ruby + pop: true + - include: regex-sub + # We are restrictive in what we allow to go after the comment character to + # avoid false positives, since the availability of comments depend on regexp + # flags. + - match: '(?:^|\s)(#)\s[[a-zA-Z0-9,. \t?!-][^\x{00}-\x{7F}]]*$' + scope: comment.line.number-sign.ruby + captures: + 1: punctuation.definition.comment.ruby + + nest-brackets-r: + - match: '\[' + scope: punctuation.section.scope.ruby + push: + - match: '\]' + scope: punctuation.section.scope.ruby + pop: true + - include: regex-sub + - include: nest-brackets-r + nest-curly-r: + - match: '\{' + scope: punctuation.section.scope.ruby + push: + - match: '\}' + scope: punctuation.section.scope.ruby + pop: true + - include: regex-sub + - include: nest-curly-r + nest-ltgt-r: + - match: \< + scope: punctuation.section.scope.ruby + push: + - match: \> + scope: punctuation.section.scope.ruby + pop: true + - include: regex-sub + - include: nest-ltgt-r + nest-parens-r: + - match: \( + scope: punctuation.section.scope.ruby + push: + - match: \) + scope: punctuation.section.scope.ruby + pop: true + - include: regex-sub + - include: nest-parens-r + + nest-brackets: + - match: '\[' + scope: punctuation.section.scope.ruby + push: + - match: '\]' + scope: punctuation.section.scope.ruby + pop: true + - include: nest-brackets + nest-curly: + - match: '\{' + scope: punctuation.section.scope.ruby + push: [nest-curly-inner, maybe-block-parameters] + nest-curly-inner: + - match: '\}' + scope: punctuation.section.scope.ruby + pop: true + - include: nest-curly + nest-ltgt: + - match: \< + scope: punctuation.section.scope.ruby + push: + - match: \> + scope: punctuation.section.scope.ruby + pop: true + - include: nest-ltgt + nest-parens: + - match: \( + scope: punctuation.section.scope.ruby + push: + - match: \) + scope: punctuation.section.scope.ruby + pop: true + - include: nest-parens + + string-placeholder: + # %[flags][width][.precision]type + # + # A format sequence consists of a percent sign, followed by optional + # flags, width, and precision indicators, then terminated with a field + # type character. + # + # Also this is used for time format in strftime. + - match: |- + (?x)% + ([#0\- +\*]|(\d+\$))* # flags + (-?\d+)? # minimum field width + (\.(\d+)?)? # precision + [diouxXDOUeEfFgGaAcCsSpnvtTbByYhHmMzZ%] # conversion type + scope: constant.other.placeholder.ruby + + escaped-char: + # SEE: https://ruby-doc.org/core-2.6.3/doc/syntax/literals_rdoc.html + # meta control sequence + - match: (?:\\(?:[MC]-|c)){1,2}[[:ascii:]] + scope: constant.character.escape.ruby + # extended unicode character + - match: \\u\{ + push: + - meta_scope: constant.character.escape.ruby + - match: \} + pop: true + - match: \h{0,6} + - match: \S + scope: invalid.illegal.escape.ruby + # octal, hex, unicode, normal escaped character + - match: \\(?:[0-7]{1,3}|x\h{1,2}|u\h{4}|.) + scope: constant.character.escape.ruby + + interpolated-ruby: + - match: '#\{' + scope: punctuation.section.interpolation.begin.ruby + push: + - clear_scopes: 1 # remove `string`/`constant` + - meta_scope: meta.interpolation.ruby + - meta_content_scope: source.ruby.embedded.ruby + - include: interpolated-ruby-expressions + - match: '(?=#[@$])' + push: + - clear_scopes: 1 # remove `string`/`constant` + - meta_scope: meta.interpolation.ruby + - include: interpolated-ruby-variables + + interpolated-heredoc-ruby: + - match: '#\{' + scope: punctuation.section.interpolation.begin.ruby + push: + - meta_scope: meta.interpolation.ruby + - meta_content_scope: source.ruby.embedded.ruby + - include: interpolated-ruby-expressions + - match: '(?=#[@$])' + push: + - meta_scope: meta.interpolation.ruby + - include: interpolated-ruby-variables + + interpolated-ruby-expressions: + - match: '\}' + scope: punctuation.section.interpolation.end.ruby + pop: true + - include: nest-curly-expressions + - include: expressions + + interpolated-ruby-variables: + - match: '(#@)[[:alpha:]_]\w*' + scope: variable.other.readwrite.instance.ruby + captures: + 1: punctuation.definition.variable.ruby + pop: true + - match: '(#@@)[[:alpha:]_]\w*' + scope: variable.other.readwrite.class.ruby + captures: + 1: punctuation.definition.variable.ruby + pop: true + - match: '(#\$)[[:alpha:]_]\w*' + scope: variable.other.readwrite.global.ruby + captures: + 1: punctuation.definition.variable.ruby + pop: true + - match: '' + pop: true + + nest-curly-expressions: + - match: '\{' + scope: punctuation.section.scope.ruby + push: [nest-curly-expressions-inner, maybe-block-parameters] + nest-curly-expressions-inner: + - match: '\}' + scope: punctuation.section.scope.ruby + pop: true + - include: nest-curly-expressions + - include: expressions + + nest-all: + - match: '\(' + scope: punctuation.definition.group.begin.ruby + push: + - match: '\)' + scope: punctuation.definition.group.end.ruby + pop: true + - include: nest-all + - include: expressions + - match: '\{' + scope: punctuation.section.scope.ruby + push: [nest-all-inner, maybe-block-parameters] + - match: '\[' + scope: punctuation.section.array.ruby + push: + - match: '\]' + scope: punctuation.section.array.ruby + pop: true + - include: nest-all + - include: expressions + nest-all-inner: + - match: '\}' + scope: punctuation.section.scope.ruby + pop: true + - include: nest-all + - include: expressions + + nest-brackets-i: + - match: '\[' + scope: punctuation.section.scope.ruby + push: + - match: '\]' + scope: punctuation.section.scope.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-brackets-i + nest-curly-i: + - match: '\{' + scope: punctuation.section.scope.ruby + push: [nest-curly-i-inner, maybe-block-parameters] + nest-curly-i-inner: + - match: '\}' + scope: punctuation.section.scope.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-curly-i + nest-ltgt-i: + - match: \< + scope: punctuation.section.scope.ruby + push: + - match: \> + scope: punctuation.section.scope.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-ltgt-i + nest-parens-i: + - match: \( + scope: punctuation.section.scope.ruby + push: + - match: \) + scope: punctuation.section.scope.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-parens-i + +###[ HEREDOCS ]################################################################ + + heredocs: + # SEE: https://ruby-doc.org/core-2.5.0/doc/syntax/literals_rdoc.html + - include: heredoc-css + - include: heredoc-js + - include: heredoc-html + - include: heredoc-ruby + - include: heredoc-shell + - include: heredoc-sql + - include: heredoc-plain + + heredoc-css: + - match: (<<[-~])(["`]?)({{heredoc_type_css}})(["`]?) + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-css-indented-interpolated, trailing-heredoc-start] + - match: (<<[-~])(')({{heredoc_type_css}})(') + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-css-indented-literal, trailing-heredoc-start] + - match: (<<)(["`]?)({{heredoc_type_css}})(["`]?) + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-css-unindented-interpolated, trailing-heredoc-start] + - match: (<<)(')({{heredoc_type_css}})(') + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-css-unindented-literal, trailing-heredoc-start] + + heredoc-css-indented-interpolated: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: source.css.embedded.ruby + - include: indented-heredoc-end + - include: interpolated-heredoc-ruby + - include: scope:source.css + - include: escaped-char + + heredoc-css-indented-literal: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: source.css.embedded.ruby + - include: indented-heredoc-end + - include: scope:source.css + + heredoc-css-unindented-interpolated: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: source.css.embedded.ruby + - include: unindented-heredoc-end + - include: scope:source.css + - include: escaped-char + + heredoc-css-unindented-literal: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: source.css.embedded.ruby + - include: unindented-heredoc-end + - include: scope:source.css + + heredoc-js: + - match: (<<[-~])(["`]?)({{heredoc_type_js}})(["`]?) + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-js-indented-interpolated, trailing-heredoc-start] + - match: (<<[-~])(')({{heredoc_type_js}})(') + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-js-indented-literal, trailing-heredoc-start] + - match: (<<)(["`]?)({{heredoc_type_js}})(["`]?) + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-js-unindented-interpolated, trailing-heredoc-start] + - match: (<<)(')({{heredoc_type_js}})(') + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-js-unindented-literal, trailing-heredoc-start] + + heredoc-js-indented-interpolated: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: source.js.embedded.ruby + - include: indented-heredoc-end + - include: interpolated-heredoc-ruby + - include: scope:source.js + - include: escaped-char + + heredoc-js-indented-literal: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: source.js.embedded.ruby + - include: indented-heredoc-end + - include: scope:source.js + + heredoc-js-unindented-interpolated: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: source.js.embedded.ruby + - include: unindented-heredoc-end + - include: scope:source.js + - include: escaped-char + + heredoc-js-unindented-literal: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: source.js.embedded.ruby + - include: unindented-heredoc-end + - include: scope:source.js + + heredoc-html: + - match: (<<[-~])(["`]?)({{heredoc_type_html}})(["`]?) + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-html-indented-interpolated, trailing-heredoc-start] + - match: (<<[-~])(')({{heredoc_type_html}})(') + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-html-indented-literal, trailing-heredoc-start] + - match: (<<)(["`]?)({{heredoc_type_html}})(["`]?) + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-html-unindented-interpolated, trailing-heredoc-start] + - match: (<<)(')({{heredoc_type_html}})(') + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-html-unindented-literal, trailing-heredoc-start] + + heredoc-html-indented-interpolated: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: text.html.embedded.ruby + - include: indented-heredoc-end + - include: interpolated-heredoc-ruby + - include: scope:text.html.basic + - include: escaped-char + + heredoc-html-indented-literal: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: text.html.embedded.ruby + - include: indented-heredoc-end + - include: scope:text.html.basic + + heredoc-html-unindented-interpolated: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: text.html.embedded.ruby + - include: unindented-heredoc-end + - include: scope:text.html.basic + - include: escaped-char + + heredoc-html-unindented-literal: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: text.html.embedded.ruby + - include: unindented-heredoc-end + - include: scope:text.html.basic + + heredoc-ruby: + - match: (<<[-~])(["`]?)({{heredoc_type_ruby}})(["`]?) + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-ruby-indented-interpolated, trailing-heredoc-start] + - match: (<<[-~])(')({{heredoc_type_ruby}})(') + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-ruby-indented-literal, trailing-heredoc-start] + - match: (<<)(["`]?)({{heredoc_type_ruby}})(["`]?) + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-ruby-unindented-interpolated, trailing-heredoc-start] + - match: (<<)(')({{heredoc_type_ruby}})(') + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-ruby-unindented-literal, trailing-heredoc-start] + + heredoc-ruby-indented-interpolated: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: source.ruby.embedded.ruby + - include: indented-heredoc-end + - include: interpolated-heredoc-ruby + - include: escaped-char + - include: expressions + + heredoc-ruby-indented-literal: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: source.ruby.embedded.ruby + - include: indented-heredoc-end + - include: expressions + + heredoc-ruby-unindented-interpolated: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: source.ruby.embedded.ruby + - include: unindented-heredoc-end + - include: interpolated-heredoc-ruby + - include: escaped-char + - include: expressions + + heredoc-ruby-unindented-literal: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: source.ruby.embedded.ruby + - include: unindented-heredoc-end + - include: expressions + + heredoc-plain: + - match: (<<[-~])(["`]?)(\w+)(["`]?) + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-plain-indented-interpolated, trailing-heredoc-start] + - match: (<<[-~])(')(\w+)(') + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-plain-indented-literal, trailing-heredoc-start] + - match: (<<)(["`]?)(\w+)(["`]?) + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-plain-unindented-interpolated, trailing-heredoc-start] + - match: (<<)(')(\w+)(') + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-plain-unindented-literal, trailing-heredoc-start] + + heredoc-plain-indented-interpolated: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: string.unquoted.heredoc.ruby + - include: indented-heredoc-end + - include: interpolated-ruby + - include: escaped-char + + heredoc-plain-indented-literal: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: string.unquoted.heredoc.ruby + - include: indented-heredoc-end + + heredoc-plain-unindented-interpolated: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: string.unquoted.heredoc.ruby + - include: unindented-heredoc-end + - include: interpolated-ruby + - include: escaped-char + + heredoc-plain-unindented-literal: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: string.unquoted.heredoc.ruby + - include: unindented-heredoc-end + + heredoc-shell: + - match: (<<[-~])(["`]?)({{heredoc_type_shell}})(["`]?) + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-shell-indented-interpolated, trailing-heredoc-start] + - match: (<<[-~])(')({{heredoc_type_shell}})(') + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-shell-indented-literal, trailing-heredoc-start] + - match: (<<)(["`]?)({{heredoc_type_shell}})(["`]?) + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-shell-unindented-interpolated, trailing-heredoc-start] + - match: (<<)(')({{heredoc_type_shell}})(') + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-shell-unindented-literal, trailing-heredoc-start] + + heredoc-shell-indented-interpolated: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: source.shell.embedded.ruby + - include: indented-heredoc-end + - include: interpolated-heredoc-ruby + - include: scope:source.shell + - include: escaped-char + + heredoc-shell-indented-literal: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: source.shell.embedded.ruby + - include: indented-heredoc-end + - include: scope:source.shell + + heredoc-shell-unindented-interpolated: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: source.shell.embedded.ruby + - include: unindented-heredoc-end + - include: scope:source.shell + - include: escaped-char + + heredoc-shell-unindented-literal: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: source.shell.embedded.ruby + - include: unindented-heredoc-end + - include: scope:source.shell + + heredoc-sql: + - match: (<<[-~])(["`]?)({{heredoc_type_sql}})(["`]?) + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-sql-indented-interpolated, trailing-heredoc-start] + - match: (<<[-~])(')({{heredoc_type_sql}})(') + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-sql-indented-literal, trailing-heredoc-start] + - match: (<<)(["`]?)({{heredoc_type_sql}})(["`]?) + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-sql-unindented-interpolated, trailing-heredoc-start] + - match: (<<)(')({{heredoc_type_sql}})(') + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-sql-unindented-literal, trailing-heredoc-start] + + heredoc-sql-indented-interpolated: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: source.sql.embedded.ruby + - include: indented-heredoc-end + - include: interpolated-heredoc-ruby + - include: scope:source.sql + - include: escaped-char + + heredoc-sql-indented-literal: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: source.sql.embedded.ruby + - include: indented-heredoc-end + - include: scope:source.sql + + heredoc-sql-unindented-interpolated: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: source.sql.embedded.ruby + - include: unindented-heredoc-end + - include: scope:source.sql + - include: escaped-char + + heredoc-sql-unindented-literal: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: source.sql.embedded.ruby + - include: unindented-heredoc-end + - include: scope:source.sql + + indented-heredoc-end: + - match: ^\s*(\3)$ # HEREDOC delimiter + scope: meta.tag.heredoc.ruby + captures: + 1: entity.name.tag.ruby + pop: true + + unindented-heredoc-end: + - match: ^\3$ # HEREDOC delimiter + scope: meta.tag.heredoc.ruby entity.name.tag.ruby + pop: true + + trailing-heredoc-start: + # This prevents clear_scopes from applying to the push token + - match: '' + set: trailing-heredoc + + trailing-heredoc: + # The rest of the line right after the heredoc tag needs to be handled + # as ordinary ruby source. The embedded syntax starts at the next line. + - clear_scopes: 2 + - match: ^ + pop: true + - include: expressions + +###[ DATA SECTION ]############################################################ + + data-section: + - match: ^__END__\n + scope: meta.string.ruby string.unquoted.program-block.ruby + push: + - meta_content_scope: text.plain + - match: (?=<?xml|<(?i:html\b)|!DOCTYPE (?i:html\b)) + push: + - meta_scope: text.html.embedded.ruby + - include: scope:text.html.basic diff --git a/syntaxes/Ruby/Snippets/#!;usr;local;bin;ruby-w.sublime-snippet b/syntaxes/Ruby/Snippets/#!;usr;local;bin;ruby-w.sublime-snippet @@ -0,0 +1,7 @@ +<snippet> + <content><![CDATA[#!/usr/bin/env ruby${TM_RUBY_SWITCHES: -wKU} +]]></content> + <tabTrigger>rb</tabTrigger> + <scope>source.ruby</scope> + <description>#!/usr/bin/env ruby -wKU</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/060-ruby-if-else.sublime-snippet b/syntaxes/Ruby/Snippets/060-ruby-if-else.sublime-snippet @@ -0,0 +1,10 @@ +<snippet> + <content><![CDATA[if ${1:condition} + $2 +else + $3 +end]]></content> + <tabTrigger>ife</tabTrigger> + <scope>source.ruby</scope> + <description>if … else … end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/070-ruby-if.sublime-snippet b/syntaxes/Ruby/Snippets/070-ruby-if.sublime-snippet @@ -0,0 +1,8 @@ +<snippet> + <content><![CDATA[if ${1:condition} + $0 +end]]></content> + <tabTrigger>if</tabTrigger> + <scope>source.ruby</scope> + <description>if … end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/080-ruby-case.sublime-snippet b/syntaxes/Ruby/Snippets/080-ruby-case.sublime-snippet @@ -0,0 +1,9 @@ +<snippet> + <content><![CDATA[case ${1:object} +when ${2:condition} + $0 +end]]></content> + <tabTrigger>case</tabTrigger> + <scope>source.ruby</scope> + <description>case … end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/Add-'#-=-'-Marker.sublime-snippet b/syntaxes/Ruby/Snippets/Add-'#-=-'-Marker.sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[# => ]]></content> + <tabTrigger>#</tabTrigger> + <scope>source.ruby</scope> + <description>Add ‘# =&gt;’ Marker</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/Array.new(10)-{-i-..-}-(Arr).sublime-snippet b/syntaxes/Ruby/Snippets/Array.new(10)-{-i-..-}-(Arr).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[Array.new(${1:10}) { ${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}${2:i}${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}$0 }]]></content> + <tabTrigger>Array</tabTrigger> + <scope>source.ruby</scope> + <description>Array.new(10) { |i| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/Benchmark_bmbm(__)-do-__-end.sublime-snippet b/syntaxes/Ruby/Snippets/Benchmark_bmbm(__)-do-__-end.sublime-snippet @@ -0,0 +1,9 @@ +<snippet> + <content><![CDATA[TESTS = ${1:10_000} +Benchmark.bmbm do |results| + $0 +end]]></content> + <tabTrigger>bm-</tabTrigger> + <scope>source.ruby</scope> + <description>Benchmark.bmbm do .. end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/Dir.glob(-..-)-do-file-..-end-(Dir).sublime-snippet b/syntaxes/Ruby/Snippets/Dir.glob(-..-)-do-file-..-end-(Dir).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[Dir.glob(${1:"${2:dir/glob/*}"}) { |${3:file}| $0 }]]></content> + <tabTrigger>Dir</tabTrigger> + <scope>source.ruby</scope> + <description>Dir.glob("..") { |file| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/Dir[-__-].sublime-snippet b/syntaxes/Ruby/Snippets/Dir[-__-].sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[Dir[${1:"${2:glob/**/*.rb}"}]]]></content> + <tabTrigger>Dir</tabTrigger> + <scope>source.ruby</scope> + <description>Dir[".."]</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/File.foreach-(-..-)-do-line-..-end-(File).sublime-snippet b/syntaxes/Ruby/Snippets/File.foreach-(-..-)-do-line-..-end-(File).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[File.foreach(${1:"${2:path/to/file}"}) { |${3:line}| $0 }]]></content> + <tabTrigger>File</tabTrigger> + <scope>source.ruby</scope> + <description>File.foreach ("..") { |line| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/File_open(-__-)-{-file-__-}.sublime-snippet b/syntaxes/Ruby/Snippets/File_open(-__-)-{-file-__-}.sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[File.open(${1:"${2:path/to/file}"}${3/(^[rwab+]+$)|.*/(?1:, ")/}${3:w}${3/(^[rwab+]+$)|.*/(?1:")/}) { |${4:file}| $0 }]]></content> + <tabTrigger>File</tabTrigger> + <scope>source.ruby</scope> + <description>File.open("..") { |file| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/File_read(-__-).sublime-snippet b/syntaxes/Ruby/Snippets/File_read(-__-).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[File.read(${1:"${2:path/to/file}"})]]></content> + <tabTrigger>File</tabTrigger> + <scope>source.ruby</scope> + <description>File.read("..")</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/Hash.new-{-hash-key-hash[key]-=-..-}-(Has).sublime-snippet b/syntaxes/Ruby/Snippets/Hash.new-{-hash-key-hash[key]-=-..-}-(Has).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[Hash.new { |${1:hash}, ${2:key}| ${1:hash}[${2:key}] = $0 }]]></content> + <tabTrigger>Hash</tabTrigger> + <scope>source.ruby</scope> + <description>Hash.new { |hash, key| hash[key] = .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/Marshal.dump(obj-file)-(Md).sublime-snippet b/syntaxes/Ruby/Snippets/Marshal.dump(obj-file)-(Md).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[File.open(${1:"${2:path/to/file}.dump"}, "wb") { |${3:file}| Marshal.dump(${4:obj}, ${3:file}) }]]></content> + <tabTrigger>Md</tabTrigger> + <scope>source.ruby</scope> + <description>Marshal.dump(.., file)</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/Marshal.load(obj)-(Ml).sublime-snippet b/syntaxes/Ruby/Snippets/Marshal.load(obj)-(Ml).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[File.open(${1:"${2:path/to/file}.dump"}, "rb") { |${3:file}| Marshal.load(${3:file}) }]]></content> + <tabTrigger>Ml</tabTrigger> + <scope>source.ruby</scope> + <description>Marshal.load(obj)</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/PStore_new(-__-).sublime-snippet b/syntaxes/Ruby/Snippets/PStore_new(-__-).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[PStore.new(${1:"${2:file_name.pstore}"})]]></content> + <tabTrigger>Pn-</tabTrigger> + <scope>source.ruby</scope> + <description>PStore.new( .. )</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/RDoc-documentation-block.sublime-snippet b/syntaxes/Ruby/Snippets/RDoc-documentation-block.sublime-snippet @@ -0,0 +1,8 @@ +<snippet> + <content><![CDATA[`[[ $TM_LINE_INDEX != 0 ]] && echo; echo`=begin rdoc + $0 +=end]]></content> + <tabTrigger>=b</tabTrigger> + <scope>source.ruby</scope> + <description>New Block</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/Wrap-in-Begin-Rescue-End.sublime-snippet b/syntaxes/Ruby/Snippets/Wrap-in-Begin-Rescue-End.sublime-snippet @@ -0,0 +1,11 @@ +<snippet> + <content><![CDATA[${TM_SELECTED_TEXT/([\t ]*).*/$1/m}begin + ${3:${TM_SELECTED_TEXT/(\A.*)|(.+)|\n\z/(?1:$0:(?2:\t$0))/g}} +${TM_SELECTED_TEXT/([\t ]*).*/$1/m}rescue ${1:StandardError}${2/.+/ => /}${2:e} +${TM_SELECTED_TEXT/([\t ]*).*/$1/m} $0 +${TM_SELECTED_TEXT/([\t ]*).*/$1/m}end +]]></content> + <tabTrigger>begin</tabTrigger> + <scope>source.ruby - comment</scope> + <description>begin … rescue … end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/YAML.dump(..-file)-(Yd-).sublime-snippet b/syntaxes/Ruby/Snippets/YAML.dump(..-file)-(Yd-).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[File.open(${1:"${2:path/to/file}.yaml"}, "w") { |${3:file}| YAML.dump(${4:obj}, ${3:file}) }]]></content> + <tabTrigger>Yd-</tabTrigger> + <scope>source.ruby</scope> + <description>YAML.dump(.., file)</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/YAML.load(file)-(Yl-).sublime-snippet b/syntaxes/Ruby/Snippets/YAML.load(file)-(Yl-).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[File.open(${1:"${2:path/to/file}.yaml"}) { |${3:file}| YAML.load(${3:file}) }]]></content> + <tabTrigger>Yl-</tabTrigger> + <scope>source.ruby</scope> + <description>YAML.load(file)</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/alias_method-..-(am).sublime-snippet b/syntaxes/Ruby/Snippets/alias_method-..-(am).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[alias_method :${1:new_name}, :${0:old_name}]]></content> + <tabTrigger>am</tabTrigger> + <scope>source.ruby</scope> + <description>alias_method ..</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/all-{-e-..-}-(all).sublime-snippet b/syntaxes/Ruby/Snippets/all-{-e-..-}-(all).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[all? { |${1:e}| $0 }]]></content> + <tabTrigger>all</tabTrigger> + <scope>source.ruby</scope> + <description>all? { |e| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/any-{-e-..-}-(any).sublime-snippet b/syntaxes/Ruby/Snippets/any-{-e-..-}-(any).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[any? { |${1:e}| $0 }]]></content> + <tabTrigger>any</tabTrigger> + <scope>source.ruby</scope> + <description>any? { |e| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/application_code-..-(app).sublime-snippet b/syntaxes/Ruby/Snippets/application_code-..-(app).sublime-snippet @@ -0,0 +1,8 @@ +<snippet> + <content><![CDATA[if __FILE__ == \$PROGRAM_NAME + $0 +end]]></content> + <tabTrigger>app</tabTrigger> + <scope>source.ruby</scope> + <description>application { .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/assert(..)-(as).sublime-snippet b/syntaxes/Ruby/Snippets/assert(..)-(as).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[assert(${1:test}, "${0:Failure message.}")]]></content> + <tabTrigger>as</tabTrigger> + <scope>source.ruby</scope> + <description>assert(..)</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/assert_equal.sublime-snippet b/syntaxes/Ruby/Snippets/assert_equal.sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[assert_equal(${1:expected}, ${0:actual})]]></content> + <tabTrigger>ase</tabTrigger> + <scope>source.ruby</scope> + <description>assert_equal(..)</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/assert_in_delta(..)-(asid).sublime-snippet b/syntaxes/Ruby/Snippets/assert_in_delta(..)-(asid).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[assert_in_delta(${1:expected_float}, ${2:actual_float}, ${0:2 ** -20})]]></content> + <tabTrigger>asid</tabTrigger> + <scope>source.ruby</scope> + <description>assert_in_delta(..)</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/assert_instance_of(..)-(asio).sublime-snippet b/syntaxes/Ruby/Snippets/assert_instance_of(..)-(asio).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[assert_instance_of(${1:ExpectedClass}, ${0:actual_instance})]]></content> + <tabTrigger>asio</tabTrigger> + <scope>source.ruby</scope> + <description>assert_instance_of(..)</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/assert_kind_of(..)-(asko).sublime-snippet b/syntaxes/Ruby/Snippets/assert_kind_of(..)-(asko).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[assert_kind_of(${1:ExpectedKind}, ${0:actual_instance})]]></content> + <tabTrigger>asko</tabTrigger> + <scope>source.ruby</scope> + <description>assert_kind_of(..)</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/assert_match(..)-(asm).sublime-snippet b/syntaxes/Ruby/Snippets/assert_match(..)-(asm).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[assert_match(/${1:expected_pattern}/, ${0:actual_string})]]></content> + <tabTrigger>asm</tabTrigger> + <scope>source.ruby</scope> + <description>assert_match(..)</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/assert_nil(..)-(asn).sublime-snippet b/syntaxes/Ruby/Snippets/assert_nil(..)-(asn).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[assert_nil(${0:instance})]]></content> + <tabTrigger>asn</tabTrigger> + <scope>source.ruby</scope> + <description>assert_nil(..)</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/assert_no_match(..)-(asnm).sublime-snippet b/syntaxes/Ruby/Snippets/assert_no_match(..)-(asnm).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[assert_no_match(/${1:unexpected_pattern}/, ${0:actual_string})]]></content> + <tabTrigger>asnm</tabTrigger> + <scope>source.ruby</scope> + <description>assert_no_match(..)</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/assert_not_equal(..)-(asne).sublime-snippet b/syntaxes/Ruby/Snippets/assert_not_equal(..)-(asne).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[assert_not_equal(${1:unexpected}, ${0:actual})]]></content> + <tabTrigger>asne</tabTrigger> + <scope>source.ruby</scope> + <description>assert_not_equal(..)</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/assert_not_nil(..)-(asnn).sublime-snippet b/syntaxes/Ruby/Snippets/assert_not_nil(..)-(asnn).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[assert_not_nil(${0:instance})]]></content> + <tabTrigger>asnn</tabTrigger> + <scope>source.ruby</scope> + <description>assert_not_nil(..)</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/assert_not_same(..)-(asns).sublime-snippet b/syntaxes/Ruby/Snippets/assert_not_same(..)-(asns).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[assert_not_same(${1:unexpected}, ${0:actual})]]></content> + <tabTrigger>asns</tabTrigger> + <scope>source.ruby</scope> + <description>assert_not_same(..)</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/assert_nothing_raised(..)-{-..-}-(asnr).sublime-snippet b/syntaxes/Ruby/Snippets/assert_nothing_raised(..)-{-..-}-(asnr).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[assert_nothing_raised(${1:Exception}) { $0 }]]></content> + <tabTrigger>asnr</tabTrigger> + <scope>source.ruby</scope> + <description>assert_nothing_raised(..) { .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/assert_nothing_thrown-{-..-}-(asnt).sublime-snippet b/syntaxes/Ruby/Snippets/assert_nothing_thrown-{-..-}-(asnt).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[assert_nothing_thrown { $0 }]]></content> + <tabTrigger>asnt</tabTrigger> + <scope>source.ruby</scope> + <description>assert_nothing_thrown { .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/assert_operator(..)-(aso).sublime-snippet b/syntaxes/Ruby/Snippets/assert_operator(..)-(aso).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[assert_operator(${1:left}, :${2:operator}, ${0:right})]]></content> + <tabTrigger>aso</tabTrigger> + <scope>source.ruby</scope> + <description>assert_operator(..)</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/assert_raise(..)-{-..-}-(asr).sublime-snippet b/syntaxes/Ruby/Snippets/assert_raise(..)-{-..-}-(asr).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[assert_raise(${1:Exception}) { $0 }]]></content> + <tabTrigger>asr</tabTrigger> + <scope>source.ruby</scope> + <description>assert_raise(..) { .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/assert_respond_to(..)-(asrt).sublime-snippet b/syntaxes/Ruby/Snippets/assert_respond_to(..)-(asrt).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[assert_respond_to(${1:object}, :${0:method})]]></content> + <tabTrigger>asrt</tabTrigger> + <scope>source.ruby</scope> + <description>assert_respond_to(..)</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/assert_same(..)-(ass).sublime-snippet b/syntaxes/Ruby/Snippets/assert_same(..)-(ass).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[assert_same(${1:expected}, ${0:actual})]]></content> + <tabTrigger>ass</tabTrigger> + <scope>source.ruby</scope> + <description>assert_same(..)</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/assert_send(..)-(ass).sublime-snippet b/syntaxes/Ruby/Snippets/assert_send(..)-(ass).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[assert_send([${1:object}, :${2:message}, ${0:args}])]]></content> + <tabTrigger>ass</tabTrigger> + <scope>source.ruby</scope> + <description>assert_send(..)</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/assert_throws(..)-{-..-}-(ast).sublime-snippet b/syntaxes/Ruby/Snippets/assert_throws(..)-{-..-}-(ast).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[assert_throws(:${1:expected}) { $0 }]]></content> + <tabTrigger>ast</tabTrigger> + <scope>source.ruby</scope> + <description>assert_throws(..) { .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/attr_accessor-..-(rw).sublime-snippet b/syntaxes/Ruby/Snippets/attr_accessor-..-(rw).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[attr_accessor :${0:attr_names}]]></content> + <tabTrigger>rw</tabTrigger> + <scope>source.ruby</scope> + <description>attr_accessor ..</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/attr_reader-..-(r).sublime-snippet b/syntaxes/Ruby/Snippets/attr_reader-..-(r).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[attr_reader :${0:attr_names}]]></content> + <tabTrigger>r</tabTrigger> + <scope>source.ruby</scope> + <description>attr_reader ..</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/attr_writer-..-(w).sublime-snippet b/syntaxes/Ruby/Snippets/attr_writer-..-(w).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[attr_writer :${0:attr_names}]]></content> + <tabTrigger>w</tabTrigger> + <scope>source.ruby</scope> + <description>attr_writer ..</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/class-..-DelegateClass-..-initialize-..-end-(class).sublime-snippet b/syntaxes/Ruby/Snippets/class-..-DelegateClass-..-initialize-..-end-(class).sublime-snippet @@ -0,0 +1,14 @@ +<snippet> + <content><![CDATA[class ${1:${TM_FILENAME/(?:\A|_)([A-Za-z0-9]+)(?:\.rb)?/(?2::\u$1)/g}} < DelegateClass(${2:ParentClass}) + def initialize${3/(^.*?\S.*)|.*/(?1:\()/}${3:args}${3/(^.*?\S.*)|.*/(?1:\))/} + super(${4:del_obj}) + + $0 + end + + +end]]></content> + <tabTrigger>cla-</tabTrigger> + <scope>source.ruby</scope> + <description>class .. &lt; DelegateClass .. initialize .. end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/class-..-ParentClass-..-initialize-..-end.sublime-snippet b/syntaxes/Ruby/Snippets/class-..-ParentClass-..-initialize-..-end.sublime-snippet @@ -0,0 +1,12 @@ +<snippet> + <content><![CDATA[class ${1:${TM_FILENAME/(?:\A|_)([A-Za-z0-9]+)(?:\.rb)?/(?2::\u$1)/g}} < ${2:ParentClass} + def initialize${3/(^.*?\S.*)|.*/(?1:\()/}${3:args}${3/(^.*?\S.*)|.*/(?1:\))/} + $0 + end + + +end]]></content> + <tabTrigger>cla</tabTrigger> + <scope>source.ruby</scope> + <description>class .. &lt; ParentClass .. initialize .. end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/class-..-Struct-..-initialize-..-end.sublime-snippet b/syntaxes/Ruby/Snippets/class-..-Struct-..-initialize-..-end.sublime-snippet @@ -0,0 +1,12 @@ +<snippet> + <content><![CDATA[${1:${TM_FILENAME/(?:\A|_)([A-Za-z0-9]+)(?:\.rb)?/(?2::\u$1)/g}} = Struct.new(:${2:attr_names}) do + def ${3:method_name} + $0 + end + + +end]]></content> + <tabTrigger>cla</tabTrigger> + <scope>source.ruby</scope> + <description>ClassName = Struct .. do .. end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/class-..-Test;;Unit;;TestCase-..-end-(tc).sublime-snippet b/syntaxes/Ruby/Snippets/class-..-Test;;Unit;;TestCase-..-end-(tc).sublime-snippet @@ -0,0 +1,14 @@ +<snippet> + <content><![CDATA[require "test/unit" + +require "${1:library_file_name}" + +class Test${2:${1/([\w&&[^_]]+)|./\u$1/g}} < Test::Unit::TestCase + def test_${3:case_name} + $0 + end +end]]></content> + <tabTrigger>tc</tabTrigger> + <scope>source.ruby</scope> + <description>class .. &lt; Test::Unit::TestCase .. end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/class-..-end-(cla).sublime-snippet b/syntaxes/Ruby/Snippets/class-..-end-(cla).sublime-snippet @@ -0,0 +1,8 @@ +<snippet> + <content><![CDATA[class ${1:${TM_FILENAME/(?:\A|_)([A-Za-z0-9]+)(?:\.rb)?/(?2::\u$1)/g}} + $0 +end]]></content> + <tabTrigger>cla</tabTrigger> + <scope>source.ruby</scope> + <description>class .. end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/class-..-initialize-..-end.sublime-snippet b/syntaxes/Ruby/Snippets/class-..-initialize-..-end.sublime-snippet @@ -0,0 +1,12 @@ +<snippet> + <content><![CDATA[class ${1:${TM_FILENAME/(?:\A|_)([A-Za-z0-9]+)(?:\.rb)?/(?2::\u$1)/g}} + def initialize${2/(^.*?\S.*)|.*/(?1:\()/}${2:args}${2/(^.*?\S.*)|.*/(?1:\))/} + $0 + end + + +end]]></content> + <tabTrigger>cla</tabTrigger> + <scope>source.ruby</scope> + <description>class .. initialize .. end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/class-..-instance_methods-..-undef-..-initialize-..-end-(class).sublime-snippet b/syntaxes/Ruby/Snippets/class-..-instance_methods-..-undef-..-initialize-..-end-(class).sublime-snippet @@ -0,0 +1,20 @@ +<snippet> + <content><![CDATA[class ${1:BlankSlate} + instance_methods.each { |meth| undef_method(meth) unless meth =~ /\A__/ } + + def initialize${2/(^.*?\S.*)|.*/(?1:\()/}${2:args}${2/(^.*?\S.*)|.*/(?1:\))/} + @${3:delegate} = ${4:delegate_object} + + $0 + end + + def method_missing(meth, *args, &block) + @${3:delegate}.send(meth, *args, &block) + end + + +end]]></content> + <tabTrigger>cla</tabTrigger> + <scope>source.ruby</scope> + <description>class BlankSlate .. initialize .. end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/class-self-__-end.sublime-snippet b/syntaxes/Ruby/Snippets/class-self-__-end.sublime-snippet @@ -0,0 +1,8 @@ +<snippet> + <content><![CDATA[class << ${1:self} + $0 +end]]></content> + <tabTrigger>cla</tabTrigger> + <scope>source.ruby</scope> + <description>class &lt;&lt; self .. end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/class_from_name()-(clafn).sublime-snippet b/syntaxes/Ruby/Snippets/class_from_name()-(clafn).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[split("::").inject(Object) { |par, const| par.const_get(const) }]]></content> + <tabTrigger>clafn</tabTrigger> + <scope>source.ruby</scope> + <description>class_from_name()</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/classify-{-e-..-}-(clas).sublime-snippet b/syntaxes/Ruby/Snippets/classify-{-e-..-}-(clas).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[classify { |${1:e}| $0 }]]></content> + <tabTrigger>cl</tabTrigger> + <scope>source.ruby</scope> + <description>classify { |e| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/collect-{-e-..-}-(col).sublime-snippet b/syntaxes/Ruby/Snippets/collect-{-e-..-}-(col).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[collect { |${1:e}| $0 }]]></content> + <tabTrigger>col</tabTrigger> + <scope>source.ruby</scope> + <description>collect { |e| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/deep_copy(..)-(dee).sublime-snippet b/syntaxes/Ruby/Snippets/deep_copy(..)-(dee).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[Marshal.load(Marshal.dump(${0:obj_to_copy}))]]></content> + <tabTrigger>deec</tabTrigger> + <scope>source.ruby</scope> + <description>deep_copy(..)</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/def-end.sublime-snippet b/syntaxes/Ruby/Snippets/def-end.sublime-snippet @@ -0,0 +1,8 @@ +<snippet> + <content><![CDATA[def ${1:method_name} + $0 +end]]></content> + <tabTrigger>def</tabTrigger> + <scope>source.ruby</scope> + <description>def … end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/def-method_missing-..-end-(mm).sublime-snippet b/syntaxes/Ruby/Snippets/def-method_missing-..-end-(mm).sublime-snippet @@ -0,0 +1,8 @@ +<snippet> + <content><![CDATA[def method_missing(meth, *args, &blk) + $0 +end]]></content> + <tabTrigger>defmm</tabTrigger> + <scope>source.ruby</scope> + <description>def method_missing .. end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/def-self-..-end-(defs).sublime-snippet b/syntaxes/Ruby/Snippets/def-self-..-end-(defs).sublime-snippet @@ -0,0 +1,8 @@ +<snippet> + <content><![CDATA[def self.${1:class_method_name} + $0 +end]]></content> + <tabTrigger>defs</tabTrigger> + <scope>source.ruby</scope> + <description>def self .. end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/def-test_-..-end-(t).sublime-snippet b/syntaxes/Ruby/Snippets/def-test_-..-end-(t).sublime-snippet @@ -0,0 +1,8 @@ +<snippet> + <content><![CDATA[def test_${1:case_name} + $0 +end]]></content> + <tabTrigger>deft</tabTrigger> + <scope>source.ruby</scope> + <description>def test_ .. end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/def_delegator-..-(defd).sublime-snippet b/syntaxes/Ruby/Snippets/def_delegator-..-(defd).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[def_delegator :${1:@del_obj}, :${2:del_meth}, :${3:new_name}]]></content> + <tabTrigger>defd</tabTrigger> + <scope>source.ruby</scope> + <description>def_delegator ..</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/def_delegators-..-(defds).sublime-snippet b/syntaxes/Ruby/Snippets/def_delegators-..-(defds).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[def_delegators :${1:@del_obj}, :${0:del_methods}]]></content> + <tabTrigger>defds</tabTrigger> + <scope>source.ruby</scope> + <description>def_delegators ..</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/def_initialize.sublime-snippet b/syntaxes/Ruby/Snippets/def_initialize.sublime-snippet @@ -0,0 +1,11 @@ +<snippet> + <content><![CDATA[ +def initialize(${1:options}) + @${1/,\s*/, @/g} = $1 +end +]]> + </content> + <tabTrigger>defi</tabTrigger> + <scope>source.ruby</scope> + <description>def initialize ..</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/delete_if-{-e-..-}-(deli).sublime-snippet b/syntaxes/Ruby/Snippets/delete_if-{-e-..-}-(deli).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[delete_if { |${1:e}| $0 }]]></content> + <tabTrigger>deli</tabTrigger> + <scope>source.ruby</scope> + <description>delete_if { |e| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/detect-{-e-..-}-(det).sublime-snippet b/syntaxes/Ruby/Snippets/detect-{-e-..-}-(det).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[detect { |${1:e}| $0 }]]></content> + <tabTrigger>det</tabTrigger> + <scope>source.ruby</scope> + <description>detect { |e| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/directory().sublime-snippet b/syntaxes/Ruby/Snippets/directory().sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[File.dirname(__FILE__)]]></content> + <tabTrigger>dir</tabTrigger> + <scope>source.ruby</scope> + <description>directory()</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/do-obj-..-end-(doo).sublime-snippet b/syntaxes/Ruby/Snippets/do-obj-..-end-(doo).sublime-snippet @@ -0,0 +1,8 @@ +<snippet> + <content><![CDATA[do${1/(^.+$)|^$/(?1: |)/}${1:variable}${1/(^.+$)|^$/(?1:|)/} + $0 +end]]></content> + <tabTrigger>dob</tabTrigger> + <scope>source.ruby</scope> + <description>Insert do |variable| … end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/downto(0)-{-n-..-}-(dow).sublime-snippet b/syntaxes/Ruby/Snippets/downto(0)-{-n-..-}-(dow).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[downto(${1:0}) { ${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}${2:n}${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}$0 }]]></content> + <tabTrigger>dow</tabTrigger> + <scope>source.ruby</scope> + <description>downto(0) { |n| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/each-{-e-..-}-(ea).sublime-snippet b/syntaxes/Ruby/Snippets/each-{-e-..-}-(ea).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[each { |${1:e}| $0 }]]></content> + <tabTrigger>ea</tabTrigger> + <scope>source.ruby</scope> + <description>each { |e| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/each_byte-{-byte-..-}-(eab).sublime-snippet b/syntaxes/Ruby/Snippets/each_byte-{-byte-..-}-(eab).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[each_byte { |${1:byte}| $0 }]]></content> + <tabTrigger>eab</tabTrigger> + <scope>source.ruby</scope> + <description>each_byte { |byte| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/each_char-{-chr-..-}-(eac-).sublime-snippet b/syntaxes/Ruby/Snippets/each_char-{-chr-..-}-(eac-).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[each_char { |${1:chr}| $0 }]]></content> + <tabTrigger>eac-</tabTrigger> + <scope>source.ruby</scope> + <description>each_char { |chr| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/each_cons(..)-{-group-..-}-(eac-).sublime-snippet b/syntaxes/Ruby/Snippets/each_cons(..)-{-group-..-}-(eac-).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[each_cons(${1:2}) { |${2:group}| $0 }]]></content> + <tabTrigger>eac-</tabTrigger> + <scope>source.ruby</scope> + <description>each_cons(..) { |group| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/each_index-{-i-..-}-(eai).sublime-snippet b/syntaxes/Ruby/Snippets/each_index-{-i-..-}-(eai).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[each_index { |${1:i}| $0 }]]></content> + <tabTrigger>eai</tabTrigger> + <scope>source.ruby</scope> + <description>each_index { |i| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/each_key-{-key-..-}-(eak).sublime-snippet b/syntaxes/Ruby/Snippets/each_key-{-key-..-}-(eak).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[each_key { |${1:key}| $0 }]]></content> + <tabTrigger>eak</tabTrigger> + <scope>source.ruby</scope> + <description>each_key { |key| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/each_line-{-line-..-}-(eal).sublime-snippet b/syntaxes/Ruby/Snippets/each_line-{-line-..-}-(eal).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[each_line$1 { |${2:line}| $0 }]]></content> + <tabTrigger>eal</tabTrigger> + <scope>source.ruby</scope> + <description>each_line { |line| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/each_pair-{-name-val-..-}-(eap).sublime-snippet b/syntaxes/Ruby/Snippets/each_pair-{-name-val-..-}-(eap).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[each_pair { |${1:name}, ${2:val}| $0 }]]></content> + <tabTrigger>eap</tabTrigger> + <scope>source.ruby</scope> + <description>each_pair { |name, val| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/each_slice-{-group-..-}-(eas).sublime-snippet b/syntaxes/Ruby/Snippets/each_slice-{-group-..-}-(eas).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[each_slice(${1:2}) { |${2:group}| $0 }]]></content> + <tabTrigger>eas-</tabTrigger> + <scope>source.ruby</scope> + <description>each_slice(..) { |group| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/each_value-{-val-..-}-(eav).sublime-snippet b/syntaxes/Ruby/Snippets/each_value-{-val-..-}-(eav).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[each_value { |${1:val}| $0 }]]></content> + <tabTrigger>eav</tabTrigger> + <scope>source.ruby</scope> + <description>each_value { |val| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/each_with_index-{-e-i-..-}-(eawi).sublime-snippet b/syntaxes/Ruby/Snippets/each_with_index-{-e-i-..-}-(eawi).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[each_with_index { |${1:e}, ${2:i}| $0 }]]></content> + <tabTrigger>eawi</tabTrigger> + <scope>source.ruby</scope> + <description>each_with_index { |e, i| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/elsif-___.sublime-snippet b/syntaxes/Ruby/Snippets/elsif-___.sublime-snippet @@ -0,0 +1,7 @@ +<snippet> + <content><![CDATA[elsif ${1:condition} + $0]]></content> + <tabTrigger>elsif</tabTrigger> + <scope>source.ruby</scope> + <description>elsif ...</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/extend-Forwardable-(Forw).sublime-snippet b/syntaxes/Ruby/Snippets/extend-Forwardable-(Forw).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[extend Forwardable]]></content> + <tabTrigger>Forw-</tabTrigger> + <scope>source.ruby</scope> + <description>extend Forwardable</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/fetch(name)-{-key-..-}-(fet).sublime-snippet b/syntaxes/Ruby/Snippets/fetch(name)-{-key-..-}-(fet).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[fetch(${1:name}) { ${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}${2:key}${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}$0 }]]></content> + <tabTrigger>fet</tabTrigger> + <scope>source.ruby</scope> + <description>fetch(name) { |key| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/fill(range)-{-i-..-}-(fil).sublime-snippet b/syntaxes/Ruby/Snippets/fill(range)-{-i-..-}-(fil).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[fill(${1:range}) { ${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}${2:i}${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}$0 }]]></content> + <tabTrigger>fil</tabTrigger> + <scope>source.ruby</scope> + <description>fill(range) { |i| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/find-{-e-..-}-(fin).sublime-snippet b/syntaxes/Ruby/Snippets/find-{-e-..-}-(fin).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[find { |${1:e}| $0 }]]></content> + <tabTrigger>fin</tabTrigger> + <scope>source.ruby</scope> + <description>find { |e| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/find_all-{-e-..-}-(fina).sublime-snippet b/syntaxes/Ruby/Snippets/find_all-{-e-..-}-(fina).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[find_all { |${1:e}| $0 }]]></content> + <tabTrigger>fina</tabTrigger> + <scope>source.ruby</scope> + <description>find_all { |e| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/flatten_once-(fla).sublime-snippet b/syntaxes/Ruby/Snippets/flatten_once-(fla).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[inject(Array.new) { |${1:arr}, ${2:a}| ${1:arr}.push(*${2:a}) }]]></content> + <tabTrigger>flao</tabTrigger> + <scope>source.ruby</scope> + <description>flatten_once()</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/flunk(..)-(fl).sublime-snippet b/syntaxes/Ruby/Snippets/flunk(..)-(fl).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[flunk("${0:Failure message.}")]]></content> + <tabTrigger>fl</tabTrigger> + <scope>source.ruby</scope> + <description>flunk(..)</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/grep(;pattern;)-{-match-..-}-(gre).sublime-snippet b/syntaxes/Ruby/Snippets/grep(;pattern;)-{-match-..-}-(gre).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[grep(${1:/${2:pattern}/}) { |${3:match}| $0 }]]></content> + <tabTrigger>gre</tabTrigger> + <scope>source.ruby</scope> + <description>grep(/pattern/) { |match| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/gsub(;..;)-{-match-..-}-(gsu).sublime-snippet b/syntaxes/Ruby/Snippets/gsub(;..;)-{-match-..-}-(gsu).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[gsub(/${1:pattern}/) { ${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}${2:match}${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}$0 }]]></content> + <tabTrigger>gsu</tabTrigger> + <scope>source.ruby</scope> + <description>gsub(/../) { |match| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/hash-pair-(-).sublime-snippet b/syntaxes/Ruby/Snippets/hash-pair-(-).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[:${1:key} => ${2:"${3:value}"}${4:, }]]></content> + <tabTrigger>:</tabTrigger> + <scope>source.ruby</scope> + <description>Hash Pair — :key =&gt; "value"</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/include-Comparable-..-(Comp).sublime-snippet b/syntaxes/Ruby/Snippets/include-Comparable-..-(Comp).sublime-snippet @@ -0,0 +1,10 @@ +<snippet> + <content><![CDATA[include Comparable + +def <=>(other) + $0 +end]]></content> + <tabTrigger>Comp</tabTrigger> + <scope>source.ruby</scope> + <description>include Comparable ..</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/include-Enumerable-..-(Enum).sublime-snippet b/syntaxes/Ruby/Snippets/include-Enumerable-..-(Enum).sublime-snippet @@ -0,0 +1,10 @@ +<snippet> + <content><![CDATA[include Enumerable + +def each(&block) + $0 +end]]></content> + <tabTrigger>Enum</tabTrigger> + <scope>source.ruby</scope> + <description>include Enumerable ..</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/inject(init)-{-mem-var-..-}-(inj).sublime-snippet b/syntaxes/Ruby/Snippets/inject(init)-{-mem-var-..-}-(inj).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[inject${1/.+/(/}${1:init}${1/.+/)/} { |${2:mem}, ${3:var}| $0 }]]></content> + <tabTrigger>inj</tabTrigger> + <scope>source.ruby</scope> + <description>inject(init) { |mem, var| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/lambda-{-args-..-}-(lam).sublime-snippet b/syntaxes/Ruby/Snippets/lambda-{-args-..-}-(lam).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[lambda { ${1/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}${1:args}${1/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}$0 }]]></content> + <tabTrigger>lam</tabTrigger> + <scope>source.ruby</scope> + <description>lambda { |args| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/loop-{-__-}.sublime-snippet b/syntaxes/Ruby/Snippets/loop-{-__-}.sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[loop { $0 }]]></content> + <tabTrigger>loo</tabTrigger> + <scope>source.ruby</scope> + <description>loop { .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/map-{-e-..-}-(map).sublime-snippet b/syntaxes/Ruby/Snippets/map-{-e-..-}-(map).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[map { |${1:e}| $0 }]]></content> + <tabTrigger>map</tabTrigger> + <scope>source.ruby</scope> + <description>map { |e| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/map_with_index-{-e-i-..-}-(mapwi).sublime-snippet b/syntaxes/Ruby/Snippets/map_with_index-{-e-i-..-}-(mapwi).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[enum_with_index.map { |${1:e}, ${2:i}| $0 }]]></content> + <tabTrigger>mapwi-</tabTrigger> + <scope>source.ruby</scope> + <description>map_with_index { |e, i| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/max-{-a-b-..-}-(max).sublime-snippet b/syntaxes/Ruby/Snippets/max-{-a-b-..-}-(max).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[max { |a, b| $0 }]]></content> + <tabTrigger>max</tabTrigger> + <scope>source.ruby</scope> + <description>max { |a, b| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/min-{-a-b-..-}-(min).sublime-snippet b/syntaxes/Ruby/Snippets/min-{-a-b-..-}-(min).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[min { |a, b| $0 }]]></content> + <tabTrigger>min</tabTrigger> + <scope>source.ruby</scope> + <description>min { |a, b| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/module-..-ClassMethods-..-end.sublime-snippet b/syntaxes/Ruby/Snippets/module-..-ClassMethods-..-end.sublime-snippet @@ -0,0 +1,19 @@ +<snippet> + <content><![CDATA[module ${1:${TM_FILENAME/(?:\A|_)([A-Za-z0-9]+)(?:\.rb)?/(?2::\u$1)/g}} + module ClassMethods + $0 + end + + module InstanceMethods + + end + + def self.included(receiver) + receiver.extend ClassMethods + receiver.send :include, InstanceMethods + end +end]]></content> + <tabTrigger>mod</tabTrigger> + <scope>source.ruby</scope> + <description>module .. ClassMethods .. end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/module-..-end.sublime-snippet b/syntaxes/Ruby/Snippets/module-..-end.sublime-snippet @@ -0,0 +1,8 @@ +<snippet> + <content><![CDATA[module ${1:${TM_FILENAME/(?:\A|_)([A-Za-z0-9]+)(?:\.rb)?/(?2::\u$1)/g}} + $0 +end]]></content> + <tabTrigger>mod</tabTrigger> + <scope>source.ruby</scope> + <description>module .. end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/module-..-module_function-..-end.sublime-snippet b/syntaxes/Ruby/Snippets/module-..-module_function-..-end.sublime-snippet @@ -0,0 +1,10 @@ +<snippet> + <content><![CDATA[module ${1:${TM_FILENAME/(?:\A|_)([A-Za-z0-9]+)(?:\.rb)?/(?2::\u$1)/g}} + module_function + + $0 +end]]></content> + <tabTrigger>mod</tabTrigger> + <scope>source.ruby</scope> + <description>module .. module_function .. end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/namespace-__-do-__-end.sublime-snippet b/syntaxes/Ruby/Snippets/namespace-__-do-__-end.sublime-snippet @@ -0,0 +1,8 @@ +<snippet> + <content><![CDATA[namespace :${1:${TM_FILENAME/\.\w+//}} do + $0 +end]]></content> + <tabTrigger>nam</tabTrigger> + <scope>source.ruby</scope> + <description>namespace :.. do .. end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/open(-path;or;url-w-)-do-doc-..-end-(ope).sublime-snippet b/syntaxes/Ruby/Snippets/open(-path;or;url-w-)-do-doc-..-end-(ope).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[open(${1:"${2:path/or/url/or/pipe}"}${3/(^[rwab+]+$)|.*/(?1:, ")/}${3:w}${3/(^[rwab+]+$)|.*/(?1:")/}) { |${4:io}| $0 }]]></content> + <tabTrigger>ope</tabTrigger> + <scope>source.ruby</scope> + <description>open("path/or/url", "w") { |io| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/open-yield-block-({).sublime-snippet b/syntaxes/Ruby/Snippets/open-yield-block-({).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[{ ${1/(^(?<var>\s*[a-z_][a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}${1:variable}${1/(^(?<var>\s*[a-z_][a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}${2:$TM_SELECTED_TEXT} ]]></content> + <tabTrigger>{</tabTrigger> + <scope>source.ruby - string - comment</scope> + <description>Insert { |variable| … }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/option_parse-{-..-}-(optp).sublime-snippet b/syntaxes/Ruby/Snippets/option_parse-{-..-}-(optp).sublime-snippet @@ -0,0 +1,32 @@ +<snippet> + <content><![CDATA[require "optparse" + +options = {${1::default => "args"}} + +ARGV.options do |opts| + opts.banner = "Usage: #{File.basename(\$PROGRAM_NAME)} [OPTIONS]${2/^\s*$|(.*\S.*)/(?1: )/}${2:OTHER_ARGS}" + + opts.separator "" + opts.separator "Specific Options:" + + $0 + + opts.separator "Common Options:" + + opts.on( "-h", "--help", "Show this message." ) do + puts opts + exit + end + + begin + opts.parse! + rescue + puts opts + exit + end +end +]]></content> + <tabTrigger>optp</tabTrigger> + <scope>source.ruby</scope> + <description>option_parse { .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/partition-{-e-..-}-(par).sublime-snippet b/syntaxes/Ruby/Snippets/partition-{-e-..-}-(par).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[partition { |${1:e}| $0 }]]></content> + <tabTrigger>par</tabTrigger> + <scope>source.ruby</scope> + <description>partition { |e| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/path_from_here(-__-).sublime-snippet b/syntaxes/Ruby/Snippets/path_from_here(-__-).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[File.join(File.dirname(__FILE__), *%w[${1:rel path here}])]]></content> + <tabTrigger>patfh</tabTrigger> + <scope>source.ruby</scope> + <description>path_from_here( .. )</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/randomize-(ran).sublime-snippet b/syntaxes/Ruby/Snippets/randomize-(ran).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[sort_by { rand }]]></content> + <tabTrigger>ran</tabTrigger> + <scope>source.ruby</scope> + <description>randomize()</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/reject-{-e-..-}-(rej).sublime-snippet b/syntaxes/Ruby/Snippets/reject-{-e-..-}-(rej).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[reject { |${1:e}| $0 }]]></content> + <tabTrigger>rej</tabTrigger> + <scope>source.ruby</scope> + <description>reject { |e| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/require-..-(req).sublime-snippet b/syntaxes/Ruby/Snippets/require-..-(req).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[require "$0"]]></content> + <tabTrigger>req</tabTrigger> + <scope>source.ruby</scope> + <description>require ".."</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/require-tc_..-..-(ts).sublime-snippet b/syntaxes/Ruby/Snippets/require-tc_..-..-(ts).sublime-snippet @@ -0,0 +1,10 @@ +<snippet> + <content><![CDATA[require "test/unit" + +require "tc_${1:test_case_file}" +require "tc_${2:test_case_file}" +]]></content> + <tabTrigger>ts</tabTrigger> + <scope>source.ruby</scope> + <description>require "tc_.." ..</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/require_gem-__.sublime-snippet b/syntaxes/Ruby/Snippets/require_gem-__.sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[require "$0"]]></content> + <tabTrigger>reqg-</tabTrigger> + <scope>source.ruby</scope> + <description>require_gem ".."</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/results_report(__)-{-__-}.sublime-snippet b/syntaxes/Ruby/Snippets/results_report(__)-{-__-}.sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[results.report("${1:name}:") { TESTS.times { $0 } }]]></content> + <tabTrigger>rep</tabTrigger> + <scope>source.ruby</scope> + <description>results.report(..) { .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/reverse_each-{-e-..-}-(rea).sublime-snippet b/syntaxes/Ruby/Snippets/reverse_each-{-e-..-}-(rea).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[reverse_each { |${1:e}| $0 }]]></content> + <tabTrigger>reve</tabTrigger> + <scope>source.ruby</scope> + <description>reverse_each { |e| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/scan(;..;)-{-match-..-}-(sca).sublime-snippet b/syntaxes/Ruby/Snippets/scan(;..;)-{-match-..-}-(sca).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[scan(/${1:pattern}/) { |${2:match}| $0 }]]></content> + <tabTrigger>sca</tabTrigger> + <scope>source.ruby</scope> + <description>scan(/../) { |match| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/select-{-e-..-}-(sel).sublime-snippet b/syntaxes/Ruby/Snippets/select-{-e-..-}-(sel).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[select { |${1:e}| $0 }]]></content> + <tabTrigger>sel</tabTrigger> + <scope>source.ruby</scope> + <description>select { |e| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/service_object.sublime-snippet b/syntaxes/Ruby/Snippets/service_object.sublime-snippet @@ -0,0 +1,19 @@ +<snippet> +<content><![CDATA[class ${1:${TM_FILENAME/(?:\A|_)([A-Za-z0-9]+)(?:\.rb)?/(?2::\u$1)/g}} + def self.call(*args) + new(*args).call + end + + def initialize(${2:options}) + @${2/,\s*/, @/g} = $2 + end + + def call + $0 + end +end]]> +</content> + <tabTrigger>cla</tabTrigger> + <scope>source.ruby</scope> + <description>Service Object skeleton</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/singleton_class().sublime-snippet b/syntaxes/Ruby/Snippets/singleton_class().sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[class << self; self end]]></content> + <tabTrigger>sinc</tabTrigger> + <scope>source.ruby</scope> + <description>singleton_class()</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/sort-{-a-b-..-}-(sor).sublime-snippet b/syntaxes/Ruby/Snippets/sort-{-a-b-..-}-(sor).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[sort { |a, b| $0 }]]></content> + <tabTrigger>sor</tabTrigger> + <scope>source.ruby</scope> + <description>sort { |a, b| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/sort_by-{-e-..-}-(sorb).sublime-snippet b/syntaxes/Ruby/Snippets/sort_by-{-e-..-}-(sorb).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[sort_by { |${1:e}| $0 }]]></content> + <tabTrigger>sorb</tabTrigger> + <scope>source.ruby</scope> + <description>sort_by { |e| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/step(2)-{-e-..-}-(ste).sublime-snippet b/syntaxes/Ruby/Snippets/step(2)-{-e-..-}-(ste).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[step(${1:2}) { ${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}${2:n}${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}$0 }]]></content> + <tabTrigger>ste</tabTrigger> + <scope>source.ruby</scope> + <description>step(2) { |e| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/sub(;..;)-{-match-..-}-(sub).sublime-snippet b/syntaxes/Ruby/Snippets/sub(;..;)-{-match-..-}-(sub).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[sub(/${1:pattern}/) { ${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}${2:match}${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}$0 }]]></content> + <tabTrigger>sub</tabTrigger> + <scope>source.ruby</scope> + <description>sub(/../) { |match| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/task-task_name-=-[-dependent-tasks]-do-__-end.sublime-snippet b/syntaxes/Ruby/Snippets/task-task_name-=-[-dependent-tasks]-do-__-end.sublime-snippet @@ -0,0 +1,9 @@ +<snippet> + <content><![CDATA[desc "${1:Task description}" +task :${2:${3:task_name} => ${4:[:${5:dependent, :tasks}]}} do + $0 +end]]></content> + <tabTrigger>tas</tabTrigger> + <scope>source.ruby</scope> + <description>task :task_name =&gt; [:dependent, :tasks] do .. end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/times-{-n-..-}-(tim).sublime-snippet b/syntaxes/Ruby/Snippets/times-{-n-..-}-(tim).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[times { ${1/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}${1:n}${1/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}$0 }]]></content> + <tabTrigger>tim</tabTrigger> + <scope>source.ruby</scope> + <description>times { |n| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/transaction(-__-)-do-__-end.sublime-snippet b/syntaxes/Ruby/Snippets/transaction(-__-)-do-__-end.sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[transaction${1/(^.*?\S.*)|.*/(?1:\()/}${1:true}${1/(^.*?\S.*)|.*/(?1:\))/} { $0 }]]></content> + <tabTrigger>tra</tabTrigger> + <scope>source.ruby</scope> + <description>transaction( .. ) { .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/unix_filter-..-(uni).sublime-snippet b/syntaxes/Ruby/Snippets/unix_filter-..-(uni).sublime-snippet @@ -0,0 +1,8 @@ +<snippet> + <content><![CDATA[ARGF.each_line$1 do |${2:line}| + $0 +end]]></content> + <tabTrigger>unif</tabTrigger> + <scope>source.ruby</scope> + <description>unix_filter { .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/unless-(unless).sublime-snippet b/syntaxes/Ruby/Snippets/unless-(unless).sublime-snippet @@ -0,0 +1,8 @@ +<snippet> + <content><![CDATA[unless ${1:condition} + $0 +end]]></content> + <tabTrigger>unless</tabTrigger> + <scope>source.ruby</scope> + <description>unless … end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/until-___-end.sublime-snippet b/syntaxes/Ruby/Snippets/until-___-end.sublime-snippet @@ -0,0 +1,8 @@ +<snippet> + <content><![CDATA[until ${1:condition} + $0 +end]]></content> + <tabTrigger>until</tabTrigger> + <scope>source.ruby</scope> + <description>until ... end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/untitled.sublime-snippet b/syntaxes/Ruby/Snippets/untitled.sublime-snippet @@ -0,0 +1,9 @@ +<snippet> + <content><![CDATA[opts.on( "-${1:o}", "--${2:long-option-name}"${3/^\s*$|(.*\S.*)/(?1:, )/}${3:String}, + "${4:Option description.}" ) do |${6:opt}| + $0 +end]]></content> + <tabTrigger>opt</tabTrigger> + <scope>source.ruby</scope> + <description>option(..)</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/upto(1.0;0.0)-{-n-..-}-(upt).sublime-snippet b/syntaxes/Ruby/Snippets/upto(1.0;0.0)-{-n-..-}-(upt).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[upto(${1:1.0/0.0}) { ${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}${2:n}${2/(^(?<var>\s*(?:\*|\*?[a-z_])[a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:| )/}$0 }]]></content> + <tabTrigger>upt</tabTrigger> + <scope>source.ruby</scope> + <description>upto(1.0/0.0) { |n| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/usage_if()-(usai).sublime-snippet b/syntaxes/Ruby/Snippets/usage_if()-(usai).sublime-snippet @@ -0,0 +1,8 @@ +<snippet> + <content><![CDATA[if ARGV.$1 + abort "Usage: #{\$PROGRAM_NAME} ${2:ARGS_GO_HERE}" +end]]></content> + <tabTrigger>usai</tabTrigger> + <scope>source.ruby</scope> + <description>usage_if()</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/usage_unless()-(usau).sublime-snippet b/syntaxes/Ruby/Snippets/usage_unless()-(usau).sublime-snippet @@ -0,0 +1,8 @@ +<snippet> + <content><![CDATA[unless ARGV.$1 + abort "Usage: #{\$PROGRAM_NAME} ${2:ARGS_GO_HERE}" +end]]></content> + <tabTrigger>usau</tabTrigger> + <scope>source.ruby</scope> + <description>usage_unless()</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/when.sublime-snippet b/syntaxes/Ruby/Snippets/when.sublime-snippet @@ -0,0 +1,7 @@ +<snippet> + <content><![CDATA[when ${1:condition} + $0]]></content> + <tabTrigger>when</tabTrigger> + <scope>source.ruby</scope> + <description>when …</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/while-___-end.sublime-snippet b/syntaxes/Ruby/Snippets/while-___-end.sublime-snippet @@ -0,0 +1,8 @@ +<snippet> + <content><![CDATA[while ${1:condition} + $0 +end]]></content> + <tabTrigger>while</tabTrigger> + <scope>source.ruby</scope> + <description>while ... end</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/xmlread(__).sublime-snippet b/syntaxes/Ruby/Snippets/xmlread(__).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[REXML::Document.new(File.read(${1:"${2:path/to/file}"}))]]></content> + <tabTrigger>xml-</tabTrigger> + <scope>source.ruby</scope> + <description>xmlread(..)</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/xpath(__)-{-__-}.sublime-snippet b/syntaxes/Ruby/Snippets/xpath(__)-{-__-}.sublime-snippet @@ -0,0 +1,8 @@ +<snippet> + <content><![CDATA[elements.each(${1:"${2://XPath}"}) do |${3:node}| + $0 +end]]></content> + <tabTrigger>xpa</tabTrigger> + <scope>source.ruby</scope> + <description>xpath(..) { .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/yields-RDoc-comment.sublime-snippet b/syntaxes/Ruby/Snippets/yields-RDoc-comment.sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[ :yields: ${0:arguments}]]></content> + <tabTrigger>y</tabTrigger> + <scope>source.ruby comment</scope> + <description>:yields:</description> +</snippet> diff --git a/syntaxes/Ruby/Snippets/zip(enums)-{-row-..-}-(zip).sublime-snippet b/syntaxes/Ruby/Snippets/zip(enums)-{-row-..-}-(zip).sublime-snippet @@ -0,0 +1,6 @@ +<snippet> + <content><![CDATA[zip(${1:enums}) { |${2:row}| $0 }]]></content> + <tabTrigger>zip</tabTrigger> + <scope>source.ruby</scope> + <description>zip(enums) { |row| .. }</description> +</snippet> diff --git a/syntaxes/Ruby/Symbol List - Classes, Modules.tmPreferences b/syntaxes/Ruby/Symbol List - Classes, Modules.tmPreferences @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<plist version="1.0"> +<dict> + <key>scope</key> + <string> + source.ruby entity.name.class, + source.ruby entity.name.module + </string> + <key>settings</key> + <dict> + <key>showInSymbolList</key> + <integer>1</integer> + <key>showInIndexedSymbolList</key> + <integer>1</integer> + <key>symbolIndexTransformation</key> + <string>/^(::)?([[:alnum:]_]+::)*//;</string> + </dict> +</dict> +</plist> diff --git a/syntaxes/Ruby/Symbol List - Methods.tmPreferences b/syntaxes/Ruby/Symbol List - Methods.tmPreferences @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<plist version="1.0"> +<dict> + <key>scope</key> + <string>source.ruby entity.name.function</string> + <key>settings</key> + <dict> + <key>showInSymbolList</key> + <integer>1</integer> + <key>showInIndexedSymbolList</key> + <integer>1</integer> + <key>symbolIndexTransformation</key> + <string>/^([[:alnum:]_]+(::|\.))*//;</string> + </dict> +</dict> +</plist> diff --git a/syntaxes/Ruby/syntax_test_ruby.rb b/syntaxes/Ruby/syntax_test_ruby.rb @@ -0,0 +1,1397 @@ +# SYNTAX TEST "Packages/Ruby/Ruby.sublime-syntax" + +################## +# block comments +################## + +=begin +#<- comment.block.documentation.ruby punctuation.definition.comment.begin.ruby +#^^^^^ comment.block.documentation.ruby punctuation.definition.comment.begin.ruby + =end +# ^^^^^ comment.block.documentation.ruby - punctuation +=end +#<- comment.block.documentation.ruby punctuation.definition.comment.end.ruby +#^^^ comment.block.documentation.ruby punctuation.definition.comment.end.ruby + +################## +# line comments +################## + +## comment +#<- comment.line.number-sign.ruby punctuation.definition.comment.ruby +#^ comment.line.number-sign.ruby punctuation.definition.comment.ruby +# ^^^^^^^^ comment.line.number-sign.ruby - punctuation + + ## comment +#^ - comment - punctuation +# ^^ comment.line.number-sign.ruby punctuation.definition.comment.ruby +# ^^^^^^^^^ comment.line.number-sign.ruby - punctuation + +################## +# Heredocs +################## + +# HEREDOC with indented end tag containing an interpolated string +puts <<~EOF; # comment +#^^^^ - meta.string - string.unquoted +# ^^^ meta.string.heredoc.ruby - meta.tag +# ^^^ meta.string.heredoc.ruby meta.tag.heredoc.ruby +# ^^^ punctuation.definition.heredoc.ruby +# ^^^ entity.name.tag.ruby +# ^ punctuation.terminator.statement.ruby - meta.string - string +# ^ comment.line.number-sign.ruby punctuation.definition.comment.ruby - meta.string - string + Indented string! +# ^^^^^^^^^^^^^^^^^ meta.string.heredoc.ruby string.unquoted.heredoc.ruby + #{ sym } #@var +# ^ meta.string.heredoc.ruby string.unquoted.heredoc.ruby - meta.interpolation +# ^^^^^^^^ meta.string.heredoc.ruby meta.interpolation.ruby +# ^ meta.string.heredoc.ruby string.unquoted.heredoc.ruby - meta.interpolation +# ^^^^^ meta.string.heredoc.ruby meta.interpolation.ruby variable.other.readwrite.instance.ruby +# ^ meta.string.heredoc.ruby string.unquoted.heredoc.ruby - meta.interpolation +# ^^ punctuation.section.interpolation.begin.ruby +# ^^^^^ source.ruby.embedded.ruby +# ^ punctuation.section.interpolation.end.ruby +# ^^ punctuation.definition.variable.ruby +# ^^^^^ variable.other.readwrite.instance.ruby + EOF +# ^^^ meta.string.heredoc.ruby meta.tag.heredoc.ruby entity.name.tag.ruby +# ^ - meta.string - string.unquoted + +# HEREDOC with indented end tag containing a plain string +puts <<~'EOF'; # comment +#^^^^ - meta.string - string.unquoted +# ^^^ meta.string.heredoc.ruby - meta.tag +# ^^^^^ meta.string.heredoc.ruby meta.tag.heredoc.ruby +# ^^^ punctuation.definition.heredoc.ruby +# ^ punctuation.definition.tag.begin.ruby +# ^^^ entity.name.tag.ruby +# ^ punctuation.definition.tag.end.ruby +# ^ punctuation.terminator.statement.ruby - meta.string - string +# ^ comment.line.number-sign.ruby punctuation.definition.comment.ruby - meta.string - string + Indented string! +# ^^^^^^^^^^^^^^^^^ meta.string.heredoc.ruby string.unquoted.heredoc.ruby + #{ sym } #@var +# ^^^^^^^^^^^^^^^^^ meta.string.heredoc.ruby string.unquoted.heredoc.ruby - meta.interpolation + EOF +# ^^^ meta.string.heredoc.ruby meta.tag.heredoc.ruby entity.name.tag.ruby +# ^ - meta.string - string.unquoted + +# HEREDOC with unindented end tag containing an interpolated string +puts <<EOF; # comment +#^^^^ - meta.string - string.unquoted +# ^^ meta.string.heredoc.ruby - meta.tag +# ^^^ meta.string.heredoc.ruby meta.tag.heredoc.ruby +# ^^ punctuation.definition.heredoc.ruby +# ^^^ entity.name.tag.ruby +# ^ punctuation.terminator.statement.ruby - meta.string - string +# ^ comment.line.number-sign.ruby punctuation.definition.comment.ruby - meta.string - string + Indented string! +# ^^^^^^^^^^^^^^^^^ meta.string.heredoc.ruby string.unquoted.heredoc.ruby + #{ sym } #@var +# ^ meta.string.heredoc.ruby string.unquoted.heredoc.ruby - meta.interpolation +# ^^^^^^^^ meta.string.heredoc.ruby meta.interpolation.ruby +# ^ meta.string.heredoc.ruby string.unquoted.heredoc.ruby - meta.interpolation +# ^^^^^ meta.string.heredoc.ruby meta.interpolation.ruby variable.other.readwrite.instance.ruby +# ^ meta.string.heredoc.ruby string.unquoted.heredoc.ruby - meta.interpolation +# ^^ punctuation.section.interpolation.begin.ruby +# ^^^^^ source.ruby.embedded.ruby +# ^ punctuation.section.interpolation.end.ruby +# ^^ punctuation.definition.variable.ruby +# ^^^^^ variable.other.readwrite.instance.ruby + EOF +#^^^^^ meta.string.heredoc.ruby string.unquoted.heredoc.ruby +EOF +#^^ meta.string.heredoc.ruby meta.tag.heredoc.ruby entity.name.tag.ruby +# ^ - meta.string - string.unquoted + +# HEREDOC with unindented end tag containing a plain string +puts <<'EOF'; # comment +#^^^^ - meta.string - string.unquoted +# ^^ meta.string.heredoc.ruby - meta.tag +# ^^^^^ meta.string.heredoc.ruby meta.tag.heredoc.ruby +# ^^ punctuation.definition.heredoc.ruby +# ^ punctuation.definition.tag.begin.ruby +# ^^^ entity.name.tag.ruby +# ^ punctuation.definition.tag.end.ruby +# ^ punctuation.terminator.statement.ruby - meta.string - string +# ^ comment.line.number-sign.ruby punctuation.definition.comment.ruby - meta.string - string + Indented string! +# ^^^^^^^^^^^^^^^^^ meta.string.heredoc.ruby string.unquoted.heredoc.ruby + #{ sym } #@var +# ^^^^^^^^^^^^^^^^^ meta.string.heredoc.ruby string.unquoted.heredoc.ruby - meta.interpolation + EOF +#^^^^^ meta.string.heredoc.ruby string.unquoted.heredoc.ruby +EOF +#^^ meta.string.heredoc.ruby meta.tag.heredoc.ruby entity.name.tag.ruby +# ^ - meta.string - string.unquoted + +puts <<-HTML; # comment +#^^^^ - meta.string - string.unquoted +# ^^^ meta.string.heredoc.ruby - meta.tag +# ^^^^ meta.string.heredoc.ruby meta.tag.heredoc.ruby +# ^^^ punctuation.definition.heredoc.ruby +# ^^^^ entity.name.tag.ruby +# ^ punctuation.terminator.statement.ruby - meta.string +# ^ comment.line.number-sign.ruby punctuation.definition.comment.ruby - meta.string - string + <body> +# ^^^^^^ meta.string.heredoc.ruby text.html.embedded.ruby meta.tag.structure + #{ sym } #@var +# ^ meta.string.heredoc.ruby text.html.embedded.ruby - meta.interpolation +# ^^^^^^^^ meta.string.heredoc.ruby meta.interpolation.ruby +# ^ meta.string.heredoc.ruby text.html.embedded.ruby - meta.interpolation +# ^^^^^ meta.string.heredoc.ruby meta.interpolation.ruby variable.other.readwrite.instance.ruby +# ^ meta.string.heredoc.ruby text.html.embedded.ruby - meta.interpolation +# ^^ punctuation.section.interpolation.begin.ruby +# ^^^^^ source.ruby.embedded.ruby +# ^ punctuation.section.interpolation.end.ruby +# ^^ punctuation.definition.variable.ruby +# ^^^^^ variable.other.readwrite.instance.ruby + </body> +# ^^^^^^^ meta.string.heredoc.ruby text.html.embedded.ruby meta.tag.structure.any.html + HTML +# ^^^^ meta.string.heredoc.ruby meta.tag.heredoc.ruby entity.name.tag.ruby +# ^ - meta.string - string.unquoted + +class_eval <<-RUBY, __FILE__, __LINE__ + 1 + def #{sym}(*args, &block) +# ^^^^ meta.string.heredoc.ruby - meta.interpolation +# ^^^^^^ meta.string.heredoc.ruby source.ruby.embedded.ruby meta.interpolation.ruby +# ^^^^^^^^^^^^^^^ meta.string.heredoc.ruby source.ruby.embedded.ruby - meta.interpolation +# ^^ punctuation.section.interpolation.begin.ruby +# ^ punctuation.section.interpolation.end.ruby + custom(Mime[:#{sym}], *args, &block) + end +RUBY +#^^^ meta.string.heredoc.ruby meta.tag.heredoc.ruby entity.name.tag.ruby +# ^ - meta.string - string.unquoted + +puts <<-SH; # comment +# ^^^^^ meta.string.heredoc.ruby +# ^^^ punctuation.definition.heredoc.ruby +# ^^ entity.name.tag.ruby +# ^ punctuation.terminator.statement.ruby - meta.string - string +# ^ comment.line.number-sign.ruby punctuation.definition.comment.ruby - meta.string - string + git log +# ^^^^^^^ meta.string.heredoc.ruby source.shell.embedded.ruby + SH +# ^^ meta.string.heredoc.ruby meta.tag.heredoc.ruby entity.name.tag.ruby +# ^ - meta.string - string.unquoted + +puts <<-SHELL; # comment +# ^^^ meta.string.heredoc.ruby punctuation.definition.heredoc.ruby +# ^^^^^ meta.string.heredoc.ruby meta.tag.heredoc.ruby entity.name.tag.ruby +# ^ punctuation.terminator.statement.ruby - meta.string - string +# ^ comment.line.number-sign.ruby punctuation.definition.comment.ruby - meta.string - string + git log +# ^^^^^^^ meta.string.heredoc.ruby source.shell.embedded.ruby + SHELL +# ^^^^^ meta.string.heredoc.ruby meta.tag.heredoc.ruby entity.name.tag.ruby +# ^ - meta.string - string.unquoted + +DB.fetch(<<-SQL, conn).name +#^^^^^^^^^^^^^^^^^^^^^^^^^^ source.ruby +# ^^^^^^ meta.string.heredoc.ruby +# ^^^ punctuation.definition.heredoc.ruby +# ^^^ entity.name.tag.ruby +# ^^^^^^^^^^^^ - meta.string - string +# ^ punctuation.separator +# ^ punctuation.definition.group.end +SELECT * FROM #$users; +#^^^^^^^^^^^^^ meta.string.heredoc.ruby source.sql.embedded.ruby - meta.interpolation +# ^^^^^^^ meta.string.heredoc.ruby source.sql.embedded.ruby meta.interpolation.ruby variable.other.readwrite.global +# ^ meta.string.heredoc.ruby source.sql.embedded.ruby - meta.interpolation +SQL +#^^ meta.string.heredoc.ruby meta.tag.heredoc.ruby entity.name.tag.ruby +# ^ - meta.string - string.unquoted + +foo, bar = <<BAR, 2 +#^^^^^^^^^^^^^^^^^^ source.ruby +# ^^ meta.string.heredoc.ruby - meta.tag +# ^^^ meta.string.heredoc.ruby meta.tag.heredoc.ruby +# ^^^ - meta.string.heredoc +# ^^ punctuation.definition.heredoc.ruby +# ^^^ entity.name.tag.ruby +# ^ punctuation.separator +# ^ constant.numeric +BAR +#^^ meta.string.heredoc.ruby meta.tag.heredoc.ruby entity.name.tag.ruby +# ^ - meta.string - string.unquoted + +################## +# Numbers +################## + + 1234 +#^^^^ meta.number.integer.decimal.ruby constant.numeric.value.ruby + 1_234 +#^^^^^ meta.number.integer.decimal.ruby constant.numeric.value.ruby + 0d170 +#^^ meta.number.integer.decimal.ruby constant.numeric.base.ruby +# ^^^ meta.number.integer.decimal.ruby constant.numeric.value.ruby + 0D170 +#^^ meta.number.integer.decimal.ruby constant.numeric.base.ruby +# ^^^ meta.number.integer.decimal.ruby constant.numeric.value.ruby + 0xAa +#^^ meta.number.integer.hexadecimal.ruby constant.numeric.base.ruby +# ^^ meta.number.integer.hexadecimal.ruby constant.numeric.value.ruby + 0XAa +#^^ meta.number.integer.hexadecimal.ruby constant.numeric.base.ruby +# ^^ meta.number.integer.hexadecimal.ruby constant.numeric.value.ruby + 0252 +#^ meta.number.integer.octal.ruby constant.numeric.base.ruby +# ^^^ meta.number.integer.octal.ruby constant.numeric.value.ruby + 0o252 +#^^ meta.number.integer.octal.ruby constant.numeric.base.ruby +# ^^^ meta.number.integer.octal.ruby constant.numeric.value.ruby + 0O252 +#^^ meta.number.integer.octal.ruby constant.numeric.base.ruby +# ^^^ meta.number.integer.octal.ruby constant.numeric.value.ruby + 0b10101010 +#^^ meta.number.integer.binary.ruby constant.numeric.base.ruby +# ^^^^^^^^ meta.number.integer.binary.ruby constant.numeric.value.ruby + 0B10101010 +#^^ meta.number.integer.binary.ruby constant.numeric.base.ruby +# ^^^^^^^^ meta.number.integer.binary.ruby constant.numeric.value.ruby + 12. +#^^ meta.number.integer.decimal.ruby constant.numeric.value.ruby +# ^ punctuation.accessor - constant.numeric - invalid.illegal + 12.ir +#^^ meta.number.integer.decimal.ruby constant.numeric.value.ruby +# ^ punctuation.accessor - constant.numeric - invalid.illegal +# ^^ - constant.numeric - invalid.illegal - storage.type.numeric + + 12.34 +#^^^^^ meta.number.float.decimal.ruby constant.numeric.value.ruby +# ^ punctuation.separator.decimal + 1234e-2 +#^^^^^^^ meta.number.float.decimal.ruby constant.numeric.value.ruby + 1.234E1 +#^^^^^^^ meta.number.float.decimal.ruby constant.numeric.value.ruby +# ^ punctuation.separator.decimal + 12e3r +#^^^^ meta.number.float.decimal.ruby constant.numeric.value.ruby +# ^ meta.number.float.decimal.ruby constant.numeric.suffix.ruby invalid.illegal.numeric.rational.ruby + 1.2e3r +#^^^^^ meta.number.float.decimal.ruby constant.numeric.value.ruby +# ^ punctuation.separator.decimal +# ^ meta.number.float.decimal.ruby constant.numeric.suffix.ruby invalid.illegal.numeric.rational.ruby + + 12r +#^^ meta.number.rational.decimal.ruby constant.numeric.value.ruby +# ^ meta.number.rational.decimal.ruby constant.numeric.suffix.ruby + 12.3r +#^^^^ meta.number.rational.decimal.ruby constant.numeric.value.ruby +# ^ punctuation.separator.decimal +# ^ meta.number.rational.decimal.ruby constant.numeric.suffix.ruby + 0d170r +#^^ meta.number.rational.decimal.ruby constant.numeric.base.ruby +# ^^^ meta.number.rational.decimal.ruby constant.numeric.value.ruby +# ^ meta.number.rational.decimal.ruby constant.numeric.suffix.ruby + 0xAar +#^^ meta.number.rational.hexadecimal.ruby constant.numeric.base.ruby +# ^^ meta.number.rational.hexadecimal.ruby constant.numeric.value.ruby +# ^ meta.number.rational.hexadecimal.ruby constant.numeric.suffix.ruby + 0o252r +#^^ meta.number.rational.octal.ruby constant.numeric.base.ruby +# ^^^ meta.number.rational.octal.ruby constant.numeric.value.ruby +# ^ meta.number.rational.octal.ruby constant.numeric.suffix.ruby + 0b10101010r +#^^ meta.number.rational.binary.ruby constant.numeric.base.ruby +# ^^^^^^^^ meta.number.rational.binary.ruby constant.numeric.value.ruby +# ^ meta.number.rational.binary.ruby constant.numeric.suffix.ruby + + 12i +#^^ meta.number.imaginary.decimal.ruby constant.numeric.value.ruby +# ^ meta.number.imaginary.decimal.ruby constant.numeric.suffix.ruby + 12.3i +#^^^^ meta.number.imaginary.decimal.ruby constant.numeric.value.ruby +# ^ punctuation.separator.decimal +# ^ meta.number.imaginary.decimal.ruby constant.numeric.suffix.ruby + 12e3i +#^^^^ meta.number.imaginary.decimal.ruby constant.numeric.value.ruby +# ^ meta.number.imaginary.decimal.ruby constant.numeric.suffix.ruby + 12e-3i +#^^^^^ meta.number.imaginary.decimal.ruby constant.numeric.value.ruby +# ^ meta.number.imaginary.decimal.ruby constant.numeric.suffix.ruby + 1.2e3i +#^^^^^ meta.number.imaginary.decimal.ruby constant.numeric.value.ruby +# ^ punctuation.separator.decimal +# ^ meta.number.imaginary.decimal.ruby constant.numeric.suffix.ruby + 1.2e-3i +#^^^^^^ meta.number.imaginary.decimal.ruby constant.numeric.value.ruby +# ^ punctuation.separator.decimal +# ^ meta.number.imaginary.decimal.ruby constant.numeric.suffix.ruby + 12ri +#^^ meta.number.imaginary.decimal.ruby constant.numeric.value.ruby +# ^^ meta.number.imaginary.decimal.ruby constant.numeric.suffix.ruby + 12.3ri +#^^^^ meta.number.imaginary.decimal.ruby constant.numeric.value.ruby +# ^ punctuation.separator.decimal +# ^^ meta.number.imaginary.decimal.ruby constant.numeric.suffix.ruby + 0d170i +#^^ meta.number.imaginary.decimal.ruby constant.numeric.base.ruby +# ^^^ meta.number.imaginary.decimal.ruby constant.numeric.value.ruby +# ^ meta.number.imaginary.decimal.ruby constant.numeric.suffix.ruby + 0d170ri +#^^ meta.number.imaginary.decimal.ruby constant.numeric.base.ruby +# ^^^ meta.number.imaginary.decimal.ruby constant.numeric.value.ruby +# ^^ meta.number.imaginary.decimal.ruby constant.numeric.suffix.ruby + 0xAai +#^^ meta.number.imaginary.hexadecimal.ruby constant.numeric.base.ruby +# ^^ meta.number.imaginary.hexadecimal.ruby constant.numeric.value.ruby +# ^ meta.number.imaginary.hexadecimal.ruby constant.numeric.suffix.ruby + 0xAari +#^^ meta.number.imaginary.hexadecimal.ruby constant.numeric.base.ruby +# ^^ meta.number.imaginary.hexadecimal.ruby constant.numeric.value.ruby +# ^^ meta.number.imaginary.hexadecimal.ruby constant.numeric.suffix.ruby + 0o252i +#^^ meta.number.imaginary.octal.ruby constant.numeric.base.ruby +# ^^^ meta.number.imaginary.octal.ruby constant.numeric.value.ruby +# ^ meta.number.imaginary.octal.ruby constant.numeric.suffix.ruby + 0o252ri +#^^ meta.number.imaginary.octal.ruby constant.numeric.base.ruby +# ^^^ meta.number.imaginary.octal.ruby constant.numeric.value.ruby +# ^^ meta.number.imaginary.octal.ruby constant.numeric.suffix.ruby + 0b10101010i +#^^ meta.number.imaginary.binary.ruby constant.numeric.base.ruby +# ^^^^^^^^ meta.number.imaginary.binary.ruby constant.numeric.value.ruby +# ^ meta.number.imaginary.binary.ruby constant.numeric.suffix.ruby + 0b10101010ri +#^^ meta.number.imaginary.binary.ruby constant.numeric.base.ruby +# ^^^^^^^^ meta.number.imaginary.binary.ruby constant.numeric.value.ruby +# ^^ meta.number.imaginary.binary.ruby constant.numeric.suffix.ruby + 12e3ri +#^^^^ meta.number.imaginary.decimal.ruby constant.numeric.value.ruby +# ^^ meta.number.imaginary.decimal.ruby constant.numeric.suffix.ruby +# ^ invalid.illegal.numeric + 1.2e3ri +#^^^ meta.number.imaginary.decimal.ruby constant.numeric.value.ruby +# ^^ meta.number.imaginary.decimal.ruby constant.numeric.value.ruby +# ^ invalid.illegal.numeric.ruby +# ^^ meta.number.imaginary.decimal.ruby constant.numeric.suffix.ruby + 12ir +#^^ meta.number.imaginary.decimal.ruby constant.numeric.value.ruby +# ^^ meta.number.imaginary.decimal.ruby constant.numeric.suffix.ruby +# ^ invalid.illegal.numeric + 12.3ir +#^^^^ meta.number.imaginary.decimal.ruby constant.numeric.value.ruby +# ^ punctuation.separator.decimal +# ^^ meta.number.imaginary.decimal.ruby constant.numeric.suffix.ruby +# ^ invalid.illegal.numeric + 12e3ir +#^^ meta.number.imaginary.decimal.ruby constant.numeric.value.ruby +# ^^ meta.number.imaginary.decimal.ruby constant.numeric.value.ruby +# ^^ meta.number.imaginary.decimal.ruby constant.numeric.suffix.ruby +# ^ invalid.illegal.numeric + 1.2e3ir +#^^^ meta.number.imaginary.decimal.ruby constant.numeric.value.ruby +# ^ punctuation.separator.decimal +# ^^ meta.number.imaginary.decimal.ruby constant.numeric.value.ruby +# ^^ meta.number.imaginary.decimal.ruby constant.numeric.suffix.ruby +# ^ invalid.illegal.numeric + 0d170ir +#^^ meta.number.imaginary.decimal.ruby constant.numeric.base.ruby +# ^^^ meta.number.imaginary.decimal.ruby constant.numeric.value.ruby +# ^^ meta.number.imaginary.decimal.ruby constant.numeric.suffix.ruby +# ^ invalid.illegal.numeric + 0xAair +#^^ meta.number.imaginary.hexadecimal.ruby constant.numeric.base.ruby +# ^^ meta.number.imaginary.hexadecimal.ruby constant.numeric.value.ruby +# ^^ meta.number.imaginary.hexadecimal.ruby constant.numeric.suffix.ruby +# ^ invalid.illegal.numeric + 0o252ir +#^^ meta.number.imaginary.octal.ruby constant.numeric.base.ruby +# ^^^ meta.number.imaginary.octal.ruby constant.numeric.value.ruby +# ^^ meta.number.imaginary.octal.ruby constant.numeric.suffix.ruby +# ^ invalid.illegal.numeric + 0b10101010ir +#^^ meta.number.imaginary.binary.ruby constant.numeric.base.ruby +# ^^^^^^^^ meta.number.imaginary.binary.ruby constant.numeric.value.ruby +# ^^ meta.number.imaginary.binary.ruby constant.numeric.suffix.ruby +# ^ invalid.illegal.numeric + +################## +# Strings +################## + +puts 'test' + +str = "number %d" % 11 + # ^^ string.quoted.double.ruby constant.other.placeholder.ruby +str = 'number %d' % 11 + # ^^ string.quoted.single.ruby constant.other.placeholder.ruby +str = 'number %08d' % 11 + # ^^^^ string.quoted.single.ruby constant.other.placeholder.ruby +str = 'number %.2f' % 11 + # ^^^^ string.quoted.single.ruby constant.other.placeholder.ruby +str = 'number %-8.2d' % 11 + # ^^^^^^ string.quoted.single.ruby constant.other.placeholder.ruby +str = '%2$02d' % [212.00, 3] + # ^^^^^^ string.quoted.single.ruby constant.other.placeholder.ruby +str = sprintf("%1$*2$s %2$d", "hello", -8) +# ^^^^^^^ string.quoted.double.ruby constant.other.placeholder.ruby +# ^^^^ string.quoted.double.ruby constant.other.placeholder.ruby + +################## +# Escape sequences +################## + + "This string has a quote: \". As you can see, it is escaped" +# ^^ constant.character.escape.ruby + "\a bell, ASCII 07h (BEL)" +# ^^ constant.character.escape.ruby + "\b backspace, ASCII 08h (BS)" +# ^^ constant.character.escape.ruby + "\t horizontal tab, ASCII 09h (TAB)" +# ^^ constant.character.escape.ruby + "\n newline (line feed), ASCII 0Ah (LF)" +# ^^ constant.character.escape.ruby + "\v vertical tab, ASCII 0Bh (VT)" +# ^^ constant.character.escape.ruby + "\f form feed, ASCII 0Ch (FF)" +# ^^ constant.character.escape.ruby + "\r carriage return, ASCII 0Dh (CR)" +# ^^ constant.character.escape.ruby + "\e escape, ASCII 1Bh (ESC)" +# ^^ constant.character.escape.ruby + "\s space, ASCII 20h (SPC)" +# ^^ constant.character.escape.ruby + "\\ backslash" +# ^^ constant.character.escape.ruby + "\0 \7 \07 \007 \0170 octal bit pattern, where nnn is 1-3 octal digits ([0-7])" +# ^^ constant.character.escape.ruby +# ^ - constant +# ^^ constant.character.escape.ruby +# ^ - constant +# ^^^ constant.character.escape.ruby +# ^ - constant +# ^^^^ constant.character.escape.ruby +# ^ - constant +# ^^^^ constant.character.escape.ruby +# ^ - constant + "\x0 \xF \x0F \x0FF hexadecimal bit pattern, where nn is 1-2 hexadecimal digits ([0-9a-fA-F])" +# ^^^ constant.character.escape.ruby +# ^ - constant +# ^^^ constant.character.escape.ruby +# ^ - constant +# ^^^^ constant.character.escape.ruby +# ^ - constant +# ^^^^ constant.character.escape.ruby +# ^ - constant + "\u0B \u0AF4 Unicode character, where nnnn is exactly 4 hexadecimal digits ([0-9a-fA-F])" +# ^^ constant.character.escape.ruby +# ^^ - constant +# ^^^^^^ constant.character.escape.ruby + "\u{nnnn Ab0 09AFaf ...} Unicode character(s), where each nnnn is 1-6 hexadecimal digits ([0-9a-fA-F])" +# ^^^^^^^^^^^^^^^^^^^^^^^ constant.character.escape.ruby +# ^^^^ invalid.illegal.escape.ruby +# ^^^ invalid.illegal.escape.ruby +# ^ - constant + "\cx or \C-x control character, where x is an ASCII printable character" +# ^^^ constant.character.escape.ruby +# ^^^^ - constant +# ^^^^ constant.character.escape.ruby +# ^ - constant + "\M-x meta character, where x is an ASCII printable character" +# ^^^^ constant.character.escape.ruby +# ^ - constant + "\M-\C-x meta control character, where x is an ASCII printable character" +# ^^^^^^^ constant.character.escape.ruby +# ^ - constant + "\M-\cx same as above" +# ^^^^^^ constant.character.escape.ruby +# ^ - constant + "\c\M-x same as above" +# ^^^^^^ constant.character.escape.ruby +# ^ - constant + "\c? or \C-? delete, ASCII 7Fh (DEL)" +# ^^^ constant.character.escape.ruby +# ^^^^ - constant +# ^^^^ constant.character.escape.ruby +# ^ - constant + +################## +# Interpolation +################## + + "#{MyParams.new.require(:filename)}" +# ^ meta.string.ruby string.quoted.double.ruby - meta.interpolation +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.ruby meta.interpolation.ruby - string +# ^ meta.string.ruby string.quoted.double.ruby - meta.interpolation +# ^ punctuation.definition.string.begin.ruby +# ^^ punctuation.section.interpolation.begin.ruby +# ^ punctuation.section.interpolation.end.ruby +# ^ punctuation.definition.string.end.ruby + %I[#{ENV['APP_NAME']} apple #@orange#@@juice banana] +# ^^^ meta.string.ruby - meta.interpolation +# ^^^^^^ meta.string.ruby meta.interpolation.ruby - string +# ^^^^^^^^^^^^^^^ meta.environment-variable.ruby +# ^^^^^^^^^^ meta.string.ruby meta.interpolation.ruby meta.string.ruby +# ^^ meta.string.ruby meta.interpolation.ruby - string +# ^^^^^ constant.other.symbol.ruby +# ^^^^^^^^^^^^^^^^ meta.string.ruby meta.interpolation.ruby - string +# ^^^^^^ constant.other.symbol.ruby +# ^^^ punctuation.definition.string.begin.ruby +# ^^^ string.quoted.other.literal.upper.ruby +# ^^ punctuation.section.interpolation.begin.ruby +# ^^^ variable.other.constant.ruby +# ^^^^^^^^^^ string.quoted.single.ruby +# ^^^^^^^ string.quoted.other.literal.upper.ruby +# ^^ punctuation.definition.variable.ruby +# ^^^^^^^^ variable.other.readwrite.instance.ruby +# ^^^ punctuation.definition.variable.ruby +# ^^^^^^^^ variable.other.readwrite.class.ruby +# ^ punctuation.definition.string.end.ruby +# ^ string.quoted.other.literal.upper.ruby + %x[ foo #@bar [ foo #@bar [ foo #@bar ] baz ] baz ] +# ^^^^^^^^ meta.string.ruby string.interpolated.ruby - meta.interpolation +# ^^^^^ meta.string.ruby meta.interpolation.ruby - string +# ^^^^^^^ meta.string.ruby string.interpolated.ruby - meta.interpolation +# ^^^^^ meta.string.ruby meta.interpolation.ruby - string +# ^^^^^^^ meta.string.ruby string.interpolated.ruby - meta.interpolation +# ^^^^^ meta.string.ruby meta.interpolation.ruby - string +# ^^^^^^^^^^^^^^ meta.string.ruby string.interpolated.ruby - meta.interpolation +# ^^^ punctuation.definition.string.begin.ruby +# ^^^^^ variable.other.readwrite.instance.ruby +# ^ punctuation.section.scope.ruby +# ^^^^^ variable.other.readwrite.instance.ruby +# ^ punctuation.section.scope.ruby +# ^^^^^ variable.other.readwrite.instance.ruby +# ^ punctuation.section.scope.ruby +# ^ punctuation.section.scope.ruby +# ^ punctuation.definition.string.end.ruby + +################## +# Constants +################## + +lower_snake_case = 1 +# ^^^^^^^^^^^^^^ -meta.constant.ruby -entity.name.constant.ruby +lowerCamelCase = 2 +# ^^^^^^^^^^^^ -meta.constant.ruby -entity.name.constant.ruby +UpperCamelCase = 3 +# ^^^^^^^^^^^^ meta.constant.ruby entity.name.constant.ruby +UPPER_SNAKE_CASE = 4 +# ^^^^^^^^^^^^^^ meta.constant.ruby entity.name.constant.ruby +A, B, C = 0 +# <- entity.name.constant +# ^ entity.name.constant +# ^ entity.name.constant + +Symbol === :foo +# ^^^^ variable.other.constant.ruby -meta.constant.ruby +# ^^^^ + + :'foo #{ } #@bar baz' +# ^^^^^^^^^^^^^^^^^^^^^ meta.constant.ruby - meta.interpolation +# ^^ punctuation.definition.constant.ruby +# ^^^^^^^^^^^^^^^^^^^^^ constant.other.symbol.single-quoted.ruby +# ^ punctuation.definition.constant.ruby + :"foo #{ } #@bar baz" +# ^^^^^^ meta.constant.ruby - meta.interpolation +# ^^^^ meta.constant.ruby meta.interpolation.ruby - constant +# ^ meta.constant.ruby - meta.interpolation +# ^^^^^ meta.constant.ruby meta.interpolation.ruby - constant +# ^^^^^ meta.constant.ruby - meta.interpolation +# ^^ punctuation.definition.constant.ruby +# ^^^^^^ constant.other.symbol.double-quoted.ruby +# ^^ punctuation.section.interpolation.begin.ruby +# ^ punctuation.section.interpolation.end.ruby +# ^^ punctuation.definition.variable.ruby +# ^^^^^ variable.other.readwrite.instance.ruby +# ^^^^ constant.other.symbol.double-quoted.ruby +# ^ punctuation.definition.constant.ruby + +################## +# Character literals +################## + + ## meta control sequences + + ?\C-a ?\ca ?\c-a #=> "\x01" +#^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^ constant.character.ruby +# ^ - constant + ?\M-a ?\m-a ?\ma #=> "\xE1" +#^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^ constant.character.ruby +# ^^^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^^ constant.character.ruby +# ^^^ invalid.illegal.character.ruby +# ^ - constant + ?\M-\C-a ?\M-\ca #=> "\x81" +#^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^^^^^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^^^^^ constant.character.ruby +# ^ - constant + ?\C-\M-a ?\c\M-a #=> "\x81", same as above +#^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^^^^^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^^^^^ constant.character.ruby +# ^ - constant + + ## hexadecimal + + ?\x10 ?\xAF ?\xAG ?\x0AF +#^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^^^ constant.character.ruby +# ^^^^ invalid.illegal.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^^^^ constant.character.ruby +# ^^^^^ invalid.illegal.character.ruby +# ^ - constant + + ## octal + + ?\00 ?\07 ?\000 ?\077 ?\080 ?\0777 +#^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^^^ constant.character.ruby +# ^^^^ invalid.illegal.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^^^^ constant.character.ruby +# ^^^^^ invalid.illegal.character.ruby +# ^ - constant + + ## escape sequences + + ?\b ?\n ?\s ?\\ ?\\n ?\bn +#^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^ constant.character.ruby +# ^ - constant +# ^ constant.character.ruby punctuation.definition.constant.ruby +# ^^^ constant.character.ruby invalid.illegal.character.ruby +# ^ - constant +# ^ constant.character.ruby punctuation.definition.constant.ruby +# ^^^ constant.character.ruby invalid.illegal.character.ruby +# ^ - constant + + ## unicode + + ?\u{41} #=> "A" +# ^^^ meta.constant.ruby - meta.braces.ruby constant.character.ruby +# ^^^^ meta.constant.ruby meta.braces.ruby - constant.character.ruby +# ^ punctuation.definition.constant.ruby +# ^ punctuation.section.braces.begin.ruby +# ^^ meta.number.integer.hexadecimal.ruby constant.numeric.value.ruby +# ^ punctuation.section.braces.end.ruby + ?\u{012ACF 0gxs} +# ^^^ meta.constant.ruby - meta.braces.ruby constant.character.ruby +# ^^^^^^^^^^^^^ meta.constant.ruby meta.braces.ruby - constant.character.ruby +# ^ punctuation.definition.constant.ruby +# ^ punctuation.section.braces.begin.ruby +# ^^^^^^ meta.number.integer.hexadecimal.ruby constant.numeric.value.ruby +# ^ meta.number.integer.hexadecimal.ruby constant.numeric.value.ruby +# ^^^ invalid.illegal.escape.ruby +# ^ punctuation.section.braces.end.ruby + + ## normal character literals + + ?0 ?1 ?9 ?20 +#^ - constant +# ^ punctuation.definition.constant.ruby +# ^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^ constant.character.ruby +# ^ - constant +# ^ keyword.operator.conditional.ruby +# ^^ meta.number.integer.decimal.ruby constant.numeric.value.ruby + ?a ?A ?あ ?abc ?a0 +#^ - constant +# ^ punctuation.definition.constant.ruby +# ^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^^ constant.character.ruby +# ^^^ invalid.illegal.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^^ constant.character.ruby +# ^^ invalid.illegal.character.ruby +# ^ - constant + ?* ?" ?( ?[ ?{ ?. ?# ?_ ?\ +#^ - constant +# ^ punctuation.definition.constant.ruby +# ^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^ constant.character.ruby +# ^ - constant +# ^ punctuation.definition.constant.ruby +# ^^ constant.character.ruby +# ^ - constant + +################## +# Constant reserved keyword symbols +################## + +begin: 'begin' +# ^^^^ constant.other.symbol +end: 'end' +# ^^ constant.other.symbol +require: 'require' +# ^^^^^^ constant.other.symbol +class: 'class' +# ^^^^ constant.other.symbol +module: 'module' +# ^^^^^ constant.other.symbol + +################## +# Operators +################## + + , +# ^ punctuation.separator.sequence.ruby + ; +# ^ punctuation.terminator.statement.ruby + . +# ^ punctuation.accessor.dot.ruby + :: +# ^^ punctuation.accessor.double-colon.ruby + <<= +# ^^^ keyword.operator.assignment.augmented.ruby + &&= +# ^^^ keyword.operator.assignment.augmented.ruby + ||= +# ^^^ keyword.operator.assignment.augmented.ruby + **= +# ^^^ keyword.operator.assignment.augmented.ruby + += +# ^^ keyword.operator.assignment.augmented.ruby + -= +# ^^ keyword.operator.assignment.augmented.ruby + *= +# ^^ keyword.operator.assignment.augmented.ruby + /= +# ^^ keyword.operator.assignment.augmented.ruby + &= +# ^^ keyword.operator.assignment.augmented.ruby + |= +# ^^ keyword.operator.assignment.augmented.ruby + ^= +# ^^ keyword.operator.assignment.augmented.ruby + << +# ^^ keyword.operator.assignment.augmented.ruby + >> +# ^^ keyword.operator.other.ruby + + +# ^ keyword.operator.arithmetic.ruby + - +# ^ keyword.operator.arithmetic.ruby + * +# ^ keyword.operator.arithmetic.ruby + ** +# ^^ keyword.operator.arithmetic.ruby + / +# ^ keyword.operator.arithmetic.ruby + % +# ^ keyword.operator.arithmetic.ruby + !~ +# ^^ keyword.operator.comparison.ruby + =~ +# ^^ keyword.operator.comparison.ruby + <=> +# ^^^ keyword.operator.comparison.ruby + == +# ^^ keyword.operator.comparison.ruby + != +# ^^ keyword.operator.comparison.ruby + >= +# ^^ keyword.operator.comparison.ruby + <= +# ^^ keyword.operator.comparison.ruby + > +# ^ keyword.operator.comparison.ruby + < +# ^ keyword.operator.comparison.ruby + && +# ^^ keyword.operator.logical.ruby + || +# ^^ keyword.operator.logical.ruby + ! +# ^ keyword.operator.logical.ruby + ? +# ^ keyword.operator.conditional.ruby + : +# ^ keyword.operator.conditional.ruby + ~ +# ^ keyword.operator.bitwise.ruby + & +# ^ keyword.operator.bitwise.ruby + | +# ^ keyword.operator.bitwise.ruby + ^ +# ^ keyword.operator.bitwise.ruby + .. +# ^^ keyword.operator.range.ruby + ... +# ^^^ keyword.operator.range.ruby + +################## +# Blocks +################## + +[self.class.name, @name].map do |*args| +# ^ variable.language.ruby +# ^ variable.other.readwrite.instance.ruby punctuation.definition.variable.ruby +# ^^^^ variable.other.readwrite.instance.ruby +# ^ keyword.operator.splat.ruby +# ^ variable.parameter.ruby +end + +{ |a, b=2, *c| a + b} +# <- punctuation.section.scope +# ^^^^^^^^^^^^ meta.block.parameters +# ^ punctuation.definition.parameters.begin +# ^ variable.parameter +# ^ punctuation.separator +# ^ variable.parameter +# ^^ meta.block.parameters.default-value +# ^ keyword.operator.assignment +# ^ constant.numeric +# ^ punctuation.separator +# ^ keyword.operator.splat +# ^ variable.parameter +# ^ punctuation.definition.parameters.end +# ^ punctuation.section.scope + +do |&bl| end +# <- keyword.control.block.do.ruby +# ^^^^^ meta.block.parameters +# ^ punctuation.definition.parameters +# ^ keyword.operator +# ^^ variable.parameter +# ^ punctuation.definition.parameters + +{ |a={|b={a: 1, b: 2}|}| a * 2 } +# ^^^^^^^^^^^^^^^^^^^^^^ meta.block.parameters +# ^ punctuation.definition.parameters.begin +# ^ variable.parameter +# ^^^^^^^^^^^^^^^^^^^ meta.block.parameters.default-value +# ^^^^^^^^^^^^^^^^ meta.block.parameters meta.block.parameters +# ^ variable.parameter +# ^^^^^^^^^^^^^ meta.block.parameters.default-value meta.block.parameters.default-value +# ^ keyword.operator.assignment +# ^^ constant.other.symbol +# ^ constant.numeric +# ^ punctuation.separator +# ^^ constant.other.symbol +# ^ constant.numeric +# ^ punctuation.definition.parameters.end +# ^ punctuation.definition.parameters.end +# ^ keyword.operator.arithmetic + + +################## +# Modules, classes and methods +################## + +module MyModule +#^^^^^^^^^^^^^^ meta.namespace +# <- meta.namespace keyword.declaration.namespace +#^^^^^ keyword.declaration.namespace +# ^ - entity - keyword - storage +# ^^^^^^^^ entity.name.namespace +end + +module MyModule::OtherModule +#^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.namespace +# <- meta.namespace keyword.declaration.namespace +# ^^^^^^^^^^^^^^^^^^^^^ entity.name.namespace +#^^^^^ keyword.declaration.namespace +# ^ - entity - keyword - storage +# ^^^^^^^^ support.other.namespace +# ^^ punctuation.accessor.double-colon +# ^^^^^^^^^^^ entity.name.namespace +end + +class ::MyModule::MyClass < MyModule::InheritedClass +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.class +# <- meta.class keyword.declaration.class +#^^^^ keyword.declaration.class +# ^ - entity - keyword - storage - punctuation +# ^^ punctuation.accessor.double-colon +# ^^^^^^^^ support.other.namespace +# ^^ punctuation.accessor.double-colon +# ^^^^^^^ entity.name.class +# ^ punctuation.separator.inheritance +# ^^^^^^^^^^^^^^^^^^^^^^^^ entity.other.inherited-class +# ^^ punctuation.accessor.double-colon + + def my_method(param1, param2) +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function +# ^^^ keyword.declaration.function +# ^^^^^^^^^ entity.name.function +# ^^^^^^^^^^^^^^^^ meta.function.parameters +# ^ punctuation.definition.group.begin +# ^ punctuation.separator - variable.parameter +# ^ punctuation.definition.group.end + end + + def self.my_second_method *arg_without_parens # comment +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function +# ^^^ keyword.declaration.function +# ^^^^ variable.language +# ^ punctuation.accessor.dot +# ^^^^^^^^^^^^^^^^ entity.name.function +# ^^^^^^^^^^^^^^^^^^^ meta.function.parameters +# ^ keyword.operator.splat +# ^^^^^^^^^^^^^^^^^^ variable.parameter +# ^^^^^^^^^ comment.line.number-sign + end + + def self.my_third_method(a, b="foo", c=[], d=foo(), *args) +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function +# ^^^ keyword.declaration.function +# ^^^^ variable.language +# ^ punctuation.accessor.dot +# ^^^^^^^^^^^^^^^ entity.name.function +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters +# ^ punctuation.definition.group.begin +# ^ variable.parameter +# ^ punctuation.separator - variable.parameter +# ^ variable.parameter +# ^^^^^^ meta.function.parameters.default-value +# ^ keyword.operator - variable.parameter +# ^^^^^ string.quoted - variable.parameter +# ^ punctuation.separator +# ^ variable.parameter +# ^ keyword.operator.assignment +# ^^ punctuation.section.array +# ^ punctuation.separator +# ^ variable.parameter +# ^ keyword.operator.assignment +# ^^ punctuation.definition.group +# ^ punctuation.separator +# ^ keyword.operator +# ^^^^ variable.parameter +# ^ punctuation.definition.group.end + end + + def nested((a, b), c, (d, *e)) +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function +# ^^^ keyword.declaration.function +# ^^^^^^ entity.name.function +# ^^^^^^^^^^^^^^^^^^^^ meta.function.parameters +# ^ punctuation.definition.group.begin +# ^ punctuation.definition.group.begin +# ^ variable.parameter +# ^ punctuation.separator +# ^ variable.parameter +# ^ punctuation.definition.group.end +# ^ punctuation.separator +# ^ variable.parameter +# ^ punctuation.separator +# ^ punctuation.definition.group.begin +# ^ variable.parameter +# ^ punctuation.separator +# ^ keyword.operator.splat +# ^ variable.parameter +# ^^ punctuation.definition.group.end + end + + def block_param(&block) +# ^^^ keyword.declaration.function +# ^^^^^^^^ meta.function.parameters +# ^ keyword.operator +# ^^^^^ variable.parameter + end + + def keyword_args a: nil, b: true +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function +# ^^^^^^^^^^^^^^^ meta.function.parameters +# ^^^^^ meta.function.parameters.default-value +# ^ punctuation.separator +# ^^^ constant.language +# ^ punctuation.separator +# ^ punctuation.separator +# ^^^^ constant.language + end + + def multiline_args(a, # a comment +# ^^^^^^^^^^^^^^^^^^^^^ meta.function +# ^^ meta.function.parameters +# ^ punctuation.separator +# ^^^^^^^^^^^ comment.line.number-sign + b) +# ^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters +# ^ punctuation.definition.group.end + end +end + +def MyModule::module_method +#^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function +# ^^^^^^^^^^^^^^^^^^^^^^^ entity.name.function +# ^^^^^^^^ support.other.namespace +# ^^ punctuation.accessor.double-colon + super /pattern/ +# ^^^^^ support.function.builtin.ruby +# ^^^^^^^^^ meta.string.regexp.ruby +end + +def my_function +#^^^^^^^^^^^^^^ meta.function +# ^^^^^^^^^^^ entity.name.function +end + +f = MyModule::MyClass.new +# ^^ punctuation.accessor.double-colon + +def f.my_instance_method +#^^^^^^^^^^^^^^^^^^^^^^^ meta.function +# ^^^^^^^^^^^^^^^^^^^^ entity.name.function +# ^ punctuation.accessor.dot +end + +class MyClass +# ^ meta.class.ruby keyword.declaration.class.ruby +# ^ meta.class.ruby entity.name.class.ruby + + prepend Module.new +# ^ keyword.other.special-method.ruby +# ^ support.class.ruby +# ^ keyword.other.special-method.ruby + + + A, B, C = :a, :b, :c +# ^ meta.constant.ruby entity.name.constant.ruby +# ^ punctuation.separator.sequence.ruby +# ^ meta.constant.ruby entity.name.constant.ruby +# ^ punctuation.separator.sequence.ruby +# ^ meta.constant.ruby entity.name.constant.ruby +end + + +################## +# Well-known methods +################## + +puts "Output" +# <- support.function.builtin + +abort "Ending" +# <- support.function.builtin + +exit! 2 +#^^^^ support.function.builtin + +get :name, -> { "John" } +# ^^ meta.function.ruby keyword.declaration.function.anonymous.ruby + +################## +# Symbol literals +################## + + FIELDS = %i[a b c] +# ^^^^^^ meta.constant.ruby entity.name.constant.ruby +# ^ keyword.operator.assignment.ruby +# ^^^ punctuation.definition.string.begin.ruby +# ^ constant.other.symbol.ruby +# ^ constant.other.symbol.ruby +# ^ constant.other.symbol.ruby +# ^ punctuation.definition.string.end.ruby + + %i(a b c) +# ^^^ punctuation.definition.string.begin.ruby +# ^ constant.other.symbol.ruby +# ^ constant.other.symbol.ruby +# ^ constant.other.symbol.ruby +# ^ punctuation.definition.string.end.ruby + + %I[#{'a'} b #@c#@@d e] +# ^^^ meta.string.ruby - meta.interpolation +# ^^ source.ruby meta.string.ruby meta.interpolation.ruby punctuation.section.interpolation.begin.ruby +# ^^^ meta.string.ruby meta.interpolation.ruby meta.string.ruby +# ^ source.ruby meta.string.ruby meta.interpolation.ruby punctuation.section.interpolation.end.ruby +# ^ constant.other.symbol.ruby +# ^^^^^^^ meta.string.ruby meta.interpolation.ruby - string +# ^ constant.other.symbol.ruby +# ^ punctuation.definition.string.end.ruby + +################## +# String literals +################## + + %w[a b c] +# ^^^ punctuation.definition.string.begin.ruby +# ^^^^^ string.quoted.other.literal.lower.ruby +# ^ punctuation.definition.string.end.ruby + + %w(a b c) +# ^^^ punctuation.definition.string.begin.ruby +# ^^^^^ string.quoted.other.literal.lower.ruby +# ^ punctuation.definition.string.end.ruby + +################## +# Tokens with Multiple Meanings +################## + +method? 1 +# ^ - keyword.operator + +(methodname)?foobar : baz +# ^ keyword.operator.conditional +# ^ keyword.operator.conditional + +methodname ?foo : baz +# ^ keyword.operator.conditional +# ^ keyword.operator.conditional + +puts 1 ?1 : 2 +# ^ keyword.operator.conditional +# ^ constant.numeric +# ^ keyword.operator.conditional + +puts 1 ?12 : 2 +# ^ keyword.operator.conditional +# ^^ constant.numeric +# ^ keyword.operator.conditional + +puts ?1 +# ^^ constant.character.ruby + +puts 1 ? foo:bar +# ^ keyword.operator.conditional +# ^ keyword.operator.conditional +# ^^^ - constant.other.symbol + +puts 1 ? foo::baz:bar +# ^ keyword.operator.conditional +# ^^ punctuation.accessor.double-colon +# ^^^ - constant.other.symbol +# ^ keyword.operator.conditional + +puts foo: bar +# ^^^^ constant.other.symbol + + +################## +# Regular expressions vs division operator +################## + +"foo".sub /t{1,}/i +# ^^^^^^^^ string.regexp +# ^ keyword.other +"foo".sub! /t{1,}/i +# ^^^^^^^^ string.regexp +# ^ keyword.other +"foo".sub!(/t{1,}/i) +# ^^^^^^^^ string.regexp +# ^ keyword.other +"foo".gsub /t{1,}/i +# ^^^^^^^^ string.regexp +# ^ keyword.other +"foo".gsub! /t{1,}/i +# ^^^^^^^^ string.regexp +# ^ keyword.other +"foo".gsub!(/t{1,}/i) +# ^^^^^^^^ string.regexp +# ^ keyword.other +"foo".eql? /t{1,}/i +# ^^^^^^^^ string.regexp +# ^ keyword.other +"foo".eql?(/t{1,}/i) +# ^^^^^^^^ string.regexp +# ^ keyword.other +'foo'.match? /t{1,}/i +# ^^^^^^^^ string.regexp +# ^ keyword.other +'foo'.match?(/t{1,}/i) +# ^^^^^^^^ string.regexp +# ^ keyword.other +'foo'.matches?(/t{1,}/i) +# ^^^^^^^^ string.regexp +# ^ keyword.other + +a = /(foo)*baz/m +# ^^^^^^^^^^^^ string.regexp + +a = /{foo}*baz/m +# ^^^^^^^^^^^^ string.regexp + +a = /?foo*baz/m +# ^^^^^^^^^^^ string.regexp + +a = /=foo/m +# ^^ keyword.operator.assignment.augmented.ruby +# ^^^^^^^ - string.regexp + +begin +# <- keyword.control.block.begin +end while /foo/ =~ bar +# ^^^^^ string.regexp + +if /foo/i =~ baz +# <- keyword.control.conditional.if +# ^^^^^^ string.regexp +# ^^ keyword.operator +end +# <- keyword.control.block.end.ruby + +if baz =~ /foo/i +# ^^ keyword.operator +# ^^^^^^ string.regexp +end +# <- keyword.control.block.end.ruby + +['a()', 'b()'].select { |var| /^a\(/ =~ var } +# ^^^^^^ string.regexp + +{foo: /bar/} +# ^^^^^ string.regexp + +str = "#{('A'.ord + index / (26*26) - 1).chr}" +# ^ keyword.operator +# ^^ constant.numeric +# ^ keyword.operator + +if 1 / 2 == 3 +# ^ keyword.operator +# ^^ keyword.operator +end + +a = 1 / 2 +# ^ keyword.operator.arithmetic + +b = testing! / foo +# ^ keyword.operator.arithmetic + +rule /`/ do +# ^^^ string.regexp +# ^ - string.regexp string.regexp +# ^^ keyword.control.block.do +end + +################## +# Crazy Stuff Found Online™ +################## + +( +def huh?(a, b=def huh?(a); "h?"; end) +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters +# ^^^^^^^^^^^ meta.function meta.function +# ^^^ meta.function.parameters meta.function.parameters +#^^ keyword.declaration.function +# ^ variable.parameter + a +end + +p huh?("H", 1) + huh?("u") + huh?("gs") +) + + +# issue #923 +foo = 2 / @d +# ^^ - string.regexp.classic +# ^ variable.other.readwrite.instance punctuation.definition.variable +# ^ keyword.operator.arithmetic.ruby + +# issue #933 +a = b / "c" +# ^^^ string.quoted.double.ruby - string.regexp.classic.ruby +# ^ keyword.operator.arithmetic.ruby + +foo / "bar/bla" +# ^ keyword.operator.arithmetic.ruby +# ^^^^^^^^^ string.quoted.double.ruby + +{ + /foo/ => :foo +# ^^^^^ string.regexp.classic.ruby +} + + assert_no_match /1/, "2" +# ^^^^^^^^^^^^^^^ support.function.builtin.ruby +# ^ punctuation.definition.string.begin.ruby +# ^^^ meta.string.regexp.ruby string.regexp.classic.ruby +# ^ punctuation.definition.string.end.ruby +# ^ punctuation.separator.sequence.ruby +# ^^^ string.quoted.double.ruby + +# issue #2181 +foo << bar if baz.include?(x) +# ^^ keyword.control.conditional.if.ruby +foo << bar.baz if baz.include?(x) +# ^^ keyword.control.conditional.if.ruby +foo << bar.assert_match if baz.include?(x) +# ^^ keyword.control.conditional.if.ruby +foo << bar.to_s if baz.include?(x) +# ^^ keyword.control.conditional.if.ruby