Grammar class final
A language grammar: an ordered list of Rules plus a named repository of reusable rule lists.
Grammars are immutable and usually const, so an unused grammar costs
nothing and is tree-shaken away. A grammar is compiled lazily the first
time it is used and the compiled form is cached for its lifetime.
When several rules can match, the one that starts earliest wins. Among rules starting at the same position, the one listed first wins.
Constructors
-
Grammar({required String name, required List<
Rule> rules, List<String> aliases = const [], List<String> fileExtensions = const [], List<String> fileNames = const [], Map<String, List< repository = const {}, bool caseInsensitive = false, bool unicode = false, List<Rule> >String> shebangs = const [], List<String> signatures = const [], String? restartLine, bool detectable = true}) -
Creates a grammar.
const
Properties
-
aliases
→ List<
String> -
Other names this language is known by, such as
jsforjavascript.final - caseInsensitive → bool
-
Whether patterns and keywords ignore case.
final
- detectable → bool
-
Whether
LanguageDetectormay pick this grammar. Off for catch-all grammars such as plain text and the generic fallback.final -
fileExtensions
→ List<
String> -
File extensions without the dot, such as
dartorjson.final -
fileNames
→ List<
String> -
Whole file names, such as
DockerfileorCMakeLists.txt. These take priority over fileExtensions.final - hashCode → int
-
The hash code for this object.
no setterinherited
- name → String
-
Canonical, lower-case language name, such as
dart.final -
repository
→ Map<
String, List< Rule> > -
Named rule lists that IncludeRule can reference.
final
- restartLine → String?
-
Lines that no rule looks past, such as blank lines in Markdown.
final
-
rules
→ List<
Rule> -
Rules active at the top level of a document.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
shebangs
→ List<
String> -
Interpreter names that identify this language in a
#!first line, such aspythonorbash. Used by language detection.final -
signatures
→ List<
String> -
Patterns that strongly suggest this language, such as
^import 'package:. Used by language detection.final - unicode → bool
-
Whether patterns are compiled in unicode mode.
final
Methods
-
extend(
{String? name, List< Rule> rules = const [], Map<String, List< repository = const {}, List<Rule> >String> ? aliases, List<String> ? fileExtensions, List<String> ? fileNames}) → Grammar - Returns a new grammar based on this one.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
-
validate(
) → void - Compiles every part of the grammar now, so mistakes surface at once instead of the first time a region is used.
-
withKeywords(
{Map< String, List< add = const {}, Iterable<String> >String> remove = const []}) → Grammar - Returns this grammar with its keyword tables changed.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited