Code Monkey home page Code Monkey logo

microsoft / vscode-textmate Goto Github PK

View Code? Open in Web Editor NEW
540.0 58.0 106.0 5.87 MB

A library that helps tokenize text using Text Mate grammars.

License: MIT License

JavaScript 2.50% TypeScript 88.24% CSS 1.30% Go 0.49% HTML 1.01% Java 0.23% Makefile 0.22% Rust 0.21% CoffeeScript 0.24% Batchfile 0.20% C 0.33% C++ 0.40% Clojure 0.48% F# 0.25% Groovy 1.57% Lua 0.10% Objective-C 0.56% PHP 0.32% Perl 0.77% PowerShell 0.57%
grammar grammar-files textmate vscode

vscode-textmate's Introduction

VSCode TextMate Build Status

An interpreter for grammar files as defined by TextMate. TextMate grammars use the oniguruma dialect (https://github.com/kkos/oniguruma). Supports loading grammar files from JSON or PLIST format. This library is used in VS Code. Cross - grammar injections are currently not supported.

Installing

npm install vscode-textmate

Using

const fs = require('fs');
const path = require('path');
const vsctm = require('vscode-textmate');
const oniguruma = require('vscode-oniguruma');

/**
 * Utility to read a file as a promise
 */
function readFile(path) {
    return new Promise((resolve, reject) => {
        fs.readFile(path, (error, data) => error ? reject(error) : resolve(data));
    })
}

const wasmBin = fs.readFileSync(path.join(__dirname, './node_modules/vscode-oniguruma/release/onig.wasm')).buffer;
const vscodeOnigurumaLib = oniguruma.loadWASM(wasmBin).then(() => {
    return {
        createOnigScanner(patterns) { return new oniguruma.OnigScanner(patterns); },
        createOnigString(s) { return new oniguruma.OnigString(s); }
    };
});

// Create a registry that can create a grammar from a scope name.
const registry = new vsctm.Registry({
    onigLib: vscodeOnigurumaLib,
    loadGrammar: (scopeName) => {
        if (scopeName === 'source.js') {
            // https://github.com/textmate/javascript.tmbundle/blob/master/Syntaxes/JavaScript.plist
            return readFile('./JavaScript.plist').then(data => vsctm.parseRawGrammar(data.toString()))
        }
        console.log(`Unknown scope name: ${scopeName}`);
        return null;
    }
});

// Load the JavaScript grammar and any other grammars included by it async.
registry.loadGrammar('source.js').then(grammar => {
    const text = [
        `function sayHello(name) {`,
        `\treturn "Hello, " + name;`,
        `}`
    ];
    let ruleStack = vsctm.INITIAL;
    for (let i = 0; i < text.length; i++) {
        const line = text[i];
        const lineTokens = grammar.tokenizeLine(line, ruleStack);
        console.log(`\nTokenizing line: ${line}`);
        for (let j = 0; j < lineTokens.tokens.length; j++) {
            const token = lineTokens.tokens[j];
            console.log(` - token from ${token.startIndex} to ${token.endIndex} ` +
              `(${line.substring(token.startIndex, token.endIndex)}) ` +
              `with scopes ${token.scopes.join(', ')}`
            );
        }
        ruleStack = lineTokens.ruleStack;
    }
});

/* OUTPUT:

Unknown scope name: source.js.regexp

Tokenizing line: function sayHello(name) {
 - token from 0 to 8 (function) with scopes source.js, meta.function.js, storage.type.function.js
 - token from 8 to 9 ( ) with scopes source.js, meta.function.js
 - token from 9 to 17 (sayHello) with scopes source.js, meta.function.js, entity.name.function.js
 - token from 17 to 18 (() with scopes source.js, meta.function.js, punctuation.definition.parameters.begin.js
 - token from 18 to 22 (name) with scopes source.js, meta.function.js, variable.parameter.function.js
 - token from 22 to 23 ()) with scopes source.js, meta.function.js, punctuation.definition.parameters.end.js
 - token from 23 to 24 ( ) with scopes source.js
 - token from 24 to 25 ({) with scopes source.js, punctuation.section.scope.begin.js

Tokenizing line:        return "Hello, " + name;
 - token from 0 to 1 (  ) with scopes source.js
 - token from 1 to 7 (return) with scopes source.js, keyword.control.js
 - token from 7 to 8 ( ) with scopes source.js
 - token from 8 to 9 (") with scopes source.js, string.quoted.double.js, punctuation.definition.string.begin.js
 - token from 9 to 16 (Hello, ) with scopes source.js, string.quoted.double.js
 - token from 16 to 17 (") with scopes source.js, string.quoted.double.js, punctuation.definition.string.end.js
 - token from 17 to 18 ( ) with scopes source.js
 - token from 18 to 19 (+) with scopes source.js, keyword.operator.arithmetic.js
 - token from 19 to 20 ( ) with scopes source.js
 - token from 20 to 24 (name) with scopes source.js, support.constant.dom.js
 - token from 24 to 25 (;) with scopes source.js, punctuation.terminator.statement.js

Tokenizing line: }
 - token from 0 to 1 (}) with scopes source.js, punctuation.section.scope.end.js

*/

For grammar authors

See vscode-tmgrammar-test that can help you write unit tests against your grammar.

API doc

See the main.ts file

Developing

  • Clone the repository
  • Run npm install
  • Compile in the background with npm run watch
  • Run tests with npm test
  • Run benchmark with npm run benchmark
  • Troubleshoot a grammar with npm run inspect -- PATH_TO_GRAMMAR PATH_TO_FILE

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

License

MIT

vscode-textmate's People

Contributors

aeschli avatar alexdima avatar asottile avatar bpasero avatar chrisdias avatar dbaeumer avatar deepak1556 avatar dependabot[bot] avatar hediet avatar kieferrm avatar lramos15 avatar lszomoru avatar mjbvz avatar msftgits avatar msftrncs avatar notwearingpants avatar rzhao271 avatar yanpas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vscode-textmate's Issues

invalid backref number/name when parsing ruby

Take the ruby file from https://github.com/Homebrew/homebrew/blob/master/Library/Homebrew/os/mac/xcode.rb and paste it into VS Code, you get an exception: the mode failed to tokenize the input

invalid backref number/name: Error: invalid backref number/name
at Error (native)
at createOnigScanner (/home/martinae/VSCode-linux-x64/resources/app/node_modules/vscode-textmate/release/main.js:565:16)
at RegExpSourceList.compile (/home/martinae/VSCode-linux-x64/resources/app/node_modules/vscode-textmate/release/main.js:607:30)
at BeginEndRule.compile (/home/martinae/VSCode-linux-x64/resources/app/node_modules/vscode-textmate/release/main.js:735:45)
at matchRule (/home/martinae/VSCode-linux-x64/resources/app/node_modules/vscode-textmate/release/main.js:1148:60)
at matchRuleOrInjections (/home/martinae/VSCode-linux-x64/resources/app/node_modules/vscode-textmate/release/main.js:1160:23)
at scanNext (/home/martinae/VSCode-linux-x64/resources/app/node_modules/vscode-textmate/release/main.js:1193:17)
at _tokenizeString (/home/martinae/VSCode-linux-x64/resources/app/node_modules/vscode-textmate/release/main.js:1189:9)
at Grammar.tokenizeLine (/home/martinae/VSCode-linux-x64/resources/app/node_modules/vscode-textmate/release/main.js:1049:9)
at e.tokenize (file:////home/martinae/VSCode-linux-x64/resources/app/out/vs/workbench/workbench.main.js:1625:2260)

x64 bug in extension regex processing causes runaway memory use

From @coe-jeubanks on September 29, 2017 17:38

  • VSCode Version: Code 1.16.1 (27492b6bf3acb0775d82d2f87b25a93490673c6d, 2017-09-14T16:38:23.027Z)
  • OS Version: Windows_NT x64 10.0.15063
  • Extensions:
Extension Author (truncated) Version
plsql cas 0.0.3
jet dio 0.0.1
xml Dot 1.9.2
backspace-plusplus jri 0.0.16
csharp ms- 1.12.1
PowerShell ms- 1.4.3
SQR Cit 0.2.5

(1 theme extensions excluded)


Extension processing using x64 version of VS Code improperly handles single quote regex match of "('(?:\\'|.)*?')" with a string containing a pound sign character (e.g. 'string#'). Symptom is runaway memory use until the workstation becomes unresponsive.

Steps to Reproduce:

  1. Install SQR 0.2.5 extension
  2. Open a file containing a single line: print 'Emp# ' (+1,1)

Reproduces without extensions: No

Copied from original issue: microsoft/vscode#35391

Freeze with large unicode range and case insensitivity

From
microsoft/vscode#40279

Create a PHP file with

<?php
$img = "data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAABQAAD/4QMraHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjMtYzAxMSA2Ni4xNDU2NjEsIDIwMTIvMDIvMDYtMTQ6NTY6MjcgICAgICAgICI+IDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+IDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiIHhtbG5zOnhtcD0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLyIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bXA6Q3JlYXRvclRvb2w9IkFkb2JlIFBob3Rvc2hvcCBDUzYgKFdpbmRvd3MpIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOjk3QzYwMjlGNkM2MDExRTc4RUFDQjQwNkJDQjRCMEUwIiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOjk3QzYwMkEwNkM2MDExRTc4RUFDQjQwNkJDQjRCMEUwIj4gPHhtcE1NOkRlcml2ZW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AAAAAAAAAAAAAAAgC4AAAAAAAAAAAAAAAAAIAuAAAAAAAAAAAAAAAAACALgAAAAAAAAAAAAAAAAAgC4AAAAAAAAAAAAAAAAAIAuAAAAAAAAAAAAAAAAACALgAAAAAAAAAAAAAAAAAgC4AAAAAAAAAAAAAAAAAIEioAAAAAAAAAAAAAAAAAJH/2gAIAQEAAQUChCHMK1laytZWsrWVrK1laytZWsrWVrK1laytZWsrWVrK1laytZWsrWVrK1laytZWsrWVrK1laytZWsrWVrJQh+19eySyvr2SWV9eySyvr2SWV9eySyvr2SWV9eySyvr15erjjn6z6z6z6zj18fvXllfXr+TLGxUKfFn8+vGvLK+vX8mfSqUjzqnxNjOF8KbFp68a8sr69fy/8OPVHmeBrLJQlzCXolxOGvLK+vX/ANc8cFs/8f0pZX168vMuXPyLPkWfIs+RZx5l8c68sr69kllfXsksr69kllfXsksr69kllfXsksr69kllfXsksr69klmE4cQsWWLLFliyxZYssWWLLFliyxZYssWWLLFliyxZYssWWLLFliyxZYssWWLLFliyxZYssWWLLFliyxZYslOH7//aAAgBAgABBQL8yH//2gAIAQMAAQUC/Mh//9oACAECAgY/AmQ//9oACAEDAgY/AmQ//9oACAEBAQY/AoKsEVVRNV0KRYpFikWKRYpFikWKRYpFikWKRYpFikWKRYpFikWKRYpFikWKRYpFikWKRYpFikWKRYpFikWKRYpFikWKRYpFikWKRYpFikWIf0Tyvnx9FIYp2Xjy2UhinZePLZSGKdl48tlIYp2Xjy2UhinZePLZSGKdl48tlIYp2Xjy2UhinQaJH8vqfr+5+v7n6/ufr+55jonz6Djy2UhinQch58qvohppovxh0HHlspDFOg5P4ElHzp6oflJPxRDVf4QXTwqexDoOPLZSGKdByqppppH2kamvt/kSSexxyToOPLZSGKdBKPsvr8P+evj46e3QceWykMU6DXymvyPWR6yPWR6yNfK/Reg48tlIYp2Xjy2UhinZePLZSGKdl48tlIYp2Xjy2UhinZePLZSGKdl48tlIYp2Xjy2UhinZePLZSGKdl48tlIIs0RURNU1Lxc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AAAAASAAAAAAAAAAAAAAAAAAQSSSSSSSSSSSSSSSSSSD/2gAIAQEDAT8QeJiAYRtttbtkfsR+xH7EfsR+xH7EfsR+xH7EfsR+xH7EfsR+xH7EfsR+xH7EfsR+xH7EfsR+xH7EfsR+xH7EfsR+xH7EfsR+xH7EfsR+xH7DVMUJC2A9t1VJkfx0ZXH8dGVx/HRlcfx0ZXH8dGVx/HRlcfx0ZXH8egcuFrtnThVbFXM6uZ1czq5m5+lGm1Xy1Rt0KuP49Aiq0Va7/wAh9uqPKdO7b8IRRlqhyaRd6PYouCi4EVeirTr+F0KuP49B7P7BmzZivelappee4k6FBaIH2d6biMtu+Sbz+EVQO/ibo+zXKIfhdCrj+PQN0C7rskt7N9PVD3+jSmyYukm2eyS3bNxy3T4Tz933Y3Kjt14Tyn9GPm7r5ISq326FXH8eg2QnaLldE/pv8FaoWirTsdquPj55yO1aUrToVcfx6B+m4oBU+7o2/wAq1atW87qapgzXKSdCrj+OjK4/joyuP46Mrj+OjK4/joyuP46Mrj+OjK4/joyuP46MrWJiAQRNNN7NEfuR+5H7kfuR+5H7kfuR+5H7kfuR+5H7kfuR+5H7kfuR+5H7kfuR+5H7kfuR+5H7kfuR+5H7kfuR+5H7kfuR+5H7kfuR+5H7jVMWJi3A99lVpH//2gAIAQIDAT8Q+ch//9oACAEDAwE/EPnIf//Z";

The regex that causes the freeze is
(?i)([a-z_\x{7f}-\x{7fffffff}\\][a-z0-9_\x{7f}-\x{7fffffff}\\]*)(?=\s*::)
Removing the (?i) or removing \x{7f}-\x{7fffffff} fixes the issue.

Interestingly it doesnt freeze in Atom, so maybe there is some trick or Oniguruma update that we miss.

[Proposal] Add API to map tokens in a given scope to specific token types (string/comment/other)

Problem
Many languages use strings as more than just strings. A classic example is JavaScript require/import paths:

import 'a/b/c.js'

Here the string 'a/b/c.js' has a special role (import path) distinct from that of a normal string.

When editing such strings, we'd really like the experience to be more like when you are working in any other part of the language. That includes enabling quickSuggestions and other language features. However these language features are currently disabled inside of all strings

Proposal
Add a new tokenTypeMap that maps scopes to a StandardTokenType. This map would behave similarly to the existing IEmbeddedLanguagesMap.

For the above import path example, we'd create a map:

{
     "meta.import.path.ts": StandardTokenType.Other
}

and pass this to the grammar engine. During parsing, the map would be consulted so that tokens in scopes such as:

  • unicorn.import.sep.ts
  • meta.import.path.ts
  • string.quoted.single.ts
  • meta.import.ts
  • source.ts

Would have type Other rather than type String.

Doesn't support excluding scope selector in *.tmTheme files

I have tried tokenizeLine2 method to highlight some codes, but find it cannot recognize any excluding scope selectors(like string - meta.template.expression) in *.tmTheme files. This kind of scope selector are useful in some cases, so could it be supported?

Problem with end rules matching on end line

With Jade there's a problem with empty lines. See microsoft/vscode#4287.

Problem is the following example:

.ssdsd

    // asdsdas

The comment is not correctly highlighted.

It looks like the engine enters the following rule for empty lines, but doesn't exit
{
"begin": "^\s*",
"comment": "All constructs that generally span a single line starting with any number of white-spaces.",
"end": "$",
"patterns": [
....
}

===========================================
TOKENIZING LINE 1
.ssdsd

  LINE CONTAINS 1 TOKENS:
    => TOKEN (0-7): 
      .ssdsd
      * text.jade

  LINE END RULE STACK CONTAINS 1 RULES:
      * [1,1] IncludeOnlyRule "text.jade", entered @-1


===========================================
TOKENIZING LINE 2


  LINE CONTAINS 1 TOKENS:
    => TOKEN (0-1): 

      * text.jade

  LINE END RULE STACK CONTAINS 2 RULES:
      * [100,2] BeginEndRule "null", entered @0
      * [1,1] IncludeOnlyRule "text.jade", entered @-1


===========================================
TOKENIZING LINE 3
    // asdsdas

  LINE CONTAINS 2 TOKENS:
    => TOKEN (0-7): 
          // 
      * text.jade
    => TOKEN (7-14): 
      asdsdas
      * text.jade
      * meta.tag.other entity.name.tag.jade

  LINE END RULE STACK CONTAINS 1 RULES:
      * [1,1] IncludeOnlyRule "text.jade", entered @-1

Multiple ScopeName Configurations

Hello, I need to specify language configurations for different scopes in the same file. Specifically I'm making a grammar that highlights tagged template strings for Ember components. In the source.js scope I need comment bindings to use JS comment bindings, and inside the meta.source.glimmer scope (which is inside the tagged template string), I need comment bindings to use Handlebars comments: {{! }}

We're currently doing this in an Atom plugin by using grammar injection, but I see that grammar injection is not supported in VSCode, is that correct?

If this isn't the correct repo for this issue let me know.

Thanks

C's preprocessor directive #ifdef/#endif grays out code

example 1:
screen shot 2018-02-22 at 16 47 06
example 2:
screen shot 2018-02-22 at 16 47 37
example 3:
screen shot 2018-02-22 at 16 48 16

Though not defined in code, those symbols (FILESYS, USERPROG..) are to be passed in by the compiler (GCC's -D option), so the code segments are, in fact, active. Textmate shouldn't act on its own and render them as inactive.

How to define begin and end patterns which span multiple lines?

Hi, I'm trying to expand the support for my plugin, graphql-for-vscode, to support gherkin feature files, but I'm stuck while defining the grammer. The begin regexp seems to not do any matching when I specify a newline (\n):

Specifically:

With this syntax definition:

{
  "fileTypes": ["feature"],
  "scopeName": "text.gherkin.feature.graphql",
  "injectionSelector": "L:text -comment",
  "patterns": [
    {
      "begin": "graphql request\\s+\"\"\"",
      "end": "\"\"\"",
      "patterns": [
        {
          "name": "featureGQL",
          "include": "source.graphql"
        }
      ]
    }
  ]
}

I don't get any matches:
image

but modifying the source text to bring the beginning """ to the same line as graphql request does the trick:

image

I tried modifying the begin regexp to be: "begin": "graphql request\\n\\s+\"\"\"", but it didn't help - in fact, it stopped highlighting anything within quotes.

I've spent some time browsing other syntaxes in vscode and textmate, but could only find \n to be used in match regexp sections, but none yet in begin or end sections.

Unsupported textmate grammar (that contains non-advancing match rules)

This textmate grammar:
https://github.com/Benvie/JavaScriptNext.tmLanguage/blob/master/JavaScriptNext.tmLanguage

Doesn't work, shows the following error:
(command line)
[3400:0401/162730:INFO:CONSOLE(1270)] "Grammar is in an endless loop - case 3", source: (...)/vscode/node_modules/vscode-textmate/release/main.js (1270)

(chrome console, stacktrace)

Grammar is in an endless loop - case 3scanNext 

@ (...)/vscode/node_modules/vscode-textmate/release/main.js:127
0 (...)/vscode/node_modules/vscode-textmate/release/main.js:1270 Grammar is in an endless loop - case 3scanNext 
@ (...)/vscode/node_modules/vscode-textmate/release/main.js:1270_tokenizeString 
@ (...)/vscode/node_modules/vscode-textmate/release/main.js:1207Grammar.tokenizeLine 
@ (...)/vscode/node_modules/vscode-textmate/release/main.js:1067Tokenizer.tokenize 
@ TMSyntax.ts:223tokenize 
@ TMSyntax.ts:125_tokenizeLine 
@ textToHtmlTokenizer.ts:100_tokenizeLines 
@ textToHtmlTokenizer.ts:90_tokenizeToString 
@ textToHtmlTokenizer.ts:73tokenizeToString 
@ textToHtmlTokenizer.ts:17container.appendChild.htmlContentRenderer_1.renderHtml.codeBlockRenderer 
@ modesContentHover.ts:271_renderHtml 
@ htmlContentRenderer.ts:65renderHtml 
@ htmlContentRenderer.ts:35(anonymous function) 
@ modesContentHover.ts:247(anonymous function) 
@ modesContentHover.ts:246ModesContentHoverWidget._renderMessages 
@ modesContentHover.ts:226ModesContentHoverWidget._withResult 
@ modesContentHover.ts:212(anonymous function) 
@ modesContentHover.ts:141HoverOperation._onComplete 
@ hoverOperation.ts:143HoverOperation._triggerSyncComputation 
@ hoverOperation.ts:117(anonymous function) 
@ hoverOperation.ts:71RunOnceScheduler.onTimeout 
@ async.ts:566

Support ELECTRON_RUN_AS_NODE

Our next update of Electron will remove the deprecated ATOM_SHELL_INTERNAL_RUN_AS_NODE. To support both old and new world, I suggest to set both flags wherever you set ATOM_SHELL_INTERNAL_RUN_AS_NODE currently.

`main.d.ts` no longer in version control

Is there a reason the main.d.ts declaration file is no longer in the repo?

I see that the release.js creates it, but it would really help me out if you guys could go back to tracking it under version control. It may seem like an odd request, but that file is actually pretty crucial to a project I'm working on.

I'm currently working on a helper extension for the syntax grammars used by the Ionide-FSharp extension for vscode.

syntax

The idea is to have an extension that you can keep reloading quickly to test out the changes you've made to the syntax grammars. Launch the extension, it opens to an F# file with lots of tricky syntax, make a tweak, rebuild, rinse, repeat. It's pretty sweet.

But the way we build our vscode extensions is a bit different from how everyone else does. We use the fable-compiler to transpile F# code into js. ts2fable is the tool we use to create F# interfaces that we can code against, like this one for the vscode api, by parsing typescript declaration files. That's what I need the main.d.ts for. vscode-textmate will let me add a lot more detailed feedback information about how the source code is being tokenized.

I know the main.d.ts is a part of the npm module that's installed, but using that particular file in the build process we need to go through for the F# to js transpilation is a bit difficult, and we don't get the same kind of control and precision about what version of the file we want to lock into the build process. Paket is the package manager of choice for F# and one of it's great features is setting up github dependencies, which lets us lock a file to a particular hash for our builds. e.g.

github Microsoft/vscode-textmate:master release/main.d.ts (997c9419fb1cc03256d63e1042609742b30ee7e4)

This is the most reliable way to have reproducible builds, which I'd like to do my best to ensure for the people willing to put the time and effort into using this extension to improve our syntax grammars.

Sorry for the long winded and convoluted explanation, but the declaration file is one of the cornerstones to what I'm working on and it'd be really great if you could help me out.

BTW - getting node-gyp to work on my windows machine was an absolute nightmare. Once I've whittled down the steps to the precise process without all the fiddling I had to do, I'll PR it onto the readme so no one else has to go through that mess 😵

TextMate grammar regexes able to only match a single line

From @tambry on December 31, 2016 16:20

Image of improper multiline syntax highlighting

Everything between the parentheses should be coloured green, but the matching stops after the first line ends.

  • VSCode Version: 1.8.1
  • OS Version: Ubuntu 16.10 64-bit (4.8.0-30-generic)

Steps to Reproduce:

  1. Clone this minimal repro sample.
  2. Open the folder of the sample in VS Code.
  3. Press F5 to run the extension in a new VS Code instance.
  4. In the new instance open the test.matchbug file that's in the repro sample's root directory.
  5. Code is improperly highlighted.

How the regex should match

Copied from original issue: microsoft/vscode#17964

vscode-textmate doesn't build with recent versions of TypeScript

  • VSCode Version: Code 1.16.0 (787b31c0474e6165390b5a5989c9619e3e16f953, 2017-09-06T16:12:42.401Z)
  • OS Version: Darwin x64 16.7.0
  • Extensions: n/a

To reproduce clone then npm install, prepublish step fails (with child_process error from tsc).

Reverting to [email protected] (the version in the package.json) fixes the issue.

~/Source/vscode
$ git clone [email protected]:Microsoft/vscode-textmate.git
Cloning into 'vscode-textmate'...
remote: Counting objects: 1691, done.
remote: Total 1691 (delta 0), reused 0 (delta 0), pack-reused 1691
Receiving objects: 100% (1691/1691), 2.10 MiB | 2.06 MiB/s, done.
Resolving deltas: 100% (1032/1032), done.

~/Source/vscode
$ cd vscode-textmate/

~/Source/vscode/vscode-textmate master
$ npm install
npm WARN deprecated [email protected]: Typings is deprecated in favor of NPM @types -- see README for more information
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue

> [email protected] install /Users/mike/Source/vscode/vscode-textmate/node_modules/oniguruma
> node-gyp rebuild

    ... oniguruma compilation output ...

npm WARN prepublish-on-install As of npm@5, `prepublish` scripts are deprecated.
npm WARN prepublish-on-install Use `prepare` for build steps and `prepublishOnly` for upload-only.
npm WARN prepublish-on-install See the deprecation note in `npm help scripts` for more information.

> [email protected] prepublish /Users/mike/Source/vscode/vscode-textmate
> node scripts/release.js

child_process.js:634
    throw err;
    ^

Error: Command failed: node node_modules/typescript/bin/tsc
    at checkExecSyncError (child_process.js:591:13)
    at Object.execSync (child_process.js:631:13)
    at Object.<anonymous> (/Users/mike/Source/vscode/vscode-textmate/scripts/release.js:5:4)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Function.Module.runMain (module.js:609:10)
    at startup (bootstrap_node.js:158:16)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] prepublish: `node scripts/release.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] prepublish script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/mike/.npm/_logs/2017-09-10T03_21_16_772Z-debug.log

~/Source/vscode/vscode-textmate master
$ node_modules/typescript/bin/tsc --version
Version 2.5.2

~/Source/vscode/vscode-textmate master
$ node_modules/typescript/bin/tsc
src/types.ts(31,2): error TS2411: Property '$vscodeTextmateLocation' of type 'ILocation' is not assignable to string index type 'IRawRule'.
src/types.ts(60,2): error TS2411: Property '$vscodeTextmateLocation' of type 'ILocation' is not assignable to string index type 'IRawRule'.

~/Source/vscode/vscode-textmate master
$ tsc --version
Version 2.4.1

~/Source/vscode/vscode-textmate master
$ tsc
src/types.ts(31,2): error TS2411: Property '$vscodeTextmateLocation' of type 'ILocation' is not assignable to string index type 'IRawRule'.
src/types.ts(60,2): error TS2411: Property '$vscodeTextmateLocation' of type 'ILocation' is not assignable to string index type 'IRawRule'.

~/Source/vscode/vscode-textmate master
$ npm install [email protected] --force
npm WARN using --force I sure hope you know what you are doing.
npm notice created a lockfile as package-lock.json. You should commit this file.
+ [email protected]
updated 1 package in 2.116s

~/Source/vscode/vscode-textmate master ?
$ node_modules/typescript/bin/tsc --version
Version 2.0.8

~/Source/vscode/vscode-textmate master ?
$ node_modules/typescript/bin/tsc

~/Source/vscode/vscode-textmate master ?
$

Support lookbehind begin rules

For an injection grammar:

{
	"fileTypes": [],
	"injectionSelector": "L:string.template.tsx",
	"patterns": [
		{
			"include": "#superjs-code-block"
		}
	],
	"repository": {
		"superjs-code-block": {
			"begin": "(?<=superjs`)",
			"end": "end",
			"patterns": [
				{
					"include": "#a"
				}
			]
		},
		"a": {
			"name": "a",
			"match": "a"
		}
	},
	"scopeName": "superjs.codeblock"
}

The grammar is currently marked invalid since the begin rule in superjs-code-block is considered non consuming

onig_scanner.node is not a valid Win32 application

If I clone this repo which exposes vscode-textmate as a simple REPL for testing scopes and run tools/tokenize.js, everything works fine.

But if I try to reference this package in a vscode extension, when I call grammar.tokenizeLine I get an error: Error: %1 is not a valid Win32 application.\r\n\\?\c:\Users\path\to\extension\node_modules\oniguruma\build\Release\onig_scanner.node

Any idea why this is?

Format strings not being handled in grammar

Given the grammar:

https://github.com/textmate/markdown.tmbundle/blob/master/Syntaxes/Markdown.tmLanguage it seems that vscode can't properly handle the construct https://github.com/textmate/markdown.tmbundle/blob/master/Syntaxes/Markdown.tmLanguage#L105

i.e.: when parsing a markdown with '##' with this construct (markup.heading.${1/(#)(#)?(#)?(#)?(#)?(#)?/${6:?6:${5:?5:${4:?4:${3:?3:${2:?2:1}}}}}/}.markdown), it'd be expected that the result is markup.heading.2.markdown, whereas vscode is just giving markup.heading.${1/(#)(#)?(#)?(#)?(#)?(#)?/${6:?6:${5:?5:${4:?4:${3:?3:${2:?2:1}}}}}/}.markdown as the result.

grammar parser has problems

From @jens1o on June 22, 2017 15:24

  • VSCode Version: Code - Insiders 1.14.0-insider (a49a42680a4269b79c4e80f6d754bbded03a0593, 2017-06-21T05:15:42.843Z)
  • OS Version: Windows_NT ia32 10.0.15063
  • Extensions:
Extension Author (truncated) Version
path-intellisense chr 1.4.2
gitlens eam 4.1.3
tslint eg2 0.15.0
LogFileHighlighter emi 1.1.1
vscode-reveal evi 0.0.9
php-debug fel 1.10.0
php-intellisense fel 1.4.1
auto-close-tag for 0.4.2
gc-excelviewer Gra 1.1.15
GitHubIssues Hoo 0.1.2
composer ika 0.5.0
smarty imp 0.2.0
json-to-ts Mar 1.4.3
vscode-apache mrm 1.1.1
cpptools ms- 0.11.4
php-docblocker nei 1.2.0
vscode-versionlens pfl 0.19.1
vscode-icons rob 7.9.0
sharecode Rol 0.4.1
code-spell-checker str 1.2.0
vscode-todo-highlight way 0.5.5
highlight-trailing-white-spaces yba 0.0.2

(1 theme extensions excluded)


see atom/language-php#221

It works in Atom, but not in vscode. :/

Copied from original issue: microsoft/vscode#29271

Problems in syntax highlighting after backticks in Javascript

In this JS code:

//
Relay.injectNetworkLayer(
  new Relay.DefaultNetworkLayer(`${window.location.origin}/graphql`, {
    credentials: 'same-origin',
  }),
);

function loadStories() {
  const context = require.context('../src/', true, /__stories__\/.+\.js$/);
  context.keys().forEach(context);
}

The loadStories function has barely any highlighting, and even comments are incorrectly highlighted after a string interpolation:

image

Handle empty capture rules

  1. create an extension from https://raw.githubusercontent.com/textmate/markdown.tmbundle/master/Syntaxes/Markdown.tmLanguage
  2. Run the extension
  3. create a README.md file with below contents
  4. open it

Contents:

# README
## This is the README for your extension "test-ts"
You can author your README using Visual Studio Code.  Here are some useful editor keyboard shortcuts:

* Split the editor (`Cmd+\` on OSX or `Ctrl+\` on Windows and Linux)
* Toggle preview (`Shift+CMD+V` on OSX or `Shift+Ctrl+V` on Windows and Linux)
* Press `Ctrl+Space` (Windows, Linux) or `Cmd+Space` (OSX) to see a list of Markdown snippets

### For more information
* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown)
* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/)

**Enjoy!**

//Users/bpasero/Development/Microsoft/monaco/out/vs/workbench/electron-browser/shell.js:240 Cannot read property 'split' of null: TypeError: Cannot read property 'split' of null
at DecodeMap.getTokenIds (file:////Users/bpasero/Development/Microsoft/monaco/out/vs/editor/node/textMate/TMSyntax.js:127:34)
at decodeTextMateToken

VSCode's tmLanguage support cannot match zero-width `begin` and `end` correctly.

The syntax is:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>fileTypes</key>
    <array>
        <string>testlang</string>
    </array>
    <key>name</key>
    <string>testlang</string>
    <key>patterns</key>
    <array>
        <dict>
            <key>include</key>
            <string>#indentedVerbatimOp</string>
        </dict>
    </array>
    <key>repository</key>
    <dict>
        <key>indentedVerbatimOp</key>
        <dict>
            <key>begin</key>
            <string>^([ \t]*)(?=(.*?)\|$)</string>
            <key>end</key>
            <string>^(?!\1[ \t])(?=[ \t]*\S)</string>
            <key>name</key>
            <string>string.unquoted.verbatim.youki</string>
        </dict>
    </dict>
    <key>scopeName</key>
    <string>text.testlang</string>
    <key>uuid</key>
    <string>159375af-d9b4-448c-a9da-d235eadf3556</string>
</dict>
</plist>

It matches indented block with a leading line ending with a bar (|). I've found that Code cannot match the block's ending, which is zero-width:
image

Sublime can match it perfectly:
image

If I add some character to the end tag then Code works again:

            <key>end</key>
            <string>^(?!\1[ \t])(?=[ \t]*\S)xx</string>

image

Native dependencies cause module version mismatch

I'm trying to use vscode-textmate in a language server I'm writing but I'm having troubles with native dependencies.

Error: Module version mismatch. Expected 50, got 51.
    at Error (native)
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:178:20)
    at Object.Module._extensions..node (module.js:583:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:178:20)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> ([...]/node_modules/oniguruma/lib/oniguruma.js:4:17)

I'm running Visual Studio code on a Mac (Version 1.11.2) and the version of the library I'm using is: "vscode-textmate": "^3.1.4"

This vscode discussion suggests that using native dependencies isn't going to work nicely in general. How does affect this project? Is there any plan or known workaround?

Grammar Injection doesn't not work on multi-line content

From @zh4ui on October 29, 2017 13:8

I tried to inject TOML grammar into markdown, however the TOML colorizer only works on the first line (i.e. a = "b" in the image), it doesn't work on the following line (i.e. d = "c" in the image)

begin-toml-end

My tmLanguage.json for the injection is like:

{
	"fileTypes": [],
	"injectionSelector": "text.html.markdown",
	"name": "tomlfrontmatter",
	"patterns": [
		{
			"begin": "\\Abegin\\s*",
			"end": "(^|\\G)end\\s*$",
				
				"patterns": [
					{
						"include": "source.toml"
					}
				]
		}
	],
	"scopeName": "toml.frontmatter.markdown"
}

The complete source code is at: https://github.com/zh4ui/vscode-markdowntoml.git

  • VSCode Version: Version 1.17.2 (1.17.2)
  • OS Version: macOS 10.13 (17A405)

Steps to Reproduce:

  1. install the Better TOML for TOML colorizer
  2. git clone https://github.com/zh4ui/vscode-markdowntoml.git
  3. cd vscode-markdowntoml && code .
  4. F5 to debug the code
  5. Create a markdown file in the [Extension Development Host]
  6. type in the content
begin a = "b"
c = "d"
end

Reproduces without extensions: No

Copied from original issue: microsoft/vscode#37098

Support or begin/while rules

The markdown and make grammars use begin/while rules rather than begin/end loops. Currently, there is no support for begin/while.

TextMate scope selectors: scope exclusion is not implemented

From @monk-time on September 4, 2017 14:51

  • VSCode Version: Code 1.15.1 (41abd21afdf7424c89319ee7cb0445cc6f376959, 2017-08-16T18:07:25.676Z)
  • OS Version: Windows_NT x64 6.1.7601
  • Extensions:
Extension Author (truncated) Version
intellij-idea-keybindings k-- 0.2.13
selectline-statusbar tom 0.0.2

Also the same result with today's VS Code Insiders build.


According to the documentation for TextMate scope selectors, VSCode supports the syntax for excluding matching scopes:

entity.name.method - source.java matches all scopes that start with entity.name.method but not if a parent scope matches source.java

This functionality is used in at least one built-in theme that I could find:
https://github.com/Microsoft/vscode/blob/c00bdb74ee665cccfc5c4e41520893bb19ef61e5/extensions/theme-monokai/themes/monokai-color-theme.json#L316

But it seems that this syntax makes the selector with - in it invalid, and VSCode doesn't apply the given rule to anything at all.

Steps to Reproduce:

  1. Put this rule for syntax highlighting in the settings. Confirm that comments turn yellow at least in some files.
{
    "editor.tokenColorCustomizations": {
        "textMateRules": [
            {
                "scope": "comment",
                "settings": {
                    "foreground": "#FFFF00"
                }
            }
        ]
    }
}
  1. Change the line with the scope selector to:
    "scope": "comment - source.js",
    Expected result: comments that changed their color after step 1 remain yellow in all files except in .js.
    Actual result: all comments reset to a color defined by the current theme.

Reproduces without extensions: Yes

Copied from original issue: microsoft/vscode#33802

Html script closing-tag not detected when occurs immediately after 2 slashes

Hi, I found a bug, with the html grammar in VS Code, when you place a closing script-tag in the same line immediately after 2 fwd slashes, as:
<script> //</script>
the grammar will not detect the closing tag, and will display it with wrong color, see images.

(I'm not sure if the issue is related only to vscode-textmate, or it belongs to textmate/html.tmbundle).

VS Code:
sample

Visual Studio 2015:
capture


  • VSCode Version: Code 1.13.1 (379d2efb5539b09112c793d3d9a413017d736f89, 2017-06-14T18:21:47.485Z)
  • OS Version: Windows_NT ia32 10.0.15063

Steps to Reproduce:

  1. Open any html document with VSCode.
  2. Insert a script element in the document, and place the script's closing-tag immediately after 2 fwd slashes.

injection scope selector of type meta.object-literal not working

I was trying to update and see if natewallace/language-vscode-javascript-angular2 extension works with the new typescript grammar by changing template.ng.json to use meta.object-literal instead of meta.block injection scope selector. The extension doesn't work because I think it treats the dash as minus operator. I modified the grammar and the injection rule from meta.object-literal to meta.objectliteral and the extension works as expected.

Note this is the typescript code I tried:

import {Component, HostListener, Directive} from 'angular2/core';

@Directive({selector: 'button[counting]'})
class CountClicks {
  numberOfClicks = 0;
  @HostListener('click', ['$event.target']) onClick(btn) {
    console.log("button", btn, "number of clicks:", this.numberOfClicks++);
  }
}
@Component({
  selector: 'my-app',
  template: `<button counting>Increment</button>`,
  directives: [CountClicks]
})
export class AppComponent {
  constructor() { console.clear(); }
}

With the extension working the line should have colors from the scope of tags

template: `<button counting>Increment</button>` 

How to use package inside VS Code

npm install vscode-textmate seems to require dev tools to compile native C code.
Since VSC already have correct grammar and installed package precompiled for the current platform - is there a way to load it along with the preinstalled language grammar?

Line ends in grammar files

I'm trying to adopt vscode-textmate for https://github.com/PowerShell/EditorSyntax testing.
From my very early test harness prototype, I found few issues with vscode-textmate.

If I'm trying to use a grammar file with "\n" line-endings on Windows (where usually it's "\r\n"), then reading a grammar file fails with this error

F:\dev\EditorSyntax\node-test\node_modules\vscode-textmate\release\main.js:1573
        var injections = this._locator.getInjections(rawGrammar.scopeName);
                                                               ^

TypeError: Cannot read property 'scopeName' of null
    at Registry.loadGrammarFromPathSync (F:\dev\EditorSyntax\node-test\node_modules\vscode-textmate\release\main.js:1573:64)
    at tokenizeCodeSnippet (F:\dev\EditorSyntax\node-test\index.js:33:31)
    at Main (F:\dev\EditorSyntax\node-test\index.js:53:13)
    at Object.<anonymous> (F:\dev\EditorSyntax\node-test\index.js:58:1)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)

Then, if I replace line-ends, everything works fine.

Tokenizer fails when line is empty / newlines

I don't know if i'm doing it correctly, but i'm actually doing:

let ruleStack
const tokens = snippet.split('\n').reduce((tokenList, line) => {
   const r = grammar.tokenizeLine(line, ruleStack)
   ruleStack = r.ruleStack

So basically i split the piece of code by new line characters and tokenize line by line. The problem is that some lines contain just new line characters, for example an empty line that separate 2 lines of code like this:

var foo
// <--- this line contains just \n
var bar

But since i'm splitting the new line characters to parse line by line, that line contains nothing now.

But the tokenizer still generates this:

{ tokens: [ { startIndex: 0, endIndex: 1, scopes: [Object] } ],
  ruleStack: 
   [ StackElement {
       ruleId: 1,
       enterPos: -1,
       endRule: null,
       scopeName: 'source.js',
       contentName: null,
       whileRule: null } ] }

startIndex 0 is ok, but why endIndex is 1 and not 0? Looks like there is a character but there is none.

If you add line.charCodeAt(0) you get NaN because there is nothing there. the same with line.slice(0, 1)

Elixir.tmLanguage works in Sublime but fails in VSCode

From @net on March 12, 2017 13:4

When using the official Elixir.tmLanguage file found here, lines that begin with a whitespace character or an arbitrary unhighlighted token (e.g. foo) are not highlighted (see screenshot below).

screen shot 2017-03-12 at 8 57 24 am

The Elixir.tmLanguage file does—of course—work perfectly fine in TextMate and Sublime.

https://github.com/elixir-lang/elixir-tmbundle/blob/master/Syntaxes/Elixir.tmLanguage

  • VSCode Version: 1.10.2
  • OS Version: macOS 10.12.3 (Sierra)

Copied from original issue: microsoft/vscode#22477

HTML injection rule not correctly handled

The html grammar has the following 'R' injection rule which is not handled in vscode textmate

	"injections": {
		"R:text.html - (comment.block, text.html source)": {
			"comment": "Use R: to ensure this matches after any other injections.",
			"patterns": [
				{
					"match": "<",
					"name": "invalid.illegal.bad-angle-bracket.html"
				}
			]
		}
	},

2 issues

  • comma in expressions not expected (it was assumed that it can only be top level)
  • R: not handled

Support nested repositories

https://raw.githubusercontent.com/textmate/markdown.tmbundle/master/Syntaxes/Markdown.tmLanguage uses includes that refer to nested repositories:

<key>patterns</key>
    <array>
        <dict>
            <key>include</key>
            <string>#block</string>
        </dict>
    </array>
    <key>repository</key>
    <dict>
        <key>block</key>
        <dict>
            <key>patterns</key>
            <array>
                ….
                <dict>
                    <key>include</key>
                    <string>#blockquote </string>
                </dict>
                ….
            </array>
            <key>repository</key>
            <dict>
                <key>blockquote</key>
                <dict>
                …

The problem is likely on line 667

          return new IncludeOnlyRule(… , desc.repository || repository)); 

or maybe merging the two repositories?

Fix While Behavior to Match TextMate

Following up on #24, I still don't think we handle while rules correctly.

Here's a toy TextMate grammar I've been using to test this:

{   patterns = (
        {   include = '#alist'; },
        {   include = '#blist'; },
    );
    repository = {
        alist = {
            name = 'alist';
            begin = 'A';
            while = 'a';
            patterns = (
                {   include = '#alist'; },
                {   include = '#blist'; },
                {   include = '#letter'; },
            );
        };
        letter = {
            name = 'constant.language.json';
            match = 'x';
        };
        blist = {
            name = 'blist';
            begin = 'B';
            while = 'b';
            patterns = (
                {   include = '#alist'; },
                {   include = '#blist'; },
                {   include = '#number'; },
            );
        };
        number = {
            name = 'constant.numeric.json';
            match = '\d';
        };
    };
}

After using this grammar in TextMate, I believe the behavior of while is actually:

  1. On a new line, check all while conditions from bottom of the stack to the top.
  2. If any of them fails, then pop everything after that while rule off the stack, along with the failed rule.

while is not documented anywhere as far as I could find. This behavior also differs from other productions, but all this does make some sense for the markdown grammar at least.

Here's a few samples that show these behaviors:

A 1x
a B 1x
ab 1x
b 1x
a 1x

A 1x
a B 1x
ab 1x
a 1x
b 1x

A 1x
a B 1x
ba 1x
a 1x
b 1x

A 1x
a B 1x
bab 1x
a 1x
b 1x

screen shot 2016-09-22 at 7 36 10 pm

Comparing the second and third examples, the only difference is the swap of ab to ba on the third line. In the ba case, we see that the alist while must be run first because it matches the a in the string. blist while is then checked, but there is no b after the a so it fails.

A few other points to consider:

  • while checks can consume text. This is required for properly parsing indented lists in markdown.
  • while checks run from the beginning of the line, or from wherever the last while check consumed up to.
  • But while does not have to match starting at beginning of the line. It can match anywhere in the line. This is shown in the third example with bab 1x The outermost alist starts matching from the second character.

I'm putting together some test cases for this behavior and will try getting together a PR sometime next week.

Recommend Projects

  • React photo React

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

  • Vue.js photo Vue.js

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

  • Typescript photo Typescript

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

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

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

Recommend Topics

  • javascript

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

  • web

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

  • server

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

  • Machine learning

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

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

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

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.