# Custom Language Support

**URL:** <https://discuss.codemirror.net/t/custom-language-support/7144>\
**Category:** Uncategorized\
**Created:** [September 26, 2023, 9:49pm UTC](https://discuss.codemirror.net/t/custom-language-support/7144 "2023-09-26T21:49:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TrackerJo](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/trackerjo/32/3764_2.png) [@TrackerJo](https://discuss.codemirror.net/u/TrackerJo)\
**Post date:** [September 26, 2023, 9:49pm UTC](https://discuss.codemirror.net/t/custom-language-support/7144/1 "2023-09-26T21:49:58Z")

</div>

So I’m currently in the process of making my own IDE for my own language that I made, it’s kind of a mix of Java and JavaScript, and I was wondering if it’s possible to add support for a custom language using code mirror?

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [September 27, 2023, 8:30am UTC](https://discuss.codemirror.net/t/custom-language-support/7144/2 "2023-09-27T08:30:48Z")

</div>

Yes, language modes can be implemented in 3rd-party code. See for example [here](https://codemirror.net/examples/lang-package/).

---

<div class="post-metadata">

**Author:** ![TrackerJo](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/trackerjo/32/3764_2.png) [@TrackerJo](https://discuss.codemirror.net/u/TrackerJo)\
**Post date:** [September 28, 2023, 12:20am UTC](https://discuss.codemirror.net/t/custom-language-support/7144/3 "2023-09-28T00:20:04Z")

</div>

Thanks for the quick reply!

---

<div class="post-metadata">

**Author:** ![TrackerJo](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/trackerjo/32/3764_2.png) [@TrackerJo](https://discuss.codemirror.net/u/TrackerJo)\
**Post date:** [September 30, 2023, 1:57am UTC](https://discuss.codemirror.net/t/custom-language-support/7144/4 "2023-09-30T01:57:57Z")

</div>

How would I have the parser be able to tell the difference between FunctionName and VarName?  
Heres what I have for them

```auto
@tokens {
  VarName { StringLiteral }
  FunctionName { StringLiteral }
}

FunctionDeclaration{
  FunctionKW space FunctionName OpenParenthesis (DataType space VarName ("," DataType space VarName)*)? ClosedParenthesis Block
}

FunctionCall{
  FunctionName OpenParenthesis (expression ("," expression)*)? ClosedParenthesis
}
expression { Number | String | BinaryExpression | ParenthesizedExpression | Declaration | ListElement | ListSubscript | ConditionalExpression | VarName !var}

Declaration {
  LetKW space DataType space VarName space Equal space expression
}

```

I included some of the uses for VarName and the only two uses for FunctionName. I’m assuming you’d tell the parser any StringLiteral followed by an OpenParenthesis is a FunctionName, but I can’t figure out how exactly to do that.

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [September 30, 2023, 11:27am UTC](https://discuss.codemirror.net/t/custom-language-support/7144/5 "2023-09-30T11:27:22Z")

</div>

If you just want the styling to be different, the best way would be to make sure the argument list is its own node (so that the arguments aren’t direct children of `FunctionCall`) and to assign a different style tag (say `tags.function(tags.variableName)`) to `FunctionCall/VarName` in `styleTags`.

If you want these to be different in the syntax tree, you’ll need an external tokenizer that tokenizer `VarName`/`FunctionName`, first scanning through the identifier and then looking ahead to check for a `(` char in order to determine which token to emit. (But this might get messy if you, somewhere in your syntax, end up allowing `VarName` to occur in front of a left paren in some other rule).
